fixed some exceptions

This commit is contained in:
kremsy 2014-04-19 22:59:11 +02:00 committed by Steffen Schröder
parent 94bd951a43
commit 7525b96ba1
6 changed files with 129 additions and 123 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
namespace ManiaControl\Bills; namespace ManiaControl\Bills;
use ManiaControl\Players\Player;
/** /**
* ManiaControl BillData Structure * ManiaControl BillData Structure
@ -22,9 +23,9 @@ class BillData {
/** /**
* Construct new BillData * Construct new BillData
* @param unknown $function * @param mixed $function
* @param unknown $player * @param Player $player
* @param unknown $amount * @param int $amount
* @param string $pay * @param string $pay
* @param string $receiverLogin * @param string $receiverLogin
*/ */

View File

@ -7,7 +7,6 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\Bill; use Maniaplanet\DedicatedServer\Structures\Bill;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* ManiaControl Bill-Manager * ManiaControl Bill-Manager
@ -58,17 +57,11 @@ class BillManager implements CallbackListener {
return false; return false;
} }
try {
if (!$receiver) { if (!$receiver) {
$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message); $bill = $this->maniaControl->client->sendBill($player->login, $amount, $message);
} else { } else {
$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver); $bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver);
} }
} catch(Exception $e) {
// TODO: handle errors like 'too few server planets' - throw other like connection errors
$this->maniaControl->errorHandler->triggerDebugNotice("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $e->getMessage());
return false;
}
$this->openBills[$bill] = new BillData($function, $player, $amount); $this->openBills[$bill] = new BillData($function, $player, $amount);
return true; return true;
@ -89,14 +82,7 @@ class BillManager implements CallbackListener {
return false; return false;
} }
try {
$bill = $this->maniaControl->client->pay($receiverLogin, $amount, $message); $bill = $this->maniaControl->client->pay($receiverLogin, $amount, $message);
} catch(Exception $e) {
// 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());
$this->maniaControl->errorHandler->triggerDebugNotice("Couldn't create payout of {$amount} planets to '{$receiverLogin}' " . $e->getMessage());
return false;
}
$this->openBills[$bill] = new BillData($function, $receiverLogin, $amount, true); $this->openBills[$bill] = new BillData($function, $receiverLogin, $amount, true);

View File

@ -13,10 +13,11 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Maps\Map;
use ManiaControl\Maps\MapManager; use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use ManiaControl\Maps\Map; use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
/** /**
* Class offering a Configurator for Script Settings * Class offering a Configurator for Script Settings
@ -117,12 +118,9 @@ 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(NotInScriptModeException $e) {
if ($e->getMessage() == 'Not in script mode.') {
return false; return false;
} }
throw $e;
}
$mysqli = $this->maniaControl->database->mysqli; $mysqli = $this->maniaControl->database->mysqli;
$serverId = $this->maniaControl->server->index; $serverId = $this->maniaControl->server->index;
@ -185,7 +183,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
try { try {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings(); $scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch(Exception $e) { } catch(NotInScriptModeException $e) {
//do nothing //do nothing
} }
@ -320,12 +318,9 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
try { try {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings(); $scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch(Exception $e) { } catch(NotInScriptModeException $e) {
if ($e->getMessage() == 'Not in script mode.') {
return; return;
} }
throw $e;
}
$prefixLength = strlen(self::ACTION_PREFIX_SETTING); $prefixLength = strlen(self::ACTION_PREFIX_SETTING);
@ -389,12 +384,9 @@ 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(NotInScriptModeException $e) {
if ($e->getMessage() == 'Not in script mode.') {
return; return;
} }
throw $e;
}
if (!isset($scriptSettings[$setting])) { if (!isset($scriptSettings[$setting])) {
var_dump('no setting ' . $setting); var_dump('no setting ' . $setting);
@ -415,11 +407,15 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
* @param bool * @param bool
*/ */
private function applyNewScriptSettings(array $newSettings, Player $player) { private function applyNewScriptSettings(array $newSettings, Player $player) {
if (!$newSettings) return true; if (!$newSettings) {
return true;
}
try { try {
$this->maniaControl->client->setModeScriptSettings($newSettings); $this->maniaControl->client->setModeScriptSettings($newSettings);
} catch(Exception $e) { } catch(Exception $e) {
//TODO temp added 19.04.2014
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 416 ScriptSettings.php" . $e->getMessage());
$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

@ -19,6 +19,8 @@ class FaultException extends Exception
return new CouldNotWritePlaylistFileException($faultString, $faultCode); return new CouldNotWritePlaylistFileException($faultString, $faultCode);
case 'Start index out of bound.': case 'Start index out of bound.':
return new StartIndexOutOfBoundException($faultString, $faultCode); return new StartIndexOutOfBoundException($faultString, $faultCode);
case 'Not in script mode.':
return new NotInScriptModeException($faultString, $faultCode);
} }
return new self($faultString, $faultCode); return new self($faultString, $faultCode);
@ -28,4 +30,5 @@ class FaultException extends Exception
class LoginUnknownException extends FaultException {} class LoginUnknownException extends FaultException {}
class CouldNotWritePlaylistFileException extends FaultException {} class CouldNotWritePlaylistFileException extends FaultException {}
class StartIndexOutOfBoundException extends FaultException {} class StartIndexOutOfBoundException extends FaultException {}
class NotInScriptModeException extends FaultException {}
?> ?>

View File

@ -25,6 +25,7 @@ use ManiaControl\Update\UpdateManager;
use Maniaplanet\DedicatedServer\Connection; use Maniaplanet\DedicatedServer\Connection;
use Maniaplanet\DedicatedServer\Transport\TransportException; use Maniaplanet\DedicatedServer\Transport\TransportException;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php'; require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php';
require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php'; require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php';
@ -132,6 +133,7 @@ class ManiaControl implements CommandListener, TimerListener {
/** /**
* Checks connection every xxx Minutes * Checks connection every xxx Minutes
*
* @param $time * @param $time
*/ */
public function checkConnection($time) { public function checkConnection($time) {
@ -243,7 +245,7 @@ class ManiaControl implements CommandListener, TimerListener {
$this->client->sendHideManialinkPage(); $this->client->sendHideManialinkPage();
// Close the client connection // Close the client connection
$this->client->delete($this->server->ip, $this->server->port); $this->client->delete($this->server->ip, $this->server->port);
} catch(FatalException $e) { } catch(TransportException $e) {
$this->errorHandler->triggerDebugNotice($e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine()); $this->errorHandler->triggerDebugNotice($e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine());
} }
} }
@ -399,7 +401,7 @@ class ManiaControl implements CommandListener, TimerListener {
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);
} }
} catch(FatalException $e) { } catch(Exception $e) {
// TODO remove // TODO remove
if ($this->errorHandler) { if ($this->errorHandler) {
$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString()); $this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
@ -420,12 +422,9 @@ class ManiaControl implements CommandListener, TimerListener {
try { try {
$scriptSettings = $this->client->getModeScriptSettings(); $scriptSettings = $this->client->getModeScriptSettings();
} catch(Exception $e) { } catch(NotInScriptModeException $e) {
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)) {
return; return;
@ -435,6 +434,9 @@ class ManiaControl implements CommandListener, TimerListener {
try { try {
$this->client->setModeScriptSettings($scriptSettings); $this->client->setModeScriptSettings($scriptSettings);
} catch(Exception $e) { } catch(Exception $e) {
//TODO temp added 19.04.2014
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage());
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

@ -63,15 +63,19 @@ class Server implements CallbackListener {
* Load the Server Configuration from the Config XML * Load the Server Configuration from the Config XML
*/ */
public function loadConfig() { public function loadConfig() {
if (!$this->maniaControl->config) trigger_error('Error loading Server Config!', E_USER_ERROR); if (!$this->maniaControl->config) {
trigger_error('Error loading Server Config!', E_USER_ERROR);
}
// Config id // Config id
$id = null; $id = null;
global $argv; global $argv;
foreach($argv as $arg) { foreach($argv as $arg) {
$parts = explode('=', $arg); $parts = explode('=', $arg);
if (count($parts) < 2) continue; if (count($parts) < 2)
if ($parts[0] != '-id') continue; continue;
if ($parts[0] != '-id')
continue;
$id = $parts[1]; $id = $parts[1];
break; break;
} }
@ -80,34 +84,45 @@ class Server implements CallbackListener {
$serverTag = null; $serverTag = null;
if ($id) { if ($id) {
$serverTags = $this->maniaControl->config->xpath("server[@id='{$id}']"); $serverTags = $this->maniaControl->config->xpath("server[@id='{$id}']");
if ($serverTags) $serverTag = $serverTags[0]; if ($serverTags)
if (!$serverTag) trigger_error("No Server configured with the ID '{$id}'!", E_USER_ERROR); $serverTag = $serverTags[0];
} if (!$serverTag)
else { trigger_error("No Server configured with the ID '{$id}'!", E_USER_ERROR);
} else {
$serverTags = $this->maniaControl->config->xpath('server'); $serverTags = $this->maniaControl->config->xpath('server');
if ($serverTags) $serverTag = $serverTags[0]; if ($serverTags)
if (!$serverTag) trigger_error('No Server configured!', E_USER_ERROR); $serverTag = $serverTags[0];
if (!$serverTag)
trigger_error('No Server configured!', E_USER_ERROR);
} }
// Host // Host
$host = $serverTag->xpath('host'); $host = $serverTag->xpath('host');
if ($host) $host = (string) $host[0]; if ($host)
if (!$host) trigger_error("Invalid server configuration (host).", E_USER_ERROR); $host = (string)$host[0];
if (!$host)
trigger_error("Invalid server configuration (host).", E_USER_ERROR);
// Port // Port
$port = $serverTag->xpath('port'); $port = $serverTag->xpath('port');
if ($port) $port = (string) $port[0]; if ($port)
if (!$port) trigger_error("Invalid server configuration (port).", E_USER_ERROR); $port = (string)$port[0];
if (!$port)
trigger_error("Invalid server configuration (port).", E_USER_ERROR);
// Login // Login
$login = $serverTag->xpath('login'); $login = $serverTag->xpath('login');
if ($login) $login = (string) $login[0]; if ($login)
if (!$login) trigger_error("Invalid server configuration (login).", E_USER_ERROR); $login = (string)$login[0];
if (!$login)
trigger_error("Invalid server configuration (login).", E_USER_ERROR);
// Pass // Pass
$pass = $serverTag->xpath('pass'); $pass = $serverTag->xpath('pass');
if ($pass) $pass = (string) $pass[0]; if ($pass)
if (!$pass) trigger_error("Invalid server configuration (password).", E_USER_ERROR); $pass = (string)$pass[0];
if (!$pass)
trigger_error("Invalid server configuration (password).", E_USER_ERROR);
// Create config object // Create config object
$this->config = new Config($id, $host, $port, $login, $pass); $this->config = new Config($id, $host, $port, $login, $pass);
@ -287,8 +302,7 @@ class Server implements CallbackListener {
public function getGameMode($stringValue = false, $parseValue = null) { public function getGameMode($stringValue = false, $parseValue = null) {
if (is_int($parseValue)) { if (is_int($parseValue)) {
$gameMode = $parseValue; $gameMode = $parseValue;
} } else {
else {
$gameMode = $this->maniaControl->client->getGameMode(); $gameMode = $this->maniaControl->client->getGameMode();
} }
if ($stringValue) { if ($stringValue) {
@ -323,8 +337,10 @@ class Server implements CallbackListener {
public function getValidationReplay($login) { public function getValidationReplay($login) {
try { try {
$replay = $this->maniaControl->client->getValidationReplay($login); $replay = $this->maniaControl->client->getValidationReplay($login);
} } catch(Exception $e) {
catch (Exception $e) { //TODO temp added 19.04.2014
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 330 Server.php" . $e->getMessage());
trigger_error("Couldn't get validation replay of '{$login}'. " . $e->getMessage()); trigger_error("Couldn't get validation replay of '{$login}'. " . $e->getMessage());
return null; return null;
} }
@ -352,8 +368,10 @@ class Server implements CallbackListener {
// Save ghost replay // Save ghost replay
try { try {
$this->maniaControl->client->saveBestGhostsReplay($login, $fileName); $this->maniaControl->client->saveBestGhostsReplay($login, $fileName);
} } catch(Exception $e) {
catch (Exception $e) { //TODO temp added 19.04.2014
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 360 Server.php" . $e->getMessage());
trigger_error("Couldn't save ghost replay. " . $e->getMessage()); trigger_error("Couldn't save ghost replay. " . $e->getMessage());
return null; return null;
} }