]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix kicked player not receiving the kick message (if sent with Send_Notification)
authorterencehill <piuntn@gmail.com>
Tue, 11 May 2021 13:45:26 +0000 (15:45 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 11 May 2021 13:45:26 +0000 (15:45 +0200)
qcsrc/common/mutators/mutator/kick_teamkiller/sv_kick_teamkiller.qc
qcsrc/server/client.qc
qcsrc/server/main.qc
qcsrc/server/main.qh

index d91546af5711fcfa9b9848202cc7c775c3aca151..f8e364fddca307cab249b853f72c8ec3ac6921a5 100644 (file)
@@ -28,7 +28,7 @@ MUTATOR_HOOKFUNCTION(kick_teamkiller, PlayerDies)
        if (teamkills >= autocvar_g_kick_teamkiller_lower_limit &&
            teamkills >= autocvar_g_kick_teamkiller_rate*playtime/60.0)
        {
-               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_KICK_TEAMKILL, attacker.netname);
-               dropclient(attacker);
+               if (dropclient_schedule(attacker))
+                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_KICK_TEAMKILL, attacker.netname);
        }
 }
index 01426367afebdb31c6419dfe3308cd10a60c1b3e..7d3c1faca69520d5faa995bcfa443259d4ba668a 100644 (file)
@@ -2458,9 +2458,8 @@ void PlayerPreThink (entity this)
                        && (IS_SPEC(this) || IS_OBSERVER(this)) && !this.caplayer
                        && time > (CS(this).spectatortime + autocvar_g_maxplayers_spectator_blocktime))
                {
-                       Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
-                       dropclient(this);
-                       return;
+                       if (dropclient_schedule(this))
+                               Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_QUIT_KICK_SPECTATING);
                }
        }
 
@@ -2747,8 +2746,8 @@ void PlayerPostThink (entity this)
                                }
                                else
                                {
-                                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_KICK_IDLING, this.netname, maxidle_time);
-                                       dropclient(this);
+                                       if (dropclient_schedule(this))
+                                               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_KICK_IDLING, this.netname, maxidle_time);
                                }
                                return;
                        }
index 13574bf0edcf2347f87610da627a7f6c8ff40e6b..73f473ae979752c412265e06e3bf596daf66dee8 100644 (file)
 #include <server/weapons/csqcprojectile.qh>
 #include <server/world.qh>
 
+void dropclient_do(entity this)
+{
+       if (this.owner)
+               dropclient(this.owner);
+       delete(this);
+}
+/**
+ * Schedules dropclient for a player and returns true;
+ * if dropclient is already scheduled (for that player) it does nothing and returns false.
+ *
+ * NOTE: this function exists only to allow sending a message to the kicked player with
+ * Send_Notification, which doesn't work if called together with dropclient
+ */
+bool dropclient_schedule(entity this)
+{
+       bool scheduled = false;
+       FOREACH_ENTITY_CLASS("dropclient_handler", true,
+       {
+               if(it.owner == this)
+               {
+                       scheduled = true;
+                       break; // can't use return here, compiler shows a warning
+               }
+       });
+       if (scheduled)
+               return false;
+
+       entity e = new_pure(dropclient_handler);
+       setthink(e, dropclient_do);
+       e.owner = this;
+       e.nextthink = time + 0.1;
+       return true;
+}
+
 void CreatureFrame_hotliquids(entity this)
 {
        if (this.contents_damagetime >= time)
index 0685ca71f37d6a6bff68b5b11ddbe4402d816f99..e189601a7c467cf9f757616fbc9ada286c9d62ae 100644 (file)
@@ -16,6 +16,8 @@ bool autocvar_g_balance_falldamage_onlyvertical;
 #define autocvar_slowmo cvar("slowmo")
 float autocvar_sys_ticrate;
 
+bool dropclient_schedule(entity this);
+
 /** print(), but only print if the server is not local */
 void dedicated_print(string input);