code improvements

This commit is contained in:
Steffen Schröder 2013-12-31 15:27:25 +01:00
parent 42384ebd75
commit 32624e0946

View File

@ -57,9 +57,10 @@ class PlayerManager implements CallbackListener {
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this, 'playerInfoChanged');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
'playerDisconnect');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERINFOCHANGED, $this,
'playerInfoChanged');
}
/**
@ -133,18 +134,17 @@ class PlayerManager implements CallbackListener {
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) {
$string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
//$nickname = Formatter::stripCodes($player->nickname); // TODO: strip codes without colour codes like in serverviewer
//TODO standart notification colour from settings or something
$this->maniaControl->chat->sendChat(
'$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined');
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION,$player->login);
$chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' .
$player->getCountry() . ' $z$s$0f0joined!';
$this->maniaControl->chat->sendChat($chatMessage);
$this->maniaControl->chat->sendInformation('This server uses ManiaControl v' . ManiaControl::VERSION . '!', $player->login);
}
$this->maniaControl->log('Player joined: ' . $player->login . " / " . Formatter::stripCodes($player->nickname) . " Nation:" . $player->getCountry() . " IP: " .$player->ipAddress);
$logMessage = "Player joined: {$player->login} / " . Formatter::stripCodes($player->nickname) . " Nation: " .
$player->getCountry() . " IP: {$player->ipAddress}";
$this->maniaControl->log($logMessage);
// Trigger own callback
// Trigger own PlayerJoined callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERJOINED, array(self::CB_PLAYERJOINED, $player));
}
@ -160,13 +160,11 @@ class PlayerManager implements CallbackListener {
// Trigger own callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECTED, array(self::CB_PLAYERDISCONNECTED, $player));
if($player == null || $player->isFakePlayer())
return;
if ($player == null || $player->isFakePlayer()) return;
$played = Formatter::formatTimeH(time() - $player->joinTime);
$this->maniaControl->log("Player left: " . $player->login . " / " . Formatter::stripCodes($player->nickname) . " Playtime: " . $played);
$this->maniaControl->log(
"Player left: " . $player->login . " / " . Formatter::stripCodes($player->nickname) . " Playtime: " . $played);
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game');
@ -175,12 +173,12 @@ class PlayerManager implements CallbackListener {
/**
* Update PlayerInfo
*
* @param array $callback
*/
public function playerInfoChanged(array $callback) {
$player = $this->getPlayer($callback[1][0]['Login']);
if($player == null)
return;
if ($player == null) return;
$player->teamId = $callback[1][0]["TeamId"];
$player->isSpectator = $callback[1][0]["SpectatorStatus"];