- refactored many try-catch clauses

- added todos for validating catching
This commit is contained in:
Steffen Schröder 2014-02-13 14:21:25 +01:00
parent 10dfd6b0cb
commit 4197dc82ff
23 changed files with 213 additions and 293 deletions

View File

@ -191,12 +191,7 @@ class CallbackManager {
return; return;
} }
try { $callbacks = $this->maniaControl->client->executeCallbacks();
$callbacks = $this->maniaControl->client->executeCallbacks();
} catch(\Exception $e) {
trigger_error("Error reading server callbacks. " . $e->getMessage());
return;
}
// Handle callbacks // Handle callbacks
foreach($callbacks as $callback) { foreach($callbacks as $callback) {

View File

@ -2,6 +2,7 @@
namespace ManiaControl; namespace ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Chat utility class * Chat utility class
* *
@ -73,7 +74,8 @@ class Chat {
} else { } else {
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login); $this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
} }
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
return false; return false;
} }
return true; return true;

View File

@ -14,6 +14,7 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\MapManager; use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class offering a Configurator for Script Settings * Class offering a Configurator for Script Settings
@ -109,8 +110,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
public function loadSettingsFromDatabase() { public function loadSettingsFromDatabase() {
try { try {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings(); $scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch(\Exception $e) { } catch(Exception $e) {
return false; if ($e->getMessage() == 'Not in script mode.') {
return false;
}
throw $e;
} }
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
@ -137,7 +141,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
try { try {
$this->maniaControl->client->setModeScriptSettings($loadedSettings); $this->maniaControl->client->setModeScriptSettings($loadedSettings);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error('Error occured: ' . $e->getMessage()); trigger_error('Error occured: ' . $e->getMessage());
return false; return false;
} }
@ -160,19 +164,21 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
try { try {
$scriptInfo = $this->maniaControl->client->getModeScriptInfo(); $scriptInfo = $this->maniaControl->client->getModeScriptInfo();
} catch(\Exception $e) { } catch(Exception $e) {
// Not in script mode if ($e->getMessage() == 'Not in script mode.') {
$label = new Label(); $label = new Label();
$frame->add($label); $frame->add($label);
$label->setText($e->getMessage()); $label->setText($e->getMessage());
return $frame; return $frame;
}
throw $e;
} }
$scriptParams = $scriptInfo->paramDescs; $scriptParams = $scriptInfo->paramDescs;
try { try {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings(); $scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch(\Exception $e) { } catch(Exception $e) {
//do nothing //do nothing
} }
@ -303,8 +309,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
try { try {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings(); $scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch(\Exception $e) { } catch(Exception $e) {
return; if ($e->getMessage() == 'Not in script mode.') {
return;
}
throw $e;
} }
$prefixLength = strlen(self::ACTION_PREFIX_SETTING); $prefixLength = strlen(self::ACTION_PREFIX_SETTING);
@ -369,8 +378,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
public function toggleBooleanSetting($setting, Player $player) { public function toggleBooleanSetting($setting, Player $player) {
try { try {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings(); $scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch(\Exception $e) { } catch(Exception $e) {
return; if ($e->getMessage() == 'Not in script mode.') {
return;
}
throw $e;
} }
if (!isset($scriptSettings[$setting])) { if (!isset($scriptSettings[$setting])) {
@ -398,7 +410,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
try { try {
$this->maniaControl->client->setModeScriptSettings($newSettings); $this->maniaControl->client->setModeScriptSettings($newSettings);
} catch(\Exception $e) { } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return false; return false;
} }

View File

@ -100,25 +100,22 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
return false; return false;
} }
$serverSettings = $this->maniaControl->client->getServerOptions()->toArray(); $serverSettings = $this->maniaControl->client->getServerOptions()->toArray();
while($row = $result->fetch_object()) { $applySettings = false;
while ($row = $result->fetch_object()) {
if (!isset($serverSettings[$row->settingName])) { if (!isset($serverSettings[$row->settingName])) {
continue; continue;
} }
$oldType = gettype($serverSettings[$row->settingName]); $oldType = gettype($serverSettings[$row->settingName]);
$serverSettings[$row->settingName] = $row->settingValue; $serverSettings[$row->settingName] = $row->settingValue;
settype($serverSettings[$row->settingName], $oldType); settype($serverSettings[$row->settingName], $oldType);
$applySettings = true;
} }
$result->close(); $result->close();
if (!$serverSettings) { if (!$applySettings) {
return true; return true;
} }
try { $this->maniaControl->client->setServerOptions($serverSettings);
$this->maniaControl->client->setServerOptions($serverSettings);
} catch(\Exception $e) {
trigger_error('Error occured: ' . $e->getMessage());
return false;
}
return true; return true;
} }
@ -325,13 +322,7 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
if (!$newSettings) { if (!$newSettings) {
return true; return true;
} }
$this->maniaControl->client->setServerOptions($newSettings);
try {
$this->maniaControl->client->setServerOptions($newSettings);
} catch(\Exception $e) {
trigger_error('Error occured: ' . $e->getMessage());
return false;
}
// Save Settings into Database // Save Settings into Database
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;

View File

@ -21,6 +21,7 @@ use ManiaControl\Settings\SettingManager;
use ManiaControl\Statistics\StatisticManager; use ManiaControl\Statistics\StatisticManager;
use ManiaControl\Update\UpdateManager; use ManiaControl\Update\UpdateManager;
use Maniaplanet\DedicatedServer\Connection; use Maniaplanet\DedicatedServer\Connection;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
require_once __DIR__ . '/Maniaplanet/DedicatedServer/Connection.php'; require_once __DIR__ . '/Maniaplanet/DedicatedServer/Connection.php';
require_once __DIR__ . '/GbxDataFetcher/gbxdatafetcher.inc.php'; require_once __DIR__ . '/GbxDataFetcher/gbxdatafetcher.inc.php';
@ -216,12 +217,11 @@ class ManiaControl implements CommandListener {
// Hide manialinks // Hide manialinks
try { try {
$this->client->sendHideManialinkPage(); $this->client->sendHideManialinkPage();
} catch(Exception $e) {
// Close the client connection
$this->client->delete($this->server->ip, $this->server->port);
} catch(\Exception $e) {
//do nothing
} }
// Close the client connection
$this->client->delete($this->server->ip, $this->server->port);
$this->log('Quitting ManiaControl!'); $this->log('Quitting ManiaControl!');
exit(); exit();
@ -343,28 +343,19 @@ class ManiaControl implements CommandListener {
try { try {
$this->client = Connection::factory($host, $port, self::CONNECT_TIMEOUT, $login, $pass); $this->client = Connection::factory($host, $port, self::CONNECT_TIMEOUT, $login, $pass);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even needed to try-catch here? we will crash anyways
trigger_error("Couldn't authenticate on server with user '{$login}'! " . $e->getMessage(), E_USER_ERROR); trigger_error("Couldn't authenticate on server with user '{$login}'! " . $e->getMessage(), E_USER_ERROR);
} }
// Enable callback system // Enable callback system
try { $this->client->enableCallbacks(true);
$this->client->enableCallbacks(true);
} catch(\Exception $e) {
trigger_error("Couldn't enable callbacks! " . $e->getMessage(), E_USER_ERROR);
}
// Wait for server to be ready // Wait for server to be ready
if (!$this->server->waitForStatus(4)) { if (!$this->server->waitForStatus(4)) {
trigger_error("Server couldn't get ready!", E_USER_ERROR); trigger_error("Server couldn't get ready!", E_USER_ERROR);
} }
// Set api version
/*
* if(!$this->client->query('SetApiVersion', self::API_VERSION)) { trigger_error("Couldn't set API version '" . self::API_VERSION . "'! This
* might cause problems. " . $this->getClientErrorText()); }
*/
// Connect finished // Connect finished
$this->log("Server Connection successfully established!"); $this->log("Server Connection successfully established!");
@ -378,9 +369,11 @@ class ManiaControl implements CommandListener {
try { try {
$scriptSettings = $this->client->getModeScriptSettings(); $scriptSettings = $this->client->getModeScriptSettings();
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't get mode script settings. " . $e->getMessage()); if ($e->getMessage() == 'Not in script mode.') {
return; return;
}
throw $e;
} }
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) { if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
@ -390,7 +383,7 @@ class ManiaControl implements CommandListener {
$scriptSettings['S_UseScriptCallbacks'] = true; $scriptSettings['S_UseScriptCallbacks'] = true;
try { try {
$this->client->setModeScriptSettings($scriptSettings); $this->client->setModeScriptSettings($scriptSettings);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't set mode script settings to enable script callbacks. " . $e->getMessage()); trigger_error("Couldn't set mode script settings to enable script callbacks. " . $e->getMessage());
return; return;
} }

View File

@ -5,6 +5,7 @@ namespace ManiaControl\ManiaExchange;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map; use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager; use ManiaControl\Maps\MapManager;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Mania Exchange Info Searcher Class * Mania Exchange Info Searcher Class
@ -285,7 +286,10 @@ class ManiaExchangeManager {
$scriptInfos = $this->maniaControl->client->getModeScriptInfo(); $scriptInfos = $this->maniaControl->client->getModeScriptInfo();
$mapTypes = $scriptInfos->compatibleMapTypes; $mapTypes = $scriptInfos->compatibleMapTypes;
$url .= '&mtype=' . $mapTypes; $url .= '&mtype=' . $mapTypes;
} catch(\Exception $e) { } catch(Exception $e) {
if ($e->getMessage() != 'Not in script mode.') {
throw $e;
}
//dont append map tpye //dont append map tpye
} }

View File

@ -10,6 +10,7 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Manialink manager class * Manialink manager class
@ -148,7 +149,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
return $success; return $success;
} }
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
return false; return false;
} }

View File

@ -11,6 +11,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager; use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class offering commands to manage maps * Class offering commands to manage maps
@ -106,7 +107,8 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
} else { } else {
try { try {
$mapIndex = $this->maniaControl->client->getNextMapIndex(); $mapIndex = $this->maniaControl->client->getNextMapIndex();
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
trigger_error("Error while Reading the next Map Index"); trigger_error("Error while Reading the next Map Index");
$this->maniaControl->chat->sendError("Error while Reading next Map Inde"); $this->maniaControl->chat->sendError("Error while Reading next Map Inde");
return; return;
@ -190,7 +192,8 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
try { try {
$this->maniaControl->client->nextMap(); $this->maniaControl->client->nextMap();
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
$this->maniaControl->chat->sendError("Error while Skipping the Map"); $this->maniaControl->chat->sendError("Error while Skipping the Map");
return; return;
} }
@ -216,7 +219,8 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->log($message, true); $this->maniaControl->log($message, true);
try { try {
$this->maniaControl->client->restartMap(); $this->maniaControl->client->restartMap();
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
//do nothing //do nothing
} }
} }

View File

@ -24,6 +24,7 @@ use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* MapList Widget Class * MapList Widget Class
@ -511,7 +512,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
case self::ACTION_SWITCH_MAP: case self::ACTION_SWITCH_MAP:
try { try {
$this->maniaControl->client->jumpToMapIndex($mapId); $this->maniaControl->client->jumpToMapIndex($mapId);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
$this->maniaControl->chat->sendError("Error while Jumping to Map Index"); $this->maniaControl->chat->sendError("Error while Jumping to Map Index");
break; break;
} }
@ -542,7 +544,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
try { try {
$index = $this->maniaControl->mapManager->getMapIndex($map); $index = $this->maniaControl->mapManager->getMapIndex($map);
$this->maniaControl->client->jumpToMapIndex($index); $this->maniaControl->client->jumpToMapIndex($index);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
$this->maniaControl->chat->sendError("Error while Switching Map"); $this->maniaControl->chat->sendError("Error while Switching Map");
} }
}); });

View File

@ -12,6 +12,7 @@ use ManiaControl\ManiaExchange\ManiaExchangeList;
use ManiaControl\ManiaExchange\ManiaExchangeManager; use ManiaControl\ManiaExchange\ManiaExchangeManager;
use ManiaControl\ManiaExchange\MXMapInfo; use ManiaControl\ManiaExchange\MXMapInfo;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Manager for Maps * Manager for Maps
@ -216,24 +217,13 @@ class MapManager implements CallbackListener {
} }
// Remove map // Remove map
try { $this->maniaControl->client->removeMap($map->fileName);
$this->maniaControl->client->removeMap($map->fileName);
} catch(\Exception $e) {
trigger_error("Couldn't remove current map. " . $e->getMessage());
$this->maniaControl->chat->sendError("Couldn't remove map.", $admin);
return;
}
if ($eraseFile) { if ($eraseFile) {
// Check if ManiaControl can even write to the maps dir // Check if ManiaControl can even write to the maps dir
try { $mapDir = $this->maniaControl->client->getMapsDirectory();
$mapDir = $this->maniaControl->client->getMapsDirectory();
} catch(\Exception $e) { // Delete map file
trigger_error("Couldn't get map directory. " . $e->getMessage());
$this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $admin->login);
return;
}
if (!@unlink($mapDir . $map->fileName)) { if (!@unlink($mapDir . $map->fileName)) {
trigger_error("Couldn't remove Map '{$mapDir}{$map->fileName}'."); trigger_error("Couldn't remove Map '{$mapDir}{$map->fileName}'.");
$this->maniaControl->chat->sendError("ManiaControl couldn't remove the MapFile.", $admin->login); $this->maniaControl->chat->sendError("ManiaControl couldn't remove the MapFile.", $admin->login);
@ -281,7 +271,7 @@ class MapManager implements CallbackListener {
try { try {
$this->maniaControl->client->chooseNextMapList($mapArray); $this->maniaControl->client->chooseNextMapList($mapArray);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Error while restructuring the Maplist. " . $e->getMessage()); trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
return false; return false;
} }
@ -307,7 +297,7 @@ class MapManager implements CallbackListener {
try { try {
$this->maniaControl->client->chooseNextMapList($mapArray); $this->maniaControl->client->chooseNextMapList($mapArray);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't shuffle mapList. " . $e->getMessage()); trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
return false; return false;
} }
@ -345,6 +335,7 @@ class MapManager implements CallbackListener {
$map->authorZone = $mapFetcher->authorZone; $map->authorZone = $mapFetcher->authorZone;
$map->comment = $mapFetcher->comment; $map->comment = $mapFetcher->comment;
} catch(\Exception $e) { } catch(\Exception $e) {
// TODO: replace \Exception with api exception class (?)
trigger_error($e->getMessage()); trigger_error($e->getMessage());
} }
} }
@ -355,14 +346,7 @@ class MapManager implements CallbackListener {
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps * Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/ */
private function updateFullMapList() { private function updateFullMapList() {
$maps = $this->maniaControl->client->getMapList(100, 0);
try {
$maps = $this->maniaControl->client->getMapList(100, 0);
} catch(\Exception $e) {
trigger_error("Couldn't fetch mapList. " . $e->getMessage());
return null;
}
$tempList = array(); $tempList = array();
foreach($maps as $rpcMap) { foreach($maps as $rpcMap) {
@ -388,12 +372,7 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function fetchCurrentMap() { private function fetchCurrentMap() {
try { $rpcMap = $this->maniaControl->client->getCurrentMapInfo();
$rpcMap = $this->maniaControl->client->getCurrentMapInfo();
} catch(\Exception $e) {
trigger_error("Couldn't fetch map info. " . $e->getMessage());
return false;
}
if (array_key_exists($rpcMap->uId, $this->maps)) { if (array_key_exists($rpcMap->uId, $this->maps)) {
$this->currentMap = $this->maps[$rpcMap->uId]; $this->currentMap = $this->maps[$rpcMap->uId];
@ -508,14 +487,7 @@ class MapManager implements CallbackListener {
* @param bool $update * @param bool $update
*/ */
public function addMapFromMx($mapId, $login, $update = false) { public function addMapFromMx($mapId, $login, $update = false) {
// Check if ManiaControl can even write to the maps dir $mapDir = $this->maniaControl->client->getMapsDirectory();
try {
$mapDir = $this->maniaControl->client->getMapsDirectory();
} catch(\Exception $e) {
trigger_error("Couldn't get map directory. " . $e->getMessage());
$this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $login);
return;
}
if (is_numeric($mapId)) { if (is_numeric($mapId)) {
// Check if map exists // Check if map exists
@ -590,7 +562,8 @@ class MapManager implements CallbackListener {
} else { } else {
try { try {
$this->maniaControl->client->writeFileFromString($mapFileName, $file); $this->maniaControl->client->writeFileFromString($mapFileName, $file);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: add check for error message - throw other stuff like connection errors
$this->maniaControl->chat->sendError("Map is too big for a remote save.", $login); $this->maniaControl->chat->sendError("Map is too big for a remote save.", $login);
return; return;
} }
@ -599,7 +572,7 @@ class MapManager implements CallbackListener {
// Check for valid map // Check for valid map
try { try {
$this->maniaControl->client->checkMapForCurrentServerParams($mapFileName); $this->maniaControl->client->checkMapForCurrentServerParams($mapFileName);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $e->getMessage()); trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $e->getMessage());
$this->maniaControl->chat->sendError('Wrong MapType or not validated!', $login); $this->maniaControl->chat->sendError('Wrong MapType or not validated!', $login);
return; return;
@ -608,7 +581,8 @@ class MapManager implements CallbackListener {
// Add map to map list // Add map to map list
try { try {
$this->maniaControl->client->insertMap($mapFileName); $this->maniaControl->client->insertMap($mapFileName);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
$this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login); $this->maniaControl->chat->sendError("Couldn't add map to match settings!", $login);
return; return;
} }

View File

@ -9,6 +9,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* MapQueue Class * MapQueue Class
@ -183,7 +184,8 @@ class MapQueue implements CallbackListener, CommandListener {
try { try {
$this->maniaControl->client->chooseNextMap($map->fileName); $this->maniaControl->client->chooseNextMap($map->fileName);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
//do nothing //do nothing
} }
} }

View File

@ -11,6 +11,7 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* PlayerActions Class * PlayerActions Class
@ -84,8 +85,8 @@ class PlayerActions {
try { try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER); $this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch(Exception $e) {
} catch(\Exception $e) { // TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -93,7 +94,8 @@ class PlayerActions {
if($userIsAbleToSelect) { if($userIsAbleToSelect) {
try { try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE); $this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -130,7 +132,8 @@ class PlayerActions {
try { try {
$this->maniaControl->client->forcePlayerTeam($target->login, $teamId); $this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exceptions should be "wrong login" or "not in team mode" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -167,7 +170,8 @@ class PlayerActions {
try { try {
$this->maniaControl->client->forceSpectator($target->login, $spectatorState); $this->maniaControl->client->forceSpectator($target->login, $spectatorState);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -181,7 +185,8 @@ class PlayerActions {
// Free player slot // Free player slot
try { try {
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login); $this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
//do nothing //do nothing
} }
} }
@ -205,7 +210,8 @@ class PlayerActions {
try { try {
$this->maniaControl->client->unIgnore($targetLogin); $this->maniaControl->client->unIgnore($targetLogin);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $adminLogin); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $adminLogin);
return; return;
} }
@ -232,12 +238,7 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
try { $this->maniaControl->client->ignore($targetLogin);
$this->maniaControl->client->ignore($targetLogin);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!'; $chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!';
@ -349,7 +350,8 @@ class PlayerActions {
} else { } else {
$this->maniaControl->client->kick($target->login, $message); $this->maniaControl->client->kick($target->login, $message);
} }
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -384,12 +386,7 @@ class PlayerActions {
return; return;
} }
try { $this->maniaControl->client->ban($target->login, $message);
$this->maniaControl->client->ban($target->login, $message);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
// Announce ban // Announce ban
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);

View File

@ -10,6 +10,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Server\Server; use ManiaControl\Server\Server;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class offering various Admin Commands related to Players * Class offering various Admin Commands related to Players
@ -105,7 +106,8 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
try { try {
$this->maniaControl->client->autoTeamBalance(); $this->maniaControl->client->autoTeamBalance();
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
@ -267,15 +269,9 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
if (isset($messageParts[1]) && is_numeric($messageParts[1])) { if (isset($messageParts[1]) && is_numeric($messageParts[1])) {
$amount = intval($messageParts[1]); $amount = intval($messageParts[1]);
} }
try { for ($i = 0; $i < $amount; $i++) {
for($i = 0; $i < $amount; $i++) { $this->maniaControl->client->connectFakePlayer();
$this->maniaControl->client->connectFakePlayer();
}
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
} }
$this->maniaControl->chat->sendSuccess('Fake players connected!', $player->login); $this->maniaControl->chat->sendSuccess('Fake players connected!', $player->login);
} }
@ -290,14 +286,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$this->maniaControl->client->disconnectFakePlayer('*');
try {
$this->maniaControl->client->disconnectFakePlayer('*');
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login); $this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login);
} }

View File

@ -23,6 +23,7 @@ use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* PlayerList Widget Class * PlayerList Widget Class
@ -650,7 +651,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
try { try {
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); $this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1); $this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
} }
break; break;
case self::ACTION_OPEN_PLAYER_DETAILED: case self::ACTION_OPEN_PLAYER_DETAILED:
@ -721,8 +723,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
try { try {
$this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); $this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login); $this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(\Exception $e) { } catch(Exception $e) {
//do nothing //do nothing
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
} }
}); });
break; break;
@ -745,7 +748,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$message = '$39F You got kicked due a Public vote!$z '; $message = '$39F You got kicked due a Public vote!$z ';
try { try {
$this->maniaControl->client->kick($target->login, $message); $this->maniaControl->client->kick($target->login, $message);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $target->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $target->login);
return; return;
} }

View File

@ -7,6 +7,7 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\SystemInfos; use Maniaplanet\DedicatedServer\Structures\SystemInfos;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class providing Information about theconnected ManiaPlanet Server * Class providing Information about theconnected ManiaPlanet Server
@ -162,12 +163,7 @@ class Server implements CallbackListener {
*/ */
public function getDataDirectory() { public function getDataDirectory() {
if ($this->dataDirectory == '') { if ($this->dataDirectory == '') {
try { $this->dataDirectory = $this->maniaControl->client->gameDataDirectory();
$this->dataDirectory = $this->maniaControl->client->gameDataDirectory();
} catch(\Exception $e) {
trigger_error("Couldn't get data directory. " . $e->getMessage());
return null;
}
} }
return $this->dataDirectory; return $this->dataDirectory;
} }
@ -199,29 +195,12 @@ class Server implements CallbackListener {
} }
/** /**
* Get the Server Info * Get Server Player Info
* *
* @param bool $detailed
* @return array * @return array
*/ */
public function getInfo($detailed = false) { public function getInfo() {
if ($detailed) { return $this->maniaControl->client->getMainServerPlayerInfo();
$login = $this->login;
try {
$info = $this->maniaControl->client->getDetailedPlayerInfo($login);
} catch(\Exception $e) {
trigger_error("Couldn't fetch detailed server info. " . $e->getMessage());
return null;
}
return $info;
}
try {
$info = $this->maniaControl->client->getMainServerPlayerInfo();
} catch(\Exception $e) {
trigger_error("Couldn't fetch server info. " . $e->getMessage());
return null;
}
return $info;
} }
/** /**
@ -230,14 +209,7 @@ class Server implements CallbackListener {
* @return array * @return array
*/ */
public function getOptions() { public function getOptions() {
try { return $this->maniaControl->client->getServerOptions();
$options = $this->maniaControl->client->getServerOptions();
} catch(\Exception $e) {
trigger_error("Couldn't fetch server options. " . $e->getMessage());
return null;
}
return $options;
} }
/** /**
@ -246,13 +218,7 @@ class Server implements CallbackListener {
* @return string * @return string
*/ */
public function getName() { public function getName() {
try { return $this->maniaControl->client->getServerName();
$name = $this->maniaControl->client->getServerName();
} catch(\Exception $e) {
trigger_error("Couldn't fetch server name. " . $e->getMessage());
return null;
}
return $name;
} }
@ -262,13 +228,7 @@ class Server implements CallbackListener {
* @return string * @return string
*/ */
public function getVersion() { public function getVersion() {
try { return $this->maniaControl->client->getVersion();
$version = $this->maniaControl->client->getVersion();
} catch(\Exception $e) {
trigger_error("Couldn't fetch server version. " . $e->getMessage());
return null;
}
return $version;
} }
/** /**
@ -277,14 +237,7 @@ class Server implements CallbackListener {
* @return SystemInfos * @return SystemInfos
*/ */
public function getSystemInfo() { public function getSystemInfo() {
try { return $this->maniaControl->client->getSystemInfo();
$systemInfo = $this->maniaControl->client->getSystemInfo();
} catch(\Exception $e) {
trigger_error("Couldn't fetch server system info. " . $e->getMessage());
return null;
}
return $systemInfo;
} }
/** /**
@ -298,12 +251,7 @@ class Server implements CallbackListener {
if (is_int($parseValue)) { if (is_int($parseValue)) {
$gameMode = $parseValue; $gameMode = $parseValue;
} else { } else {
try { $gameMode = $this->maniaControl->client->getGameMode();
$gameMode = $this->maniaControl->client->getGameMode();
} catch(\Exception $e) {
trigger_error("Couldn't fetch current game mode. " . $e->getMessage());
return null;
}
} }
if ($stringValue) { if ($stringValue) {
switch($gameMode) { switch($gameMode) {
@ -337,7 +285,7 @@ class Server implements CallbackListener {
public function getValidationReplay(Player $player) { public function getValidationReplay(Player $player) {
try { try {
$replay = $this->maniaControl->client->getValidationReplay($player->login); $replay = $this->maniaControl->client->getValidationReplay($player->login);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't get validation replay of '{$player->login}'. " . $e->getMessage()); trigger_error("Couldn't get validation replay of '{$player->login}'. " . $e->getMessage());
return null; return null;
} }
@ -365,7 +313,7 @@ class Server implements CallbackListener {
// Save ghost replay // Save ghost replay
try { try {
$this->maniaControl->client->saveBestGhostsReplay($player->login, $fileName); $this->maniaControl->client->saveBestGhostsReplay($player->login, $fileName);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't save ghost replay. " . $e->getMessage()); trigger_error("Couldn't save ghost replay. " . $e->getMessage());
return null; return null;
} }

View File

@ -13,6 +13,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class offering various commands related to the dedicated server * Class offering various commands related to the dedicated server
@ -105,8 +106,11 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
//Check if Pause exists in current GameMode //Check if Pause exists in current GameMode
try { try {
$scriptInfos = $this->maniaControl->client->getModeScriptInfo(); $scriptInfos = $this->maniaControl->client->getModeScriptInfo();
} catch(\Exception $e) { } catch(Exception $e) {
return; if ($e->getMessage() == 'Not in script mode.') {
return;
}
throw $e;
} }
$pauseExists = false; $pauseExists = false;
foreach($scriptInfos->commandDescs as $param) { foreach($scriptInfos->commandDescs as $param) {
@ -160,9 +164,12 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
try { try {
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Extend', '10'); $this->maniaControl->client->triggerModeScriptEvent('WarmUp_Extend', '10');
} catch(\Exception $e) { } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); if ($e->getMessage() == 'Not in script mode.') {
return; $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
throw $e;
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> extended the WarmUp by 10 seconds!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> extended the WarmUp by 10 seconds!');
@ -182,9 +189,12 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
try { try {
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Stop', ''); $this->maniaControl->client->triggerModeScriptEvent('WarmUp_Stop', '');
} catch(\Exception $e) { } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); if ($e->getMessage() == 'Not in script mode.') {
return; $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
throw $e;
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!');
@ -202,9 +212,12 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
} }
try { try {
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True)); $this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
} catch(\Exception $e) { } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); if ($e->getMessage() == 'Not in script mode.') {
return; $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
throw $e;
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> paused the Game!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> paused the Game!');
@ -305,12 +318,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
return; return;
} }
$serverName = $params[1]; $serverName = $params[1];
try { $this->maniaControl->client->setServerName($serverName);
$this->maniaControl->client->setServerName($serverName);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess("Server name changed to: '{$serverName}'!", $player->login); $this->maniaControl->chat->sendSuccess("Server name changed to: '{$serverName}'!", $player->login);
} }
@ -332,12 +340,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!"; $successMessage = "Password changed to: '{$password}'!";
} }
try { $this->maniaControl->client->setServerPassword($password);
$this->maniaControl->client->setServerPassword($password);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess($successMessage, $player->login); $this->maniaControl->chat->sendSuccess($successMessage, $player->login);
} }
@ -359,12 +362,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!"; $successMessage = "Spectator password changed to: '{$password}'!";
} }
try { $this->maniaControl->client->setServerPasswordForSpectator($password);
$this->maniaControl->client->setServerPasswordForSpectator($password);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess($successMessage, $player->login); $this->maniaControl->chat->sendSuccess($successMessage, $player->login);
} }
@ -394,13 +392,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$amount = 0; $amount = 0;
} }
try { $this->maniaControl->client->setMaxPlayers($amount);
$this->maniaControl->client->setMaxPlayers($amount);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess("Changed max players to: {$amount}", $player->login); $this->maniaControl->chat->sendSuccess("Changed max players to: {$amount}", $player->login);
} }
@ -430,12 +422,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$amount = 0; $amount = 0;
} }
try { $this->maniaControl->client->setMaxSpectators($amount);
$this->maniaControl->client->setMaxSpectators($amount);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess("Changed max spectators to: {$amount}", $player->login); $this->maniaControl->chat->sendSuccess("Changed max spectators to: {$amount}", $player->login);
} }
@ -443,16 +430,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* Perform server shutdown * Perform server shutdown
* *
* @param string $login * @param string $login
* @return bool
*/ */
private function shutdownServer($login = '#') { private function shutdownServer($login = '#') {
try { $this->maniaControl->client->stopServer();
$this->maniaControl->client->stopServer();
} catch(\Exception $e) {
trigger_error("Server shutdown command from '{login}' failed. " . $e->getMessage());
return false;
}
$this->maniaControl->quit("Server shutdown requested by '{$login}'"); $this->maniaControl->quit("Server shutdown requested by '{$login}'");
return true;
} }
} }

View File

@ -6,6 +6,7 @@ use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Formatter; use ManiaControl\Formatter;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Update\UpdateManager; use ManiaControl\Update\UpdateManager;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class reports Usage * Class reports Usage
@ -56,18 +57,18 @@ class UsageReporter implements TimerListener {
$properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->server->getName()); $properties['ServerName'] = Formatter::stripDirtyCodes($this->maniaControl->server->getName());
$properties['PlayerCount'] = $this->maniaControl->playerManager->getPlayerCount(); $properties['PlayerCount'] = $this->maniaControl->playerManager->getPlayerCount();
try { $maxPlayers = $this->maniaControl->client->getMaxPlayers();
$maxPlayers = $this->maniaControl->client->getMaxPlayers(); $properties['MaxPlayers'] = $maxPlayers["CurrentValue"];
$properties['MaxPlayers'] = $maxPlayers["CurrentValue"];
} catch(\Exception $e) {
$properties['MaxPlayers'] = -1;
}
try { try {
$scriptName = $this->maniaControl->client->getScriptName(); $scriptName = $this->maniaControl->client->getScriptName();
$properties['ScriptName'] = $scriptName["CurrentValue"]; $properties['ScriptName'] = $scriptName["CurrentValue"];
} catch(\Exception $e) { } catch(Exception $e) {
$properties['ScriptName'] = ''; if ($e->getMessage() == 'Not in script mode.') {
$properties['ScriptName'] = '';
} else {
throw $e;
}
} }
$json = json_encode($properties); $json = json_encode($properties);

View File

@ -4,6 +4,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* ManiaControl Chat-Message Plugin * ManiaControl Chat-Message Plugin
@ -308,10 +309,11 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$msg = '$i$ff0 $<' . $player->nickname . '$>$s$39f chooses to boot back to the real world!'; $msg = '$i$ff0 $<' . $player->nickname . '$>$s$39f chooses to boot back to the real world!';
$this->maniaControl->chat->sendChat($msg, null, true); $this->maniaControl->chat->sendChat($msg, null, true);
$message = '$39F Thanks for Playing, please come back soon!$z '; $message = '$39F Thanks for Playing, see you around!$z';
try { try {
$this->maniaControl->client->kick($player->login, $message); $this->maniaControl->client->kick($player->login, $message);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
@ -330,7 +332,8 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$message = '$39F Thanks for Playing, please come back soon!$z '; $message = '$39F Thanks for Playing, please come back soon!$z ';
try { try {
$this->maniaControl->client->kick($player->login, $message); $this->maniaControl->client->kick($player->login, $message);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
@ -350,7 +353,8 @@ class ChatMessagePlugin implements CommandListener, Plugin {
// force into spec // force into spec
try { try {
$this->maniaControl->client->forceSpectator($player->login, 3); $this->maniaControl->client->forceSpectator($player->login, 3);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login); $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
@ -358,7 +362,8 @@ class ChatMessagePlugin implements CommandListener, Plugin {
// free player slot // free player slot
try { try {
$this->maniaControl->client->spectatorReleasePlayerSlot($player->login); $this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
//to nothing //to nothing
} }
} }

View File

@ -26,6 +26,7 @@ use ManiaControl\Plugins\Plugin;
use ManiaControl\Server\Server; use ManiaControl\Server\Server;
use ManiaControl\Server\ServerCommands; use ManiaControl\Server\ServerCommands;
use Maniaplanet\DedicatedServer\Structures\VoteRatio; use Maniaplanet\DedicatedServer\Structures\VoteRatio;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
@ -260,8 +261,12 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame'); $itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame');
$this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game'); $this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game');
} }
} catch(\Exception $e) { } catch(Exception $e) {
//do nothing if ($e->getMessage() == 'Not in script mode.') {
// Do nothing
} else {
throw $e;
}
} }
//Menu SkipMap //Menu SkipMap

View File

@ -16,6 +16,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Donation plugin * Donation plugin
@ -335,7 +336,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?'; $message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
try { try {
$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver); $bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: handle errors like 'too few server planets' - throw other like connection errors
trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $e->getMessage()); trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $e->getMessage());
$this->maniaControl->chat->sendError("Creating donation failed.", $player->login); $this->maniaControl->chat->sendError("Creating donation failed.", $player->login);
return false; return false;
@ -378,8 +380,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
try { try {
$bill = $this->maniaControl->client->pay($receiver, $amount, $message); $bill = $this->maniaControl->client->pay($receiver, $amount, $message);
} catch(\Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't retrieve server planets. " . $e->getMessage()); // TODO: handle errors like 'too few server planets' - throw other like connection errors
trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $e->getMessage()); trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $e->getMessage());
$this->maniaControl->chat->sendError("Creating payout failed.", $player->login); $this->maniaControl->chat->sendError("Creating payout failed.", $player->login);
return false; return false;
@ -401,13 +403,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return false; return false;
} }
try { $planets = $this->maniaControl->client->getServerPlanets();
$planets = $this->maniaControl->client->getServerPlanets();
} catch(\Exception $e) {
trigger_error("Couldn't retrieve server planets. " . $e->getMessage());
return false;
}
$message = "This Server has {$planets} Planets!"; $message = "This Server has {$planets} Planets!";
return $this->maniaControl->chat->sendInformation($message, $player->login); return $this->maniaControl->chat->sendInformation($message, $player->login);
} }

View File

@ -6,6 +6,7 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* ManiaControl Obstacle Plugin * ManiaControl Obstacle Plugin
@ -128,8 +129,12 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
$param = $player->login . ";" . $params[1] . ";"; $param = $player->login . ";" . $params[1] . ";";
try{ try{
$this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param); $this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param);
} catch(\Exception $e){ } catch(Exception $e) {
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage()); if ($e->getMessage() == 'Not in script mode.') {
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
return;
}
throw $e;
} }
} }

View File

@ -14,6 +14,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Queue plugin * Queue plugin
@ -289,14 +290,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) { if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
try { try {
$this->maniaControl->client->forceSpectator($player->login, 2); $this->maniaControl->client->forceSpectator($player->login, 2);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError("Error while leaving the Queue", $player->login); $this->maniaControl->chat->sendError("Error while leaving the Queue", $player->login);
return; return;
} }
try { try {
$this->maniaControl->client->forceSpectator($player->login, 0); $this->maniaControl->client->forceSpectator($player->login, 0);
} catch(\Exception $e) { } } catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
}
$teams = array(); $teams = array();
/** @var Player $player */ /** @var Player $player */
@ -319,7 +323,9 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
try { try {
$this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam); $this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam);
} catch(\Exception $e) { } } catch(Exception $e) {
// TODO: only possible valid exceptions should be "wrong login" or "not in team mode" - throw others (like connection error)
}
if(isset($this->spectators[$player->login])) { if(isset($this->spectators[$player->login])) {
unset($this->spectators[$player->login]); unset($this->spectators[$player->login]);

View File

@ -15,6 +15,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswerListener, TimerListener { class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswerListener, TimerListener {
/** /**
@ -467,7 +468,8 @@ class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswer
try { try {
$billId = $this->maniaControl->client->pay($player->login, (int)$balance, $message); $billId = $this->maniaControl->client->pay($player->login, (int)$balance, $message);
} catch(\Exception $e) { } catch(Exception $e) {
// TODO: handle errors like 'too few server planets' - throw other like connection errors
return; return;
} }