improved exceptions
This commit is contained in:
parent
7525b96ba1
commit
ce22feee51
@ -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;
|
||||
|
@ -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 {}
|
||||
?>
|
||||
|
@ -11,13 +11,15 @@ 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
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener {
|
||||
/*
|
||||
@ -130,9 +132,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
* @return bool
|
||||
*/
|
||||
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
|
||||
$manialinkText = (string) $manialinkText;
|
||||
$manialinkText = (string)$manialinkText;
|
||||
|
||||
if(!$manialinkText) {
|
||||
if (!$manialinkText) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -150,7 +152,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
}
|
||||
if (is_array($logins)) {
|
||||
$success = true;
|
||||
foreach ($logins as $login) {
|
||||
foreach($logins as $login) {
|
||||
$subSuccess = $this->maniaControl->client->sendDisplayManialinkPage($login, $manialinkText, $timeout, $hideOnClick);
|
||||
if (!$subSuccess) {
|
||||
$success = false;
|
||||
@ -159,11 +161,8 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
||||
|
||||
return $success;
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
if($e->getMessage() == "Login unknown.") {
|
||||
return false;
|
||||
}
|
||||
throw $e;
|
||||
} catch(LoginUnknownException $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -178,11 +177,8 @@ 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.') {
|
||||
return false;
|
||||
}
|
||||
throw $e;
|
||||
} catch(NotInScriptModeException $e) {
|
||||
return false;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
@ -196,11 +192,8 @@ 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.') {
|
||||
return false;
|
||||
}
|
||||
throw $e;
|
||||
} catch(NotInScriptModeException $e) {
|
||||
return false;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
@ -11,14 +11,14 @@ 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
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
||||
/*
|
||||
@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
});
|
||||
|
@ -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;
|
||||
|
@ -23,14 +23,14 @@ 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
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class PlayerList implements ManialinkPageAnswerListener, CallbackListener, TimerListener {
|
||||
/*
|
||||
@ -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;
|
||||
}
|
||||
$this->maniaControl->client->kick($target->login, $message);
|
||||
});
|
||||
break;
|
||||
}
|
||||
@ -767,16 +754,18 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
* @param Player $player
|
||||
*/
|
||||
public function updateWidget(Player $player) {
|
||||
foreach ($this->playersListShown as $login => $shown) {
|
||||
if (!$shown) continue;
|
||||
|
||||
foreach($this->playersListShown as $login => $shown) {
|
||||
if (!$shown) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if shown player still exists
|
||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||
if (!$player) {
|
||||
unset($this->playersListShown[$login]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Reopen widget
|
||||
if ($shown != self::SHOWN_MAIN_WINDOW) {
|
||||
$this->playersListShown[$login] = false;
|
||||
|
@ -13,14 +13,14 @@ 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
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
* @author steeffeen & kremsy
|
||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ServerCommands implements CallbackListener, CommandListener, ManialinkPageAnswerListener, TimerListener {
|
||||
/*
|
||||
@ -106,11 +106,8 @@ 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.') {
|
||||
return;
|
||||
}
|
||||
throw $e;
|
||||
} catch(NotInScriptModeException $e) {
|
||||
return;
|
||||
}
|
||||
$pauseExists = false;
|
||||
foreach($scriptInfos->commandDescs as $param) {
|
||||
@ -164,12 +161,8 @@ 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);
|
||||
return;
|
||||
}
|
||||
throw $e;
|
||||
} catch(NotInScriptModeException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> extended the WarmUp by 10 seconds!');
|
||||
@ -189,12 +182,8 @@ 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);
|
||||
return;
|
||||
}
|
||||
throw $e;
|
||||
} catch(NotInScriptModeException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!');
|
||||
@ -212,12 +201,8 @@ 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);
|
||||
return;
|
||||
}
|
||||
throw $e;
|
||||
} catch(NotInScriptModeException $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> paused the Game!');
|
||||
|
Loading…
Reference in New Issue
Block a user