From: terencehill Date: Wed, 30 May 2018 12:44:23 +0000 (+0200) Subject: Merge branch 'master' into terencehill/min_spec_time X-Git-Tag: xonotic-v0.8.5~2067^2 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=bc50c2d7ca3e0a44ed1712400ef8e170e6df8210;hp=e95e817d04d9233dd9d3ce3f70f09de8379ed443 Merge branch 'master' into terencehill/min_spec_time --- diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index fff50d249..d706f8107 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1224,16 +1224,7 @@ void ClientConnect(entity this) JoinBestTeam(this, false); // if the team number is valid, keep it this.playerid = playerid_save; - if (autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) { - TRANSMUTE(Observer, this); - } else { - if (!teamplay || autocvar_g_balance_teams) { - TRANSMUTE(Player, this); - campaign_bots_may_start = true; - } else { - TRANSMUTE(Observer, this); // do it anyway - } - } + TRANSMUTE(Observer, this); PlayerStats_GameReport_AddEvent(sprintf("kills-%d", this.playerid)); @@ -2144,9 +2135,11 @@ void PrintWelcomeMessage(entity this) } } +const int MIN_SPEC_TIME = 1; bool joinAllowed(entity this) { if (CS(this).version_mismatch) return false; + if (time < CS(this).jointime + MIN_SPEC_TIME) return false; if (!nJoinAllowed(this, this)) return false; if (teamplay && lockteams) return false; if (ShowTeamSelection(this)) return false; @@ -2577,6 +2570,8 @@ void PlayerPreThink (entity this) PrintWelcomeMessage(this); if (IS_PLAYER(this)) { + if (IS_REAL_CLIENT(this) && time < CS(this).jointime + MIN_SPEC_TIME) + error("Client can't be spawned as player on connection!"); if(!PlayerThink(this)) return; } @@ -2585,6 +2580,20 @@ void PlayerPreThink (entity this) IntermissionThink(this); return; } + else if (IS_REAL_CLIENT(this) && !CS(this).autojoin_checked && time >= CS(this).jointime + MIN_SPEC_TIME) + { + CS(this).autojoin_checked = true; + // don't do this in ClientConnect + // many things can go wrong if a client is spawned as player on connection + if (MUTATOR_CALLHOOK(AutoJoinOnConnection, this) + || (!(autocvar_sv_spectate || autocvar_g_campaign || this.team_forced < 0) + && (!teamplay || autocvar_g_balance_teams))) + { + campaign_bots_may_start = true; + Join(this); + return; + } + } else if (IS_OBSERVER(this)) { ObserverThink(this); } diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index 7499ee8dd..72732037f 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -114,6 +114,7 @@ CLASS(Client, Object) ATTRIB(Client, cmd_floodtime, float, this.cmd_floodtime); ATTRIB(Client, wasplayer, bool, this.wasplayer); ATTRIB(Client, weaponorder_byimpulse, string, this.weaponorder_byimpulse); + ATTRIB(Client, autojoin_checked, bool, this.wasplayer); // networked cvars diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index d1ba087a2..ca3ce6fcc 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -27,6 +27,12 @@ MUTATOR_HOOKABLE(PutClientInServer, EV_PutClientInServer); /**/ MUTATOR_HOOKABLE(ForbidSpawn, EV_ForbidSpawn); +/** returns true if client should be put as player on connection */ +#define EV_AutoJoinOnConnection(i, o) \ + /** player */ i(entity, MUTATOR_ARGV_0_entity) \ + /**/ +MUTATOR_HOOKABLE(AutoJoinOnConnection, EV_AutoJoinOnConnection); + /** called when player spawns to determine whether to give them random start weapons. Return true to forbid giving them. */ #define EV_ForbidRandomStartWeapons(i, o) \ /** player */ i(entity, MUTATOR_ARGV_0_entity) \ diff --git a/qcsrc/server/mutators/mutator/gamemode_lms.qc b/qcsrc/server/mutators/mutator/gamemode_lms.qc index a57b2ae2d..eaacc0fb8 100644 --- a/qcsrc/server/mutators/mutator/gamemode_lms.qc +++ b/qcsrc/server/mutators/mutator/gamemode_lms.qc @@ -232,7 +232,10 @@ MUTATOR_HOOKFUNCTION(lms, ClientDisconnect) MUTATOR_HOOKFUNCTION(lms, MakePlayerObserver) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); + + if (!IS_PLAYER(player)) + return true; lms_RemovePlayer(player); return true; // prevent team reset @@ -242,9 +245,6 @@ MUTATOR_HOOKFUNCTION(lms, ClientConnect) { entity player = M_ARGV(0, entity); - TRANSMUTE(Player, player); - campaign_bots_may_start = true; - if(GameRules_scoring_add(player, LMS_LIVES, LMS_NewPlayerLives()) <= 0) { GameRules_scoring_add(player, LMS_RANK, 666); // mark as forced spectator for the hud code @@ -252,6 +252,13 @@ MUTATOR_HOOKFUNCTION(lms, ClientConnect) } } +MUTATOR_HOOKFUNCTION(lms, AutoJoinOnConnection) +{ + if(autocvar_g_campaign) + return false; + return true; +} + MUTATOR_HOOKFUNCTION(lms, PlayerPreThink) { entity player = M_ARGV(0, entity); @@ -381,7 +388,7 @@ MUTATOR_HOOKFUNCTION(lms, Bot_FixCount, CBC_ORDER_EXCLUSIVE) MUTATOR_HOOKFUNCTION(lms, ClientCommand_Spectate) { - entity player = M_ARGV(0, entity); + entity player = M_ARGV(0, entity); if(warmup_stage || player.lms_spectate_warning) {