- refactored many try-catch clauses

- added todos for validating catching
This commit is contained in:
Steffen Schröder
2014-02-13 14:21:25 +01:00
parent 10dfd6b0cb
commit 4197dc82ff
23 changed files with 213 additions and 293 deletions

View File

@ -11,6 +11,7 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Formatter;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkManager;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
* PlayerActions Class
@ -84,8 +85,8 @@ class PlayerActions {
try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} 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(), $admin->login);
return;
}
@ -93,7 +94,8 @@ class PlayerActions {
if($userIsAbleToSelect) {
try {
$this->maniaControl->client->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} 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(), $admin->login);
return;
}
@ -130,7 +132,8 @@ class PlayerActions {
try {
$this->maniaControl->client->forcePlayerTeam($target->login, $teamId);
} 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)
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
@ -167,7 +170,8 @@ class PlayerActions {
try {
$this->maniaControl->client->forceSpectator($target->login, $spectatorState);
} 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(), $admin->login);
return;
}
@ -181,7 +185,8 @@ class PlayerActions {
// Free player slot
try {
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
} catch(\Exception $e) {
} catch(Exception $e) {
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
//do nothing
}
}
@ -205,7 +210,8 @@ class PlayerActions {
try {
$this->maniaControl->client->unIgnore($targetLogin);
} 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(), $adminLogin);
return;
}
@ -232,12 +238,7 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
try {
$this->maniaControl->client->ignore($targetLogin);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
$this->maniaControl->client->ignore($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!';
@ -349,7 +350,8 @@ class PlayerActions {
} else {
$this->maniaControl->client->kick($target->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(), $admin->login);
return;
}
@ -384,12 +386,7 @@ class PlayerActions {
return;
}
try {
$this->maniaControl->client->ban($target->login, $message);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $admin->login);
return;
}
$this->maniaControl->client->ban($target->login, $message);
// Announce ban
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);