]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_ccmds.c
sys: Initialize the memory subsystem in main()
[xonotic/darkplaces.git] / sv_ccmds.c
index f15f2f4b2697055ae60c66812c955fc1e8fc753b..e4fd309deb6c3202c37aadc0a9800b896720fbfd 100644 (file)
@@ -409,15 +409,7 @@ 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;
-               }
                print = Con_Printf;
-       }
        else
                print = SV_ClientPrintf;
 
@@ -938,6 +930,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 +954,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;
@@ -1040,18 +1048,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)
@@ -1510,15 +1507,49 @@ static void SV_SendCvar_f(cmd_state_t *cmd)
 static void SV_Ent_Create_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
+       prvm_edict_t *ed;
        ddef_t *key;
        int i;
-       qboolean expectval = false, haveorigin = false;
+       qboolean haveorigin;
+
+       qboolean expectval = false;
        void (*print)(const char *, ...) = (cmd->source == src_client ? SV_ClientPrintf : Con_Printf);
 
-       prvm_edict_t *ed = PRVM_ED_Alloc(SVVM_prog);
+       if(!Cmd_Argc(cmd))
+               return;
+
+       ed = PRVM_ED_Alloc(SVVM_prog);
 
        PRVM_ED_ParseEpair(prog, ed, PRVM_ED_FindField(prog, "classname"), Cmd_Argv(cmd, 1), false);
 
+       // Spawn where the player is aiming. We need a view matrix first.
+       if(cmd->source == src_client)
+       {
+               vec3_t org, temp, dest;
+               matrix4x4_t view;
+               trace_t trace;
+               char buf[128];
+
+               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, 0, 0, collision_extendmovelength.value);
+
+               dpsnprintf(buf, sizeof(buf), "%g %g %g", trace.endpos[0], trace.endpos[1], trace.endpos[2]);
+               PRVM_ED_ParseEpair(prog, ed, PRVM_ED_FindField(prog, "origin"), buf, false);
+
+               haveorigin = true;
+       }
+       // Or spawn at a specified origin.
+       else
+       {
+               print = Con_Printf;
+               haveorigin = false;
+       }
+
        // Allow more than one key/value pair by cycling between expecting either one.
        for(i = 2; i < Cmd_Argc(cmd); i++)
        {
@@ -1531,7 +1562,11 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
                                return;
                        }
 
-                       if(!strcmp(Cmd_Argv(cmd, i), "origin") && !haveorigin)
+                       /*
+                        * This is mostly for dedicated server console, but if the
+                        * player gave a custom origin, we can ignore the traceline.
+                        */
+                       if(!strcmp(Cmd_Argv(cmd, i), "origin"))
                                haveorigin = true;
 
                        expectval = true;
@@ -1546,8 +1581,6 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
        if(!haveorigin)
        {
                print("Missing origin\n");
-               if(cmd->source == src_client)
-                       print("This should never happen if you're a player. Please report this to a developer.\n");
                PRVM_ED_Free(prog, ed);
                return;
        }
@@ -1572,7 +1605,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)
 {
@@ -1655,4 +1761,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");
 }