improved exceptions
This commit is contained in:
parent
7525b96ba1
commit
ce22feee51
@ -4,6 +4,7 @@ namespace ManiaControl;
|
|||||||
|
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chat Utility Class
|
* Chat Utility Class
|
||||||
@ -80,10 +81,7 @@ class Chat {
|
|||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
|
$this->maniaControl->client->chatSendServerMessage($chatMessage, $login);
|
||||||
} catch(Exception $e){
|
} catch(LoginUnknownException $e){
|
||||||
if($e->getMessage() != "Login unknown."){
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,6 +21,10 @@ class FaultException extends Exception
|
|||||||
return new StartIndexOutOfBoundException($faultString, $faultCode);
|
return new StartIndexOutOfBoundException($faultString, $faultCode);
|
||||||
case 'Not in script mode.':
|
case 'Not in script mode.':
|
||||||
return new NotInScriptModeException($faultString, $faultCode);
|
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);
|
return new self($faultString, $faultCode);
|
||||||
@ -31,4 +35,6 @@ class LoginUnknownException extends FaultException {}
|
|||||||
class CouldNotWritePlaylistFileException extends FaultException {}
|
class CouldNotWritePlaylistFileException extends FaultException {}
|
||||||
class StartIndexOutOfBoundException extends FaultException {}
|
class StartIndexOutOfBoundException extends FaultException {}
|
||||||
class NotInScriptModeException extends FaultException {}
|
class NotInScriptModeException extends FaultException {}
|
||||||
|
class ChangeInProgressException extends FaultException {}
|
||||||
|
class PlayerIsNotSpectatorException extends FaultException {}
|
||||||
?>
|
?>
|
||||||
|
@ -11,6 +11,8 @@ use ManiaControl\Callbacks\CallbackManager;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||||
|
use Maniaplanet\DedicatedServer\Xmlrpc\LoginUnknownException;
|
||||||
|
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manialink Manager Class
|
* Manialink Manager Class
|
||||||
@ -159,12 +161,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
} catch(Exception $e) {
|
} catch(LoginUnknownException $e) {
|
||||||
if($e->getMessage() == "Login unknown.") {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -178,12 +177,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
public function enableAltMenu(Player $player) {
|
public function enableAltMenu(Player $player) {
|
||||||
try {
|
try {
|
||||||
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $player->login);
|
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_EnableAltMenu', $player->login);
|
||||||
} catch(Exception $e) {
|
} catch(NotInScriptModeException $e) {
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,12 +192,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
public function disableAltMenu(Player $player) {
|
public function disableAltMenu(Player $player) {
|
||||||
try {
|
try {
|
||||||
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $player->login);
|
$success = $this->maniaControl->client->triggerModeScriptEvent('LibXmlRpc_DisableAltMenu', $player->login);
|
||||||
} catch(Exception $e) {
|
} catch(NotInScriptModeException $e) {
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
return $success;
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use ManiaControl\ManiaControl;
|
|||||||
use ManiaControl\Manialinks\IconManager;
|
use ManiaControl\Manialinks\IconManager;
|
||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\ChangeInProgressException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class offering Commands to manage Maps
|
* Class offering Commands to manage Maps
|
||||||
@ -210,10 +210,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->restartMap();
|
$this->maniaControl->client->restartMap();
|
||||||
} catch(Exception $e) {
|
} catch(ChangeInProgressException $e) {
|
||||||
if ($e->getMessage() != 'Change in progress.') {
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,7 +553,9 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
|
|||||||
$index = $this->maniaControl->mapManager->getMapIndex($map);
|
$index = $this->maniaControl->mapManager->getMapIndex($map);
|
||||||
$this->maniaControl->client->jumpToMapIndex($index);
|
$this->maniaControl->client->jumpToMapIndex($index);
|
||||||
} catch(Exception $e) {
|
} 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");
|
$this->maniaControl->chat->sendError("Error while Switching Map");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -109,7 +109,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
|||||||
try {
|
try {
|
||||||
$this->maniaControl->client->autoTeamBalance();
|
$this->maniaControl->client->autoTeamBalance();
|
||||||
} catch(Exception $e) {
|
} 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)
|
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||||
return;
|
return;
|
||||||
|
@ -23,7 +23,7 @@ use ManiaControl\Formatter;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Manialinks\ManialinkManager;
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
use Maniaplanet\DedicatedServer\Xmlrpc\PlayerIsNotSpectatorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PlayerList Widget Class
|
* PlayerList Widget Class
|
||||||
@ -650,10 +650,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
try {
|
try {
|
||||||
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||||
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
||||||
} catch(Exception $e) {
|
} catch(PlayerIsNotSpectatorException $e) {
|
||||||
if($e->getMessage() != "The player is not a spectator"){
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::ACTION_OPEN_PLAYER_DETAILED:
|
case self::ACTION_OPEN_PLAYER_DETAILED:
|
||||||
@ -724,10 +721,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
try {
|
try {
|
||||||
$this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
$this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||||
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
||||||
} catch(Exception $e) {
|
} catch(PlayerIsNotSpectatorException $e) {
|
||||||
if ($e->getMessage() != 'Login unknown.' && $e->getMessage() != 'The player is not a spectator') {
|
|
||||||
$this->maniaControl->chat->sendException($e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@ -748,14 +742,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
$votesPlugin->undefineVote('kick');
|
$votesPlugin->undefineVote('kick');
|
||||||
|
|
||||||
$message = '$39F You got kicked due a Public vote!$z ';
|
$message = '$39F You got kicked due a Public vote!$z ';
|
||||||
try {
|
|
||||||
$this->maniaControl->client->kick($target->login, $message);
|
$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;
|
break;
|
||||||
}
|
}
|
||||||
@ -768,7 +755,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
*/
|
*/
|
||||||
public function updateWidget(Player $player) {
|
public function updateWidget(Player $player) {
|
||||||
foreach($this->playersListShown as $login => $shown) {
|
foreach($this->playersListShown as $login => $shown) {
|
||||||
if (!$shown) continue;
|
if (!$shown) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if shown player still exists
|
// Check if shown player still exists
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
@ -13,7 +13,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;
|
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class offering various Commands related to the Dedicated Server
|
* 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
|
//Check if Pause exists in current GameMode
|
||||||
try {
|
try {
|
||||||
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
|
||||||
} catch(Exception $e) {
|
} catch(NotInScriptModeException $e) {
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
$pauseExists = false;
|
$pauseExists = false;
|
||||||
foreach($scriptInfos->commandDescs as $param) {
|
foreach($scriptInfos->commandDescs as $param) {
|
||||||
if ($param->name == "Command_ForceWarmUp") {
|
if ($param->name == "Command_ForceWarmUp") {
|
||||||
@ -164,13 +161,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Extend', '10');
|
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Extend', '10');
|
||||||
} catch(Exception $e) {
|
} catch(NotInScriptModeException $e) {
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> extended the WarmUp by 10 seconds!');
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> extended the WarmUp by 10 seconds!');
|
||||||
}
|
}
|
||||||
@ -189,13 +182,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Stop', '');
|
$this->maniaControl->client->triggerModeScriptEvent('WarmUp_Stop', '');
|
||||||
} catch(Exception $e) {
|
} catch(NotInScriptModeException $e) {
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!');
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!');
|
||||||
}
|
}
|
||||||
@ -212,13 +201,9 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
|
$this->maniaControl->client->sendModeScriptCommands(array('Command_ForceWarmUp' => True));
|
||||||
} catch(Exception $e) {
|
} catch(NotInScriptModeException $e) {
|
||||||
if ($e->getMessage() == 'Not in script mode.') {
|
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> paused the Game!');
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> paused the Game!');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user