fix problems with losing colors on connect and leaving ghosts on the scoreboard and...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 20 Oct 2004 02:40:59 +0000 (02:40 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 20 Oct 2004 02:40:59 +0000 (02:40 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4675 d7cf8633-e32d-0410-b094-e92efae38249

host.c
host_cmd.c
pr_cmds.c
pr_edict.c
server.h
sv_main.c

diff --git a/host.c b/host.c
index d861278..2ac6255 100644 (file)
--- a/host.c
+++ b/host.c
@@ -434,6 +434,27 @@ void SV_DropClient(qboolean crash)
                }
        }
 
+       // remove leaving player from scoreboard
+       // clear a fields that matter to DP_SV_CLIENTNAME and DP_SV_CLIENTCOLORS, and also frags
+       ED_ClearEdict(host_client->edict);
+       //host_client->edict->v->netname = PR_SetString(host_client->name);
+       //if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
+       //      val->_float = 0;
+       //host_client->edict->v->frags = 0;
+       host_client->name[0] = 0;
+       host_client->colors = 0;
+       host_client->frags = 0;
+       // send notification to all clients
+       MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
+       MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+       MSG_WriteString (&sv.reliable_datagram, host_client->name);
+       MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
+       MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+       MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
+       MSG_WriteByte (&sv.reliable_datagram, svc_updatefrags);
+       MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+       MSG_WriteShort (&sv.reliable_datagram, host_client->frags);
+
        // free the client now
        if (host_client->entitydatabase)
                EntityFrame_FreeDatabase(host_client->entitydatabase);
@@ -444,13 +465,6 @@ void SV_DropClient(qboolean crash)
        // clear the client struct (this sets active to false)
        memset(host_client, 0, sizeof(*host_client));
 
-       // force next SV_UpdateToReliableMessages to update this client's
-       // scoreboard data by plugging in fake old values that don't match the
-       // new empty values
-       strlcpy(host_client->old_name, "nothing", sizeof(host_client->old_name));
-       host_client->old_frags = 1;
-       host_client->old_colors = 1;
-
        // update server listing on the master because player count changed
        // (which the master uses for filtering empty/full servers)
        NetConn_Heartbeat(1);
index 07ca90a..6d98512 100644 (file)
@@ -757,19 +757,19 @@ void Host_Name_f (void)
        
        host_client->nametime = sv.time + 5;
 
-       if (strcmp(host_client->name, newName) && host_client->name[0] && strcmp(host_client->name, "unconnected"))
-               SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
-       strcpy(host_client->name, newName);
-       strcpy(host_client->old_name, newName);
-       if (sv_player)
-               sv_player->v->netname = PR_SetString(host_client->name);
-       //Con_Printf("Host_Name_f: host_client->edict->netname = %s, sv_player->netname = %s, host_client->name = %s\n", PR_GetString(host_client->edict->v->netname), PR_GetString(sv_player->v->netname), host_client->name);
-
-// send notification to all clients
-
-       MSG_WriteByte(&sv.reliable_datagram, svc_updatename);
-       MSG_WriteByte(&sv.reliable_datagram, host_client->number);
-       MSG_WriteString(&sv.reliable_datagram, host_client->name);
+       // point the string back at updateclient->name to keep it safe
+       strlcpy (host_client->name, newName, sizeof (host_client->name));
+       host_client->edict->v->netname = PR_SetString(host_client->name);
+       if (strcmp(host_client->old_name, host_client->name))
+       {
+               if (host_client->spawned)
+                       SV_BroadcastPrintf("%s changed name to %s\n", host_client->name, newName);
+               strcpy(host_client->old_name, host_client->name);
+               // send notification to all clients
+               MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
+               MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+               MSG_WriteString (&sv.reliable_datagram, host_client->name);
+       }
 }
 
 
@@ -981,12 +981,14 @@ void Host_Color_f(void)
                        sv_player->v->team = bottom + 1;
                }
                host_client->colors = playercolor;
-               host_client->old_colors = playercolor;
-
-               // send notification to all clients
-               MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
-               MSG_WriteByte (&sv.reliable_datagram, host_client->number);
-               MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
+               if (host_client->old_colors != host_client->colors)
+               {
+                       host_client->old_colors = host_client->colors;
+                       // send notification to all clients
+                       MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
+                       MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+                       MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
+               }
        }
 }
 
@@ -1217,13 +1219,13 @@ void Host_Spawn_f (void)
                        continue;
                MSG_WriteByte (&host_client->message, svc_updatename);
                MSG_WriteByte (&host_client->message, i);
-               MSG_WriteString (&host_client->message, client->old_name);
+               MSG_WriteString (&host_client->message, client->name);
                MSG_WriteByte (&host_client->message, svc_updatefrags);
                MSG_WriteByte (&host_client->message, i);
-               MSG_WriteShort (&host_client->message, client->old_frags);
+               MSG_WriteShort (&host_client->message, client->frags);
                MSG_WriteByte (&host_client->message, svc_updatecolors);
                MSG_WriteByte (&host_client->message, i);
-               MSG_WriteByte (&host_client->message, client->old_colors);
+               MSG_WriteByte (&host_client->message, client->colors);
        }
 
        // send all current light styles
index 5785174..dca3e92 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -2218,15 +2218,21 @@ void PF_setcolor (void)
        }
 
        client = svs.clients + entnum-1;
-       if ((val = GETEDICTFIELDVALUE(client->edict, eval_clientcolors)))
-               val->_float = i;
+       if (client->edict)
+       {
+               if ((val = GETEDICTFIELDVALUE(client->edict, eval_clientcolors)))
+                       val->_float = i;
+               client->edict->v->team = (i & 15) + 1;
+       }
        client->colors = i;
-       client->old_colors = i;
-       client->edict->v->team = (i & 15) + 1;
-
-       MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
-       MSG_WriteByte (&sv.reliable_datagram, entnum - 1);
-       MSG_WriteByte (&sv.reliable_datagram, i);
+       if (client->old_colors != client->colors)
+       {
+               client->old_colors = client->colors;
+               // send notification to all clients
+               MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
+               MSG_WriteByte (&sv.reliable_datagram, client->number);
+               MSG_WriteByte (&sv.reliable_datagram, client->colors);
+       }
 }
 
 /*
index 0482bcf..0e8fbc6 100644 (file)
@@ -209,9 +209,16 @@ void ED_ClearEdict (edict_t *e)
        num = NUM_FOR_EDICT(e) - 1;
        if (num >= 0 && num < svs.maxclients)
        {
+               eval_t *val;
+               // set colormap and team on newly created player entity
                e->v->colormap = num + 1;
                e->v->team = (svs.clients[num].colors & 15) + 1;
+               // set netname/clientcolors back to client values so that
+               // DP_SV_CLIENTNAME and DPV_SV_CLIENTCOLORS will not immediately
+               // reset them
                e->v->netname = PR_SetString(svs.clients[num].name);
+               if ((val = GETEDICTFIELDVALUE(e, eval_clientcolors)))
+                       val->_float = svs.clients[num].colors;
        }
 }
 
index 8e94e5a..04512bc 100644 (file)
--- a/server.h
+++ b/server.h
@@ -149,8 +149,6 @@ typedef struct client_s
        char name[64], old_name[64];
        int colors, old_colors;
        int frags, old_frags;
-       // other properties not sent across the network
-       int pmodel;
 
        // visibility state
        float visibletime[MAX_EDICTS];
index dc71764..6d9a20b 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -1115,65 +1115,54 @@ void SV_UpdateToReliableMessages (void)
        int i, j;
        client_t *client;
        eval_t *val;
-       char *s;
+       char *name;
 
 // check for changes to be sent over the reliable streams
        for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
        {
                // update the host_client fields we care about according to the entity fields
                sv_player = EDICT_NUM(i+1);
-               s = PR_GetString(sv_player->v->netname);
-               if (s != host_client->name)
-               {
-                       if (s == NULL)
-                               s = "";
-                       // point the string back at host_client->name to keep it safe
-                       strlcpy (host_client->name, s, sizeof (host_client->name));
-                       sv_player->v->netname = PR_SetString(host_client->name);
-               }
-               if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)) && host_client->colors != val->_float)
-                       host_client->colors = val->_float;
-               host_client->frags = sv_player->v->frags;
-               if (gamemode == GAME_NEHAHRA)
-                       if ((val = GETEDICTFIELDVALUE(sv_player, eval_pmodel)) && host_client->pmodel != val->_float)
-                               host_client->pmodel = val->_float;
-
-               // if the fields changed, send messages about the changes
+
+               // DP_SV_CLIENTNAME
+               name = PR_GetString(sv_player->v->netname);
+               if (name == NULL)
+                       name = "";
+               // always point the string back at host_client->name to keep it safe
+               strlcpy (host_client->name, name, sizeof (host_client->name));
+               sv_player->v->netname = PR_SetString(host_client->name);
                if (strcmp(host_client->old_name, host_client->name))
                {
+                       if (host_client->spawned)
+                               SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
                        strcpy(host_client->old_name, host_client->name);
-                       for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
-                       {
-                               if (!client->netconnection)
-                                       continue;
-                               MSG_WriteByte (&client->message, svc_updatename);
-                               MSG_WriteByte (&client->message, i);
-                               MSG_WriteString (&client->message, host_client->name);
-                       }
+                       // send notification to all clients
+                       MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
+                       MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+                       MSG_WriteString (&sv.reliable_datagram, host_client->name);
                }
+
+               // DP_SV_CLIENTCOLORS
+               // this is always found (since it's added by the progs loader)
+               if ((val = GETEDICTFIELDVALUE(sv_player, eval_clientcolors)))
+                       host_client->colors = (int)val->_float;
                if (host_client->old_colors != host_client->colors)
                {
                        host_client->old_colors = host_client->colors;
-                       for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
-                       {
-                               if (!client->netconnection)
-                                       continue;
-                               MSG_WriteByte (&client->message, svc_updatecolors);
-                               MSG_WriteByte (&client->message, i);
-                               MSG_WriteByte (&client->message, host_client->colors);
-                       }
+                       // send notification to all clients
+                       MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
+                       MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+                       MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
                }
+
+               // frags
+               host_client->frags = (int)sv_player->v->frags;
                if (host_client->old_frags != host_client->frags)
                {
                        host_client->old_frags = host_client->frags;
-                       for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
-                       {
-                               if (!client->netconnection)
-                                       continue;
-                               MSG_WriteByte (&client->message, svc_updatefrags);
-                               MSG_WriteByte (&client->message, i);
-                               MSG_WriteShort (&client->message, host_client->frags);
-                       }
+                       // send notification to all clients
+                       MSG_WriteByte (&sv.reliable_datagram, svc_updatefrags);
+                       MSG_WriteByte (&sv.reliable_datagram, host_client->number);
+                       MSG_WriteShort (&sv.reliable_datagram, host_client->frags);
                }
        }