From: black Date: Sat, 1 Jan 2005 19:00:33 +0000 (+0000) Subject: -Added 2 builtins to make the hostcache stuff easier extensible. X-Git-Tag: xonotic-v0.1.0preview~5249 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=8a092a84b4409b8e2fa4fd5a03e88c2c2ea7d255;ds=sidebyside -Added 2 builtins to make the hostcache stuff easier extensible. More to follow soon. -Cmd now has a shutdown function so it doesnt leak anything (hopefully). git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4893 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cmd.c b/cmd.c index fe455296..f8c3f1fc 100644 --- a/cmd.c +++ b/cmd.c @@ -459,6 +459,16 @@ void Cmd_Init (void) Cmd_AddCommand ("seta", Cvar_SetA_f); } +/* +============ +Cmd_Shutdown +============ +*/ +void Cmd_Shutdown(void) +{ + Mem_FreePool(&cmd_mempool); +} + /* ============ Cmd_Argc diff --git a/cmd.h b/cmd.h index 35ce36f2..c05f7062 100644 --- a/cmd.h +++ b/cmd.h @@ -80,6 +80,7 @@ typedef enum extern cmd_source_t cmd_source; void Cmd_Init (void); +void Cmd_Shutdown (void); void Cmd_AddCommand (const char *cmd_name, xcommand_t function); // called by the init functions of other parts of the program to diff --git a/host.c b/host.c index 0b73b653..a1a9d129 100644 --- a/host.c +++ b/host.c @@ -1022,6 +1022,7 @@ void Host_Shutdown(void) VID_Shutdown(); } + Cmd_Shutdown(); Sys_Shutdown(); Log_Close (); } diff --git a/prvm_cmds.c b/prvm_cmds.c index ba52d121..4bf7209b 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -166,6 +166,8 @@ float stringtokeynum(string key) sethostcachesort(float field, float descending) refreshhostcache() float gethostcachenumber(float fld, float hostnr) +float gethostcacheindexforkey(string key) + addwantedhostcachekey(string key) */ #include "quakedef.h" @@ -3806,9 +3808,59 @@ refreshhostcache() */ 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) @@ -3959,7 +4011,9 @@ prvm_builtin_t vm_m_builtins[] = { 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);