cleanup, exception handling
This commit is contained in:
committed by
Steffen Schröder
parent
796d46f199
commit
a17037c3cb
@ -3,6 +3,7 @@
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
@ -300,9 +301,10 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
$this->maniaControl->chat->sendChat($msg, null, true);
|
||||
|
||||
$message = '$39F Thanks for Playing, please come back soon!$z';
|
||||
$success = $this->maniaControl->client->kick($player->login, $message);
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
try {
|
||||
$this->maniaControl->client->kick($player->login, $message);
|
||||
} catch(Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -318,9 +320,10 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
$this->maniaControl->chat->sendChat($msg, null, true);
|
||||
|
||||
$message = '$39F Thanks for Playing, please come back soon!$z';
|
||||
$success = $this->maniaControl->client->kick($player->login, $message);
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
try {
|
||||
$this->maniaControl->client->kick($player->login, $message);
|
||||
} catch(Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -337,9 +340,10 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
|
||||
if($this->maniaControl->settingManager->getSetting($this, self::SETTING_AFK_FORCE_SPEC)) {
|
||||
// force into spec
|
||||
$success = $this->maniaControl->client->forceSpectator($player->login, 3);
|
||||
if(!$success) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($player->login, 3);
|
||||
} catch(Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -347,6 +351,7 @@ class ChatMessagePlugin implements CommandListener, Plugin {
|
||||
try {
|
||||
$this->maniaControl->client->spectatorReleasePlayerSlot($player->login);
|
||||
} catch(Exception $e) {
|
||||
//to nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
use ManiaControl\Server\ServerCommands;
|
||||
|
||||
|
||||
|
@ -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
|
||||
@ -327,11 +328,14 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
}
|
||||
|
||||
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?';
|
||||
if(!$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver)) {
|
||||
trigger_error("Couldn't create donation of {$amount} planets from '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText());
|
||||
try {
|
||||
$bill = $this->maniaControl->client->sendBill($player->login, $amount, $message, $receiver);
|
||||
} catch(Exception $e) {
|
||||
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;
|
||||
}
|
||||
|
||||
$this->openBills[$bill] = array(true, $player->login, $receiver, $amount, time());
|
||||
|
||||
return true;
|
||||
@ -366,11 +370,16 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
$receiver = $player->login;
|
||||
}
|
||||
$message = 'Payout from $<' . $this->maniaControl->server->getName() . '$>.';
|
||||
if(!$bill = $this->maniaControl->client->pay($receiver, $amount, $message)) {
|
||||
trigger_error("Couldn't create payout of {$amount} planets by '{$player->login}' for '{$receiver}'. " . $this->maniaControl->getClientErrorText());
|
||||
|
||||
try {
|
||||
$bill = $this->maniaControl->client->pay($receiver, $amount, $message);
|
||||
} catch(Exception $e) {
|
||||
trigger_error("Couldn't retrieve server planets. " . $e->getMessage());
|
||||
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;
|
||||
}
|
||||
|
||||
$this->openBills[$bill] = array(false, $player->login, $receiver, $amount, time());
|
||||
return true;
|
||||
}
|
||||
@ -387,10 +396,13 @@ class DonationPlugin implements CallbackListener, CommandListener, Plugin {
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return false;
|
||||
}
|
||||
if(!$planets = $this->maniaControl->client->getServerPlanets()) {
|
||||
trigger_error("Couldn't retrieve server planets. " . $this->maniaControl->getClientErrorText());
|
||||
try {
|
||||
$planets = $this->maniaControl->client->getServerPlanets();
|
||||
} catch(Exception $e) {
|
||||
trigger_error("Couldn't retrieve server planets. " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
$message = "This Server has {$planets} Planets!";
|
||||
return $this->maniaControl->chat->sendInformation($message, $player->login);
|
||||
}
|
||||
|
Reference in New Issue
Block a user