+
+ for (i = 0, j = 0;host_client->name[i];i++)
+ if (host_client->name[i] != '\r' && host_client->name[i] != '\n')
+ host_client->name[j++] = host_client->name[i];
+ host_client->name[j] = 0;
+
+ if(host_client->name[0] == 1 || host_client->name[0] == 2)
+ // may interfere with chat area, and will needlessly beep; so let's add a ^7
+ {
+ memmove(host_client->name + 2, host_client->name, sizeof(host_client->name) - 2);
+ host_client->name[sizeof(host_client->name) - 1] = 0;
+ host_client->name[0] = STRING_COLOR_TAG;
+ host_client->name[1] = '0' + STRING_COLOR_DEFAULT;
+ }
+
+ COM_StringLengthNoColors(host_client->name, 0, &valid_colors);
+ if(!valid_colors) // NOTE: this also proves the string is not empty, as "" is a valid colored string
+ {
+ size_t l;
+ l = strlen(host_client->name);
+ if(l < sizeof(host_client->name) - 1)
+ {
+ // duplicate the color tag to escape it
+ host_client->name[i] = STRING_COLOR_TAG;
+ host_client->name[i+1] = 0;
+ //Con_DPrintf("abuse detected, adding another trailing color tag\n");
+ }
+ else
+ {
+ // remove the last character to fix the color code
+ host_client->name[l-1] = 0;
+ //Con_DPrintf("abuse detected, removing a trailing color tag\n");
+ }
+ }
+
+ // find the last color tag offset and decide if we need to add a reset tag
+ for (i = 0, j = -1;host_client->name[i];i++)
+ {
+ if (host_client->name[i] == STRING_COLOR_TAG)
+ {
+ if (host_client->name[i+1] >= '0' && host_client->name[i+1] <= '9')
+ {
+ j = i;
+ // if this happens to be a reset tag then we don't need one
+ if (host_client->name[i+1] == '0' + STRING_COLOR_DEFAULT)
+ j = -1;
+ i++;
+ continue;
+ }
+ if (host_client->name[i+1] == STRING_COLOR_TAG)
+ {
+ i++;
+ continue;
+ }
+ }
+ }
+ // does not end in the default color string, so add it
+ if (j >= 0 && strlen(host_client->name) < sizeof(host_client->name) - 2)
+ memcpy(host_client->name + strlen(host_client->name), STRING_COLOR_DEFAULT_STR, strlen(STRING_COLOR_DEFAULT_STR) + 1);
+