From 417873f0b1c599f833f65969e8713659396130a3 Mon Sep 17 00:00:00 2001 From: NewboO Date: Sat, 3 May 2014 19:53:34 +0200 Subject: [PATCH] Adaptation to new dedicated-api --- application/core/Maps/MapManager.php | 4 +- application/core/Players/Player.php | 69 ++++++++++++++-------- application/core/Players/PlayerManager.php | 25 +++----- application/core/Server/Server.php | 2 +- 4 files changed, 57 insertions(+), 43 deletions(-) diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index e6496296..686ec4ff 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -306,7 +306,7 @@ class MapManager implements CallbackListener { } else { // Write map via write file method try { - $this->maniaControl->client->writeFileFromString($relativeMapFileName, $file); + $this->maniaControl->client->writeFile($relativeMapFileName, $file); } catch (InvalidArgumentException $e) { if ($e->getMessage() == 'data are too big') { $this->maniaControl->chat->sendError("Map is too big for a remote save.", $login); @@ -720,4 +720,4 @@ class MapManager implements CallbackListener { return count($this->maps); } // TODO: add local map by filename -} +} diff --git a/application/core/Players/Player.php b/application/core/Players/Player.php index ce405551..1371cc2d 100644 --- a/application/core/Players/Player.php +++ b/application/core/Players/Player.php @@ -59,36 +59,29 @@ class Player { public $currentTargetId = 0; /** - * Construct a player from ManiaPlanet Player structure - * - * @param \Maniaplanet\DedicatedServer\Structures\Player $mpPlayer + * @param bool $connected */ - public function __construct($mpPlayer) { - if (!$mpPlayer) { - $this->isConnected = false; - return; - } + public function __construct($connected) + { + $this->isConnected = $connected; + if ($connected) { + $this->joinTime = time(); + } + } + + /** + * Update from ManiaPlanet PlayerInfo structure + * @param \Maniaplanet\DedicatedServer\Structures\PlayerInfo $mpPlayer + */ + public function setInfo($mpPlayer) + { $this->pid = $mpPlayer->playerId; $this->login = $mpPlayer->login; $this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName); $this->rawNickname = $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->daysSinceZoneInscription = $mpPlayer->hoursSinceZoneInscription / 24; - $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; @@ -108,7 +101,37 @@ class Player { $this->autoTarget = $mpPlayer->autoTarget; $this->currentTargetId = $mpPlayer->currentTargetId; - $this->joinTime = time(); + if (!$this->nickname) { + $this->nickname = $this->login; + } + } + + /** + * Update from ManiaPlanet PlayerDetailedInfo structure + * @param \Maniaplanet\DedicatedServer\Structures\PlayerDetailedInfo $mpPlayer + */ + public function setDetailedInfo($mpPlayer) + { + $this->pid = $mpPlayer->playerId; + $this->login = $mpPlayer->login; + $this->nickname = Formatter::stripDirtyCodes($mpPlayer->nickName); + $this->rawNickname = $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->daysSinceZoneInscription = $mpPlayer->hoursSinceZoneInscription / 24; + $this->ipAddress = $mpPlayer->iPAddress; + $this->clientVersion = $mpPlayer->clientVersion; + $this->downloadRate = $mpPlayer->downloadRate; + $this->uploadRate = $mpPlayer->uploadRate; + $this->skins = $mpPlayer->skins; if (!$this->nickname) { $this->nickname = $this->login; diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 2061a974..2ae124dd 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -116,26 +116,16 @@ class PlayerManager implements CallbackListener, TimerListener { if ($playerItem->playerId <= 0) { continue; } - - $detailedPlayerInfo = $this->maniaControl->client->getDetailedPlayerInfo($playerItem->login); - $playerItem->path = $detailedPlayerInfo->path; - $playerItem->language = $detailedPlayerInfo->language; - $playerItem->clientVersion = $detailedPlayerInfo->clientVersion; - $playerItem->iPAddress = $detailedPlayerInfo->iPAddress; - $playerItem->isSpectator = $detailedPlayerInfo->isSpectator; - $playerItem->avatar = $detailedPlayerInfo->avatar; - $playerItem->ladderStats = $detailedPlayerInfo->ladderStats; - $playerItem->downloadRate = $detailedPlayerInfo->downloadRate; - $playerItem->uploadRate = $detailedPlayerInfo->uploadRate; - - $playerItem->hoursSinceZoneInscription = $detailedPlayerInfo->hoursSinceZoneInscription; + $detailedPlayerInfo = $this->maniaControl->client->getDetailedPlayerInfo($playerItem->login); //Check if the Player is in a Team, to notify if its a TeamMode or not if ($playerItem->teamId != -1) { $this->maniaControl->server->setTeamMode(true); } - $player = new Player($playerItem); + $player = new Player(true); + $player->setInfo($playerItem); + $player->setDetailedInfo($detailedPlayerInfo); $player->hasJoinedGame = true; $this->addPlayer($player); } @@ -220,7 +210,8 @@ class PlayerManager implements CallbackListener, TimerListener { $login = $callback[1][0]; try { $playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login); - $player = new Player($playerInfo); + $player = new Player(true); + $player->setDetailedInfo($playerInfo); $this->addPlayer($player); } catch (LoginUnknownException $e) { @@ -381,7 +372,7 @@ class PlayerManager implements CallbackListener, TimerListener { return null; } - $player = new Player(null); + $player = new Player(false); $player->index = $row->index; $player->login = $row->login; $player->rawNickname = $row->nickname; @@ -482,7 +473,7 @@ class PlayerManager implements CallbackListener, TimerListener { return null; } - $player = new Player(null); + $player = new Player(false); $player->index = $playerIndex; $player->login = $row->login; $player->rawNickname = $row->nickname; diff --git a/application/core/Server/Server.php b/application/core/Server/Server.php index 61036c37..f948c314 100644 --- a/application/core/Server/Server.php +++ b/application/core/Server/Server.php @@ -275,7 +275,7 @@ class Server implements CallbackListener { /** * Get Server Player Info * - * @return \Maniaplanet\DedicatedServer\Structures\Player + * @return \Maniaplanet\DedicatedServer\Structures\PlayerInfo */ public function getInfo() { return $this->maniaControl->client->getMainServerPlayerInfo();