}
}
+ // 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);
// 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);
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);
+ }
}
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);
+ }
}
}
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
}
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);
+ }
}
/*
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;
}
}
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];
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);
}
}