/* * @brief Return the width of the specified string in pixels. This will vary based * on the currently bound font. Color escapes are omitted. */ r_pixel_t R_StringWidth(const char *s) { char stripped[MAX_STRING_CHARS]; StripColor(s, stripped); return strlen(stripped) * r_draw.font->char_width; }
/* * G_ClientUserInfoChanged */ void G_ClientUserInfoChanged(g_edict_t *ent, const char *user_info) { const char *s; char *c; char name[MAX_NET_NAME]; int player_num, i; boolean_t color; g_client_t *cl; // check for malformed or illegal info strings if (!ValidateUserInfo(user_info)) { user_info = "\\name\\newbie\\skin\\qforcer/enforcer"; } cl = ent->client; // set name, use a temp buffer to compute length and crutch up bad names s = GetUserInfo(user_info, "name"); strncpy(name, s, sizeof(name) - 1); name[sizeof(name) - 1] = 0; color = false; c = name; i = 0; // trim to 15 printable chars while (i < 15) { if (!*c) break; if (IS_COLOR(c)) { color = true; c += 2; continue; } c++; i++; } name[c - name] = 0; if (!i) // name had nothing printable strcpy(name, "newbie"); if (color) // reset to white strcat(name, "^7"); if (strncmp(cl->persistent.net_name, name, sizeof(cl->persistent.net_name))) { if (*cl->persistent.net_name != '\0') gi.BroadcastPrint(PRINT_MEDIUM, "%s changed name to %s\n", cl->persistent.net_name, name); strncpy(cl->persistent.net_name, name, sizeof(cl->persistent.net_name) - 1); cl->persistent.net_name[sizeof(cl->persistent.net_name) - 1] = 0; } #ifdef HAVE_MYSQL if(mysql != NULL) { // escape name for safe db insertions StripColor(cl->persistent.net_name, name); mysql_real_escape_string(mysql, name, cl->persistent.sql_name, sizeof(cl->persistent.sql_name)); } #endif // set skin if ((g_level.teams || g_level.ctf) && cl->persistent.team) // players must use team_skin to change s = cl->persistent.team->skin; else s = GetUserInfo(user_info, "skin"); if (*s != '\0') // something valid-ish was provided strncpy(cl->persistent.skin, s, sizeof(cl->persistent.skin) - 1); else { strcpy(cl->persistent.skin, "qforcer/enforcer"); cl->persistent.skin[sizeof(cl->persistent.skin) - 1] = 0; } // set color s = GetUserInfo(user_info, "color"); cl->persistent.color = ColorByName(s, 243); player_num = ent - g_game.edicts - 1; // combine name and skin into a config_string gi.ConfigString(CS_CLIENT_INFO + player_num, va("%s\\%s", cl->persistent.net_name, cl->persistent.skin)); // save off the user_info in case we want to check something later strncpy(ent->client->persistent.user_info, user_info, sizeof(ent->client->persistent.user_info) - 1); }