]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
LMS: improve handling of forced spectators in warmup and countdown to game start...
authorterencehill <piuntn@gmail.com>
Mon, 16 Aug 2021 18:41:01 +0000 (20:41 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 16 Aug 2021 18:41:01 +0000 (20:41 +0200)
qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc
qcsrc/common/gamemodes/gamemode/lms/sv_lms.qc
qcsrc/common/minigames/sv_minigames.qc
qcsrc/server/client.qc
qcsrc/server/client.qh
qcsrc/server/clientkill.qc
qcsrc/server/command/sv_cmd.qc
qcsrc/server/mutators/events.qh

index ba2402f2768229c8576c3399a1084bb99649b02e..c7ba4198462e299c5b07cba7cfbe7049ea6f6584 100644 (file)
@@ -302,6 +302,10 @@ MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver)
 {
        entity player = M_ARGV(0, entity);
 
+       bool is_forced = M_ARGV(1, bool);
+       if (is_forced && player.caplayer)
+               player.caplayer = 0;
+
        if (IS_PLAYER(player) && !IS_DEAD(player))
                ca_LastPlayerForTeam_Notify(player);
        if (player.killindicator_teamchange == -2) // player wants to spectate
index b05a960dde448b10f98fe72a7ec148bb04fa4eb9..556f76294d23b5dbd1fb15f4af905e9e1aea30c9 100644 (file)
@@ -310,6 +310,7 @@ MUTATOR_HOOKFUNCTION(lms, ClientDisconnect)
 MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
 {
        entity player = M_ARGV(0, entity);
+       bool is_forced = M_ARGV(1, bool);
 
        if (!IS_PLAYER(player))
                return true;
@@ -321,8 +322,13 @@ MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver)
                TRANSMUTE(Observer, player);
                player.lmsplayer = 0;
        }
-       else if (!GameRules_scoring_add(player, LMS_RANK, 0))
-               lms_RemovePlayer(player);
+       else
+       {
+               if (is_forced)
+                       player.lms_spectate_warning = 2;
+               if (!GameRules_scoring_add(player, LMS_RANK, 0))
+                       lms_RemovePlayer(player);
+       }
        return true;  // prevent team reset
 }
 
index 21f81055a463f59aa7650992bb59b14c6b5d36dd..a1fb3631dd8b4c634787b8a93c855b5934ab8de3 100644 (file)
@@ -148,9 +148,7 @@ int minigame_addplayer(entity minigame_session, entity player)
                Net_LinkEntity(player_pointer, false, 0, minigame_SendEntity);
 
                if ( !IS_OBSERVER(player) && autocvar_sv_minigames_observer )
-               {
-                       PutObserverInServer(player);
-               }
+                       PutObserverInServer(player, true);
                if ( autocvar_sv_minigames_observer == 2 )
                        Player_SetForcedTeamIndex(player, TEAM_FORCE_SPECTATOR);
 
index a9758146f5dddfaca618b7ddc6b6a624fa7da1ef..943404e02adf1bc55a060daa392458f4424fe3e1 100644 (file)
@@ -6,7 +6,6 @@
 #include <common/effects/qc/globalsound.qh>
 #include <common/ent_cs.qh>
 #include <common/gamemodes/_mod.qh>
-#include <common/gamemodes/gamemode/lms/sv_lms.qh>
 #include <common/gamemodes/gamemode/nexball/sv_nexball.qh>
 #include <common/items/_mod.qh>
 #include <common/items/inventory.qh>
@@ -236,9 +235,9 @@ void setplayermodel(entity e, string modelname)
 }
 
 /** putting a client as observer in the server */
-void PutObserverInServer(entity this)
+void PutObserverInServer(entity this, bool is_forced)
 {
-       bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver, this);
+       bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver, this, is_forced);
        PlayerState_detach(this);
 
        if (IS_PLAYER(this))
@@ -820,7 +819,7 @@ void PutClientInServer(entity this)
        MUTATOR_CALLHOOK(PutClientInServer, this);
 
        if (IS_OBSERVER(this)) {
-               PutObserverInServer(this);
+               PutObserverInServer(this, false);
        } else if (IS_PLAYER(this)) {
                PutPlayerInServer(this);
        }
@@ -1789,7 +1788,7 @@ bool SpectateSet(entity this)
        accuracy_resend(this);
 
        if(!SpectateUpdate(this))
-               PutObserverInServer(this);
+               PutObserverInServer(this, false);
 
        return true;
 }
@@ -2293,7 +2292,7 @@ void ObserverOrSpectatorThink(entity this)
                                TRANSMUTE(Observer, this);
                                PutClientInServer(this);
                        } else if(!SpectateUpdate(this) && !SpectateNext(this)) {
-                               PutObserverInServer(this);
+                               PutObserverInServer(this, false);
                                this.would_spectate = true;
                        }
                }
@@ -2319,7 +2318,7 @@ void ObserverOrSpectatorThink(entity this)
                        }
                }
                if(is_spec && !SpectateUpdate(this))
-                       PutObserverInServer(this);
+                       PutObserverInServer(this, false);
        }
        if (is_spec)
                this.flags |= FL_CLIENT | FL_NOTARGET;
@@ -2677,10 +2676,7 @@ void PlayerPostThink (entity this)
                                if (IS_PLAYER(this) && autocvar_sv_maxidle_playertospectator > 0)
                                {
                                        Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MOVETOSPEC_IDLING, this.netname, maxidle_time);
-                                       if (this.caplayer)
-                                               this.caplayer = 0;
-                                       this.lms_spectate_warning = 2; // TODO: mutator hook for players forcibly moved to spectator?
-                                       PutObserverInServer(this);
+                                       PutObserverInServer(this, true);
                                }
                                else
                                {
index 3199d155a9c853c17d82cf67b5c26c3d7b467fe1..2f7bfbb0b0e320605f20f296f080ecca7e6da240 100644 (file)
@@ -381,7 +381,7 @@ bool Spectate(entity this, entity pl);
 
 void ClientInit_Spawn();
 
-void PutObserverInServer(entity this);
+void PutObserverInServer(entity this, bool is_forced);
 
 void SetSpectatee(entity this, entity spectatee);
 void SetSpectatee_status(entity this, int spectatee_num);
index e87a2b11831c350714e352ddd436e08ade9ba6b7..9b29273a65b2f65edd5c2c3830e1230a64d20c29 100644 (file)
@@ -24,7 +24,7 @@ void ClientKill_Now_TeamChange(entity this)
        {
                if (blockSpectators)
                        Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
-               PutObserverInServer(this);
+               PutObserverInServer(this, false);
        }
        else
        {
index 5a9fae567589e695843c8702ff91ef11e0dea5ea..47e9f922abe4daf27b5f8e696b05ff87b908d654 100644 (file)
@@ -184,8 +184,7 @@ void GameCommand_allspec(int request, int argc)
                        string reason = argv(1);
                        int n = 0;
                        FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
-                               if (it.caplayer) it.caplayer = 0;
-                               PutObserverInServer(it);
+                               PutObserverInServer(it, true);
                                ++n;
                        });
                        if (n)   bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
@@ -1009,8 +1008,7 @@ void GameCommand_moveplayer(int request, int argc)
                                                string pl_name = playername(client.netname, client.team, false);
                                                if (!IS_SPEC(client) && !IS_OBSERVER(client))
                                                {
-                                                       if (client.caplayer) client.caplayer = 0;
-                                                       PutObserverInServer(client);
+                                                       PutObserverInServer(client, true);
 
                                                        successful = strcat(successful, (successful ? ", " : ""), pl_name);
                                                }
index f33fc4598e0f785f04a5138b27ebcab5b835125b..ee5d18a69157a9d6210bc211ed0f813748578442 100644 (file)
@@ -10,6 +10,7 @@
 /** called when a player becomes observer, after shared setup */
 #define EV_MakePlayerObserver(i, o) \
     /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+    /** is_forced */ i(bool, MUTATOR_ARGV_1_bool) \
     /**/
 MUTATOR_HOOKABLE(MakePlayerObserver, EV_MakePlayerObserver)