[qw] Clean up player info processing

It should be much harder for a malicious server to crash the client
(there were a few holes in there still).

Also, set the fallback (server didn't specify) top/bottom colors to be
such that the default colors from the skin are used instead of white.
This commit is contained in:
Bill Currie 2024-01-13 13:22:52 +09:00
parent ad852a15b6
commit 6c03d72c26
3 changed files with 26 additions and 36 deletions

View file

@ -35,8 +35,10 @@
#define MAX_CACHED_SKINS 128
#define MAX_SKIN_LENGTH 32
#define TOP_RANGE 16 // soldier uniform colors
#define BOTTOM_RANGE 96
#define TOP_COLOR 1 // soldier uniform colors
#define BOTTOM_COLOR 6
#define TOP_RANGE (TOP_COLOR * 16)
#define BOTTOM_RANGE (BOTTOM_COLOR * 16)
#define RSSHOT_WIDTH 320
#define RSSHOT_HEIGHT 200

View file

@ -310,8 +310,8 @@ CL_ParseServerInfo (void)
for (i = 0; i < cl.maxclients; i++) {
cl.players[i].userinfo = Info_ParseString ("name\\", 0, 0);
cl.players[i].name = Info_Key (cl.players[i].userinfo, "name");
cl.players[i].topcolor = 0;
cl.players[i].bottomcolor = 0;
cl.players[i].topcolor = TOP_COLOR;
cl.players[i].bottomcolor = BOTTOM_COLOR;
}
Sbar_SetPlayers (cl.players, cl.maxclients);
Sbar_SetTeamplay (teamplay);//FIXME updates?

View file

@ -996,42 +996,30 @@ CL_ParseClientdata (void)
static void
CL_ProcessUserInfo (int slot, player_info_t *player)
{
char skin[MAX_SKIN_LENGTH] = { 0 };
const char *s;
s = Info_ValueForKey (player->userinfo, "skin");
if (strlen(s) < sizeof skin) {
QFS_StripExtension (s, skin);
if (!strequal (s, skin))
Info_SetValueForKey (player->userinfo, "skin", skin, 1);
} else {
Info_SetValueForKey (player->userinfo, "skin", skin, 1);
}
while (!(player->name = Info_Key (player->userinfo, "name"))) {
if (player->userid)
Info_SetValueForKey (player->userinfo, "name",
va (0, "user-%i [exploit]",
player->userid), 1);
else
Info_SetValueForKey (player->userinfo, "name", "", 1);
const char *name = "";
if (player->userid) {
name = va (0, "user-%i [exploit]", player->userid);
}
Info_SetValueForKey (player->userinfo, "name", name, 1);
}
player->topcolor = atoi (Info_ValueForKey (player->userinfo, "topcolor"));
player->bottomcolor =
atoi (Info_ValueForKey (player->userinfo, "bottomcolor"));
const char *tc = Info_ValueForKey (player->userinfo, "topcolor");
const char *bc = Info_ValueForKey (player->userinfo, "bottomcolor");
player->topcolor = tc ? atoi (tc) : TOP_COLOR;
player->bottomcolor = bc ? atoi (bc) : BOTTOM_COLOR;
while (!(player->team = Info_Key (player->userinfo, "team")))
Info_SetValueForKey (player->userinfo, "team", "", 1);
while (!(player->skinname = Info_Key (player->userinfo, "skin")))
Info_SetValueForKey (player->userinfo, "skin", "", 1);
while (!(player->chat = Info_Key (player->userinfo, "chat")))
Info_SetValueForKey (player->userinfo, "chat", "0", 1);
while (!(player->team = Info_Key (player->userinfo, "team"))) {
Info_SetValueForKey (player->userinfo, "team", "", 1);
}
while (!(player->skinname = Info_Key (player->userinfo, "skin"))) {
Info_SetValueForKey (player->userinfo, "skin", "", 1);
}
while (!(player->chat = Info_Key (player->userinfo, "chat"))) {
Info_SetValueForKey (player->userinfo, "chat", "0", 1);
}
if (Info_ValueForKey (player->userinfo, "*spectator")[0])
player->spectator = true;
else
player->spectator = false;
const char *spec = Info_ValueForKey (player->userinfo, "*spectator");
player->spectator = spec && *spec;
mod_funcs->Skin_SetTranslation (slot + 1, player->topcolor,
player->bottomcolor);