From 769147e7c75b20c57fcc78a602b45d9824c66ec8 Mon Sep 17 00:00:00 2001 From: kremsy Date: Tue, 28 Jan 2014 17:12:23 +0100 Subject: [PATCH] small improvements --- application/core/Maps/MapManager.php | 1 + application/core/Players/Player.php | 65 +++++++++------------- application/core/Players/PlayerManager.php | 42 +++++++------- 3 files changed, 50 insertions(+), 58 deletions(-) diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index ad73b613..729934ad 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -10,6 +10,7 @@ use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\ManiaExchange\ManiaExchangeList; use ManiaControl\ManiaExchange\ManiaExchangeManager; +use ManiaControl\ManiaExchange\MXMapInfo; use ManiaControl\Players\Player; /** diff --git a/application/core/Players/Player.php b/application/core/Players/Player.php index 66ac78a4..f105df80 100644 --- a/application/core/Players/Player.php +++ b/application/core/Players/Player.php @@ -35,10 +35,6 @@ class Player { public $downloadRate = -1; public $uploadRate = -1; public $skins = null; - public $stateUpdateLatency; //TODO format? - public $stateUpdatePeriod; //TODO format? - public $latestNetworkActivity; //TODO format? - public $packetLossRate; //TODO format? public $maniaPlanetPlayDays = -1; //Flags details @@ -66,35 +62,30 @@ class Player { * @param \Maniaplanet\DedicatedServer\Structures\Player $mpPlayer */ public function __construct($mpPlayer) { - if(!$mpPlayer) { + if (!$mpPlayer) { $this->isConnected = false; return; } - $this->pid = $mpPlayer->playerId; - $this->login = $mpPlayer->login; - $this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName); - $this->path = $mpPlayer->path; - $this->language = $mpPlayer->language; - $this->avatar = $mpPlayer->avatar['FileName']; - $this->allies = $mpPlayer->allies; - $this->clubLink = $mpPlayer->clubLink; - $this->teamId = $mpPlayer->teamId; - $this->isOfficial = $mpPlayer->isInOfficialMode; - $this->ladderScore = $mpPlayer->ladderStats['PlayerRankings'][0]['Score']; - $this->ladderRank = $mpPlayer->ladderStats['PlayerRankings'][0]['Ranking']; - $this->ladderStats = $mpPlayer->ladderStats; - $this->maniaPlanetPlayDays = $mpPlayer->hoursSinceZoneInscription / 24; //TODO change - $this->ipAddress = $mpPlayer->iPAddress; - $this->clientVersion = $mpPlayer->clientVersion; - $this->downloadRate = $mpPlayer->downloadRate; - $this->uploadRate = $mpPlayer->uploadRate; - $this->skins = $mpPlayer->skins; - $this->stateUpdateLatency = $mpPlayer->stateUpdateLatency; - $this->stateUpdatePeriod = $mpPlayer->stateUpdatePeriod; - $this->latestNetworkActivity = $mpPlayer->latestNetworkActivity; - $this->packetLossRate = $mpPlayer->packetLossRate; - + $this->pid = $mpPlayer->playerId; + $this->login = $mpPlayer->login; + $this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName); + $this->path = $mpPlayer->path; + $this->language = $mpPlayer->language; + $this->avatar = $mpPlayer->avatar['FileName']; + $this->allies = $mpPlayer->allies; + $this->clubLink = $mpPlayer->clubLink; + $this->teamId = $mpPlayer->teamId; + $this->isOfficial = $mpPlayer->isInOfficialMode; + $this->ladderScore = $mpPlayer->ladderStats['PlayerRankings'][0]['Score']; + $this->ladderRank = $mpPlayer->ladderStats['PlayerRankings'][0]['Ranking']; + $this->ladderStats = $mpPlayer->ladderStats; + $this->maniaPlanetPlayDays = $mpPlayer->hoursSinceZoneInscription / 24; //TODO change + $this->ipAddress = $mpPlayer->iPAddress; + $this->clientVersion = $mpPlayer->clientVersion; + $this->downloadRate = $mpPlayer->downloadRate; + $this->uploadRate = $mpPlayer->uploadRate; + $this->skins = $mpPlayer->skins; //Flag Details $this->forcedSpectatorState = $mpPlayer->forceSpectator; @@ -114,10 +105,8 @@ class Player { $this->autoTarget = $mpPlayer->autoTarget; $this->currentTargetId = $mpPlayer->currentTargetId; - $this->joinTime = time(); - - if($this->nickname == '') { + if ($this->nickname == '') { $this->nickname = $this->login; } } @@ -139,7 +128,7 @@ class Player { */ public function getProvince() { $pathParts = explode('|', $this->path); - if(isset($pathParts[3])) { + if (isset($pathParts[3])) { return $pathParts[3]; } return $this->getCountry(); @@ -152,13 +141,13 @@ class Player { */ public function getCountry() { $pathParts = explode('|', $this->path); - if(isset($pathParts[2])) { + if (isset($pathParts[2])) { return $pathParts[2]; } - if(isset($pathParts[1])) { + if (isset($pathParts[1])) { return $pathParts[1]; } - if(isset($pathParts[0])) { + if (isset($pathParts[0])) { return $pathParts[0]; } return $this->path; @@ -171,10 +160,10 @@ class Player { */ public function getContinent() { $pathParts = explode('|', $this->path); - if(isset($pathParts[1])) { + if (isset($pathParts[1])) { return $pathParts[1]; } - if(isset($pathParts[0])) { + if (isset($pathParts[0])) { return $pathParts[0]; } return $this->path; diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 30e7a311..e5cbb83d 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -86,12 +86,12 @@ class PlayerManager implements CallbackListener { UNIQUE KEY `login` (`login`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player Data' AUTO_INCREMENT=1;"; $playerTableStatement = $mysqli->prepare($playerTableQuery); - if($mysqli->error) { + if ($mysqli->error) { trigger_error($mysqli->error, E_USER_ERROR); return false; } $playerTableStatement->execute(); - if($playerTableStatement->error) { + if ($playerTableStatement->error) { trigger_error($playerTableStatement->error, E_USER_ERROR); return false; } @@ -108,7 +108,7 @@ class PlayerManager implements CallbackListener { // Add all players $players = $this->maniaControl->client->getPlayerList(300, 0, 2); foreach($players as $playerItem) { - if($playerItem->playerId <= 0) { + if ($playerItem->playerId <= 0) { continue; } @@ -120,7 +120,9 @@ class PlayerManager implements CallbackListener { $playerItem->isSpectator = $detailedPlayerInfo->isSpectator; $playerItem->avatar = $detailedPlayerInfo->avatar; $playerItem->ladderStats = $detailedPlayerInfo->ladderStats; - + $playerItem->downloadRate = $detailedPlayerInfo->downloadRate; + $playerItem->uploadRate = $detailedPlayerInfo->uploadRate; + $playerItem->hoursSinceZoneInscription = $detailedPlayerInfo->hoursSinceZoneInscription; $player = new Player($playerItem); @@ -157,7 +159,7 @@ class PlayerManager implements CallbackListener { // Trigger own callback $this->maniaControl->callbackManager->triggerCallback(self::CB_PLAYERDISCONNECTED, array(self::CB_PLAYERDISCONNECTED, $player)); - if($player == null || $player->isFakePlayer()) { + if ($player == null || $player->isFakePlayer()) { return; } @@ -165,7 +167,7 @@ class PlayerManager implements CallbackListener { $logMessage = "Player left: {$player->login} / {$player->nickname} Playtime: {$played}"; $this->maniaControl->log(Formatter::stripCodes($logMessage)); - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) { $this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $s$0f0has left the game'); } } @@ -177,7 +179,7 @@ class PlayerManager implements CallbackListener { */ public function playerInfoChanged(array $callback) { $player = $this->getPlayer($callback[1][0]['Login']); - if($player == null) { + if ($player == null) { return; } @@ -190,8 +192,8 @@ class PlayerManager implements CallbackListener { $player->updateSpectatorStatus($callback[1][0]["SpectatorStatus"]); //Check if Player finished joining the game - if($player->hasJoinedGame && !$prevJoinState) { - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) { + if ($player->hasJoinedGame && !$prevJoinState) { + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES) && !$player->isFakePlayer()) { $string = array(0 => '$0f0Player', 1 => '$0f0Moderator', 2 => '$0f0Admin', 3 => '$0f0SuperAdmin', 4 => '$0f0MasterAdmin'); $chatMessage = '$s$0f0' . $string[$player->authLevel] . ' $fff' . $player->nickname . '$z$s$0f0 Nation:$fff ' . $player->getCountry() . ' $z$s$0f0joined!'; $this->maniaControl->chat->sendChat($chatMessage); @@ -231,7 +233,7 @@ class PlayerManager implements CallbackListener { public function getPlayerByIndex($index) { foreach($this->players as $player) { /** @var Player $player */ - if($player->index == $index) { + if ($player->index == $index) { return $player; } @@ -247,7 +249,7 @@ class PlayerManager implements CallbackListener { * @return \ManiaControl\Players\Player */ public function getPlayer($login) { - if(!isset($this->players[$login])) { + if (!isset($this->players[$login])) { return null; } return $this->players[$login]; @@ -273,12 +275,12 @@ class PlayerManager implements CallbackListener { * @return Player $player */ private function removePlayer($login, $savePlayedTime = true) { - if(!isset($this->players[$login])) { + if (!isset($this->players[$login])) { return null; } $player = $this->players[$login]; unset($this->players[$login]); - if($savePlayedTime) { + if ($savePlayedTime) { $this->updatePlayedTime($player); } return $player; @@ -294,13 +296,13 @@ class PlayerManager implements CallbackListener { private function getPlayerFromDatabaseByIndex($playerIndex) { $mysqli = $this->maniaControl->database->mysqli; - if(!is_numeric($playerIndex)) { + if (!is_numeric($playerIndex)) { return null; } $query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = " . $playerIndex . ";"; $result = $mysqli->query($query); - if(!$result) { + if (!$result) { trigger_error($mysqli->error); return null; } @@ -340,13 +342,13 @@ class PlayerManager implements CallbackListener { `nickname` = VALUES(`nickname`), `path` = VALUES(`path`);"; $playerStatement = $mysqli->prepare($playerQuery); - if($mysqli->error) { + if ($mysqli->error) { trigger_error($mysqli->error); return false; } $playerStatement->bind_param('sss', $player->login, $player->nickname, $player->path); $playerStatement->execute(); - if($playerStatement->error) { + if ($playerStatement->error) { trigger_error($playerStatement->error); $playerStatement->close(); return false; @@ -357,13 +359,13 @@ class PlayerManager implements CallbackListener { // Get Player Auth Level from DB $playerQuery = "SELECT `authLevel` FROM `" . self::TABLE_PLAYERS . "` WHERE `index` = ?;"; $playerStatement = $mysqli->prepare($playerQuery); - if($mysqli->error) { + if ($mysqli->error) { trigger_error($mysqli->error); return false; } $playerStatement->bind_param('i', $player->index); $playerStatement->execute(); - if($playerStatement->error) { + if ($playerStatement->error) { trigger_error($playerStatement->error); $playerStatement->close(); return false; @@ -384,7 +386,7 @@ class PlayerManager implements CallbackListener { * @return bool */ private function updatePlayedTime(Player $player) { - if(!$player) { + if (!$player) { return false; } $playedTime = time() - $player->joinTime;