float stringtokeynum(string key)
- resethostcachemask()
- sethostcachemaskstring(float fld, string str)
- sethostcachemasknumber(float fld, float num, float op)
+ resethostcachemasks()
+ sethostcachemaskstring(float mask, float fld, string str)
+ sethostcachemasknumber(float mask, float fld, float num, float op)
resorthostcache()
sethostcachesort(float field, float descending)
refreshhostcache()
float gethostcachenumber(float fld, float hostnr)
+float gethostcacheindexforkey(string key)
+ addwantedhostcachekey(string key)
*/
#include "quakedef.h"
for( ; *str; *out++ = *str++ );
// now jump over the old contents
for( ; *in ; in++ )
- if( *in == '\'' || *in == '\\' && !*++in )
+ if( *in == '\'' || (*in == '\\' && !*++in) )
break;
if( !in ) {
/*
========================
-VM_M_resethostcachemask
+VM_M_resethostcachemasks
-resethostcachemask()
+resethostcachemasks()
========================
*/
-void VM_M_resethostcachemask( void )
+void VM_M_resethostcachemasks( void )
{
- HostCache_ResetMask();
+ HostCache_ResetMasks();
}
========================
VM_M_sethostcachemaskstring
-sethostcachemaskstring(float field, string str)
+sethostcachemaskstring(float mask, float fld, string str, float op)
+0-511 and
+512 - 1024 or
========================
*/
void VM_M_sethostcachemaskstring( void )
{
char *str;
+ int masknr;
+ hostcache_mask_t *mask;
+ int field;
- VM_SAFEPARMCOUNT( 2, VM_M_sethostcachemask );
+ VM_SAFEPARMCOUNT( 4, VM_M_sethostcachemaskstring );
str = PRVM_G_STRING( OFS_PARM1 );
if( !str )
- PRVM_ERROR( "VM_M_sethostcachemask: null string passed!" );
+ PRVM_ERROR( "VM_M_sethostcachemaskstring: null string passed!" );
+
+ masknr = PRVM_G_FLOAT( OFS_PARM0 );
+ if( masknr >= 0 && masknr <= HOSTCACHE_ANDMASKCOUNT )
+ mask = &hostcache_andmasks[masknr];
+ else if( masknr >= 512 && masknr - 512 <= HOSTCACHE_ORMASKCOUNT )
+ mask = &hostcache_ormasks[masknr - 512 ];
+ else {
+ Con_Printf( "VM_M_sethostcachemaskstring: invalid mask number %i\n", masknr );
+ return;
+ }
- switch( (int) PRVM_G_FLOAT( OFS_PARM0 ) ) {
+ field = (int) PRVM_G_FLOAT( OFS_PARM1 );
+
+ switch( field ) {
case HCIF_CNAME:
- strncpy( hostcache_currentmask.info.cname, PRVM_G_STRING( OFS_PARM1 ), sizeof(hostcache_currentmask.info.cname) );
+ strncpy( mask->info.cname, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.cname) );
break;
case HCIF_NAME:
- strncpy( hostcache_currentmask.info.name, PRVM_G_STRING( OFS_PARM1 ), sizeof(hostcache_currentmask.info.name) );
+ strncpy( mask->info.name, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.name) );
break;
case HCIF_MAP:
- strncpy( hostcache_currentmask.info.map, PRVM_G_STRING( OFS_PARM1 ), sizeof(hostcache_currentmask.info.map) );
+ strncpy( mask->info.map, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.map) );
break;
case HCIF_MOD:
- strncpy( hostcache_currentmask.info.mod, PRVM_G_STRING( OFS_PARM1 ), sizeof(hostcache_currentmask.info.mod) );
+ strncpy( mask->info.mod, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.mod) );
break;
case HCIF_GAME:
- strncpy( hostcache_currentmask.info.game, PRVM_G_STRING( OFS_PARM1 ), sizeof(hostcache_currentmask.info.game) );
+ strncpy( mask->info.game, PRVM_G_STRING( OFS_PARM2 ), sizeof(mask->info.game) );
break;
default:
- Con_Printf( "VM_M_sethostcachemask: Bad field number %i passed!\n", PRVM_G_INT( OFS_PARM0 ) );
+ Con_Printf( "VM_M_sethostcachemaskstring: Bad field number %i passed!\n", field );
+ return;
}
+
+ mask->active = true;
+ mask->tests[field] = (int) PRVM_G_FLOAT( OFS_PARM3 );
}
/*
========================
VM_M_sethostcachemasknumber
-sethostcachemasknumber(float field, float num, float op)
+sethostcachemasknumber(float mask, float fld, float num, float op)
+
+0-511 and
+512 - 1024 or
========================
*/
void VM_M_sethostcachemasknumber( void )
{
int number;
- hostcache_maskop_t operand;
- VM_SAFEPARMCOUNT( 3, VM_M_sethostcachemasknumber );
+ hostcache_mask_t *mask;
+ int masknr;
+ int field;
+ VM_SAFEPARMCOUNT( 4, VM_M_sethostcachemasknumber );
+
+ masknr = PRVM_G_FLOAT( OFS_PARM0 );
+ if( masknr >= 0 && masknr <= HOSTCACHE_ANDMASKCOUNT )
+ mask = &hostcache_andmasks[masknr];
+ else if( masknr >= 512 && masknr - 512 <= HOSTCACHE_ORMASKCOUNT )
+ mask = &hostcache_ormasks[masknr - 512 ];
+ else {
+ Con_Printf( "VM_M_sethostcachemasknumber: invalid mask number %i\n", masknr );
+ return;
+ }
- number = PRVM_G_FLOAT( OFS_PARM1 );
- operand = (int) PRVM_G_FLOAT( OFS_PARM2 );
+ number = PRVM_G_FLOAT( OFS_PARM2 );
+ field = (int) PRVM_G_FLOAT( OFS_PARM1 );
- switch( (int) PRVM_G_FLOAT( OFS_PARM0 ) ) {
+ switch( field ) {
case HCIF_MAXPLAYERS:
- hostcache_currentmask.info.maxplayers = number;
- hostcache_currentmask.maxplayerstest = operand;
+ mask->info.maxplayers = number;
break;
case HCIF_NUMPLAYERS:
- hostcache_currentmask.info.numplayers = number;
- hostcache_currentmask.numplayerstest = operand;
+ mask->info.numplayers = number;
break;
case HCIF_PING:
- hostcache_currentmask.info.ping = number;
- hostcache_currentmask.pingtest = operand;
+ mask->info.ping = number;
break;
case HCIF_PROTOCOL:
- hostcache_currentmask.info.protocol = number;
- hostcache_currentmask.protocoltest = operand;
+ mask->info.protocol = number;
break;
default:
- Con_Printf( "VM_M_sethostcachemask: Bad field number %i passed!\n", PRVM_G_INT( OFS_PARM0 ) );
+ Con_Printf( "VM_M_sethostcachemasknumber: Bad field number %i passed!\n", field );
+ return;
}
+
+ mask->active = true;
+ mask->tests[field] = (int) PRVM_G_FLOAT( OFS_PARM3 );
}
*/
void VM_M_refreshhostcache( void )
{
+ VM_SAFEPARMCOUNT( 0, VM_M_refreshhostcache );
HostCache_QueryList();
}
+/*
+========================
+VM_M_gethostcacheindexforkey
+
+float gethostcacheindexforkey(string key)
+========================
+*/
+void VM_M_gethostcacheindexforkey( void )
+{
+ char *key;
+ VM_SAFEPARMCOUNT( 1, VM_M_gethostcacheindexforkey );
+
+ key = PRVM_G_STRING( OFS_PARM0 );
+ VM_CheckEmptyString( key );
+
+ if( !strcmp( key, "cname" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_CNAME;
+ else if( !strcmp( key, "ping" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_PING;
+ else if( !strcmp( key, "game" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_GAME;
+ else if( !strcmp( key, "mod" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_MOD;
+ else if( !strcmp( key, "map" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_MAP;
+ else if( !strcmp( key, "name" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_NAME;
+ else if( !strcmp( key, "maxplayers" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_MAXPLAYERS;
+ else if( !strcmp( key, "numplayers" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_NUMPLAYERS;
+ else if( !strcmp( key, "protocol" ) )
+ PRVM_G_FLOAT( OFS_RETURN ) = HCIF_PROTOCOL;
+ else
+ PRVM_G_FLOAT( OFS_RETURN ) = -1;
+}
+
+/*
+========================
+VM_M_addwantedhostcachekey
+
+addwantedhostcachekey(string key)
+========================
+*/
+void VM_M_addwantedhostcachekey( void )
+{
+ VM_SAFEPARMCOUNT( 1, VM_M_addwantedhostcachekey );
+}
+
prvm_builtin_t vm_m_builtins[] = {
0, // to be consistent with the old vm
// common builtings (mostly)
VM_M_gethostcachestring,
VM_M_parseentitydata,
VM_M_stringtokeynum,
- VM_M_resethostcachemask,
+ VM_M_resethostcachemasks,
VM_M_sethostcachemaskstring,
VM_M_sethostcachemasknumber,
VM_M_resorthostcache,
VM_M_sethostcachesort,
VM_M_refreshhostcache,
- VM_M_gethostcachenumber // 621
+ VM_M_gethostcachenumber,
+ VM_M_gethostcacheindexforkey,
+ VM_M_addwantedhostcachekey // 623
};
const int vm_m_numbuiltins = sizeof(vm_m_builtins) / sizeof(prvm_builtin_t);