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,13 +11,15 @@ 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
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @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 {
|
class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -130,9 +132,9 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
|
public function sendManialink($manialinkText, $logins = null, $timeout = 0, $hideOnClick = false) {
|
||||||
$manialinkText = (string) $manialinkText;
|
$manialinkText = (string)$manialinkText;
|
||||||
|
|
||||||
if(!$manialinkText) {
|
if (!$manialinkText) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +152,7 @@ class ManialinkManager implements ManialinkPageAnswerListener, CallbackListener
|
|||||||
}
|
}
|
||||||
if (is_array($logins)) {
|
if (is_array($logins)) {
|
||||||
$success = true;
|
$success = true;
|
||||||
foreach ($logins as $login) {
|
foreach($logins as $login) {
|
||||||
$subSuccess = $this->maniaControl->client->sendDisplayManialinkPage($login, $manialinkText, $timeout, $hideOnClick);
|
$subSuccess = $this->maniaControl->client->sendDisplayManialinkPage($login, $manialinkText, $timeout, $hideOnClick);
|
||||||
if (!$subSuccess) {
|
if (!$subSuccess) {
|
||||||
$success = false;
|
$success = false;
|
||||||
@ -159,11 +161,8 @@ 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,11 +177,8 @@ 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,11 +192,8 @@ 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,14 +11,14 @@ 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
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @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 {
|
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
|
||||||
/*
|
/*
|
||||||
@ -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,14 +23,14 @@ 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
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @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 {
|
class PlayerList implements ManialinkPageAnswerListener, CallbackListener, TimerListener {
|
||||||
/*
|
/*
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -767,8 +754,10 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
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,14 +13,14 @@ 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
|
||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
* @copyright ManiaControl Copyright © 2014 ManiaControl Team
|
* @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 {
|
class ServerCommands implements CallbackListener, CommandListener, ManialinkPageAnswerListener, TimerListener {
|
||||||
/*
|
/*
|
||||||
@ -106,11 +106,8 @@ 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) {
|
||||||
@ -164,12 +161,8 @@ 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.') {
|
return;
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
|
||||||
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,12 +182,8 @@ 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.') {
|
return;
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw $e;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!');
|
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> stopped the WarmUp!');
|
||||||
@ -212,12 +201,8 @@ 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.') {
|
return;
|
||||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
|
||||||
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