]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_user.c
fix a couple EDICT_NUM errors that often happened when loading savegames with more...
[xonotic/darkplaces.git] / sv_user.c
index cc0a412ab6bb2ea54c91d991b0dd9b83ede62dd6..1e4b655832deda88b7c19122798f6492c35b37f2 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -476,7 +476,7 @@ void SV_ReadClientMove (usercmd_t *move)
        // if paused or a local game, don't predict
        if (sv_predict.integer && (svs.maxclients > 1) && (!sv.paused))
                host_client->latency = host_client->ping;
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ping)))
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_ping)))
                val->_float = host_client->ping * 1000.0;
 
        // read current angles
@@ -484,13 +484,13 @@ void SV_ReadClientMove (usercmd_t *move)
        for (i = 0;i < 3;i++)
                angle[i] = MSG_ReadFloat ();
 
-       VectorCopy (angle, host_client->edict->v->v_angle);
+       VectorCopy (angle, sv_player->v->v_angle);
 
        // read movement
        move->forwardmove = MSG_ReadShort ();
        move->sidemove = MSG_ReadShort ();
        move->upmove = MSG_ReadShort ();
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_movement)))
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_movement)))
        {
                val->vector[0] = move->forwardmove;
                val->vector[1] = move->sidemove;
@@ -499,19 +499,19 @@ void SV_ReadClientMove (usercmd_t *move)
 
        // read buttons
        bits = MSG_ReadByte ();
-       host_client->edict->v->button0 = bits & 1;
-       host_client->edict->v->button2 = (bits & 2)>>1;
+       sv_player->v->button0 = bits & 1;
+       sv_player->v->button2 = (bits & 2)>>1;
        // LordHavoc: added 6 new buttons
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button3))) val->_float = ((bits >> 2) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button4))) val->_float = ((bits >> 3) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button5))) val->_float = ((bits >> 4) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button6))) val->_float = ((bits >> 5) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button7))) val->_float = ((bits >> 6) & 1);
-       if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_button8))) val->_float = ((bits >> 7) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button3))) val->_float = ((bits >> 2) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button4))) val->_float = ((bits >> 3) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button5))) val->_float = ((bits >> 4) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button6))) val->_float = ((bits >> 5) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button7))) val->_float = ((bits >> 6) & 1);
+       if ((val = GETEDICTFIELDVALUE(sv_player, eval_button8))) val->_float = ((bits >> 7) & 1);
 
        i = MSG_ReadByte ();
        if (i)
-               host_client->edict->v->impulse = i;
+               sv_player->v->impulse = i;
 }
 
 /*
@@ -528,13 +528,13 @@ qboolean SV_ReadClientMessage (void)
        int             cmd;
        char            *s;
 
-       do
+       for (;;)
        {
 nextmsg:
                ret = NET_GetMessage (host_client->netconnection);
                if (ret == -1)
                {
-                       Sys_Printf ("SV_ReadClientMessage: NET_GetMessage failed\n");
+                       Con_Printf ("SV_ReadClientMessage: NET_GetMessage failed\n");
                        return false;
                }
                if (!ret)
@@ -542,7 +542,7 @@ nextmsg:
 
                MSG_BeginReading ();
 
-               while (1)
+               for(;;)
                {
                        if (!host_client->active)
                                // a command caused an error
@@ -550,20 +550,12 @@ nextmsg:
 
                        if (msg_badread)
                        {
-                               Sys_Printf ("SV_ReadClientMessage: badread\n");
+                               Con_Printf ("SV_ReadClientMessage: badread\n");
                                return false;
                        }
 
                        cmd = MSG_ReadChar ();
 
-#ifndef NOROUTINGFIX
-                       if (cmd != -1 && host_client->waitingforconnect)
-                       {
-                               host_client->waitingforconnect = false;
-                               host_client->sendserverinfo = true;
-                       }
-#endif
-
                        switch (cmd)
                        {
                        case -1:
@@ -571,7 +563,7 @@ nextmsg:
                                goto nextmsg;
 
                        default:
-                               Sys_Printf ("SV_ReadClientMessage: unknown command char %i\n", cmd);
+                               Con_Printf ("SV_ReadClientMessage: unknown command char %i\n", cmd);
                                return false;
 
                        case clc_nop:
@@ -579,8 +571,17 @@ nextmsg:
 
                        case clc_stringcmd:
                                s = MSG_ReadString ();
-                               ret = 0;
-                               if (strncasecmp(s, "status", 6) == 0
+                               if (strncasecmp(s, "spawn", 5) == 0
+                                || strncasecmp(s, "begin", 5) == 0
+                                || strncasecmp(s, "prespawn", 8) == 0)
+                                       Cmd_ExecuteString (s, src_client);
+                               else if (SV_ParseClientCommandQC)
+                               {
+                                       G_INT(OFS_PARM0) = PR_SetString(s);
+                                       pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
+                                       PR_ExecuteProgram ((func_t)(SV_ParseClientCommandQC - pr_functions), "");
+                               }
+                               else if (strncasecmp(s, "status", 6) == 0
                                 || strncasecmp(s, "name", 4) == 0
                                 || strncasecmp(s, "say", 3) == 0
                                 || strncasecmp(s, "say_team", 8) == 0
@@ -588,21 +589,15 @@ nextmsg:
                                 || strncasecmp(s, "color", 5) == 0
                                 || strncasecmp(s, "kill", 4) == 0
                                 || strncasecmp(s, "pause", 5) == 0
-                                || strncasecmp(s, "spawn", 5) == 0
-                                || strncasecmp(s, "begin", 5) == 0
-                                || strncasecmp(s, "prespawn", 8) == 0
                                 || strncasecmp(s, "kick", 4) == 0
                                 || strncasecmp(s, "ping", 4) == 0
                                 || strncasecmp(s, "ban", 3) == 0
                                 || strncasecmp(s, "pmodel", 6) == 0
                                 || (gamemode == GAME_NEHAHRA && (strncasecmp(s, "max", 3) == 0 || strncasecmp(s, "monster", 7) == 0 || strncasecmp(s, "scrag", 5) == 0 || strncasecmp(s, "gimme", 5) == 0 || strncasecmp(s, "wraith", 6) == 0))
                                 || (gamemode != GAME_NEHAHRA && (strncasecmp(s, "god", 3) == 0 || strncasecmp(s, "notarget", 8) == 0 || strncasecmp(s, "fly", 3) == 0 || strncasecmp(s, "give", 4) == 0 || strncasecmp(s, "noclip", 6) == 0)))
-                               {
-                                       ret = 1;
                                        Cmd_ExecuteString (s, src_client);
-                               }
                                else
-                                       Con_DPrintf("%s tried to %s\n", host_client->name, s);
+                                       Con_Printf("%s tried to %s\n", host_client->name, s);
                                break;
 
                        case clc_disconnect:
@@ -618,8 +613,6 @@ nextmsg:
                        }
                }
        }
-       while (ret == 1);
-
        return true;
 }
 
@@ -642,8 +635,7 @@ void SV_RunClients (void)
 
                if (!SV_ReadClientMessage ())
                {
-                       // client misbehaved...
-                       SV_DropClient (false);
+                       SV_DropClient (false); // client misbehaved...
                        continue;
                }