]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
CA: Forbid spawning players in a more correct way, adding a hook for it; visually...
authorterencehill <piuntn@gmail.com>
Wed, 24 Aug 2016 11:41:12 +0000 (13:41 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 24 Aug 2016 11:41:12 +0000 (13:41 +0200)
qcsrc/server/client.qc
qcsrc/server/mutators/events.qh
qcsrc/server/mutators/mutator/gamemode_ca.qc

index ed2faee72dd7ed73e1ef21998c2703efc204f209..0c48324254d567bc20c2ede64e6f1df0544bca3c 100644 (file)
@@ -1698,7 +1698,7 @@ void SpectateCopy(entity this, entity spectatee)
 bool SpectateUpdate(entity this)
 {
        if(!this.enemy)
-           return false;
+               return false;
 
        if(!IS_PLAYER(this.enemy) || this == this.enemy)
        {
@@ -1861,12 +1861,8 @@ void ShowRespawnCountdown(entity this)
        }
 }
 
-.float caplayer;
-
 void LeaveSpectatorMode(entity this)
 {
-       if(this.caplayer)
-               return;
        if(nJoinAllowed(this, this))
        {
                if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0)
@@ -2009,8 +2005,9 @@ void ObserverThink(entity this)
                MinigameImpulse(this, this.impulse);
                this.impulse = 0;
        }
+
        if (this.flags & FL_JUMPRELEASED) {
-               if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
+               if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) {
                        this.flags &= ~FL_JUMPRELEASED;
                        this.flags |= FL_SPAWNING;
                } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) {
@@ -2049,8 +2046,9 @@ void SpectatorThink(entity this)
                        return;
                }
        }
+
        if (this.flags & FL_JUMPRELEASED) {
-               if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) {
+               if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) {
                        this.flags &= ~FL_JUMPRELEASED;
                        this.flags |= FL_SPAWNING;
                } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) {
index 7e40b1af1e80daba8461dba1e543dfddd9f3d4ff..c8c3415561248834da720ca1858b64c26c8469b0 100644 (file)
@@ -16,6 +16,14 @@ MUTATOR_HOOKABLE(MakePlayerObserver, EV_MakePlayerObserver)
     /**/
 MUTATOR_HOOKABLE(PutClientInServer, EV_PutClientInServer);
 
+/**
+ * return true to prevent a spectator/observer to spawn as player
+ */
+ #define EV_ForbidSpawn(i, o) \
+    /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(ForbidSpawn, EV_ForbidSpawn);
+
 /** called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here) */
 #define EV_PlayerSpawn(i, o) \
        /** player spawning */ i(entity, MUTATOR_ARGV_0_entity) \
index 75c9d600849934b9c2af6c408edea4fb35e63354..8dda62f0b29a6d689c486c5a90eaf847e5d2f4c0 100644 (file)
@@ -166,6 +166,22 @@ MUTATOR_HOOKFUNCTION(ca, PlayerSpawn)
                eliminatedPlayers.SendFlags |= 1;
 }
 
+MUTATOR_HOOKFUNCTION(ca, ForbidSpawn)
+{
+       entity player = M_ARGV(0, entity);
+
+       if (!allowed_to_spawn)
+       {
+               if (player.jointime != time && !player.caplayer) // not when connecting
+               {
+                       player.caplayer = 0.5;
+                       Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_JOIN_LATE);
+               }
+               return true;
+       }
+       return false;
+}
+
 MUTATOR_HOOKFUNCTION(ca, PutClientInServer)
 {
        entity player = M_ARGV(0, entity);