]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_ccmds.c
protocol/dp8: Implement parting messages
[xonotic/darkplaces.git] / sv_ccmds.c
index b1d2a4e79925479b351b460601d3da5cdff25c04..036f4c63f1588cae58155a02479a9ec77f9ae1b7 100644 (file)
@@ -61,9 +61,9 @@ static void SV_Map_f(cmd_state_t *cmd)
        if (gamemode == GAME_DELUXEQUAKE)
                Cvar_Set(&cvars_all, "warpmark", "");
 
-       cls.demonum = -1;               // stop demo loop in case this fails
+       if(host.hook.Disconnect)
+               host.hook.Disconnect(false, NULL);
 
-       CL_Disconnect ();
        SV_Shutdown();
 
        if(svs.maxclients != svs.maxclients_next)
@@ -74,12 +74,8 @@ static void SV_Map_f(cmd_state_t *cmd)
                svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
        }
 
-#ifdef CONFIG_MENU
-       // remove menu
-       if (key_dest == key_menu || key_dest == key_menu_grabbed)
-               MR_ToggleMenu(0);
-#endif
-       key_dest = key_game;
+       if(host.hook.ToggleMenu)
+               host.hook.ToggleMenu();
 
        svs.serverflags = 0;                    // haven't completed an episode yet
        strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
@@ -112,12 +108,8 @@ static void SV_Changelevel_f(cmd_state_t *cmd)
                return;
        }
 
-#ifdef CONFIG_MENU
-       // remove menu
-       if (key_dest == key_menu || key_dest == key_menu_grabbed)
-               MR_ToggleMenu(0);
-#endif
-       key_dest = key_game;
+       if(host.hook.ToggleMenu)
+               host.hook.ToggleMenu();
 
        SV_SaveSpawnparms ();
        strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
@@ -149,12 +141,8 @@ static void SV_Restart_f(cmd_state_t *cmd)
                return;
        }
 
-#ifdef CONFIG_MENU
-       // remove menu
-       if (key_dest == key_menu || key_dest == key_menu_grabbed)
-               MR_ToggleMenu(0);
-#endif
-       key_dest = key_game;
+       if(host.hook.ToggleMenu)
+               host.hook.ToggleMenu();
 
        strlcpy(mapname, sv.name, sizeof(mapname));
        SV_SpawnServer(mapname);
@@ -712,68 +700,6 @@ static void SV_Pings_f(cmd_state_t *cmd)
                MSG_WriteString(&host_client->netconnection->message, "\n");
 }
 
-/*
-====================
-SV_User_f
-
-user <name or userid>
-
-Dump userdata / masterdata for a user
-====================
-*/
-static void SV_User_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
-{
-       int             uid;
-       int             i;
-
-       if (Cmd_Argc(cmd) != 2)
-       {
-               Con_Printf ("Usage: user <username / userid>\n");
-               return;
-       }
-
-       uid = atoi(Cmd_Argv(cmd, 1));
-
-       for (i = 0;i < cl.maxclients;i++)
-       {
-               if (!cl.scores[i].name[0])
-                       continue;
-               if (cl.scores[i].qw_userid == uid || !strcasecmp(cl.scores[i].name, Cmd_Argv(cmd, 1)))
-               {
-                       InfoString_Print(cl.scores[i].qw_userinfo);
-                       return;
-               }
-       }
-       Con_Printf ("User not in server.\n");
-}
-
-/*
-====================
-SV_Users_f
-
-Dump userids for all current players
-====================
-*/
-static void SV_Users_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
-{
-       int             i;
-       int             c;
-
-       c = 0;
-       Con_Printf ("userid frags name\n");
-       Con_Printf ("------ ----- ----\n");
-       for (i = 0;i < cl.maxclients;i++)
-       {
-               if (cl.scores[i].name[0])
-               {
-                       Con_Printf ("%6i %4i %s\n", cl.scores[i].qw_userid, cl.scores[i].frags, cl.scores[i].name);
-                       c++;
-               }
-       }
-
-       Con_Printf ("%i total users\n", c);
-}
-
 /*
 ==================
 SV_Status_f
@@ -814,7 +740,7 @@ static void SV_Status_f(cmd_state_t *cmd)
        print ("version:  %s build %s (gamename %s)\n", gamename, buildstring, gamenetworkfiltername);
        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 ("timing:   %s\n", SV_TimingReport(vabuf, sizeof(vabuf)));
        print ("players:  %i active (%i max)\n\n", players, svs.maxclients);
 
        if (in == 1)
@@ -1100,6 +1026,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;
@@ -1158,10 +1085,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;
@@ -1340,7 +1268,7 @@ static void SV_Viewmodel_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
        prvm_edict_t    *e;
-       dp_model_t      *m;
+       model_t *m;
 
        if (!sv.active)
                return;
@@ -1369,7 +1297,7 @@ static void SV_Viewframe_f(cmd_state_t *cmd)
        prvm_prog_t *prog = SVVM_prog;
        prvm_edict_t    *e;
        int             f;
-       dp_model_t      *m;
+       model_t *m;
 
        if (!sv.active)
                return;
@@ -1387,7 +1315,7 @@ static void SV_Viewframe_f(cmd_state_t *cmd)
        }
 }
 
-static void PrintFrameName (dp_model_t *m, int frame)
+static void PrintFrameName (model_t *m, int frame)
 {
        if (m->animscenes)
                Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
@@ -1404,7 +1332,7 @@ static void SV_Viewnext_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
        prvm_edict_t    *e;
-       dp_model_t      *m;
+       model_t *m;
 
        if (!sv.active)
                return;
@@ -1431,7 +1359,7 @@ static void SV_Viewprev_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
        prvm_edict_t    *e;
-       dp_model_t      *m;
+       model_t *m;
 
        if (!sv.active)
                return;
@@ -1485,7 +1413,6 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
        int i;
        qbool haveorigin;
 
-       qbool expectval = false;
        void (*print)(const char *, ...) = (cmd->source == src_client ? SV_ClientPrintf : Con_Printf);
 
        if(!Cmd_Argc(cmd))
@@ -1524,31 +1451,24 @@ static void SV_Ent_Create_f(cmd_state_t *cmd)
        }
 
        // Allow more than one key/value pair by cycling between expecting either one.
-       for(i = 2; i < Cmd_Argc(cmd); i++)
+       for(i = 2; i < Cmd_Argc(cmd); i += 2)
        {
-               if(!expectval)
+               if(!(key = PRVM_ED_FindField(prog, Cmd_Argv(cmd, i))))
                {
-                       if(!(key = PRVM_ED_FindField(prog, Cmd_Argv(cmd, i))))
-                       {
-                               print("Key %s not found!\n", Cmd_Argv(cmd, i));
-                               PRVM_ED_Free(prog, ed);
-                               return;
-                       }
+                       print("Key %s not found!\n", Cmd_Argv(cmd, i));
+                       PRVM_ED_Free(prog, ed);
+                       return;
+               }
 
-                       /*
-                        * 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;
+               /*
+                * 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;
-               }
-               else
-               {
-                       PRVM_ED_ParseEpair(prog, ed, key, Cmd_Argv(cmd, i), false);
-                       expectval = false;
-               }
+               if (i + 1 < Cmd_Argc(cmd))
+                       PRVM_ED_ParseEpair(prog, ed, key, Cmd_Argv(cmd, i+1), false);
        }
 
        if(!haveorigin)
@@ -1583,7 +1503,7 @@ static void SV_Ent_Remove_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
        prvm_edict_t *ed;
-       int i, ednum;
+       int i, ednum = 0;
        void (*print)(const char *, ...) = (cmd->source == src_client ? SV_ClientPrintf : Con_Printf);
 
        if(!Cmd_Argc(cmd))
@@ -1638,7 +1558,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);
@@ -1662,7 +1582,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)
                        {
@@ -1707,11 +1627,9 @@ void SV_InitOperatorCommands(void)
        Cmd_AddCommand(CF_SHARED, "viewnext", SV_Viewnext_f, "change to next animation frame of viewthing entity in current level");
        Cmd_AddCommand(CF_SHARED, "viewprev", SV_Viewprev_f, "change to previous animation frame of viewthing entity in current level");
        Cmd_AddCommand(CF_SHARED, "maxplayers", SV_MaxPlayers_f, "sets limit on how many players (or bots) may be connected to the server at once");
-       Cmd_AddCommand(CF_SHARED, "user", SV_User_f, "prints additional information about a player number or name on the scoreboard");
-       Cmd_AddCommand(CF_SHARED, "users", SV_Users_f, "prints additional information about all players on the scoreboard");
-       Cmd_AddCommand(CF_SERVER, "sendcvar", SV_SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC");
+       host.hook.SV_SendCvar = SV_SendCvar_f;
 
-       // commands that do not have automatic forwarding from cmd_client, these are internal details of the network protocol and not of interest to users (if they know what they are doing they can still use a generic "cmd prespawn" or similar)
+       // commands that do not have automatic forwarding from cmd_local, these are internal details of the network protocol and not of interest to users (if they know what they are doing they can still use a generic "cmd prespawn" or similar)
        Cmd_AddCommand(CF_SERVER_FROM_CLIENT, "prespawn", SV_PreSpawn_f, "internal use - signon 1 (client acknowledges that server information has been received)");
        Cmd_AddCommand(CF_SERVER_FROM_CLIENT, "spawn", SV_Spawn_f, "internal use - signon 2 (client has sent player information, and is asking server to send scoreboard rankings)");
        Cmd_AddCommand(CF_SERVER_FROM_CLIENT, "begin", SV_Begin_f, "internal use - signon 3 (client asks server to start sending entities, and will go to signon 4 (playing) when the first entity update is received)");