/** ClientUserinfo event. Perform team balance if needed. * This function is bound to the ClientUserinfo event. It performs a team balance if the AutoTeams is active (it can be activated in the config). * * \param $data The client data. * * \return Nothing. */ public function SrvEventClientUserinfoChanged($id, $data) { $player = Server::getPlayer($id); $servername = Server::getName(); $gametype = Server::getServer()->serverInfo['g_gametype']; // Only if is a team change userInfoChanged if ($this->config[$servername]['AutoTeams'] && $data['t'] != $player->team && !in_array($gametype, array(Server::GAME_FFA, Server::GAME_LMS))) { if (!array_key_exists($servername, $this->_ClientUserinfoChangedIgnore)) { $this->_ClientUserinfoChangedIgnore[$servername] = array(); } // Only if _balance() haven't add this player in ignore list if (!in_array($id, $this->_ClientUserinfoChangedIgnore[$servername])) { $teams_count = Server::getTeamCount(); if ($player->team == Server::TEAM_SPEC) { if ($data['t'] == Server::TEAM_BLUE) { $otherteam = Server::TEAM_RED; } elseif ($data['t'] == Server::TEAM_RED) { $otherteam = Server::TEAM_BLUE; } // if player haven't use auto join and go to wrong team if ($teams_count[$data['t']] > $teams_count[$otherteam]) { $teams = array(1 => 'red', 2 => 'blue', 3 => 'spectator'); Rcon::forceteam($player->id, $teams[$otherteam]); Rcon::tell($player->id, 'Please use autojoin.'); return TRUE; } } elseif ($player->team != Server::TEAM_SPEC && $data['t'] != Server::TEAM_SPEC) { if ($player->team == Server::TEAM_BLUE) { $otherteam = Server::TEAM_RED; } elseif ($player->team == Server::TEAM_RED) { $otherteam = Server::TEAM_BLUE; } // If the player wants to go to the team with the highest number of players. if ($teams_count[$otherteam] >= $teams_count[$player->team]) { // No balance and force player in his team $teams = array(1 => 'red', 2 => 'blue', 3 => 'spectator'); Rcon::forceteam($player->id, $teams[$player->team]); Rcon::tell($player->id, 'Please stay in your team.'); return TRUE; } } else { $this->_BalanceNeeded[$servername] = TRUE; } } else { unset($this->_ClientUserinfoChangedIgnore[$servername][$id]); } } }