From e71b763075cb504369f8385c4872ffa3cd5eeac9 Mon Sep 17 00:00:00 2001 From: kremsy Date: Thu, 16 Jan 2014 21:51:25 +0100 Subject: [PATCH] exceptions spectator actions --- application/core/Players/PlayerActions.php | 28 ++++++++++++++++------ application/core/Players/PlayerList.php | 8 ++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/application/core/Players/PlayerActions.php b/application/core/Players/PlayerActions.php index b428f1e3..61b4c7d6 100644 --- a/application/core/Players/PlayerActions.php +++ b/application/core/Players/PlayerActions.php @@ -11,6 +11,8 @@ use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkManager; +use Maniaplanet\DedicatedServer\InvalidArgumentException; +use Maniaplanet\DedicatedServer\Xmlrpc\Exception; /** * PlayerActions Class @@ -82,15 +84,20 @@ class PlayerActions { return; } - $success = $this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER); - if(!$success) { + try { + $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); return; } if($userIsAbleToSelect) { - $success = $this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE); - if(!$success) { + 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); return; } @@ -161,8 +168,10 @@ class PlayerActions { } $target = $this->maniaControl->playerManager->getPlayer($targetLogin); - $success = $this->maniaControl->client->forceSpectator($target->login, $spectatorState); - if(!$success) { + 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); return; } @@ -174,7 +183,12 @@ class PlayerActions { if($releaseSlot) { // Free player slot - //$this->maniaControl->client->spectatorReleasePlayerSlot($target->login); //TODO not in spec exception mp crash + try { + $this->maniaControl->client->spectatorReleasePlayerSlot($target->login); + } catch(InvalidArgumentException $e) { + //TODO error message from $e + $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); + } } } diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 4c3fc9af..421d9c93 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -22,6 +22,8 @@ use ManiaControl\Formatter; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkManager; use ManiaControl\Manialinks\ManialinkPageAnswerListener; +use Maniaplanet\DedicatedServer\InvalidArgumentException; +use Maniaplanet\DedicatedServer\Xmlrpc\Exception; /** * PlayerList Widget Class @@ -593,7 +595,11 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener { switch($action) { case self::ACTION_SPECTATE_PLAYER: $this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); - //$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1); //TODO mc crash player is not a spectator + try { + $this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1); //TODO mc crash player is not a spectator + } catch(Exception $e) { + //TODO error message from $e + } break; case self::ACTION_OPEN_PLAYER_DETAILED: $player = $this->maniaControl->playerManager->getPlayer($adminLogin);