cleanup, exception handling

This commit is contained in:
kremsy
2014-01-20 20:51:03 +01:00
committed by Steffen Schröder
parent 796d46f199
commit a17037c3cb
13 changed files with 190 additions and 134 deletions

View File

@ -87,8 +87,7 @@ class PlayerActions {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch(Exception $e) {
//TODO $e error text
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -96,8 +95,7 @@ class PlayerActions {
try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} catch(Exception $e) {
//TODO $e error text
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
}
@ -131,9 +129,10 @@ class PlayerActions {
$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false);
}
$success = $this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
try {
$this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -170,8 +169,7 @@ class PlayerActions {
try {
$this->maniaControl->client->forceSpectator($target->login, $spectatorState);
} catch(Exception $e) {
//TODO error message from $e
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -185,7 +183,7 @@ class PlayerActions {
try {
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(Exception $e) {
//TODO error message from $e
//do nothing
}
}
}
@ -206,9 +204,10 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->unIgnore($target->login);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
try {
$this->maniaControl->client->unIgnore($targetLogin);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $adminLogin);
return;
}
@ -234,9 +233,10 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$success = $this->maniaControl->client->ignore($targetLogin);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
try {
$this->maniaControl->client->ignore($targetLogin);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -344,13 +344,14 @@ class PlayerActions {
return;
}
if($target->isFakePlayer()) {
$success = $this->maniaControl->client->disconnectFakePlayer($target->login);
} else {
$success = $this->maniaControl->client->kick($target->login, $message);
}
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
try {
if($target->isFakePlayer()) {
$this->maniaControl->client->disconnectFakePlayer($target->login);
} else {
$this->maniaControl->client->kick($target->login, $message);
}
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -384,9 +385,10 @@ class PlayerActions {
return;
}
$success = $this->maniaControl->client->ban($target->login, $message);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
try {
$this->maniaControl->client->ban($target->login, $message);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}

View File

@ -8,6 +8,7 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* Class offering various Admin Commands related to Players
@ -82,11 +83,14 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$success = $this->maniaControl->client->autoTeamBalance();
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
try {
$this->maniaControl->client->autoTeamBalance();
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> balanced Teams!');
}
@ -244,16 +248,15 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
if(isset($messageParts[1]) && is_numeric($messageParts[1])) {
$amount = intval($messageParts[1]);
}
$success = true;
for($i = 0; $i < $amount; $i++) {
if(!$this->maniaControl->client->connectFakePlayer()) {
$success = false;
try {
for($i = 0; $i < $amount; $i++) {
$this->maniaControl->client->connectFakePlayer();
}
}
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess('Fake players connected!', $player->login);
}
@ -268,11 +271,14 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
$success = $this->maniaControl->client->disconnectFakePlayer('*');
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
try {
$this->maniaControl->client->disconnectFakePlayer('*');
} catch(Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
return;
}
$this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login);
}