]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host_cmd.c
renamed snd_reload to snd_unloadallsounds to clarify its purpose
[xonotic/darkplaces.git] / host_cmd.c
index cdf3315a192565d09141fe181c7f17dbe05bbb15..165705b2ea58d8b53fd5929a4c385a8e2e92f5aa 100644 (file)
@@ -30,6 +30,8 @@ cvar_t skin = {CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (exam
 cvar_t noaim = {CVAR_USERINFO | CVAR_SAVE, "noaim", "1", "QW option to disable vertical autoaim"};
 qboolean allowcheats = false;
 
+extern qboolean host_shuttingdown;
+
 /*
 ==================
 Host_Quit_f
@@ -38,7 +40,10 @@ Host_Quit_f
 
 void Host_Quit_f (void)
 {
-       Sys_Quit (0);
+       if(host_shuttingdown)
+               Con_Printf("shutting down already!\n");
+       else
+               Sys_Quit (0);
 }
 
 
@@ -585,7 +590,7 @@ void Host_Loadgame_f (void)
        }
 
        // version
-       COM_ParseTokenConsole(&t);
+       COM_ParseToken_Simple(&t, false);
        version = atoi(com_token);
        if (version != SAVEGAME_VERSION)
        {
@@ -595,27 +600,25 @@ void Host_Loadgame_f (void)
        }
 
        // description
-       // this is a little hard to parse, as : is a separator in COM_ParseToken,
-       // so use the console parser instead
-       COM_ParseTokenConsole(&t);
+       COM_ParseToken_Simple(&t, false);
 
        for (i = 0;i < NUM_SPAWN_PARMS;i++)
        {
-               COM_ParseTokenConsole(&t);
+               COM_ParseToken_Simple(&t, false);
                spawn_parms[i] = atof(com_token);
        }
        // skill
-       COM_ParseTokenConsole(&t);
+       COM_ParseToken_Simple(&t, false);
 // this silliness is so we can load 1.06 save files, which have float skill values
        current_skill = (int)(atof(com_token) + 0.5);
        Cvar_SetValue ("skill", (float)current_skill);
 
        // mapname
-       COM_ParseTokenConsole(&t);
+       COM_ParseToken_Simple(&t, false);
        strlcpy (mapname, com_token, sizeof(mapname));
 
        // time
-       COM_ParseTokenConsole(&t);
+       COM_ParseToken_Simple(&t, false);
        time = atof(com_token);
 
        allowcheats = sv_cheats.integer != 0;
@@ -636,7 +639,7 @@ void Host_Loadgame_f (void)
        {
                // light style
                oldt = t;
-               COM_ParseTokenConsole(&t);
+               COM_ParseToken_Simple(&t, false);
                // if this is a 64 lightstyle savegame produced by Quake, stop now
                // we have to check this because darkplaces saves 256 lightstyle savegames
                if (com_token[0] == '{')
@@ -654,7 +657,7 @@ void Host_Loadgame_f (void)
        for(;;)
        {
                oldt = t;
-               COM_ParseTokenConsole(&t);
+               COM_ParseToken_Simple(&t, false);
                if (com_token[0] == '{')
                {
                        t = oldt;
@@ -669,10 +672,10 @@ void Host_Loadgame_f (void)
        for (;;)
        {
                start = t;
-               while (COM_ParseTokenConsole(&t))
+               while (COM_ParseToken_Simple(&t, false))
                        if (!strcmp(com_token, "}"))
                                break;
-               if (!COM_ParseTokenConsole(&start))
+               if (!COM_ParseToken_Simple(&start, false))
                {
                        // end of file
                        break;
@@ -697,7 +700,6 @@ void Host_Loadgame_f (void)
                                Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)", MAX_EDICTS);
                        }
                        while (entnum >= prog->max_edicts)
-                               //SV_IncreaseEdicts();
                                PRVM_MEM_IncreaseEdicts();
                        ent = PRVM_EDICT_NUM(entnum);
                        memset (ent->fields.server, 0, prog->progs->entityfields * 4);
@@ -737,6 +739,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)
@@ -771,11 +774,32 @@ void Host_Name_f (void)
 
        // 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);
@@ -1555,7 +1579,7 @@ void Host_Kick_f (void)
                if (Cmd_Argc() > 2)
                {
                        message = Cmd_Args();
-                       COM_ParseTokenConsole(&message);
+                       COM_ParseToken_Simple(&message, false);
                        if (byNumber)
                        {
                                message++;                                                      // skip the #
@@ -1891,7 +1915,7 @@ void Host_Startdemos_f (void)
 {
        int             i, c;
 
-       if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo"))
+       if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo") || COM_CheckParm("-capturedemo"))
                return;
 
        c = Cmd_Argc() - 1;
@@ -1967,9 +1991,9 @@ void Host_SendCvar_f (void)
                // 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", cvarname));
+                       Cmd_ForwardStringToServer(va("sentcvar %s", cvarname));
                else
-                       Cmd_ForwardStringToServer(va("sentcvar %s \"%s\"\n", c->name, c->string));
+                       Cmd_ForwardStringToServer(va("sentcvar %s \"%s\"", c->name, c->string));
                return;
        }
        if(!sv.active)// || !prog->funcoffsets.SV_ParseClientCommand)
@@ -2371,7 +2395,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");