]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/cmd.qc
Merge branch 'martin-t/defaults' into martin-t/okc
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / cmd.qc
index 5d6ad3adab263edf38a8c51bec8febbab19528d8..d1d79981182ceb91e560895f22f7f3d2e4c3a3df 100644 (file)
@@ -1,4 +1,8 @@
 #include "cmd.qh"
+
+#include <server/defs.qh>
+#include <server/miscfunctions.qh>
+
 #include <common/command/_mod.qh>
 
 #include "common.qh"
@@ -30,8 +34,8 @@
 
 #include <common/minigames/sv_minigames.qh>
 
-#include <common/monsters/all.qc>
-#include <common/monsters/spawn.qh>
+#include <common/monsters/_mod.qh>
+#include <common/monsters/sv_spawn.qh>
 #include <common/monsters/sv_monsters.qh>
 
 #include <lib/warpzone/common.qh>
@@ -101,11 +105,11 @@ void ClientCommand_clientversion(entity caller, float request, float argc)  // i
                        {
                                if (IS_CLIENT(caller))
                                {
-                                       caller.version = ((argv(1) == "$gameversion") ? 1 : stof(argv(1)));
+                                       CS(caller).version = ((argv(1) == "$gameversion") ? 1 : stof(argv(1)));
 
-                                       if (caller.version < autocvar_gameversion_min || caller.version > autocvar_gameversion_max)
+                                       if (CS(caller).version < autocvar_gameversion_min || CS(caller).version > autocvar_gameversion_max)
                                        {
-                                               caller.version_mismatch = 1;
+                                               CS(caller).version_mismatch = true;
                                                ClientKill_TeamChange(caller, -2);  // observe
                                        }
                                        else if (autocvar_g_campaign || autocvar_g_balance_teams)
@@ -159,18 +163,18 @@ void ClientCommand_mv_getpicture(entity caller, float request, float argc)  // i
        }
 }
 
-bool spawnAllowed(entity this);
-void LeaveSpectatorMode(entity this);
+bool joinAllowed(entity this);
+void Join(entity this);
 void ClientCommand_join(entity caller, float request)
 {
        switch (request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if (!gameover)
+                       if (!game_stopped)
                        if (IS_CLIENT(caller) && !IS_PLAYER(caller))
-                       if (spawnAllowed(caller))
-                               LeaveSpectatorMode(caller);
+                       if (joinAllowed(caller))
+                               Join(caller);
 
                        return;  // never fall through to usage
                }
@@ -242,12 +246,12 @@ void ClientCommand_ready(entity caller, float request)  // todo: anti-spam for t
                                                if (caller.ready)            // toggle
                                                {
                                                        caller.ready = false;
-                                                       bprint(caller.netname, "^2 is ^1NOT^2 ready\n");
+                                                       bprint(playername(caller, false), "^2 is ^1NOT^2 ready\n");
                                                }
                                                else
                                                {
                                                        caller.ready = true;
-                                                       bprint(caller.netname, "^2 is ready\n");
+                                                       bprint(playername(caller, false), "^2 is ready\n");
                                                }
 
                                                // cannot reset the game while a timeout is active!
@@ -312,7 +316,7 @@ void ClientCommand_say_team(entity caller, float request, float argc, string com
        }
 }
 
-.int selectedteam;
+.bool team_selected;
 void ClientCommand_selectteam(entity caller, float request, float argc)
 {
        switch (request)
@@ -354,7 +358,7 @@ void ClientCommand_selectteam(entity caller, float request, float argc)
                                                                        {
                                                                                sprint(caller, "^7You already are on that team.\n");
                                                                        }
-                                                                       else if (caller.wasplayer && autocvar_g_changeteam_banned)
+                                                                       else if (CS(caller).wasplayer && autocvar_g_changeteam_banned)
                                                                        {
                                                                                sprint(caller, "^1You cannot change team, forbidden by the server.\n");
                                                                        }
@@ -471,22 +475,35 @@ void ClientCommand_spectate(entity caller, float request)
        {
                case CMD_REQUEST_COMMAND:
                {
-                       if (IS_CLIENT(caller))
+                       if (!intermission_running && IS_CLIENT(caller))
                        {
+                               if((IS_SPEC(caller) || IS_OBSERVER(caller)) && argv(1) != "")
+                               {
+                                       entity client = GetFilteredEntity(argv(1));
+                                       int spec_accepted = VerifyClientEntity(client, false, false);
+                                       if(spec_accepted > 0 && IS_PLAYER(client))
+                                       {
+                                               if(Spectate(caller, client))
+                                                       return; // fall back to regular handling
+                                       }
+                               }
+
                                int mutator_returnvalue = MUTATOR_CALLHOOK(ClientCommand_Spectate, caller);
 
                                if (mutator_returnvalue == MUT_SPECCMD_RETURN) return;
 
-                               if ((IS_PLAYER(caller) || mutator_returnvalue == MUT_SPECCMD_FORCE) && autocvar_sv_spectate == 1) ClientKill_TeamChange(caller, -2); // observe
+                               if ((IS_PLAYER(caller) || mutator_returnvalue == MUT_SPECCMD_FORCE))
+                               if (autocvar_sv_spectate == 1)
+                                       ClientKill_TeamChange(caller, -2); // observe
                        }
-                       return;                                                                                                                        // never fall through to usage
+                       return; // never fall through to usage
                }
 
                default:
                case CMD_REQUEST_USAGE:
                {
-                       sprint(caller, "\nUsage:^3 cmd spectate\n");
-                       sprint(caller, "  No arguments required.\n");
+                       sprint(caller, "\nUsage:^3 cmd spectate <client>\n");
+                       sprint(caller, "  Where 'client' can be the player to spectate.\n");
                        return;
                }
        }
@@ -524,6 +541,12 @@ void ClientCommand_tell(entity caller, float request, float argc, string command
                {
                        if (argc >= 3)
                        {
+                               if(!IS_CLIENT(caller) && IS_REAL_CLIENT(caller)) // connecting
+                               {
+                                       print_to(caller, "You can't ^2tell^7 a message while connecting.");
+                                       return;
+                               }
+
                                entity tell_to = GetIndexedEntity(argc, 1);
                                float tell_accepted = VerifyClientEntity(tell_to, true, false);