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

View File

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

View File

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

View File

@ -60,6 +60,7 @@ class ManiaControl implements CommandListener {
const OS_UNIX = 'Unix';
const OS_WIN = 'Windows';
const CONNECT_TIMEOUT = 20;
const SCRIPT_TIMEOUT = 20;
/**
* Public properties
@ -83,6 +84,7 @@ class ManiaControl implements CommandListener {
public $statisticManager = null;
public $updateManager = null;
/**
* Private properties
*/
@ -155,21 +157,6 @@ class ManiaControl implements CommandListener {
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
*
@ -234,11 +221,8 @@ class ManiaControl implements CommandListener {
// Hide manialinks
$this->client->sendHideManialinkPage();
//TODO: $this->client->delete()
// Close connection
//$this->client->Terminate();
//Close the client connection
$this->client->delete($this->server->ip, $this->server->port);
$this->log('Quitting ManiaControl!');
exit();
@ -262,9 +246,6 @@ class ManiaControl implements CommandListener {
// Hide widgets
$this->client->sendHideManialinkPage();
// Close connection
//$this->client->Terminate(); //TODO
$this->log('Restarting ManiaControl!');
// Execute start script in background
@ -272,11 +253,9 @@ class ManiaControl implements CommandListener {
$command = 'sh ' . escapeshellarg(ManiaControlDir . '/ManiaControl.sh') . ' > /dev/null &';
exec($command);
} else {
// TODO: validate restart on windows
$command = 'start /B ' . escapeshellarg(ManiaControlDir . '/ManiaControl.bat');
pclose(popen($command, 'r'));
$command = escapeshellarg(ManiaControlDir . "\ManiaControl.bat");
system($command); //TODO, windows stucks here as long controller is running
}
exit();
}
@ -309,7 +288,7 @@ class ManiaControl implements CommandListener {
$loopStart = microtime(true);
// Disable script timeout
set_time_limit(30);
set_time_limit(self::SCRIPT_TIMEOUT);
// Manager callbacks
$this->callbackManager->manageCallbacks();
@ -322,9 +301,6 @@ class ManiaControl implements CommandListener {
}
}
//Close the client connection
//$this->client->Terminate();
// Shutdown
$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\ManiaControl;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
require_once __DIR__ . '/Map.php';
require_once __DIR__ . '/MapCommands.php';
@ -203,8 +204,10 @@ class MapManager implements CallbackListener {
$this->mxManager->unsetMap($map->mx->id);
// Remove map
if(!$this->maniaControl->client->removeMap($map->fileName)) {
trigger_error("Couldn't remove current map. " . $this->maniaControl->getClientErrorText());
try {
$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;
}
@ -247,11 +250,12 @@ class MapManager implements CallbackListener {
$mapArray = array_merge($higherMapArray, $lowerMapArray);
if(!$this->maniaControl->client->chooseNextMapList($mapArray)) {
trigger_error("Error while restructuring the Maplist. " . $this->maniaControl->getClientErrorText());
try {
$this->maniaControl->client->chooseNextMapList($mapArray);
} catch(Exception $e) {
trigger_error("Error while restructuring the Maplist. " . $e->getMessage());
return false;
}
return true;
}
@ -272,8 +276,10 @@ class MapManager implements CallbackListener {
$mapArray[] = $map->fileName;
}
if(!$this->maniaControl->client->chooseNextMapList($mapArray)) {
trigger_error("Couldn't shuffle mapList. " . $this->maniaControl->getClientErrorText());
try {
$this->maniaControl->client->chooseNextMapList($mapArray);
} catch(Exception $e) {
trigger_error("Couldn't shuffle mapList. " . $e->getMessage());
return false;
}
@ -320,8 +326,11 @@ class MapManager implements CallbackListener {
* Updates the full Map list, needed on Init, addMap and on ShuffleMaps
*/
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;
}
@ -350,10 +359,13 @@ class MapManager implements CallbackListener {
* @return bool
*/
private function fetchCurrentMap() {
if(!$rpcMap = $this->maniaControl->client->getCurrentMapInfo()) {
trigger_error("Couldn't fetch map info. " . $this->maniaControl->getClientErrorText());
try {
$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)) {
$this->currentMap = $this->maps[$rpcMap->uId];
return true;
@ -467,8 +479,10 @@ class MapManager implements CallbackListener {
*/
public function addMapFromMx($mapId, $login, $update = false) {
// Check if ManiaControl can even write to the maps dir
if(!$mapDir = $this->maniaControl->client->getMapsDirectory()) {
trigger_error("Couldn't get map directory. " . $this->maniaControl->getClientErrorText());
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;
}
@ -530,8 +544,10 @@ class MapManager implements CallbackListener {
// Check for valid map
$mapFileName = $downloadDirectory . '/' . $fileName;
if(!$response = $this->maniaControl->client->checkMapForCurrentServerParams($mapFileName)) {
trigger_error("Couldn't check if map is valid ('{$mapFileName}'). " . $this->maniaControl->getClientErrorText());
try {
$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);
return;
}

View File

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

View File

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

View File

@ -275,7 +275,7 @@ class Server implements CallbackListener {
try {
$gameMode = $this->maniaControl->client->getGameMode();
} 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;
}
}
@ -312,7 +312,7 @@ class Server implements CallbackListener {
try {
$replay = $this->maniaControl->client->getValidationReplay($player->login);
} 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 $replay;
@ -380,7 +380,7 @@ class Server implements CallbackListener {
}
if(time() - $maxWaitTime > $waitBegin) {
// 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;
}
}

View File

@ -11,6 +11,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* Class offering various commands related to the dedicated server
@ -216,8 +217,10 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
return;
}
$serverName = $params[1];
if(!$this->maniaControl->client->setServerName($serverName)) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
try {
$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);
@ -241,9 +244,10 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1];
$successMessage = "Password changed to: '{$password}'!";
}
$success = $this->maniaControl->client->setServerPassword($password);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
try {
$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);
@ -267,9 +271,10 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$password = $messageParts[1];
$successMessage = "Spectator password changed to: '{$password}'!";
}
$success = $this->maniaControl->client->setServerPasswordForSpectator($password);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
try {
$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);
@ -300,11 +305,14 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) {
$amount = 0;
}
$success = $this->maniaControl->client->setMaxPlayers($amount);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
try {
$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);
}
@ -333,9 +341,11 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
if($amount < 0) {
$amount = 0;
}
$success = $this->maniaControl->client->setMaxSpectators($amount);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
try {
$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);
@ -348,7 +358,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
* @return bool
*/
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());
return false;
}

View File

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

View File

@ -21,6 +21,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Server\ServerCommands;

View File

@ -16,6 +16,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* Donation plugin
@ -327,11 +328,14 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
}
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
if(!$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver)) {
trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText());
try {
$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);
return false;
}
$this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time());
return true;
@ -366,11 +370,16 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$receiver = $player->login;
}
$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);
return false;
}
$this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time());
return true;
}
@ -387,10 +396,13 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return false;
}
if(!$planets = $this->maniaControl->client->getServerPlanets()) {
trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText());
try {
$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!";
return $this->maniaControl->chat->sendInformation($message, $player->login);
}