本文整理汇总了PHP中Server::getTeamName方法的典型用法代码示例。如果您正苦于以下问题:PHP Server::getTeamName方法的具体用法?PHP Server::getTeamName怎么用?PHP Server::getTeamName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server::getTeamName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _balance
/** Balances teams.
* This function balances the teams according to the arrival order of the players.
* It is executed on new connections and when a player changes team (if AutoTeams is enabled in plugin config).
* It only changes the team of new players.
*
* \param $player The player who send the command. (if is player has send command)
*
* \return Nothing.
*/
private function _balance($player = null)
{
//We take player count of each team.
$teams_count = Server::getTeamCount();
if ($teams_count[Server::TEAM_RED] >= $teams_count[Server::TEAM_BLUE] + 2) {
$too_many_player = floor(($teams_count[Server::TEAM_RED] - $teams_count[Server::TEAM_BLUE]) / 2);
$src_team = Server::TEAM_RED;
$dest_team = strtolower(Server::getTeamName(Server::TEAM_BLUE));
$balance = TRUE;
} elseif ($teams_count[Server::TEAM_BLUE] >= $teams_count[Server::TEAM_RED] + 2) {
$too_many_player = floor(($teams_count[Server::TEAM_BLUE] - $teams_count[Server::TEAM_RED]) / 2);
$src_team = Server::TEAM_BLUE;
$dest_team = strtolower(Server::getTeamName(Server::TEAM_RED));
$balance = TRUE;
} else {
$balance = FALSE;
}
//If the teams are unbalanced
if ($balance) {
//We get player list
$players = Server::getPlayerList($src_team);
$last = array();
foreach ($players as $player) {
$last[$player->time] = $player->id;
}
//We sorts the players of the team by time spent on the server.
krsort($last);
//Processing loop
while ($too_many_player > 0) {
//We take the last player of the team
$player = array_shift($last);
//Add on ClientUserinfoChanged ignore list
$this->_ClientUserinfoChangedIgnore[$player] = $player;
//We change the team of the player
RCon::forceteam($player, $dest_team);
--$too_many_player;
}
RCon::say('Teams are now balanced');
} else {
if ($player !== NULL) {
RCon::tell($player, 'Teams are already balanced');
}
}
}
示例2: step
/** Executes a step of parsing.
* This function executes a step of parsing, i.e. reads the log, parses the read lines and calls the adapted events.
*
* \return TRUE if all gone correctly, FALSE otherwise.
*/
public function step()
{
$time = time();
if (!$this->_enabled || $this->_hold && $time == $this->_lastRead) {
return TRUE;
}
if ($this->_shutdownTime !== FALSE && $time - 10 > $this->_shutdownTime && !empty($this->players)) {
//Properly sending the events, allowing plugins to perform their actions.
foreach ($this->players as $id => $player) {
$this->_leelabot->plugins->callServerEvent('ClientDisconnect', $id);
}
$this->players = array();
Leelabot::message('Deleted player data for server $0', array($this->_name), E_DEBUG);
}
$this->_lastRead = time();
$data = $this->readLog();
if ($data) {
$data = explode("\n", trim($data, "\n"));
foreach ($data as $line) {
//Parsing line for event and arguments
$line = substr($line, 7);
//Remove the time (todo : see if elapsed time for the map is useful (more than when we count it ourselves))
Leelabot::printText('[' . $this->_name . '] ' . $line);
$line = explode(':', $line, 2);
if (isset($line[1])) {
$line[1] = trim($line[1]);
}
switch ($line[0]) {
//A client connects
case 'ClientConnect':
$id = intval($line[1]);
$this->players[$id] = new Storage(array('id' => $id, 'begin' => FALSE, 'team' => Server::TEAM_SPEC, 'level' => $this->_defaultLevel, 'time' => time(), 'uuid' => Leelabot::UUID()));
Leelabot::message('Client connected: $0', array($id), E_DEBUG);
$this->_leelabot->plugins->callServerEvent('ClientConnect', $id);
break;
//A client has disconnected
//A client has disconnected
case 'ClientDisconnect':
$id = intval($line[1]);
$this->_leelabot->plugins->callServerEvent('ClientDisconnect', $id);
Leelabot::message('Client disconnected: $0', array($id), E_DEBUG);
unset($this->players[$id]);
break;
//The client has re-sent his personal info (like credit name, weapons, weapmodes, card number)
//The client has re-sent his personal info (like credit name, weapons, weapmodes, card number)
case 'ClientUserinfo':
list($id, $infostr) = explode(' ', $line[1], 2);
$userinfo = Server::parseInfo($infostr);
Leelabot::message('Client send user info: $0', array($id), E_DEBUG);
Leelabot::message(' Name: $0', array($userinfo['name']), E_DEBUG);
//Basically it's a copypasta of the code user above for initial data storage
if (isset($userinfo['characterfile'])) {
$playerData['isBot'] = TRUE;
Leelabot::message(' Is a bot.', array(), E_DEBUG);
} else {
$playerData['isBot'] = FALSE;
$address = explode(':', $userinfo['ip']);
$playerData['addr'] = $address[0];
$playerData['port'] = $address[1];
$playerData['guid'] = $userinfo['cl_guid'];
Leelabot::message(' GUID: $0', array($playerData['guid']));
Leelabot::message(' IP: $0', array($playerData['addr']));
}
$playerData['name'] = preg_replace('#^[0-9]#', '', $userinfo['name']);
$playerData['id'] = $id;
$this->_leelabot->plugins->callServerEvent('ClientUserinfo', array($id, $userinfo));
$this->players[$id]->merge($playerData);
//Binding IP pointer
if (!isset($this->players[$id]->ip)) {
$this->players[$id]->ip =& $this->players[$id]->addr;
}
if (!isset($this->players[$id]->other)) {
$this->players[$id]->other = $userinfo;
} else {
$this->players[$id]->other = array_merge($this->players[$id]->other, $userinfo);
}
break;
//Change in client userinfo, useful for gathering teams
//Change in client userinfo, useful for gathering teams
case 'ClientUserinfoChanged':
list($id, $infostr) = explode(' ', $line[1], 2);
$userinfo = Server::parseInfo($infostr);
Leelabot::message('Client has send changed user info: $0', array($id), E_DEBUG);
Leelabot::message(' Name: $0', array($userinfo['n']), E_DEBUG);
Leelabot::message(' Team: $0', array(Server::getTeamName($userinfo['t'])), E_DEBUG);
$this->_leelabot->plugins->callServerEvent('ClientUserinfoChanged', array($id, $userinfo));
$this->players[$id]->team = $userinfo['t'];
$this->players[$id]->other['cg_rgb'] = $userinfo['a0'] . ' ' . $userinfo['a1'] . ' ' . $userinfo['a2'];
$this->players[$id]->name = preg_replace('#^[0-9]#', '', $userinfo['n']);
break;
//Player start to play
//Player start to play
case 'ClientBegin':
$id = intval($line[1]);
Leelabot::message('Client has begun: $0', array($id), E_DEBUG);
//.........这里部分代码省略.........
示例3: SrvEventClientUserinfoChanged
/** Client user info change : notify it in the connection log.
* This function is triggered by the ClientUserinfoChanged event. It will log his data in the connection log if necessary.
*
* \param $id The player's ID.
* \param $userinfo The player's user info.
*
* \return Nothing.
*/
public function SrvEventClientUserinfoChanged($id, $userinfo)
{
$player = Server::getPlayer($id);
$this->log('connection', 'Player ' . $player->name . ' <' . $player->uuid . '> changed :');
$this->log('connection', "\tName: " . $userinfo['n']);
$this->log('connection', "\tTeam: " . Server::getTeamName($userinfo['t']));
}