- refactored many try-catch clauses
- added todos for validating catching
This commit is contained in:
@ -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);
|
||||
|
@ -10,6 +10,7 @@ use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Server\Server;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* Class offering various Admin Commands related to Players
|
||||
@ -105,7 +106,8 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->autoTeamBalance();
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: only catch 'not in team mode' exception - throw others (like connection error)
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
@ -267,15 +269,9 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
||||
if (isset($messageParts[1]) && is_numeric($messageParts[1])) {
|
||||
$amount = intval($messageParts[1]);
|
||||
}
|
||||
try {
|
||||
for($i = 0; $i < $amount; $i++) {
|
||||
$this->maniaControl->client->connectFakePlayer();
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
for ($i = 0; $i < $amount; $i++) {
|
||||
$this->maniaControl->client->connectFakePlayer();
|
||||
}
|
||||
|
||||
$this->maniaControl->chat->sendSuccess('Fake players connected!', $player->login);
|
||||
}
|
||||
|
||||
@ -290,14 +286,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
|
||||
$this->maniaControl->authenticationManager->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->maniaControl->client->disconnectFakePlayer('*');
|
||||
} catch(\Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->maniaControl->client->disconnectFakePlayer('*');
|
||||
$this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ use ManiaControl\Formatter;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkManager;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
/**
|
||||
* PlayerList Widget Class
|
||||
@ -650,7 +651,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($adminLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||
$this->maniaControl->client->forceSpectatorTarget($adminLogin, $targetLogin, 1);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
}
|
||||
break;
|
||||
case self::ACTION_OPEN_PLAYER_DETAILED:
|
||||
@ -721,8 +723,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
try {
|
||||
$this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
|
||||
$this->maniaControl->client->spectatorReleasePlayerSlot($target->login);
|
||||
} catch(\Exception $e) {
|
||||
} catch(Exception $e) {
|
||||
//do nothing
|
||||
// TODO: only possible valid exception should be "wrong login" - throw others (like connection error)
|
||||
}
|
||||
});
|
||||
break;
|
||||
@ -745,7 +748,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
|
||||
$message = '$39F You got kicked due a Public vote!$z ';
|
||||
try {
|
||||
$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(), $target->login);
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user