From 0c6d8c010cb0fada5b6af7b4772d92f4c59a336c Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 16 Jan 2014 19:07:00 +0100 Subject: [PATCH] changes for new structure --- .../ManiaExchange/ManiaExchangeManager.php | 5 +-- .../core/Manialinks/ManialinkManager.php | 4 +- application/core/Maps/MapCommands.php | 7 ++-- application/core/Maps/MapList.php | 2 +- application/core/Maps/MapQueue.php | 6 +-- application/core/Players/Player.php | 40 ++++++++++--------- application/core/Players/PlayerActions.php | 26 ++++++------ application/core/Players/PlayerManager.php | 2 +- application/plugins/Donations.php | 9 ++--- 9 files changed, 49 insertions(+), 52 deletions(-) diff --git a/application/core/ManiaExchange/ManiaExchangeManager.php b/application/core/ManiaExchange/ManiaExchangeManager.php index 6f319ba7..0f45b5fe 100644 --- a/application/core/ManiaExchange/ManiaExchangeManager.php +++ b/application/core/ManiaExchange/ManiaExchangeManager.php @@ -233,10 +233,9 @@ class ManiaExchangeManager { $titlePrefix = strtolower(substr($titleId, 0, 2)); // Get MapTypes - $this->maniaControl->client->query('GetModeScriptInfo'); - $scriptInfos = $this->maniaControl->client->getResponse(); + $scriptInfos = $this->maniaControl->client->getModeScriptInfo(); - $mapTypes = $scriptInfos["CompatibleMapTypes"]; + $mapTypes = $scriptInfos->compatibleMapTypes; // compile search URL $url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on'; diff --git a/application/core/Manialinks/ManialinkManager.php b/application/core/Manialinks/ManialinkManager.php index 1976ddd4..8b4b169b 100644 --- a/application/core/Manialinks/ManialinkManager.php +++ b/application/core/Manialinks/ManialinkManager.php @@ -133,12 +133,12 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener return $this->maniaControl->client->sendDisplayManialinkPage(null, $manialinkText, $timeout, $hideOnClick); } if(is_string($logins)) { - return $this->maniaControl->client->sendDisplayManialinkPage(null, $logins, $manialinkText, $timeout, $hideOnClick); + return $this->maniaControl->client->sendDisplayManialinkPage($logins, $manialinkText, $timeout, $hideOnClick); } if(is_array($logins)) { $success = true; foreach($logins as $login) { - $subSuccess = $this->maniaControl->client->sendDisplayManialinkPage(null, $login, $manialinkText, $timeout, $hideOnClick); + $subSuccess = $this->maniaControl->client->sendDisplayManialinkPage($login, $manialinkText, $timeout, $hideOnClick); if(!$subSuccess) { $success = false; } diff --git a/application/core/Maps/MapCommands.php b/application/core/Maps/MapCommands.php index 8977adf7..9e9dba9d 100644 --- a/application/core/Maps/MapCommands.php +++ b/application/core/Maps/MapCommands.php @@ -105,8 +105,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb $map = $nextQueued[1]; $this->maniaControl->chat->sendInformation("Next map is $<" . $map->name . "$> from $<" . $map->authorNick . "$> requested by $<" . $requester->nickname . "$>.", $player->login); } else { - $this->maniaControl->client->query('GetNextMapIndex'); - $mapIndex = $this->maniaControl->client->getResponse(); + $mapIndex = $this->maniaControl->client->getNextMapIndex(); $maps = $this->maniaControl->mapManager->getMaps(); $map = $maps[$mapIndex]; $this->maniaControl->chat->sendInformation("Next map is $<" . $map->name . "$> from $<" . $map->authorNick . "$>.", $player->login); @@ -186,7 +185,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb $message = '$<' . $player->nickname . '$> skipped the current Map!'; $this->maniaControl->chat->sendSuccess($message); $this->maniaControl->log($message, true); - $this->maniaControl->client->query('NextMap'); + $this->maniaControl->client->nextMap(); } /** @@ -203,7 +202,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb $message = '$<' . $player->nickname . '$> restarted the current Map!'; $this->maniaControl->chat->sendSuccess($message); $this->maniaControl->log($message, true); - $this->maniaControl->client->query('RestartMap'); + $this->maniaControl->client->restartMap(); } /** diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index 200a393d..74732b8f 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -727,7 +727,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { $this->showMapList($player); break; case self::ACTION_SWITCH_MAP: - $this->maniaControl->client->query('JumpToMapIndex', $mapId); + $this->maniaControl->client->jumpToMapIndex($mapId); $mapList = $this->maniaControl->mapManager->getMaps(); $map = $mapList[$mapId]; diff --git a/application/core/Maps/MapQueue.php b/application/core/Maps/MapQueue.php index 9582d96a..2fac1d76 100644 --- a/application/core/Maps/MapQueue.php +++ b/application/core/Maps/MapQueue.php @@ -153,9 +153,9 @@ class MapQueue implements CallbackListener, CommandListener { $map = $this->nextMap[1]; - $success = $this->maniaControl->client->query('ChooseNextMap', $map->fileName); - if(!$success) { - trigger_error('[' . $this->maniaControl->client->getErrorCode() . '] ChooseNextMap - ' . $this->maniaControl->client->getErrorCode(), E_USER_WARNING); + $success = $this->maniaControl->client->chooseNextMap($map->fileName); + if(!$success) { //TODO error code? + //trigger_error('[' . $this->maniaControl->client->getErrorCode() . '] ChooseNextMap - ' . $this->maniaControl->client->getErrorCode(), E_USER_WARNING); return; } } diff --git a/application/core/Players/Player.php b/application/core/Players/Player.php index 8b9e4c65..393e55d8 100644 --- a/application/core/Players/Player.php +++ b/application/core/Players/Player.php @@ -36,30 +36,32 @@ class Player { /** * Construct a player from XmlRpc data * - * @param array $rpcInfos + * @param \Maniaplanet\DedicatedServer\Structures\Player $mpPlayer */ - public function __construct(array $rpcInfos) { - if(!$rpcInfos) { + public function __construct($mpPlayer) { + if(!$mpPlayer) { return; } - $this->pid = $rpcInfos['PlayerId']; - $this->login = $rpcInfos['Login']; - $this->nickname = Formatter::stripDirtyCodes($rpcInfos['NickName']); - $this->path = $rpcInfos['Path']; - $this->language = $rpcInfos['Language']; - $this->avatar = $rpcInfos['Avatar']['FileName']; - $this->allies = $rpcInfos['Allies']; - $this->clubLink = $rpcInfos['ClubLink']; - $this->teamId = $rpcInfos['TeamId']; - $this->isSpectator = $rpcInfos['IsSpectator']; - $this->isOfficial = $rpcInfos['IsInOfficialMode']; - $this->isReferee = $rpcInfos['IsReferee']; - $this->ladderScore = $rpcInfos['LadderStats']['PlayerRankings'][0]['Score']; - $this->ladderRank = $rpcInfos['LadderStats']['PlayerRankings'][0]['Ranking']; - $this->maniaPlanetPlayDays = $rpcInfos['HoursSinceZoneInscription'] / 24; + $rpcInfos = (array)$mpPlayer; //Temporary - $this->ipAddress = $rpcInfos['IPAddress']; + $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->isSpectator = $mpPlayer->isSpectator; + $this->isOfficial = $mpPlayer->isInOfficialMode; + $this->isReferee = $mpPlayer->isReferee; + $this->ladderScore = $mpPlayer->ladderStats['PlayerRankings'][0]['Score']; + $this->ladderRank = $mpPlayer->ladderStats['PlayerRankings'][0]['Ranking']; + $this->maniaPlanetPlayDays = $mpPlayer->hoursSinceZoneInscription / 24; + + $this->ipAddress = $mpPlayer->iPAddress; $this->joinTime = time(); diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index 97545295..416b3ef9 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -82,14 +82,14 @@ class PlayerActions { return; } - $success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER); + $success = $this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER); if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; } if($userIsAbleToSelect) { - $success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_USER_SELECTABLE); + $success = $this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE); if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; @@ -125,7 +125,7 @@ class PlayerActions { $this->forcePlayerToPlay($adminLogin, $targetLogin, true, false); } - $success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId); + $success = $this->maniaControl->client->forcePlayerTeam($target->login, $teamId); if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; @@ -161,7 +161,7 @@ class PlayerActions { } $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $success = $this->maniaControl->client->query('ForceSpectator', $target->login, $spectatorState); + $success = $this->maniaControl->client->forceSpectator($target->login, $spectatorState); if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; @@ -174,7 +174,7 @@ class PlayerActions { if($releaseSlot) { // Free player slot - $this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login); + $this->maniaControl->client->spectatorReleasePlayerSlot($target->login); } } @@ -194,7 +194,7 @@ class PlayerActions { $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $success = $this->maniaControl->client->query('UnIgnore', $target->login); + $success = $this->maniaControl->client->unIgnore($target->login); if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; @@ -222,7 +222,7 @@ class PlayerActions { $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $success = $this->maniaControl->client->query('Ignore', $targetLogin); + $success = $this->maniaControl->client->ignore($targetLogin); if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; @@ -333,9 +333,9 @@ class PlayerActions { } if($target->isFakePlayer()) { - $success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login); + $success = $this->maniaControl->client->disconnectFakePlayer($target->login); } else { - $success = $this->maniaControl->client->query('Kick', $target->login, $message); + $success = $this->maniaControl->client->kick($target->login, $message); } if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); @@ -367,7 +367,7 @@ class PlayerActions { return; } - $success = $this->maniaControl->client->query('Ban', $target->login, $message); + $success = $this->maniaControl->client->ban($target->login, $message); if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); return; @@ -462,9 +462,9 @@ class PlayerActions { * @return bool */ public function isPlayerMuted($login) { - $this->maniaControl->client->query('GetIgnoreList', 100, 0); - foreach($this->maniaControl->client->getResponse() as $ignoredPlayers) { - if($ignoredPlayers["Login"] == $login) { + $ignoreList = $this->maniaControl->client->getIgnoreList(100, 0); + foreach($ignoreList as $ignoredPlayers) { + if($ignoredPlayers->login == $login) { return true; } } diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index bfc21b3e..b323fc7e 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -117,7 +117,7 @@ class PlayerManager implements CallbackListener { if($playerItem->playerId <= 0) { continue; } - $playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($playerItem['Login']); + $playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($playerItem->login); $player = new Player($playerInfo); $this->addPlayer($player); } diff --git a/application/plugins/Donations.php b/application/plugins/Donations.php index 5a1af083..d71320fa 100644 --- a/application/plugins/Donations.php +++ b/application/plugins/Donations.php @@ -323,12 +323,11 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { } $message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?'; - if(!$this->maniaControl->client->query('SendBill', $player->login, $amount, $message, $receiver)) { + if(!$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver)) { trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); $this->maniaControl->chat->sendError("Creating donation failed.", $player->login); return false; } - $bill = $this->maniaControl->client->getResponse(); $this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time()); return true; @@ -363,12 +362,11 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { $receiver = $player->login; } $message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.'; - if(!$this->maniaControl->client->query('Pay', $receiver, $amount, $message)) { + if(!$bill = $this->maniaControl->client->pay($receiver, $amount, $message)) { trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); $this->maniaControl->chat->sendError("Creating payout failed.", $player->login); return false; } - $bill = $this->maniaControl->client->getResponse(); $this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time()); return true; } @@ -385,11 +383,10 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin { $this->maniaControl->authenticationManager->sendNotAllowed($player); return false; } - if(!$this->maniaControl->client->query('GetServerPlanets')) { + if(!$planets = $this->maniaControl->client->getServerPlanets()) { trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText()); return false; } - $planets = $this->maniaControl->client->getResponse(); $message = "This Server has {$planets} Planets!"; return $this->maniaControl->chat->sendInformation($message, $player->login); }