From d3cc9db29c315cd194edc53d01eacc94beadd6ce Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 13 Mar 2014 18:25:29 +0100 Subject: [PATCH] fixed exceptions --- .../core/ManiaExchange/ManiaExchangeManager.php | 8 +++++--- application/core/Maps/MapCommands.php | 9 ++++++++- application/core/Maps/MapManager.php | 12 ++++++++++-- application/core/Players/PlayerActions.php | 11 ++++++++++- application/core/Players/PlayerManager.php | 15 +++++++++++---- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/application/core/ManiaExchange/ManiaExchangeManager.php b/application/core/ManiaExchange/ManiaExchangeManager.php index 144ad244..ae2ec9b0 100644 --- a/application/core/ManiaExchange/ManiaExchangeManager.php +++ b/application/core/ManiaExchange/ManiaExchangeManager.php @@ -98,7 +98,9 @@ class ManiaExchangeManager { * @param $mxId */ public function unsetMap($mxId) { - unset($this->mxIdUidVector[$mxId]); + if (isset($this->mxIdUidVector[$mxId])) { + unset($this->mxIdUidVector[$mxId]); + } } /** @@ -272,9 +274,9 @@ class ManiaExchangeManager { // compile search URL $url = 'http://' . $titlePrefix . '.mania-exchange.com/tracksearch?api=on'; - $game = explode('@', $titleId); + $game = explode('@', $titleId); $envNumber = $this->getEnvironment($game[0]); - if($env != '' || $envNumber != -1){ + if ($env != '' || $envNumber != -1) { $url .= '&environments=' . $envNumber; } if ($name != '') { diff --git a/application/core/Maps/MapCommands.php b/application/core/Maps/MapCommands.php index 3a131001..82ce8b1b 100644 --- a/application/core/Maps/MapCommands.php +++ b/application/core/Maps/MapCommands.php @@ -11,6 +11,7 @@ use ManiaControl\ManiaControl; use ManiaControl\Manialinks\IconManager; use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Players\Player; +use Maniaplanet\DedicatedServer\Xmlrpc\Exception; /** * Class offering commands to manage maps @@ -205,7 +206,13 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb $this->maniaControl->chat->sendSuccess($message); $this->maniaControl->log($message, true); - $this->maniaControl->client->restartMap(); + try { + $this->maniaControl->client->restartMap(); + } catch(Exception $e) { + if ($e->getMessage() != 'Change in progress.') { + throw $e; + } + } } /** diff --git a/application/core/Maps/MapManager.php b/application/core/Maps/MapManager.php index 0d41b252..2b313f40 100644 --- a/application/core/Maps/MapManager.php +++ b/application/core/Maps/MapManager.php @@ -368,8 +368,16 @@ class MapManager implements CallbackListener { $this->maniaControl->callbackManager->triggerCallback(self::CB_MAPS_UPDATED); //Write MapList - if($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)){ - $this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE)); + if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTOSAVE_MAPLIST)) { + try { + $this->maniaControl->client->saveMatchSettings($this->maniaControl->settingManager->getSetting($this, self::SETTING_MAPLIST_FILE)); + } catch(Exception $e) { + if ($e->getMessage() == 'Unable to write the playlist file.') { + $this->maniaControl->log("Unable to write the playlist file, please checkout your MX-Folders File permissions!"); + } else { + throw $e; + } + } } } diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index 3652c355..ef410d8e 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -132,7 +132,16 @@ class PlayerActions { $this->forcePlayerToPlay($adminLogin, $targetLogin, true, false); } - $this->maniaControl->client->forcePlayerTeam($target->login, $teamId); + try { + $this->maniaControl->client->forcePlayerTeam($target->login, $teamId); + } catch(Exception $e) { + if ($e->getMessage() == "Not in Team mode.") { + $this->forcePlayerToPlay($adminLogin, $targetLogin); + return; + } else { + throw $e; + } + } $chatMessage = false; $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 7c3990ac..7ded34a5 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -9,6 +9,7 @@ use ManiaControl\Callbacks\TimerListener; use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Statistics\StatisticManager; +use Maniaplanet\DedicatedServer\Xmlrpc\Exception; /** * Class managing Players @@ -143,11 +144,17 @@ class PlayerManager implements CallbackListener, TimerListener { * @param array $callback */ public function playerConnect(array $callback) { - $login = $callback[1][0]; - $playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login); - $player = new Player($playerInfo); + $login = $callback[1][0]; + try { + $playerInfo = $this->maniaControl->client->getDetailedPlayerInfo($login); + $player = new Player($playerInfo); - $this->addPlayer($player); + $this->addPlayer($player); + } catch(Exception $e) { + if ($e->getMessage() != 'Login unknown.') { + throw $e; + } + } } /**