]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
New console commands sv_cmd, menu_cmd, cl_cmd, that call GameCommand(string s) in...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 15 Apr 2007 20:01:38 +0000 (20:01 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 15 Apr 2007 20:01:38 +0000 (20:01 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7097 d7cf8633-e32d-0410-b094-e92efae38249

mvm_cmds.c
progsvm.h
prvm_edict.c
svvm_cmds.c

index a18d71f578a5cbae8ea981f57cb42574729e6d1b..1a9a84f3837ebfe1abdc3b3b603b3dc434ec8258 100644 (file)
@@ -11,7 +11,9 @@ char *vm_m_extensions =
 "DP_QC_STRFTIME "
 "DP_QC_STRINGCOLORFUNCTIONS "
 "DP_QC_TOKENIZEBYSEPARATOR "
-"DP_QC_UNLIMITEDTEMPSTRINGS";
+"DP_QC_UNLIMITEDTEMPSTRINGS "
+"DP_QC_CMD "
+;
 
 /*
 =========
index 87806d74a24c799f4c698ea5519cda5a9d9d3167..d8eb4953a5d2d6eee5e89fc8ed64fc3a534a5ae7 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -256,6 +256,7 @@ typedef struct prvm_prog_funcoffsets_s
        func_t SV_ChangeTeam; // ssqc
        func_t SV_ParseClientCommand; // ssqc
        func_t SV_PlayerPhysics; // ssqc
+       func_t GameCommand; // any
 
        // menu qc only uses some functions, nothing else
        func_t m_display; // mqc
index 8a97b42574dd96e5e3eab2aab6c967693201cb4d..c7429950bb307724799c9dc4fdbea12b1152212b 100644 (file)
@@ -38,6 +38,8 @@ cvar_t prvm_traceqc = {0, "prvm_traceqc", "0", "prints every QuakeC statement as
 // LordHavoc: counts usage of each QuakeC statement
 cvar_t prvm_statementprofiling = {0, "prvm_statementprofiling", "0", "counts how many times each QuakeC statement has been executed, these counts are displayed in prvm_printfunction output (if enabled)"};
 
+extern sizebuf_t vm_tempstringsbuf;
+
 //============================================================================
 // mempool handling
 
@@ -985,6 +987,71 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s)
        return true;
 }
 
+/*
+=============
+PRVM_GameCommand_f
+
+Console command to send a string to QC function GameCommand of the
+indicated progs
+
+Usage:
+  sv_cmd adminmsg 3 "do not teamkill"
+  cl_cmd someclientcommand
+  menu_cmd somemenucommand
+
+All progs can support this extension; sg calls it in server QC, cg in client
+QC, mg in menu QC.
+=============
+*/
+void PRVM_GameCommand(const char *whichprogs, const char *whichcmd)
+{
+       if(Cmd_Argc() < 1)
+       {
+               Con_Printf("%s text...\n", whichcmd);
+               return;
+       }
+
+       PRVM_Begin;
+       if(!PRVM_SetProgFromString(whichprogs))
+       // note: this is not PRVM_SetProg because that one aborts "hard" using PRVM_Error
+       // also, it makes printing error messages easier!
+       {
+               Con_Printf("%s program not loaded.\n", whichprogs);
+               return;
+       }
+
+       if(!prog->funcoffsets.GameCommand)
+       {
+               Con_Printf("%s program do not support GameCommand!\n", whichprogs);
+       }
+       else
+       {
+               int restorevm_tempstringsbuf_cursize;
+               const char *s;
+
+               s = Cmd_Args();
+
+               restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
+               PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(s ? s : "");
+               PRVM_ExecuteProgram (prog->funcoffsets.GameCommand, "QC function GameCommand is missing");
+               vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
+       }
+
+       PRVM_End;
+}
+void PRVM_GameCommand_Server_f(void)
+{
+       PRVM_GameCommand("server", "sv_cmd");
+}
+void PRVM_GameCommand_Client_f(void)
+{
+       PRVM_GameCommand("client", "cl_cmd");
+}
+void PRVM_GameCommand_Menu_f(void)
+{
+       PRVM_GameCommand("menu", "menu_cmd");
+}
+
 /*
 =============
 PRVM_ED_EdictSet_f
@@ -1331,6 +1398,7 @@ void PRVM_FindOffsets(void)
        prog->funcoffsets.SV_ChangeTeam                   = PRVM_ED_FindFunctionOffset("SV_ChangeTeam");
        prog->funcoffsets.SV_ParseClientCommand           = PRVM_ED_FindFunctionOffset("SV_ParseClientCommand");
        prog->funcoffsets.SV_PlayerPhysics                = PRVM_ED_FindFunctionOffset("SV_PlayerPhysics");
+       prog->funcoffsets.GameCommand                     = PRVM_ED_FindFunctionOffset("GameCommand");
        prog->globaloffsets.SV_InitCmd                    = PRVM_ED_FindGlobalOffset("SV_InitCmd");
        prog->globaloffsets.self                          = PRVM_ED_FindGlobalOffset("self");
        prog->globaloffsets.time                          = PRVM_ED_FindGlobalOffset("time");
@@ -1910,6 +1978,9 @@ void PRVM_Init (void)
        Cmd_AddCommand ("prvm_globalset", PRVM_GlobalSet_f, "sets value of a specified global variable in the selected VM (server, client, menu)");
        Cmd_AddCommand ("prvm_edictset", PRVM_ED_EdictSet_f, "changes value of a specified property of a specified entity in the selected VM (server, client, menu)");
        Cmd_AddCommand ("prvm_printfunction", PRVM_PrintFunction_f, "prints a disassembly (QuakeC instructions) of the specified function in the selected VM (server, client, menu)");
+       Cmd_AddCommand ("cl_cmd", PRVM_GameCommand_Client_f, "calls the client QC function GameCommand with the supplied string as argument");
+       Cmd_AddCommand ("menu_cmd", PRVM_GameCommand_Menu_f, "calls the menu QC function GameCommand with the supplied string as argument");
+       Cmd_AddCommand ("sv_cmd", PRVM_GameCommand_Server_f, "calls the server QC function GameCommand with the supplied string as argument");
        // LordHavoc: optional runtime bounds checking (speed drain, but worth it for security, on by default - breaks most QCCX features (used by CRMod and others))
        Cvar_RegisterVariable (&prvm_boundscheck);
        Cvar_RegisterVariable (&prvm_traceqc);
index bbe14a7734eb2ccea85d487feada55d67ccbfac5..cfe61808d6654f1899b9ba408990a5a9487d7bbb 100644 (file)
@@ -132,6 +132,8 @@ char *vm_sv_extensions =
 "PRYDON_CLIENTCURSOR "
 "TENEBRAE_GFX_DLIGHTS "
 "TW_SV_STEPCONTROL "
+"DP_SV_CMD "
+"DP_QC_CMD "
 ;
 
 /*