]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_ccmds.c
physics: fix and refactor unsticking
[xonotic/darkplaces.git] / sv_ccmds.c
index cbd91e62e9e17912ab56664f6b3a82d3fd7c133c..aa6790e5a552d9b9a2db75ec3b772a01a292cfbe 100644 (file)
@@ -49,8 +49,6 @@ command from the console.  Active clients are kicked off.
 */
 static void SV_Map_f(cmd_state_t *cmd)
 {
-       char level[MAX_QPATH];
-
        if (Cmd_Argc(cmd) != 2)
        {
                Con_Print("map <levelname> : start a new game (kicks off all players)\n");
@@ -62,7 +60,7 @@ static void SV_Map_f(cmd_state_t *cmd)
                Cvar_Set(&cvars_all, "warpmark", "");
 
        if(host.hook.Disconnect)
-               host.hook.Disconnect();
+               host.hook.Disconnect(false, NULL);
 
        SV_Shutdown();
 
@@ -78,8 +76,7 @@ static void SV_Map_f(cmd_state_t *cmd)
                host.hook.ToggleMenu();
 
        svs.serverflags = 0;                    // haven't completed an episode yet
-       strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
-       SV_SpawnServer(level);
+       SV_SpawnServer(Cmd_Argv(cmd, 1));
 
        if(sv.active && host.hook.ConnectLocal != NULL)
                host.hook.ConnectLocal();
@@ -94,8 +91,6 @@ Goes to a new map, taking all clients along
 */
 static void SV_Changelevel_f(cmd_state_t *cmd)
 {
-       char level[MAX_QPATH];
-
        if (Cmd_Argc(cmd) != 2)
        {
                Con_Print("changelevel <levelname> : continue game on a new level\n");
@@ -104,7 +99,7 @@ static void SV_Changelevel_f(cmd_state_t *cmd)
 
        if (!sv.active)
        {
-               Con_Printf("You must be running a server to changelevel. Use 'map %s' instead\n", Cmd_Argv(cmd, 1));
+               SV_Map_f(cmd);
                return;
        }
 
@@ -112,8 +107,7 @@ static void SV_Changelevel_f(cmd_state_t *cmd)
                host.hook.ToggleMenu();
 
        SV_SaveSpawnparms ();
-       strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
-       SV_SpawnServer(level);
+       SV_SpawnServer(Cmd_Argv(cmd, 1));
        
        if(sv.active && host.hook.ConnectLocal != NULL)
                host.hook.ConnectLocal();
@@ -128,8 +122,6 @@ Restarts the current server for a dead player
 */
 static void SV_Restart_f(cmd_state_t *cmd)
 {
-       char mapname[MAX_QPATH];
-
        if (Cmd_Argc(cmd) != 1)
        {
                Con_Print("restart : restart current level\n");
@@ -144,8 +136,7 @@ static void SV_Restart_f(cmd_state_t *cmd)
        if(host.hook.ToggleMenu)
                host.hook.ToggleMenu();
 
-       strlcpy(mapname, sv.name, sizeof(mapname));
-       SV_SpawnServer(mapname);
+       SV_SpawnServer(sv.worldbasename);
        
        if(sv.active && host.hook.ConnectLocal != NULL)
                host.hook.ConnectLocal();
@@ -157,11 +148,11 @@ static void SV_Restart_f(cmd_state_t *cmd)
 static void SV_DisableCheats_c(cvar_t *var)
 {
        prvm_prog_t *prog = SVVM_prog;
-       int i = 0;
+       int i;
 
-       if (var->value == 0)
+       if (prog->loaded && var->value == 0)
        {
-               while (svs.clients[i].edict)
+               for (i = 0; i < svs.maxclients; ++i)
                {
                        if (((int)PRVM_serveredictfloat(svs.clients[i].edict, flags) & FL_GODMODE))
                                PRVM_serveredictfloat(svs.clients[i].edict, flags) = (int)PRVM_serveredictfloat(svs.clients[i].edict, flags) ^ FL_GODMODE;
@@ -173,7 +164,6 @@ static void SV_DisableCheats_c(cvar_t *var)
                                noclip_anglehack = false;
                                PRVM_serveredictfloat(svs.clients[i].edict, movetype) = MOVETYPE_WALK;
                        }
-                       i++;
                }
        }
 }
@@ -226,6 +216,7 @@ static void SV_Give_f(cmd_state_t *cmd)
        prvm_prog_t *prog = SVVM_prog;
        const char *t;
        int v;
+       int player_items;
 
        t = Cmd_Argv(cmd, 1);
        v = atoi (Cmd_Argv(cmd, 2));
@@ -335,6 +326,49 @@ static void SV_Give_f(cmd_state_t *cmd)
                                PRVM_serveredictfloat(host_client->edict, ammo_cells) = v;
                }
                break;
+       case 'a':
+               //
+               // Set the player armour value to the number specified and then adjust the armour type/colour based on the value
+               //
+               player_items = PRVM_serveredictfloat(host_client->edict, items);
+               PRVM_serveredictfloat(host_client->edict, armorvalue) = v;
+
+               // Remove whichever armour item the player currently has
+               if (gamemode == GAME_ROGUE)
+                       player_items &= ~(RIT_ARMOR1 | RIT_ARMOR2 | RIT_ARMOR3);
+               else
+                       player_items &= ~(IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3);
+
+               if (v > 150)
+               {
+                       // Give red armour
+                       PRVM_serveredictfloat(host_client->edict, armortype) = 0.8;
+                       if (gamemode == GAME_ROGUE)
+                               player_items |= RIT_ARMOR3;
+                       else
+                               player_items |= IT_ARMOR3;
+               }
+               else if (v > 100)
+               {
+                       // Give yellow armour
+                       PRVM_serveredictfloat(host_client->edict, armortype) = 0.6;
+                       if (gamemode == GAME_ROGUE)
+                               player_items |= RIT_ARMOR2;
+                       else
+                               player_items |= IT_ARMOR2;
+               }
+               else if (v >= 0)
+               {
+                       // Give green armour
+                       PRVM_serveredictfloat(host_client->edict, armortype) = 0.3;
+                       if (gamemode == GAME_ROGUE)
+                               player_items |= RIT_ARMOR1;
+                       else
+                               player_items |= IT_ARMOR1;
+               }
+
+               PRVM_serveredictfloat(host_client->edict, items) = player_items;
+               break;
        }
 }
 
@@ -469,7 +503,7 @@ static void SV_Say(cmd_state_t *cmd, qbool teamonly)
                p2[-1] = 0;
                p2--;
        }
-       strlcat(text, "\n", sizeof(text));
+       dp_strlcat(text, "\n", sizeof(text));
 
        // note: save is not a valid edict if fromServer is true
        save = host_client;
@@ -736,11 +770,12 @@ static void SV_Status_f(cmd_state_t *cmd)
        for (players = 0, i = 0;i < svs.maxclients;i++)
                if (svs.clients[i].active)
                        players++;
+
        print ("host:     %s\n", Cvar_VariableString (&cvars_all, "hostname", CF_SERVER));
-       print ("version:  %s build %s (gamename %s)\n", gamename, buildstring, gamenetworkfiltername);
+       print ("version:  %s\n", engineversion);
        print ("protocol: %i (%s)\n", Protocol_NumberForEnum(sv.protocol), Protocol_NameForEnum(sv.protocol));
-       print ("map:      %s\n", sv.name);
-       print ("timing:   %s\n", Host_TimingReport(vabuf, sizeof(vabuf)));
+       print ("map:      %s\n", sv.worldbasename);
+       print ("timing:   %s\n", SV_TimingReport(vabuf, sizeof(vabuf)));
        print ("players:  %i active (%i max)\n\n", players, svs.maxclients);
 
        if (in == 1)
@@ -779,9 +814,9 @@ static void SV_Status_f(cmd_state_t *cmd)
                }
 
                if(sv_status_privacy.integer && cmd->source != src_local && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
-                       strlcpy(ip, client->netconnection ? "hidden" : "botclient", 48);
+                       dp_strlcpy(ip, client->netconnection ? "hidden" : "botclient", 48);
                else
-                       strlcpy(ip, (client->netconnection && *client->netconnection->address) ? client->netconnection->address : "botclient", 48);
+                       dp_strlcpy(ip, (client->netconnection && *client->netconnection->address) ? client->netconnection->address : "botclient", 48);
 
                frags = client->frags;
 
@@ -837,7 +872,7 @@ void SV_Name(int clientnum)
        {
                if (host_client->begun)
                        SV_BroadcastPrintf("\003%s ^7changed name to ^3%s\n", host_client->old_name, host_client->name);
-               strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
+               dp_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);
                MSG_WriteByte (&sv.reliable_datagram, clientnum);
@@ -866,7 +901,7 @@ static void SV_Name_f(cmd_state_t *cmd)
        else
                newNameSource = Cmd_Args(cmd);
 
-       strlcpy(newName, newNameSource, sizeof(newName));
+       dp_strlcpy(newName, newNameSource, sizeof(newName));
 
        if (cmd->source == src_local)
                return;
@@ -880,7 +915,7 @@ static void SV_Name_f(cmd_state_t *cmd)
        host_client->nametime = host.realtime + max(0.0f, sv_namechangetimer.value);
 
        // point the string back at updateclient->name to keep it safe
-       strlcpy (host_client->name, newName, sizeof (host_client->name));
+       dp_strlcpy (host_client->name, newName, sizeof (host_client->name));
 
        for (i = 0, j = 0;host_client->name[i];i++)
                if (host_client->name[i] != '\r' && host_client->name[i] != '\n')
@@ -1026,6 +1061,7 @@ static void SV_Kick_f(cmd_state_t *cmd)
 {
        const char *who;
        const char *message = NULL;
+       char reason[512];
        client_t *save;
        int i;
        qbool byNumber = false;
@@ -1084,10 +1120,11 @@ static void SV_Kick_f(cmd_state_t *cmd)
                                message++;
                }
                if (message)
-                       SV_ClientPrintf("Kicked by %s: %s\n", who, message);
+                       SV_DropClient (false, va(reason, sizeof(reason), "Kicked by %s: %s", who, message)); // kicked
+                       //SV_ClientPrintf("Kicked by %s: %s\n", who, message);
                else
-                       SV_ClientPrintf("Kicked by %s\n", who);
-               SV_DropClient (false); // kicked
+                       //SV_ClientPrintf("Kicked by %s\n", who);
+                       SV_DropClient (false, va(reason, sizeof(reason), "Kicked by %s", who)); // kicked
        }
 
        host_client = save;
@@ -1136,9 +1173,9 @@ static void SV_Playermodel_f(cmd_state_t *cmd)
                return;
 
        if (Cmd_Argc (cmd) == 2)
-               strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
+               dp_strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
        else
-               strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
+               dp_strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
 
        for (i = 0, j = 0;newPath[i];i++)
                if (newPath[i] != '\r' && newPath[i] != '\n')
@@ -1156,11 +1193,11 @@ static void SV_Playermodel_f(cmd_state_t *cmd)
        */
 
        // point the string back at updateclient->name to keep it safe
-       strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
+       dp_strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
        PRVM_serveredictstring(host_client->edict, playermodel) = PRVM_SetEngineString(prog, host_client->playermodel);
        if (strcmp(host_client->old_model, host_client->playermodel))
        {
-               strlcpy(host_client->old_model, host_client->playermodel, sizeof(host_client->old_model));
+               dp_strlcpy(host_client->old_model, host_client->playermodel, sizeof(host_client->old_model));
                /*// send notification to all clients
                MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
                MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
@@ -1183,9 +1220,9 @@ static void SV_Playerskin_f(cmd_state_t *cmd)
                return;
 
        if (Cmd_Argc (cmd) == 2)
-               strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
+               dp_strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
        else
-               strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
+               dp_strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
 
        for (i = 0, j = 0;newPath[i];i++)
                if (newPath[i] != '\r' && newPath[i] != '\n')
@@ -1203,13 +1240,13 @@ static void SV_Playerskin_f(cmd_state_t *cmd)
        */
 
        // point the string back at updateclient->name to keep it safe
-       strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
+       dp_strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
        PRVM_serveredictstring(host_client->edict, playerskin) = PRVM_SetEngineString(prog, host_client->playerskin);
        if (strcmp(host_client->old_skin, host_client->playerskin))
        {
                //if (host_client->begun)
                //      SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
-               strlcpy(host_client->old_skin, host_client->playerskin, sizeof(host_client->old_skin));
+               dp_strlcpy(host_client->old_skin, host_client->playerskin, sizeof(host_client->old_skin));
                /*// send notification to all clients
                MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
                MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
@@ -1556,7 +1593,7 @@ static void SV_Ent_Remove_f(cmd_state_t *cmd)
                                return;
                }
 
-               if(!ed->priv.required->free)
+               if(!ed->free)
                {
                        print("Removed a \"%s\"\n", PRVM_GetString(prog, PRVM_serveredictstring(ed, classname)));
                        PRVM_ED_ClearEdict(prog, ed);
@@ -1580,7 +1617,7 @@ static void SV_Ent_Remove_All_f(cmd_state_t *cmd)
 
        for (i = 0, rmcount = 0, ed = PRVM_EDICT_NUM(i); i < prog->num_edicts; i++, ed = PRVM_NEXT_EDICT(ed))
        {
-               if(!ed->priv.required->free && !strcmp(PRVM_GetString(prog, PRVM_serveredictstring(ed, classname)), Cmd_Argv(cmd, 1)))
+               if(!ed->free && !strcmp(PRVM_GetString(prog, PRVM_serveredictstring(ed, classname)), Cmd_Argv(cmd, 1)))
                {
                        if(!i)
                        {
@@ -1611,7 +1648,7 @@ void SV_InitOperatorCommands(void)
        Cmd_AddCommand(CF_SERVER | CF_SERVER_FROM_CLIENT, "status", SV_Status_f, "print server status information");
        Cmd_AddCommand(CF_SHARED, "map", SV_Map_f, "kick everyone off the server and start a new level");
        Cmd_AddCommand(CF_SHARED, "restart", SV_Restart_f, "restart current level");
-       Cmd_AddCommand(CF_SHARED, "changelevel", SV_Changelevel_f, "change to another level, bringing along all connected clients");
+       Cmd_AddCommand(CF_SHARED, "changelevel", SV_Changelevel_f, "change to another level, bringing along all connected clients (or start a new level if none is loaded)");
        Cmd_AddCommand(CF_SHARED | CF_SERVER_FROM_CLIENT, "say", SV_Say_f, "send a chat message to everyone on the server");
        Cmd_AddCommand(CF_SERVER_FROM_CLIENT, "say_team", SV_Say_Team_f, "send a chat message to your team on the server");
        Cmd_AddCommand(CF_SHARED | CF_SERVER_FROM_CLIENT, "tell", SV_Tell_f, "send a chat message to only one person on the server");