From 3e5934b9b3f86a9ca16d40762b781446bfc97040 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Oct 2015 23:48:38 +1000 Subject: [PATCH] Kill another gamemode specific check --- qcsrc/server/command/cmd.qc | 26 +++++--------------------- qcsrc/server/mutators/events.qh | 11 +++++++++++ qcsrc/server/mutators/gamemode_ca.qc | 13 +++++++++++++ qcsrc/server/mutators/gamemode_lms.qc | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index ddfbe5795..dbb9e1a48 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -465,29 +465,13 @@ void ClientCommand_spectate(float request) { if(IS_CLIENT(self)) { - if(g_lms) - { - if(self.lms_spectate_warning) - { - // for the forfeit message... - self.lms_spectate_warning = 2; - // mark player as spectator - PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0)); - } - else - { - self.lms_spectate_warning = 1; - sprint(self, "WARNING: you won't be able to enter the game again after spectating in LMS. Use the same command again to spectate anyway.\n"); - return; - } - } + int mutator_returnvalue = MUTATOR_CALLHOOK(ClientCommand_Spectate, self); - if((IS_PLAYER(self) || self.caplayer) && autocvar_sv_spectate == 1) - { - if(self.caplayer && (IS_SPEC(self) || IS_OBSERVER(self))) - Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_CA_LEAVE); + if(mutator_returnvalue == MUT_SPECCMD_RETURN) + return; + + if((IS_PLAYER(self) || mutator_returnvalue == MUT_SPECCMD_FORCE) && autocvar_sv_spectate == 1) ClientKill_TeamChange(-2); // observe - } } return; // never fall through to usage } diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 04ac5c28f..7852b0ad8 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -703,4 +703,15 @@ enum { int bot_activerealplayers; int bot_realplayers; MUTATOR_HOOKABLE(Bot_FixCount, EV_Bot_FixCount); + +#define EV_ClientCommand_Spectate(i, o) \ + /**/ i(entity, __self) \ + /**/ +MUTATOR_HOOKABLE(ClientCommand_Spectate, EV_ClientCommand_Spectate); + +enum { + MUT_SPECCMD_CONTINUE, // return this flag to make the function continue as normal + MUT_SPECCMD_RETURN, // return this flag to make the function return (don't spectate) + MUT_SPECCMD_FORCE // return this flag to force the player to spectate, even if they're not a player +}; #endif diff --git a/qcsrc/server/mutators/gamemode_ca.qc b/qcsrc/server/mutators/gamemode_ca.qc index eb8831187..8881ab2ee 100644 --- a/qcsrc/server/mutators/gamemode_ca.qc +++ b/qcsrc/server/mutators/gamemode_ca.qc @@ -443,6 +443,19 @@ MUTATOR_HOOKFUNCTION(ca, Bot_FixCount, CBC_ORDER_EXCLUSIVE) return true; } +MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate) +{ + if(self.caplayer) + { + // they're going to spec, we can do other checks + if(autocvar_sv_spectate && (IS_SPEC(self) || IS_OBSERVER(self))) + Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_CA_LEAVE); + return MUT_SPECCMD_FORCE; + } + + return MUT_SPECCMD_CONTINUE; +} + void ca_Initialize() { allowed_to_spawn = true; diff --git a/qcsrc/server/mutators/gamemode_lms.qc b/qcsrc/server/mutators/gamemode_lms.qc index e9297d88b..c065e7a96 100644 --- a/qcsrc/server/mutators/gamemode_lms.qc +++ b/qcsrc/server/mutators/gamemode_lms.qc @@ -212,6 +212,24 @@ MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE) return true; } +MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate) +{ + if(self.lms_spectate_warning) + { + // for the forfeit message... + self.lms_spectate_warning = 2; + // mark player as spectator + PlayerScore_Add(self, SP_LMS_RANK, 666 - PlayerScore_Add(self, SP_LMS_RANK, 0)); + } + else + { + self.lms_spectate_warning = 1; + sprint(self, "WARNING: you won't be able to enter the game again after spectating in LMS. Use the same command again to spectate anyway.\n"); + return MUT_SPECCMD_RETURN; + } + return MUT_SPECCMD_CONTINUE; +} + // scoreboard stuff void lms_ScoreRules() { -- 2.39.2