From: bones_was_here Date: Wed, 5 May 2021 10:04:05 +0000 (+1000) Subject: Refactor SetPlayerTeam() and fix some logic regressions X-Git-Tag: xonotic-v0.8.5~419^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e4ad6899ea71b0b94c00b079477daac85e8d2fa2;p=xonotic%2Fxonotic-data.pk3dir.git Refactor SetPlayerTeam() and fix some logic regressions --- diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 5877bb37d..11509b542 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -209,19 +209,31 @@ bool Player_SetTeamIndex(entity player, int index) bool SetPlayerTeam(entity player, int team_index, int type) { int old_team_index = Entity_GetTeamIndex(player); + if (!Player_SetTeamIndex(player, team_index)) - { return false; - } + LogTeamChange(player.playerid, player.team, type); + + if (team_index != old_team_index) + { + KillPlayerForTeamChange(player); + PlayerScore_Clear(player); + CS(player).parm_idlesince = time; + + if (!IS_BOT_CLIENT(player)) + TeamBalance_AutoBalanceBots(); + + if (team_index != -1) + Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(player.team, INFO_JOIN_PLAY_TEAM), player.netname); + } + if (team_index == -1) { if (autocvar_sv_maxidle_playertospectator > 0 && CS(player).idlekick_lasttimeleft) { - // centerprint is killed and timestamps are reset here to ensure - // it's done even when manually speccing during the countdown + // this done here so it happens even when manually speccing during the countdown Kill_Notification(NOTIF_ONE_ONLY, player, MSG_CENTER, CPID_IDLING); - CS(player).parm_idlesince = time; CS(player).idlekick_lasttimeleft = 0; } else if (!CS(player).just_joined && player.frags != FRAGS_SPECTATOR) @@ -229,16 +241,7 @@ bool SetPlayerTeam(entity player, int team_index, int type) Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_QUIT_SPECTATE, player.netname); } } - else if (team_index != old_team_index) - { - PlayerScore_Clear(player); - Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(player.team, INFO_JOIN_PLAY_TEAM), player.netname); - KillPlayerForTeamChange(player); - if (!IS_BOT_CLIENT(player)) - { - TeamBalance_AutoBalanceBots(); - } - } + return true; }