improved exceptions

This commit is contained in:
kremsy 2014-04-19 23:14:37 +02:00 committed by Steffen Schröder
parent 7525b96ba1
commit ce22feee51
8 changed files with 52 additions and 82 deletions

View File

@ -4,6 +4,7 @@ namespace ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
/**
* Chat Utility Class
@ -80,10 +81,7 @@ class Chat {
}
try{
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
} catch(Exception $e){
if($e->getMessage() != "Login unknown."){
throw $e;
}
} catch(LoginUnknownException $e){
}
}
return true;

View File

@ -21,6 +21,10 @@ class FaultException extends Exception
return new StartIndexOutOfBoundException($faultString, $faultCode);
case 'Not in script mode.':
return new NotInScriptModeException($faultString, $faultCode);
case 'Change in progress.':
return new ChangeInProgressException($faultString, $faultCode);
case 'The player is not a spectator':
return new PlayerIsNotSpectatorException($faultString, $faultCode);
}
return new self($faultString, $faultCode);
@ -31,4 +35,6 @@ class LoginUnknownException extends FaultException {}
class CouldNotWritePlaylistFileException extends FaultException {}
class StartIndexOutOfBoundException extends FaultException {}
class NotInScriptModeException extends FaultException {}
class ChangeInProgressException extends FaultException {}
class PlayerIsNotSpectatorException extends FaultException {}
?>

View File

@ -11,6 +11,8 @@ use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
/**
* Manialink Manager Class
@ -159,12 +161,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
return $success;
}
} catch(Exception $e) {
if($e->getMessage() == "Login unknown.") {
} catch(LoginUnknownException $e) {
return false;
}
throw $e;
}
return true;
}
@ -178,12 +177,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
public function enableAltMenu(Player $player) {
try {
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $player->login);
} catch(Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
} catch(NotInScriptModeException $e) {
return false;
}
throw $e;
}
return $success;
}
@ -196,12 +192,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
public function disableAltMenu(Player $player) {
try {
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $player->login);
} catch(Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
} catch(NotInScriptModeException $e) {
return false;
}
throw $e;
}
return $success;
}

View File

@ -11,7 +11,7 @@ use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\IconManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException;
/**
* Class offering Commands to manage Maps
@ -210,10 +210,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
try {
$this->maniaControl->client->restartMap();
} catch(Exception $e) {
if ($e->getMessage() != 'Change in progress.') {
throw $e;
}
} catch(ChangeInProgressException $e) {
}
}

View File

@ -553,7 +553,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$index = $this->maniaControl->mapManager->getMapIndex($map);
$this->maniaControl->client->jumpToMapIndex($index);
} catch(Exception $e) {
// TODO: is it even possible that an exception other than connection errors will be thrown? - remove try-catch?
//TODO temp added 19.04.2014
$this->maniaControl->errorHandler->triggerDebugNotice("Exception line 557 MapList.php" . $e->getMessage());
$this->maniaControl->chat->sendError("Error while Switching Map");
}
});

View File

@ -109,7 +109,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
try {
$this->maniaControl->client->autoTeamBalance();
} catch(Exception $e) {
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerCommands Debug Line 110: " . $e->getMessage());
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerCommands Debug Line 112: " . $e->getMessage());
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;

View File

@ -23,7 +23,7 @@ use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException;
/**
* PlayerList Widget Class
@ -650,10 +650,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
try {
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
} catch(Exception $e) {
if($e->getMessage() != "The player is not a spectator"){
throw $e;
}
} catch(PlayerIsNotSpectatorException $e) {
}
break;
case self::ACTION_OPEN_PLAYER_DETAILED:
@ -724,10 +721,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
try {
$this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(Exception $e) {
if ($e->getMessage() != 'Login unknown.' && $e->getMessage() != 'The player is not a spectator') {
$this->maniaControl->chat->sendException($e);
}
} catch(PlayerIsNotSpectatorException $e) {
}
});
break;
@ -748,14 +742,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$votesPlugin->undefineVote('kick');
$message = '$39F You got kicked due a Public vote!$z ';
try {
$this->maniaControl->client->kick($target->login, $message);
} catch(Exception $e) {
$this->maniaControl->errorHandler->triggerDebugNotice("PlayerList Debug Line 751: " . $e->getMessage());
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $target->login);
return;
}
});
break;
}
@ -768,7 +755,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
*/
public function updateWidget(Player $player) {
foreach($this->playersListShown as $login => $shown) {
if (!$shown) continue;
if (!$shown) {
continue;
}
// Check if shown player still exists
$player = $this->maniaControl->playerManager->getPlayer($login);

View File

@ -13,7 +13,7 @@ use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
/**
* Class offering various Commands related to the Dedicated Server
@ -106,12 +106,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
//Check if Pause exists in current GameMode
try {
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
} catch(Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
} catch(NotInScriptModeException $e) {
return;
}
throw $e;
}
$pauseExists = false;
foreach($scriptInfos->commandDescs as $param) {
if ($param->name == "Command_ForceWarmUp") {
@ -164,13 +161,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
try {
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Extend', '10');
} catch(Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
} catch(NotInScriptModeException $e) {
return;
}
throw $e;
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> extended the WarmUp by 10 seconds!');
}
@ -189,13 +182,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
try {
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Stop', '');
} catch(Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
} catch(NotInScriptModeException $e) {
return;
}
throw $e;
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!');
}
@ -212,13 +201,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
}
try {
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
} catch(Exception $e) {
if ($e->getMessage() == 'Not in script mode.') {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
} catch(NotInScriptModeException $e) {
return;
}
throw $e;
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> paused the Game!');
}