]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_ccmds.c
Rename src_command to src_local, to clarify its meaning
[xonotic/darkplaces.git] / sv_ccmds.c
index f57c20c7221588ef2588db341441f493e0a77bb0..e3331dce0995c96997267b6b8f1ee50a1e2494e4 100644 (file)
@@ -84,8 +84,9 @@ static void SV_Map_f(cmd_state_t *cmd)
        svs.serverflags = 0;                    // haven't completed an episode yet
        strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
        SV_SpawnServer(level);
-       if (sv.active && cls.state == ca_disconnected)
-               CL_EstablishConnection("local:1", -2);
+
+       if(sv.active && host.hook.ConnectLocal != NULL)
+               host.hook.ConnectLocal();
 }
 
 /*
@@ -121,8 +122,9 @@ static void SV_Changelevel_f(cmd_state_t *cmd)
        SV_SaveSpawnparms ();
        strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
        SV_SpawnServer(level);
-       if (sv.active && cls.state == ca_disconnected)
-               CL_EstablishConnection("local:1", -2);
+       
+       if(sv.active && host.hook.ConnectLocal != NULL)
+               host.hook.ConnectLocal();
 }
 
 /*
@@ -156,8 +158,9 @@ static void SV_Restart_f(cmd_state_t *cmd)
 
        strlcpy(mapname, sv.name, sizeof(mapname));
        SV_SpawnServer(mapname);
-       if (sv.active && cls.state == ca_disconnected)
-               CL_EstablishConnection("local:1", -2);
+       
+       if(sv.active && host.hook.ConnectLocal != NULL)
+               host.hook.ConnectLocal();
 }
 
 //===========================================================================
@@ -408,16 +411,8 @@ SV_Pause_f
 static void SV_Pause_f(cmd_state_t *cmd)
 {
        void (*print) (const char *fmt, ...);
-       if (cmd->source == src_command)
-       {
-               // if running a client, try to send over network so the pause is handled by the server
-               if (cls.state == ca_connected)
-               {
-                       CL_ForwardToServer_f(cmd);
-                       return;
-               }
+       if (cmd->source == src_local)
                print = Con_Printf;
-       }
        else
                print = SV_ClientPrintf;
 
@@ -434,7 +429,7 @@ static void SV_Pause_f(cmd_state_t *cmd)
        }
        
        sv.paused ^= 1;
-       if (cmd->source != src_command)
+       if (cmd->source != src_local)
                SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
        else if(*(sv_adminnick.string))
                SV_BroadcastPrintf("%s %spaused the game\n", sv_adminnick.string, sv.paused ? "" : "un");
@@ -456,18 +451,10 @@ static void SV_Say(cmd_state_t *cmd, qboolean teamonly)
        char text[1024];
        qboolean fromServer = false;
 
-       if (cmd->source == src_command)
+       if (cmd->source == src_local)
        {
-               if (cls.state == ca_dedicated)
-               {
-                       fromServer = true;
-                       teamonly = false;
-               }
-               else
-               {
-                       CL_ForwardToServer_f(cmd);
-                       return;
-               }
+               fromServer = true;
+               teamonly = false;
        }
 
        if (Cmd_Argc (cmd) < 2)
@@ -534,16 +521,8 @@ static void SV_Tell_f(cmd_state_t *cmd)
        char text[MAX_INPUTLINE]; // LadyHavoc: FIXME: temporary buffer overflow fix (was 64)
        qboolean fromServer = false;
 
-       if (cmd->source == src_command)
-       {
-               if (cls.state == ca_dedicated)
-                       fromServer = true;
-               else
-               {
-                       CL_ForwardToServer_f(cmd);
-                       return;
-               }
-       }
+       if (cmd->source == src_local)
+               fromServer = true;
 
        if (Cmd_Argc (cmd) < 2)
                return;
@@ -663,16 +642,8 @@ static void SV_Ping_f(cmd_state_t *cmd)
        client_t *client;
        void (*print) (const char *fmt, ...);
 
-       if (cmd->source == src_command)
-       {
-               // if running a client, try to send over network so the client's ping report parser will see the report
-               if (cls.state == ca_connected)
-               {
-                       CL_ForwardToServer_f(cmd);
-                       return;
-               }
+       if (cmd->source == src_local)
                print = Con_Printf;
-       }
        else
                print = SV_ClientPrintf;
 
@@ -825,7 +796,7 @@ static void SV_Status_f(cmd_state_t *cmd)
        int frags;
        char vabuf[1024];
 
-       if (cmd->source == src_command)
+       if (cmd->source == src_local)
                print = Con_Printf;
        else
                print = SV_ClientPrintf;
@@ -887,7 +858,7 @@ static void SV_Status_f(cmd_state_t *cmd)
                        ping = bound(0, (int)floor(client->ping*1000+0.5), 9999);
                }
 
-               if(sv_status_privacy.integer && cmd->source != src_command && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
+               if(sv_status_privacy.integer && cmd->source != src_local && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
                        strlcpy(ip, client->netconnection ? "hidden" : "botclient", 48);
                else
                        strlcpy(ip, (client->netconnection && *client->netconnection->address) ? client->netconnection->address : "botclient", 48);
@@ -938,6 +909,23 @@ static void SV_Status_f(cmd_state_t *cmd)
        }
 }
 
+void SV_Name(int clientnum)
+{
+       prvm_prog_t *prog = SVVM_prog;
+       PRVM_serveredictstring(host_client->edict, netname) = PRVM_SetEngineString(prog, host_client->name);
+       if (strcmp(host_client->old_name, host_client->name))
+       {
+               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));
+               // send notification to all clients
+               MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
+               MSG_WriteByte (&sv.reliable_datagram, clientnum);
+               MSG_WriteString (&sv.reliable_datagram, host_client->name);
+               SV_WriteNetnameIntoDemo(host_client);
+       }       
+}
+
 /*
 ======================
 SV_Name_f
@@ -945,7 +933,6 @@ SV_Name_f
 */
 static void SV_Name_f(cmd_state_t *cmd)
 {
-       prvm_prog_t *prog = SVVM_prog;
        int i, j;
        qboolean valid_colors;
        const char *newNameSource;
@@ -961,7 +948,7 @@ static void SV_Name_f(cmd_state_t *cmd)
 
        strlcpy(newName, newNameSource, sizeof(newName));
 
-       if (cmd->source == src_command)
+       if (cmd->source == src_local)
                return;
 
        if (host.realtime < host_client->nametime && strcmp(newName, host_client->name))
@@ -1040,18 +1027,7 @@ static void SV_Name_f(cmd_state_t *cmd)
        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);
 
-       PRVM_serveredictstring(host_client->edict, netname) = PRVM_SetEngineString(prog, host_client->name);
-       if (strcmp(host_client->old_name, host_client->name))
-       {
-               if (host_client->begun)
-                       SV_BroadcastPrintf("%s ^7changed name to %s\n", host_client->old_name, 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);
-               MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
-               MSG_WriteString (&sv.reliable_datagram, host_client->name);
-               SV_WriteNetnameIntoDemo(host_client);
-       }
+       SV_Name(host_client - svs.clients);
 }
 
 static void SV_Rate_f(cmd_state_t *cmd)
@@ -1060,7 +1036,7 @@ static void SV_Rate_f(cmd_state_t *cmd)
 
        rate = atoi(Cmd_Argv(cmd, 1));
 
-       if (cmd->source == src_command)
+       if (cmd->source == src_local)
                return;
 
        host_client->rate = rate;
@@ -1159,7 +1135,7 @@ static void SV_Kick_f(cmd_state_t *cmd)
 
        if (i < svs.maxclients)
        {
-               if (cmd->source == src_command)
+               if (cmd->source == src_local)
                {
                        if (cls.state == ca_dedicated)
                                who = "Console";
@@ -1511,7 +1487,7 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
        prvm_edict_t *ed;
-       ddef_t *key;
+       mdef_t *key;
        int i;
        qboolean haveorigin;
 
@@ -1608,7 +1584,80 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
        if(cmd->source == src_client)
                Con_Printf("%s spawned a \"%s\"\n", host_client->name, Cmd_Argv(cmd, 1));
 }
-//static void SV_Ent_Remove()
+
+static void SV_Ent_Remove_f(cmd_state_t *cmd)
+{
+       prvm_prog_t *prog = SVVM_prog;
+       prvm_edict_t *ed;
+       int i, ednum;
+       void (*print)(const char *, ...) = (cmd->source == src_client ? SV_ClientPrintf : Con_Printf);
+
+       if(!Cmd_Argc(cmd))
+               return;
+
+       // Allow specifying edict by number
+       if(Cmd_Argc(cmd) > 1 && Cmd_Argv(cmd, 1))
+       {
+               ednum = atoi(Cmd_Argv(cmd, 1));
+               if(!ednum)
+               {
+                       print("Cannot remove the world\n");
+                       return;
+               }
+       }
+       // Or trace a line if it's a client who didn't specify one.
+       else if(cmd->source == src_client)
+       {
+               vec3_t org, temp, dest;
+               matrix4x4_t view;
+               trace_t trace;
+
+               SV_GetEntityMatrix(prog, host_client->edict, &view, true);
+
+               Matrix4x4_OriginFromMatrix(&view, org);
+               VectorSet(temp, 65536, 0, 0);
+               Matrix4x4_Transform(&view, temp, dest);         
+
+               trace = SV_TraceLine(org, dest, MOVE_NORMAL, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY, 0, 0, collision_extendmovelength.value);
+               
+               if(trace.ent)
+                       ednum = (int)PRVM_EDICT_TO_PROG(trace.ent);
+               if(!trace.ent || !ednum)
+                       // Don't remove the world, but don't annoy players with a print if they miss
+                       return;
+       }
+       else
+       {
+               // Only a dedicated server console should be able to reach this.
+               print("No edict given\n");
+               return;
+       }
+
+       ed = PRVM_EDICT_NUM(ednum);
+
+       if(ed)
+       {
+               // Skip players
+               for (i = 0; i < svs.maxclients; i++)
+               {
+                       if(ed == svs.clients[i].edict)
+                               return;
+               }
+
+               if(!ed->priv.required->free)
+               {
+                       print("Removed a \"%s\"\n", PRVM_GetString(prog, PRVM_serveredictstring(ed, classname)));
+                       PRVM_ED_ClearEdict(prog, ed);
+                       PRVM_ED_Free(prog, ed);
+               }
+       }
+       else
+       {
+               // This should only be reachable if an invalid edict number was given
+               print("No such entity\n");
+               return;
+       }
+}
 
 static void SV_Ent_Remove_All_f(cmd_state_t *cmd)
 {
@@ -1691,4 +1740,5 @@ void SV_InitOperatorCommands(void)
 
        Cmd_AddCommand(CMD_CHEAT | CMD_SERVER_FROM_CLIENT, "ent_create", SV_Ent_Create_f, "Creates an entity at the specified coordinate, of the specified classname. If executed from a server, origin has to be specified manually.");
        Cmd_AddCommand(CMD_CHEAT | CMD_SERVER_FROM_CLIENT, "ent_remove_all", SV_Ent_Remove_All_f, "Removes all entities of the specified classname");
+       Cmd_AddCommand(CMD_CHEAT | CMD_SERVER_FROM_CLIENT, "ent_remove", SV_Ent_Remove_f, "Removes an entity by number, or the entity you're aiming at");
 }