-Added 2 builtins to make the hostcache stuff easier extensible.
authorblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 1 Jan 2005 19:00:33 +0000 (19:00 +0000)
committerblack <black@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 1 Jan 2005 19:00:33 +0000 (19:00 +0000)
 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

cmd.c
cmd.h
host.c
prvm_cmds.c

diff --git a/cmd.c b/cmd.c
index fe45529..f8c3f1f 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -461,6 +461,16 @@ void Cmd_Init (void)
 
 /*
 ============
+Cmd_Shutdown
+============
+*/
+void Cmd_Shutdown(void)
+{
+       Mem_FreePool(&cmd_mempool);
+}
+
+/*
+============
 Cmd_Argc
 ============
 */
diff --git a/cmd.h b/cmd.h
index 35ce36f..c05f706 100644 (file)
--- 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 0b73b65..a1a9d12 100644 (file)
--- a/host.c
+++ b/host.c
@@ -1022,6 +1022,7 @@ void Host_Shutdown(void)
                VID_Shutdown();
        }
 
+       Cmd_Shutdown();
        Sys_Shutdown();
        Log_Close ();
 }
index ba52d12..4bf7209 100644 (file)
@@ -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);