- refactored many try-catch clauses
- added todos for validating catching
This commit is contained in:
@ -4,6 +4,7 @@ use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* ManiaControl Chat-Message Plugin
|
||||
@ -308,10 +309,11 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
$msg = '$i$ff0 $<' . $player->nickname . '$>$s$39f chooses to boot back to the real world!';
|
||||
$this->maniaControl->chat->sendChat($msg, null, true);
|
||||
|
||||
$message = '$39F Thanks for Playing, please come back soon!$z ';
|
||||
$message = '$39F Thanks for Playing, see you around!$z';
|
||||
try {
|
||||
$this->maniaControl->client->kick($player->login, $message);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
@ -330,7 +332,8 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
$message = '$39F Thanks for Playing, please come back soon!$z ';
|
||||
try {
|
||||
$this->maniaControl->client->kick($player->login, $message);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
@ -350,7 +353,8 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
// force into spec
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($player->login, 3);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
@ -358,7 +362,8 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
// free player slot
|
||||
try {
|
||||
$this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
//to nothing
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ use ManiaControl\Plugins\Plugin;
|
||||
use ManiaControl\Server\Server;
|
||||
use ManiaControl\Server\ServerCommands;
|
||||
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
|
||||
/**
|
||||
@ -260,8 +261,12 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
|
||||
$itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame');
|
||||
$this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game');
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
//do nothing
|
||||
} catch(Exception $e) {
|
||||
if ($e->getMessage() == 'Not in script mode.') {
|
||||
// Do nothing
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
//Menu SkipMap
|
||||
|
@ -16,6 +16,7 @@ use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* Donation plugin
|
||||
@ -335,7 +336,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
|
||||
try {
|
||||
$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: handle errors like 'too few server planets' - throw other like connection errors
|
||||
trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $e->getMessage());
|
||||
$this->maniaControl->chat->sendError("Creating donation failed.", $player->login);
|
||||
return false;
|
||||
@ -378,8 +380,8 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
|
||||
try {
|
||||
$bill = $this->maniaControl->client->pay($receiver, $amount, $message);
|
||||
} catch(\Exception $e) {
|
||||
trigger_error("Couldn't retrieve server planets. " . $e->getMessage());
|
||||
} catch(Exception $e) {
|
||||
// TODO: handle errors like 'too few server planets' - throw other like connection errors
|
||||
trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $e->getMessage());
|
||||
$this->maniaControl->chat->sendError("Creating payout failed.", $player->login);
|
||||
return false;
|
||||
@ -401,13 +403,7 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$planets = $this->maniaControl->client->getServerPlanets();
|
||||
} catch(\Exception $e) {
|
||||
trigger_error("Couldn't retrieve server planets. " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
$planets = $this->maniaControl->client->getServerPlanets();
|
||||
$message = "This Server has {$planets} Planets!";
|
||||
return $this->maniaControl->chat->sendInformation($message, $player->login);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* ManiaControl Obstacle Plugin
|
||||
@ -128,8 +129,12 @@ class ObstaclePlugin implements CallbackListener, CommandListener, Plugin {
|
||||
$param = $player->login . ";" . $params[1] . ";";
|
||||
try{
|
||||
$this->maniaControl->client->triggerModeScriptEvent(self::CB_JUMPTO, $param);
|
||||
} catch(\Exception $e){
|
||||
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
|
||||
} catch(Exception $e) {
|
||||
if ($e->getMessage() == 'Not in script mode.') {
|
||||
trigger_error("Couldn't send jump callback for '{$player->login}'. " . $e->getMessage());
|
||||
return;
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* Queue plugin
|
||||
@ -289,14 +290,17 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
|
||||
if($this->maniaControl->client->getMaxPlayers()['CurrentValue'] > (count($this->maniaControl->playerManager->players) - count($this->spectators))) {
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($player->login, 2);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError("Error while leaving the Queue", $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($player->login, 0);
|
||||
} catch(\Exception $e) { }
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
}
|
||||
|
||||
$teams = array();
|
||||
/** @var Player $player */
|
||||
@ -319,7 +323,9 @@ class QueuePlugin implements CallbackListener, CommandListener, ManialinkPageAns
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->forcePlayerTeam($player->login, $smallestTeam);
|
||||
} catch(\Exception $e) { }
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exceptions should be "wrong login" or "not in team mode" - throw others (like connection error)
|
||||
}
|
||||
|
||||
if(isset($this->spectators[$player->login])) {
|
||||
unset($this->spectators[$player->login]);
|
||||
|
@ -15,6 +15,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswerListener, TimerListener {
|
||||
/**
|
||||
@ -467,7 +468,8 @@ class SlotMachinePlugin implements Plugin, CallbackListener, ManialinkPageAnswer
|
||||
|
||||
try {
|
||||
$billId = $this->maniaControl->client->pay($player->login, (int)$balance, $message);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: handle errors like 'too few server planets' - throw other like connection errors
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user