]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
prvm: Deduplicate console command handler
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 20 Apr 2021 13:24:10 +0000 (13:24 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 20 Apr 2021 13:24:10 +0000 (13:24 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13127 d7cf8633-e32d-0410-b094-e92efae38249

csprogs.c
prvm_cmds.c
prvm_cmds.h
svvm_cmds.c

index 80666f5edaaf06eb652cdd2a01021694a92d0316..3c90ff138281745fadcf5159c756eb3c42b967ee 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -512,23 +512,7 @@ qbool CL_VM_UpdateView (double frametime)
 qbool CL_VM_ConsoleCommand (const char *text)
 {
        prvm_prog_t *prog = CLVM_prog;
-       int restorevm_tempstringsbuf_cursize;
-       qbool r = false;
-       if(!cl.csqc_loaded)
-               return false;
-       CSQC_BEGIN
-       if (PRVM_clientfunction(CSQC_ConsoleCommand))
-       {
-               PRVM_clientglobalfloat(time) = cl.time;
-               PRVM_clientglobaledict(self) = cl.csqc_server2csqcentitynumber[cl.playerentity];
-               restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
-               PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, text);
-               prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_ConsoleCommand), "QC function CSQC_ConsoleCommand is missing");
-               prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
-               r = CSQC_RETURNVAL != 0;
-       }
-       CSQC_END
-       return r;
+       return PRVM_ConsoleCommand(prog, text, &prog->funcoffsets.CSQC_ConsoleCommand, false, cl.csqc_server2csqcentitynumber[cl.playerentity], cl.time, cl.csqc_loaded, "QC function CSQC_ConsoleCommand is missing");
 }
 
 qbool CL_VM_Parse_TempEntity (void)
index 67ccb3f31151dfc810137fcd1c4f71253da8d83d..1711d33c256b647d818cc16a89516bb78ea5d305 100644 (file)
@@ -58,6 +58,34 @@ void VM_CheckEmptyString(prvm_prog_t *prog, const char *s)
                prog->error_cmd("%s: Bad string", prog->name);
 }
 
+qbool PRVM_ConsoleCommand (prvm_prog_t *prog, const char *text, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message)
+{
+       int restorevm_tempstringsbuf_cursize;
+       int save_self;
+       qbool r = false;
+
+       if(!prog_loaded)
+               return false;
+
+       if(func)
+       {
+               if(preserve_self)
+                       save_self = PRVM_gameglobaledict(self);
+               if(ptime)
+                       PRVM_gameglobalfloat(time) = ptime;
+               PRVM_gameglobaledict(self) = curself;
+               restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
+               PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, text);
+               prog->ExecuteProgram(prog, *func, error_message);
+               prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
+               if(preserve_self)
+                       PRVM_gameglobaledict(self) = save_self;
+               r = (int) PRVM_G_FLOAT(OFS_RETURN) != 0;
+       }
+
+       return r;
+}
+
 void VM_GenerateFrameGroupBlend(prvm_prog_t *prog, framegroupblend_t *framegroupblend, const prvm_edict_t *ed)
 {
        // self.frame is the interpolation target (new frame)
index c3f182c2bb5c870cfc7395c61ac807d13d174e05..c3c83b2faf588987d7c732715f6360c6da5223d8 100644 (file)
@@ -217,6 +217,7 @@ float       getserverlistindexforkey(string key)
 // general functions
 void VM_CheckEmptyString (prvm_prog_t *prog, const char *s);
 void VM_VarString(prvm_prog_t *prog, int first, char *out, int outlength);
+qbool PRVM_ConsoleCommand (prvm_prog_t *prog, const char *text, int *func, qbool preserve_self, int curself, double ptime, qbool prog_loaded, const char *error_message);
 prvm_stringbuffer_t *BufStr_FindCreateReplace (prvm_prog_t *prog, int bufindex, int flags, const char *format);
 void BufStr_Set(prvm_prog_t *prog, prvm_stringbuffer_t *stringbuffer, int strindex, const char *str);
 void BufStr_Del(prvm_prog_t *prog, prvm_stringbuffer_t *stringbuffer);
index bece8d54fe82d5e841fc551e556e0cf51bfca211..8de1d444699c454e342d251f2af945325262699f 100644 (file)
@@ -2853,26 +2853,7 @@ static void VM_SV_pointparticles(prvm_prog_t *prog)
 qbool SV_VM_ConsoleCommand (const char *text)
 {
        prvm_prog_t *prog = SVVM_prog;
-       int restorevm_tempstringsbuf_cursize;
-       int save_self;
-       qbool r = false;
-
-       if(!sv.active || !prog || !prog->loaded)
-               return false;
-
-       if (PRVM_serverfunction(ConsoleCmd))
-       {
-               save_self = PRVM_serverglobaledict(self);
-               PRVM_serverglobalfloat(time) = sv.time;
-               restorevm_tempstringsbuf_cursize = prog->tempstringsbuf.cursize;
-               PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(sv.world.prog->edicts);
-               PRVM_G_INT(OFS_PARM0) = PRVM_SetTempString(prog, text);
-               prog->ExecuteProgram(prog, PRVM_serverfunction(ConsoleCmd), "QC function ConsoleCmd is missing");
-               prog->tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
-               PRVM_serverglobaledict(self) = save_self;
-               r = (int) PRVM_G_FLOAT(OFS_RETURN) != 0;
-       }
-       return r;
+       return PRVM_ConsoleCommand(prog, text, &prog->funcoffsets.ConsoleCmd, true, PRVM_EDICT_TO_PROG(sv.world.prog->edicts), sv.time,  !(!sv.active || !prog || !prog->loaded), "QC function ConsoleCmd is missing"); 
 }
 
 // #352 void(string cmdname) registercommand (EXT_CSQC)