]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host_cmd.c
mvdsv sucks (changed *ver from showing a string like DarkPlaces Linux
[xonotic/darkplaces.git] / host_cmd.c
index 4dcc0e5d8a7363d0e80f09c7aa5a03d320b5ba3c..95647886cc0d0a433bf11514e080302e4c0ed096 100644 (file)
@@ -38,7 +38,7 @@ Host_Quit_f
 
 void Host_Quit_f (void)
 {
-       Sys_Quit ();
+       Sys_Quit (0);
 }
 
 
@@ -92,7 +92,7 @@ void Host_Status_f (void)
                }
                else
                        hours = 0;
-               print ("#%-3u %-16.16s  %3i  %2i:%02i:%02i\n", j+1, client->name, client->frags, hours, minutes, seconds);
+               print ("#%-3u %-16.16s^%i  %3i  %2i:%02i:%02i\n", j+1, client->name, STRING_COLOR_DEFAULT, client->frags, hours, minutes, seconds);
                print ("   %s\n", client->netconnection ? client->netconnection->address : "botclient");
        }
 }
@@ -737,6 +737,7 @@ cvar_t cl_name = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "_cl_name", "player", "intern
 void Host_Name_f (void)
 {
        int i, j;
+       qboolean valid_colors;
        char newName[sizeof(host_client->name)];
 
        if (Cmd_Argc () == 1)
@@ -761,21 +762,42 @@ void Host_Name_f (void)
                return;
        }
 
-       if (sv.time < host_client->nametime)
+       if (realtime < host_client->nametime)
        {
                SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
                return;
        }
 
-       host_client->nametime = sv.time + 5;
+       host_client->nametime = realtime + 5;
 
        // point the string back at updateclient->name to keep it safe
        strlcpy (host_client->name, newName, sizeof (host_client->name));
+
+       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");
+               }
+       }
+
        host_client->edict->fields.server->netname = PRVM_SetEngineString(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);
+                       SV_BroadcastPrintf("%s^%i changed name to %s\n", host_client->old_name, STRING_COLOR_DEFAULT, host_client->name);
                strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
                // send notification to all clients
                MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
@@ -819,13 +841,13 @@ void Host_Playermodel_f (void)
        }
 
        /*
-       if (sv.time < host_client->nametime)
+       if (realtime < host_client->nametime)
        {
                SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
                return;
        }
 
-       host_client->nametime = sv.time + 5;
+       host_client->nametime = realtime + 5;
        */
 
        // point the string back at updateclient->name to keep it safe
@@ -876,13 +898,13 @@ void Host_Playerskin_f (void)
        }
 
        /*
-       if (sv.time < host_client->nametime)
+       if (realtime < host_client->nametime)
        {
                SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
                return;
        }
 
-       host_client->nametime = sv.time + 5;
+       host_client->nametime = realtime + 5;
        */
 
        // point the string back at updateclient->name to keep it safe
@@ -944,8 +966,10 @@ void Host_Say(qboolean teamonly)
                p1++;
        }
        // note this uses the chat prefix \001
-       if (!fromServer)
+       if (!fromServer && !teamonly)
                dpsnprintf (text, sizeof(text), "\001%s" STRING_COLOR_DEFAULT_STR ": %s", host_client->name, p1);
+       else if (!fromServer && teamonly)
+               dpsnprintf (text, sizeof(text), "\001(%s" STRING_COLOR_DEFAULT_STR "): %s", host_client->name, p1);
        else if(*(sv_adminnick.string))
                dpsnprintf (text, sizeof(text), "\001<%s" STRING_COLOR_DEFAULT_STR "> %s", sv_adminnick.string, p1);
        else
@@ -1398,8 +1422,8 @@ void Host_Spawn_f (void)
                prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
                PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
 
-               if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
-                       Con_Printf("%s entered the game\n", host_client->name);
+               if (svs.maxclients > 1 || cls.state == ca_dedicated)
+                       Con_Printf("%s^%i entered the game\n", host_client->name, STRING_COLOR_DEFAULT);
 
                PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
        }
@@ -1953,17 +1977,19 @@ void Host_SendCvar_f (void)
 {
        int             i;
        cvar_t  *c;
+       const char *cvarname;
        client_t *old;
 
        if(Cmd_Argc() != 2)
                return;
-       c = Cvar_FindVar(Cmd_Argv(1));
+       cvarname = Cmd_Argv(1);
        if (cls.state == ca_connected)
        {
+               c = Cvar_FindVar(cvarname);
                // LordHavoc: if there is no such cvar or if it is private, send a
                // reply indicating that it has no value
                if(!c || (c->flags & CVAR_PRIVATE))
-                       Cmd_ForwardStringToServer(va("sentcvar %s\n", c->name));
+                       Cmd_ForwardStringToServer(va("sentcvar %s\n", cvarname));
                else
                        Cmd_ForwardStringToServer(va("sentcvar %s \"%s\"\n", c->name, c->string));
                return;
@@ -1980,7 +2006,7 @@ void Host_SendCvar_f (void)
                if(svs.clients[i].active && svs.clients[i].netconnection)
                {
                        host_client = &svs.clients[i];
-                       Host_ClientCommands(va("sendcvar %s\n", c->name));
+                       Host_ClientCommands(va("sendcvar %s\n", cvarname));
                }
        host_client = old;
 }
@@ -2320,8 +2346,10 @@ void Host_Pings_f (void)
        {
                packetloss = 0;
                if (svs.clients[i].netconnection)
-                       for (j = 0;j < 100;j++)
-                               packetloss += svs.clients[i].netconnection->packetlost[j];
+                       for (j = 0;j < NETGRAPH_PACKETS;j++)
+                               if (svs.clients[i].netconnection->incoming_unreliablesize[j] == NETGRAPH_LOSTPACKET)
+                                       packetloss++;
+               packetloss = packetloss * 100 / NETGRAPH_PACKETS;
                ping = (int)floor(svs.clients[i].ping*1000+0.5);
                ping = bound(0, ping, 9999);
                if (sv.protocol == PROTOCOL_QUAKEWORLD)
@@ -2365,7 +2393,7 @@ Host_InitCommands
 */
 void Host_InitCommands (void)
 {
-       dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\%s", engineversion);
+       dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp");
 
        Cmd_AddCommand_WithClientCommand ("status", Host_Status_f, Host_Status_f, "print server status information");
        Cmd_AddCommand ("quit", Host_Quit_f, "quit the game");