cleanup, exception handling

This commit is contained in:
kremsy 2014-01-20 20:51:03 +01:00 committed by Steffen Schröder
parent 796d46f199
commit a17037c3cb
13 changed files with 190 additions and 134 deletions

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Callbacks; namespace ManiaControl\Callbacks;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class for managing Server and ManiaControl Callbacks * Class for managing Server and ManiaControl Callbacks
@ -192,10 +193,10 @@ class CallbackManager {
return; return;
} }
$callbacks = $this->maniaControl->client->executeCallbacks(); try{
if(!is_array($callbacks)) { $callbacks = $this->maniaControl->client->executeCallbacks();
trigger_error("Error reading server callbacks. " . $this->maniaControl->getClientErrorText()); }catch(Exception $e){
return; trigger_error("Error reading server callbacks. " . $e->getMessage());
} }
// Handle callbacks // Handle callbacks

View File

@ -13,6 +13,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;
/** /**
* Class offering a Configurator for Script Settings * Class offering a Configurator for Script Settings
@ -123,9 +124,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
return true; return true;
} }
$success = $this->maniaControl->client->setModeScriptSettings($loadedSettings); try {
if(!$success) { $this->maniaControl->client->setModeScriptSettings($loadedSettings);
trigger_error('Error occured: ' . $this->maniaControl->getClientErrorText()); } catch(Exception $e) {
trigger_error('Error occured: ' . $e->getMessage());
return false; return false;
} }
return true; return true;
@ -374,9 +376,11 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
if(!$newSettings) { if(!$newSettings) {
return true; return true;
} }
$success = $this->maniaControl->client->setModeScriptSettings($newSettings);
if(!$success) { try {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $success = $this->maniaControl->client->setModeScriptSettings($newSettings);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return false; return false;
} }

View File

@ -13,6 +13,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;
/** /**
* Class offering a Configurator for Server Settings * Class offering a Configurator for Server Settings
@ -113,9 +114,10 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
return true; return true;
} }
$success = $this->maniaControl->client->getServerOptions($loadedSettings); try {
if(!$success) { $this->maniaControl->client->setServerOptions($loadedSettings);
trigger_error('Error occurred: ' . $this->maniaControl->getClientErrorText()); } catch(Exception $e) {
trigger_error('Error occured: ' . $e->getMessage());
return false; return false;
} }
return true; return true;
@ -329,9 +331,10 @@ class ServerSettings implements ConfiguratorMenu, CallbackListener {
return true; return true;
} }
$success = $this->maniaControl->client->setServerOptions($newSettings); try {
if(!$success) { $this->maniaControl->client->setServerOptions($newSettings);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); } catch(Exception $e) {
trigger_error('Error occured: ' . $e->getMessage());
return false; return false;
} }

View File

@ -60,6 +60,7 @@ class ManiaControl implements CommandListener {
const OS_UNIX = 'Unix'; const OS_UNIX = 'Unix';
const OS_WIN = 'Windows'; const OS_WIN = 'Windows';
const CONNECT_TIMEOUT = 20; const CONNECT_TIMEOUT = 20;
const SCRIPT_TIMEOUT = 20;
/** /**
* Public properties * Public properties
@ -83,6 +84,7 @@ class ManiaControl implements CommandListener {
public $statisticManager = null; public $statisticManager = null;
public $updateManager = null; public $updateManager = null;
/** /**
* Private properties * Private properties
*/ */
@ -155,21 +157,6 @@ class ManiaControl implements CommandListener {
return self::OS_UNIX; return self::OS_UNIX;
} }
/**
* Return message composed of client error message and error code
*
* @param object $client
* @return string
*/
public function getClientErrorText($client = null) {
/*if(is_object($client)) {
return $client->getErrorMessage() . ' (' . $client->getErrorCode() . ')';
}
return $this->client->getErrorMessage() . ' (' . $this->client->getErrorCode() . ')';*/
//TODO
}
/** /**
* Handle Version Command * Handle Version Command
* *
@ -234,11 +221,8 @@ class ManiaControl implements CommandListener {
// Hide manialinks // Hide manialinks
$this->client->sendHideManialinkPage(); $this->client->sendHideManialinkPage();
//Close the client connection
//TODO: $this->client->delete() $this->client->delete($this->server->ip, $this->server->port);
// Close connection
//$this->client->Terminate();
$this->log('Quitting ManiaControl!'); $this->log('Quitting ManiaControl!');
exit(); exit();
@ -262,9 +246,6 @@ class ManiaControl implements CommandListener {
// Hide widgets // Hide widgets
$this->client->sendHideManialinkPage(); $this->client->sendHideManialinkPage();
// Close connection
//$this->client->Terminate(); //TODO
$this->log('Restarting ManiaControl!'); $this->log('Restarting ManiaControl!');
// Execute start script in background // Execute start script in background
@ -272,11 +253,9 @@ class ManiaControl implements CommandListener {
$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &'; $command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
exec($command); exec($command);
} else { } else {
// TODO: validate restart on windows $command = escapeshellarg(ManiaControlDir . "\ManiaControl.bat");
$command = 'start /B ' . escapeshellarg(ManiaControlDir . '/ManiaControl.bat'); system($command); //TODO, windows stucks here as long controller is running
pclose(popen($command, 'r'));
} }
exit(); exit();
} }
@ -309,7 +288,7 @@ class ManiaControl implements CommandListener {
$loopStart = microtime(true); $loopStart = microtime(true);
// Disable script timeout // Disable script timeout
set_time_limit(30); set_time_limit(self::SCRIPT_TIMEOUT);
// Manager callbacks // Manager callbacks
$this->callbackManager->manageCallbacks(); $this->callbackManager->manageCallbacks();
@ -322,9 +301,6 @@ class ManiaControl implements CommandListener {
} }
} }
//Close the client connection
//$this->client->Terminate();
// Shutdown // Shutdown
$this->quit(); $this->quit();
} }

View File

@ -0,0 +1,18 @@
<?php
/**
* @version $Revision: $:
* @author $Author: $:
* @date $Date: $:
*/
namespace Maniaplanet\DedicatedServer\Structures;
class Command extends AbstractStructure
{
public $name;
public $desc;
public $type;
public $default;
}
?>

View File

@ -9,6 +9,7 @@ use ManiaControl\FileUtil;
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;
require_once __DIR__ . '/Map.php'; require_once __DIR__ . '/Map.php';
require_once __DIR__ . '/MapCommands.php'; require_once __DIR__ . '/MapCommands.php';
@ -203,8 +204,10 @@ class MapManager implements CallbackListener {
$this->mxManager->unsetMap($map->mx->id); $this->mxManager->unsetMap($map->mx->id);
// Remove map // Remove map
if(!$this->maniaControl->client->removeMap($map->fileName)) { try {
trigger_error("Couldn't remove current map. " . $this->maniaControl->getClientErrorText()); $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); $this->maniaControl->chat->sendError("Couldn't remove map.", $admin);
return; return;
} }
@ -247,11 +250,12 @@ class MapManager implements CallbackListener {
$mapArray = array_merge($higherMapArray, $lowerMapArray); $mapArray = array_merge($higherMapArray, $lowerMapArray);
if(!$this->maniaControl->client->chooseNextMapList($mapArray)) { try {
trigger_error("Error while restructuring the Maplist. " . $this->maniaControl->getClientErrorText()); $this->maniaControl->client->chooseNextMapList($mapArray);
} catch(Exception $e) {
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
return false; return false;
} }
return true; return true;
} }
@ -272,8 +276,10 @@ class MapManager implements CallbackListener {
$mapArray[] = $map->fileName; $mapArray[] = $map->fileName;
} }
if(!$this->maniaControl->client->chooseNextMapList($mapArray)) { try {
trigger_error("Couldn't shuffle mapList. " . $this->maniaControl->getClientErrorText()); $this->maniaControl->client->chooseNextMapList($mapArray);
} catch(Exception $e) {
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
return false; return false;
} }
@ -320,8 +326,11 @@ 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() {
if(!$maps = $this->maniaControl->client->getMapList(100, 0)) {
trigger_error("Couldn't fetch mapList. " . $this->maniaControl->getClientErrorText()); try {
$maps = $this->maniaControl->client->getMapList(100, 0);
} catch(Exception $e) {
trigger_error("Couldn't fetch mapList. " . $e->getMessage());
return null; return null;
} }
@ -350,10 +359,13 @@ class MapManager implements CallbackListener {
* @return bool * @return bool
*/ */
private function fetchCurrentMap() { private function fetchCurrentMap() {
if(!$rpcMap = $this->maniaControl->client->getCurrentMapInfo()) { try {
trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText()); $rpcMap = $this->maniaControl->client->getCurrentMapInfo();
} catch(Exception $e) {
trigger_error("Couldn't fetch map info. " . $e->getMessage());
return false; 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];
return true; return true;
@ -467,8 +479,10 @@ class MapManager implements CallbackListener {
*/ */
public function addMapFromMx($mapId, $login, $update = false) { public function addMapFromMx($mapId, $login, $update = false) {
// Check if ManiaControl can even write to the maps dir // Check if ManiaControl can even write to the maps dir
if(!$mapDir = $this->maniaControl->client->getMapsDirectory()) { try {
trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText()); $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); $this->maniaControl->chat->sendError("ManiaControl couldn't retrieve the maps directory.", $login);
return; return;
} }
@ -530,8 +544,10 @@ class MapManager implements CallbackListener {
// Check for valid map // Check for valid map
$mapFileName = $downloadDirectory . '/' . $fileName; $mapFileName = $downloadDirectory . '/' . $fileName;
if(!$response = $this->maniaControl->client->checkMapForCurrentServerParams($mapFileName)) { try {
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText()); $response = $this->maniaControl->client->checkMapForCurrentServerParams($mapFileName);
} catch(Exception $e) {
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $e->getMessage());
$this->maniaControl->chat->sendError('Error checking map!', $login); $this->maniaControl->chat->sendError('Error checking map!', $login);
return; return;
} }

View File

@ -87,8 +87,7 @@ class PlayerActions {
$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 $e error text $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -96,8 +95,7 @@ class PlayerActions {
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 $e error text $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
} }
@ -131,9 +129,10 @@ class PlayerActions {
$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false); $this->forcePlayerToPlay($adminLogin, $targetLogin, true, false);
} }
$success = $this->maniaControl->client->forcePlayerTeam($target->login, $teamId); try {
if(!$success) { $this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -170,8 +169,7 @@ 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 error message from $e $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
@ -185,7 +183,7 @@ class PlayerActions {
try { try {
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login); $this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(Exception $e) { } catch(Exception $e) {
//TODO error message from $e //do nothing
} }
} }
} }
@ -206,9 +204,10 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->unIgnore($target->login); try {
if(!$success) { $this->maniaControl->client->unIgnore($targetLogin);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $adminLogin);
return; return;
} }
@ -234,9 +233,10 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->ignore($targetLogin); try {
if(!$success) { $this->maniaControl->client->ignore($targetLogin);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -344,13 +344,14 @@ class PlayerActions {
return; return;
} }
if($target->isFakePlayer()) { try {
$success = $this->maniaControl->client->disconnectFakePlayer($target->login); if($target->isFakePlayer()) {
} else { $this->maniaControl->client->disconnectFakePlayer($target->login);
$success = $this->maniaControl->client->kick($target->login, $message); } else {
} $this->maniaControl->client->kick($target->login, $message);
if(!$success) { }
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }
@ -384,9 +385,10 @@ class PlayerActions {
return; return;
} }
$success = $this->maniaControl->client->ban($target->login, $message); try {
if(!$success) { $this->maniaControl->client->ban($target->login, $message);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return; return;
} }

View File

@ -8,6 +8,7 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
* Class offering various Admin Commands related to Players * Class offering various Admin Commands related to Players
@ -82,11 +83,14 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->autoTeamBalance();
if(!$success) { try {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->client->autoTeamBalance();
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> balanced Teams!'); $this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> balanced Teams!');
} }
@ -244,16 +248,15 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
if(isset($messageParts[1]) && is_numeric($messageParts[1])) { if(isset($messageParts[1]) && is_numeric($messageParts[1])) {
$amount = intval($messageParts[1]); $amount = intval($messageParts[1]);
} }
$success = true; try {
for($i = 0; $i < $amount; $i++) { for($i = 0; $i < $amount; $i++) {
if(!$this->maniaControl->client->connectFakePlayer()) { $this->maniaControl->client->connectFakePlayer();
$success = false;
} }
} } catch(Exception $e) {
if(!$success) { $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendSuccess('Fake players connected!', $player->login); $this->maniaControl->chat->sendSuccess('Fake players connected!', $player->login);
} }
@ -268,11 +271,14 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return; return;
} }
$success = $this->maniaControl->client->disconnectFakePlayer('*');
if(!$success) { try {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->client->disconnectFakePlayer('*');
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login); $this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login);
} }

View File

@ -275,7 +275,7 @@ class Server implements CallbackListener {
try { try {
$gameMode = $this->maniaControl->client->getGameMode(); $gameMode = $this->maniaControl->client->getGameMode();
} catch(Exception $e) { } catch(Exception $e) {
trigger_error("Couldn't fetch current game mode. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't fetch current game mode. " . $e->getMessage());
return null; return null;
} }
} }
@ -312,7 +312,7 @@ class Server implements CallbackListener {
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}'. " . $this->maniaControl->getClientErrorText()); trigger_error("Couldn't get validation replay of '{$player->login}'. " . $e->getMessage());
return null; return null;
} }
return $replay; return $replay;
@ -380,7 +380,7 @@ class Server implements CallbackListener {
} }
if(time() - $maxWaitTime > $waitBegin) { if(time() - $maxWaitTime > $waitBegin) {
// It took too long to reach the status // It took too long to reach the status
trigger_error("Server couldn't reach status {$statusCode} after {$maxWaitTime} seconds! " . $this->maniaControl->getClientErrorText()); trigger_error("Server couldn't reach status {$statusCode} after {$maxWaitTime} seconds! ");
return false; return false;
} }
} }

View File

@ -11,6 +11,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
@ -216,8 +217,10 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
return; return;
} }
$serverName = $params[1]; $serverName = $params[1];
if(!$this->maniaControl->client->setServerName($serverName)) { try {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->client->setServerName($serverName);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendSuccess("Server name changed to: '{$serverName}'!", $player->login); $this->maniaControl->chat->sendSuccess("Server name changed to: '{$serverName}'!", $player->login);
@ -241,9 +244,10 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!"; $successMessage = "Password changed to: '{$password}'!";
} }
$success = $this->maniaControl->client->setServerPassword($password); try {
if(!$success) { $this->maniaControl->client->setServerPassword($password);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendSuccess($successMessage, $player->login); $this->maniaControl->chat->sendSuccess($successMessage, $player->login);
@ -267,9 +271,10 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1]; $password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!"; $successMessage = "Spectator password changed to: '{$password}'!";
} }
$success = $this->maniaControl->client->setServerPasswordForSpectator($password); try {
if(!$success) { $this->maniaControl->client->setServerPasswordForSpectator($password);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendSuccess($successMessage, $player->login); $this->maniaControl->chat->sendSuccess($successMessage, $player->login);
@ -300,11 +305,14 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) { if($amount < 0) {
$amount = 0; $amount = 0;
} }
$success = $this->maniaControl->client->setMaxPlayers($amount);
if(!$success) { try {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->client->setMaxPlayers($amount);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendSuccess("Changed max players to: {$amount}", $player->login); $this->maniaControl->chat->sendSuccess("Changed max players to: {$amount}", $player->login);
} }
@ -333,9 +341,11 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) { if($amount < 0) {
$amount = 0; $amount = 0;
} }
$success = $this->maniaControl->client->setMaxSpectators($amount);
if(!$success) { try {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); $this->maniaControl->client->setMaxSpectators($amount);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
$this->maniaControl->chat->sendSuccess("Changed max spectators to: {$amount}", $player->login); $this->maniaControl->chat->sendSuccess("Changed max spectators to: {$amount}", $player->login);
@ -348,7 +358,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* @return bool * @return bool
*/ */
private function shutdownServer($login = '#') { private function shutdownServer($login = '#') {
if(!$this->maniaControl->client->stopServer()) { try {
$this->maniaControl->client->stopServer();
} catch(Exception $e) {
trigger_error("Server shutdown command from '{login}' failed. " . $this->maniaControl->getClientErrorText()); trigger_error("Server shutdown command from '{login}' failed. " . $this->maniaControl->getClientErrorText());
return false; return false;
} }

View File

@ -3,6 +3,7 @@
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception; use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/** /**
@ -300,9 +301,10 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$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, please come back soon!$z';
$success = $this->maniaControl->client->kick($player->login, $message); try {
if(!$success) { $this->maniaControl->client->kick($player->login, $message);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
} }
@ -318,9 +320,10 @@ class ChatMessagePlugin implements CommandListener, Plugin {
$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, please come back soon!$z';
$success = $this->maniaControl->client->kick($player->login, $message); try {
if(!$success) { $this->maniaControl->client->kick($player->login, $message);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
} }
@ -337,9 +340,10 @@ class ChatMessagePlugin implements CommandListener, Plugin {
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)) { if($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)) {
// force into spec // force into spec
$success = $this->maniaControl->client->forceSpectator($player->login, 3); try {
if(!$success) { $this->maniaControl->client->forceSpectator($player->login, 3);
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login); } catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return; return;
} }
@ -347,6 +351,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
try { try {
$this->maniaControl->client->spectatorReleasePlayerSlot($player->login); $this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
} catch(Exception $e) { } catch(Exception $e) {
//to nothing
} }
} }
} }

View File

@ -21,6 +21,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; 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\Server\ServerCommands; use ManiaControl\Server\ServerCommands;

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
@ -327,11 +328,14 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
} }
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?'; $message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
if(!$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver)) { try {
trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); $bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver);
} catch(Exception $e) {
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;
} }
$this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time()); $this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time());
return true; return true;
@ -366,11 +370,16 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$receiver = $player->login; $receiver = $player->login;
} }
$message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.'; $message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.';
if(!$bill = $this->maniaControl->client->pay($receiver, $amount, $message)) {
trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText()); try {
$bill = $this->maniaControl->client->pay($receiver, $amount, $message);
} catch(Exception $e) {
trigger_error("Couldn't retrieve server planets. " . $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;
} }
$this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time()); $this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time());
return true; return true;
} }
@ -387,10 +396,13 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$this->maniaControl->authenticationManager->sendNotAllowed($player); $this->maniaControl->authenticationManager->sendNotAllowed($player);
return false; return false;
} }
if(!$planets = $this->maniaControl->client->getServerPlanets()) { try {
trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText()); $planets = $this->maniaControl->client->getServerPlanets();
} catch(Exception $e) {
trigger_error("Couldn't retrieve server planets. " . $e->getMessage());
return false; 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);
} }