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

View File

@ -7,7 +7,6 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\Bill;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* ManiaControl Bill-Manager
@ -58,17 +57,11 @@ class BillManager implements CallbackListener {
return false;
}
try {
if (!$receiver) {
$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message);
} else {
$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);
return true;
@ -89,14 +82,7 @@ class BillManager implements CallbackListener {
return false;
}
try {
$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);

View File

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

View File

@ -19,6 +19,8 @@ class FaultException extends Exception
return new CouldNotWritePlaylistFileException($faultString, $faultCode);
case 'Start index out of bound.':
return new StartIndexOutOfBoundException($faultString, $faultCode);
case 'Not in script mode.':
return new NotInScriptModeException($faultString, $faultCode);
}
return new self($faultString, $faultCode);
@ -28,4 +30,5 @@ class FaultException extends Exception
class LoginUnknownException extends FaultException {}
class CouldNotWritePlaylistFileException 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\Transport\TransportException;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php';
require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php';
@ -132,6 +133,7 @@ class ManiaControl implements CommandListener, TimerListener {
/**
* Checks connection every xxx Minutes
*
* @param $time
*/
public function checkConnection($time) {
@ -243,7 +245,7 @@ class ManiaControl implements CommandListener, TimerListener {
$this->client->sendHideManialinkPage();
// Close the client connection
$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());
}
}
@ -399,7 +401,7 @@ class ManiaControl implements CommandListener, TimerListener {
if (!$this->server->waitForStatus(4)) {
trigger_error("Server couldn't get ready!", E_USER_ERROR);
}
} catch(FatalException $e) {
} catch(Exception $e) {
// TODO remove
if ($this->errorHandler) {
$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
@ -420,12 +422,9 @@ class ManiaControl implements CommandListener, TimerListener {
try {
$scriptSettings = $this->client->getModeScriptSettings();
} catch(Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
} catch(NotInScriptModeException $e) {
return;
}
throw $e;
}
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
return;
@ -435,6 +434,9 @@ class ManiaControl implements CommandListener, TimerListener {
try {
$this->client->setModeScriptSettings($scriptSettings);
} 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());
return;
}

View File

@ -63,15 +63,19 @@ class Server implements CallbackListener {
* Load the Server Configuration from the Config XML
*/
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
$id = null;
global $argv;
foreach($argv as $arg) {
$parts = explode('=', $arg);
if (count($parts) < 2) continue;
if ($parts[0] != '-id') continue;
if (count($parts) < 2)
continue;
if ($parts[0] != '-id')
continue;
$id = $parts[1];
break;
}
@ -80,34 +84,45 @@ class Server implements CallbackListener {
$serverTag = null;
if ($id) {
$serverTags = $this->maniaControl->config->xpath("server[@id='{$id}']");
if ($serverTags) $serverTag = $serverTags[0];
if (!$serverTag) trigger_error("No Server configured with the ID '{$id}'!", E_USER_ERROR);
}
else {
if ($serverTags)
$serverTag = $serverTags[0];
if (!$serverTag)
trigger_error("No Server configured with the ID '{$id}'!", E_USER_ERROR);
} else {
$serverTags = $this->maniaControl->config->xpath('server');
if ($serverTags) $serverTag = $serverTags[0];
if (!$serverTag) trigger_error('No Server configured!', E_USER_ERROR);
if ($serverTags)
$serverTag = $serverTags[0];
if (!$serverTag)
trigger_error('No Server configured!', E_USER_ERROR);
}
// Host
$host = $serverTag->xpath('host');
if ($host) $host = (string) $host[0];
if (!$host) trigger_error("Invalid server configuration (host).", E_USER_ERROR);
if ($host)
$host = (string)$host[0];
if (!$host)
trigger_error("Invalid server configuration (host).", E_USER_ERROR);
// Port
$port = $serverTag->xpath('port');
if ($port) $port = (string) $port[0];
if (!$port) trigger_error("Invalid server configuration (port).", E_USER_ERROR);
if ($port)
$port = (string)$port[0];
if (!$port)
trigger_error("Invalid server configuration (port).", E_USER_ERROR);
// Login
$login = $serverTag->xpath('login');
if ($login) $login = (string) $login[0];
if (!$login) trigger_error("Invalid server configuration (login).", E_USER_ERROR);
if ($login)
$login = (string)$login[0];
if (!$login)
trigger_error("Invalid server configuration (login).", E_USER_ERROR);
// Pass
$pass = $serverTag->xpath('pass');
if ($pass) $pass = (string) $pass[0];
if (!$pass) trigger_error("Invalid server configuration (password).", E_USER_ERROR);
if ($pass)
$pass = (string)$pass[0];
if (!$pass)
trigger_error("Invalid server configuration (password).", E_USER_ERROR);
// Create config object
$this->config = new Config($id, $host, $port, $login, $pass);
@ -287,8 +302,7 @@ class Server implements CallbackListener {
public function getGameMode($stringValue = false, $parseValue = null) {
if (is_int($parseValue)) {
$gameMode = $parseValue;
}
else {
} else {
$gameMode = $this->maniaControl->client->getGameMode();
}
if ($stringValue) {
@ -323,8 +337,10 @@ class Server implements CallbackListener {
public function getValidationReplay($login) {
try {
$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());
return null;
}
@ -352,8 +368,10 @@ class Server implements CallbackListener {
// Save ghost replay
try {
$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());
return null;
}