]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_edict.c
Win32: ioctl SIO_UDP_CONNRESET <- FALSE
[xonotic/darkplaces.git] / prvm_edict.c
index 81dd581878cfebf89a21f33e5921fd6723f0cca2..4b59235656d4bb0c05c81e1e95a075cd21101f9d 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
 
@@ -851,7 +853,7 @@ void PRVM_ED_ParseGlobals (const char *data)
        while (1)
        {
                // parse key
-               if (!COM_ParseTokenConsole(&data))
+               if (!COM_ParseToken_Simple(&data, false))
                        PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
                if (com_token[0] == '}')
                        break;
@@ -859,7 +861,7 @@ void PRVM_ED_ParseGlobals (const char *data)
                strlcpy (keyname, com_token, sizeof(keyname));
 
                // parse value
-               if (!COM_ParseTokenConsole(&data))
+               if (!COM_ParseToken_Simple(&data, false))
                        PRVM_ERROR ("PRVM_ED_ParseGlobals: EOF without closing brace");
 
                if (com_token[0] == '}')
@@ -951,8 +953,7 @@ qboolean PRVM_ED_ParseEpair(prvm_edict_t *ent, ddef_t *key, const char *s)
                        Con_Printf("PRVM_ED_ParseEpair: ev_entity reference too large (edict %u >= MAX_EDICTS %u) on %s\n", (unsigned int)i, (unsigned int)MAX_EDICTS, PRVM_NAME);
                while (i >= prog->max_edicts)
                        PRVM_MEM_IncreaseEdicts();
-                       //SV_IncreaseEdicts();
-               // if SV_IncreaseEdicts was called the base pointer needs to be updated
+               // if IncreaseEdicts was called the base pointer needs to be updated
                if (ent)
                        val = (prvm_eval_t *)((int *)ent->fields.vp + key->ofs);
                val->edict = PRVM_EDICT_TO_PROG(PRVM_EDICT_NUM((int)i));
@@ -985,6 +986,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
@@ -1044,7 +1110,7 @@ const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent)
        while (1)
        {
        // parse key
-               if (!COM_ParseTokenConsole(&data))
+               if (!COM_ParseToken_Simple(&data, false))
                        PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
                if (developer_entityparsing.integer)
                        Con_Printf("Key: \"%s\"", com_token);
@@ -1076,7 +1142,7 @@ const char *PRVM_ED_ParseEdict (const char *data, prvm_edict_t *ent)
                }
 
        // parse value
-               if (!COM_ParseTokenConsole(&data))
+               if (!COM_ParseToken_Simple(&data, false))
                        PRVM_ERROR ("PRVM_ED_ParseEdict: EOF without closing brace");
                if (developer_entityparsing.integer)
                        Con_Printf(" \"%s\"\n", com_token);
@@ -1151,7 +1217,7 @@ void PRVM_ED_LoadFromFile (const char *data)
        while (1)
        {
 // parse the opening brace
-               if (!COM_ParseTokenConsole(&data))
+               if (!COM_ParseToken_Simple(&data, false))
                        break;
                if (com_token[0] != '{')
                        PRVM_ERROR ("PRVM_ED_LoadFromFile: %s: found %s when expecting {", PRVM_NAME, com_token);
@@ -1271,6 +1337,7 @@ void PRVM_FindOffsets(void)
        prog->fieldoffsets.customizeentityforclient       = PRVM_ED_FindFieldOffset("customizeentityforclient");
        prog->fieldoffsets.dimension_hit                  = PRVM_ED_FindFieldOffset("dimension_hit");
        prog->fieldoffsets.dimension_solid                = PRVM_ED_FindFieldOffset("dimension_solid");
+       prog->fieldoffsets.disableclientprediction        = PRVM_ED_FindFieldOffset("disableclientprediction");
        prog->fieldoffsets.dphitcontentsmask              = PRVM_ED_FindFieldOffset("dphitcontentsmask");
        prog->fieldoffsets.drawonlytoclient               = PRVM_ED_FindFieldOffset("drawonlytoclient");
        prog->fieldoffsets.exteriormodeltoclient          = PRVM_ED_FindFieldOffset("exteriormodeltoclient");
@@ -1292,7 +1359,9 @@ void PRVM_FindOffsets(void)
        prog->fieldoffsets.items2                         = PRVM_ED_FindFieldOffset("items2");
        prog->fieldoffsets.lerpfrac                       = PRVM_ED_FindFieldOffset("lerpfrac");
        prog->fieldoffsets.light_lev                      = PRVM_ED_FindFieldOffset("light_lev");
+       prog->fieldoffsets.modelflags                     = PRVM_ED_FindFieldOffset("modelflags");
        prog->fieldoffsets.movement                       = PRVM_ED_FindFieldOffset("movement");
+       prog->fieldoffsets.netaddress                     = PRVM_ED_FindFieldOffset("netaddress");
        prog->fieldoffsets.nextthink                      = PRVM_ED_FindFieldOffset("nextthink");
        prog->fieldoffsets.nodrawtoclient                 = PRVM_ED_FindFieldOffset("nodrawtoclient");
        prog->fieldoffsets.pflags                         = PRVM_ED_FindFieldOffset("pflags");
@@ -1330,6 +1399,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");
@@ -1900,7 +1970,7 @@ PRVM_Init
 void PRVM_Init (void)
 {
        Cmd_AddCommand ("prvm_edict", PRVM_ED_PrintEdict_f, "print all data about an entity number in the selected VM (server, client, menu)");
-       Cmd_AddCommand ("prvm_edicts", PRVM_ED_PrintEdicts_f, "set a property on an entity number in the selected VM (server, client, menu)");
+       Cmd_AddCommand ("prvm_edicts", PRVM_ED_PrintEdicts_f, "prints all data about all entities in the selected VM (server, client, menu)");
        Cmd_AddCommand ("prvm_edictcount", PRVM_ED_Count_f, "prints number of active entities in the selected VM (server, client, menu)");
        Cmd_AddCommand ("prvm_profile", PRVM_Profile_f, "prints execution statistics about the most used QuakeC functions in the selected VM (server, client, menu)");
        Cmd_AddCommand ("prvm_fields", PRVM_Fields_f, "prints usage statistics on properties (how many entities have non-zero values) in the selected VM (server, client, menu)");
@@ -1909,6 +1979,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);
@@ -2090,7 +2163,7 @@ int PRVM_SetEngineString(const char *s)
                        return -1 - i;
        // new unknown engine string
        if (developer.integer >= 200)
-               Con_Printf("new engine string %p\n", s);
+               Con_Printf("new engine string %p = \"%s\"\n", s, s);
        for (i = prog->firstfreeknownstring;i < prog->numknownstrings;i++)
                if (!prog->knownstrings[i])
                        break;