implemented force actions

This commit is contained in:
kremsy 2015-06-26 13:06:05 +02:00
parent f2f21c3e2b
commit 491ac03078
3 changed files with 135 additions and 47 deletions

View File

@ -22,5 +22,4 @@ class CommunicationAnswer {
$this->data = $data; $this->data = $data;
$this->error = $error; $this->error = $error;
} }
} }

View File

@ -47,9 +47,18 @@ interface CommunicationMethods {
*/ */
const KICK_PLAYER = "PlayerActions.KickPlayer"; const KICK_PLAYER = "PlayerActions.KickPlayer";
//TODO implement /** Forces a player to Spectator
* Required Params
* - login
*/
const FORCE_PLAYER_TO_SPEC = "PlayerActions.ForcePlayerToSpec"; const FORCE_PLAYER_TO_SPEC = "PlayerActions.ForcePlayerToSpec";
//TODO implement
/** Forces a player to Spectator
* Required Params
* - login
* Optional Params
* - teamId (id of the team the player shoudl get forced into it)
*/
const FORCE_PLAYER_TO_PLAY = "PlayerActions.ForcePlayerToPlay"; const FORCE_PLAYER_TO_PLAY = "PlayerActions.ForcePlayerToPlay";
/** Returns the last 200 lines of the chat (inclusive player logins and nicknames) /** Returns the last 200 lines of the chat (inclusive player logins and nicknames)

View File

@ -121,6 +121,30 @@ class PlayerActions implements EchoListener, CommunicationListener {
return new CommunicationAnswer(array("success" => $success)); return new CommunicationAnswer(array("success" => $success));
}); });
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::FORCE_PLAYER_TO_SPEC, $this, function ($data) {
if (!is_object($data) || !property_exists($data, "login")) {
return new CommunicationAnswer("You have to provide a valid player Login", true);
}
//TODO allow parameters like spectator state
$success = $this->forcePlayerToSpectator(null, $data->login, self::SPECTATOR_BUT_KEEP_SELECTABLE, true, false);
return new CommunicationAnswer(array("success" => $success));
});
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::FORCE_PLAYER_TO_PLAY, $this, function ($data) {
if (!is_object($data) || !property_exists($data, "login")) {
return new CommunicationAnswer("You have to provide a valid player Login", true);
}
//TODO allow parameters like spectator state
if (property_exists($data, "teamId")) {
$success = $this->forcePlayerToTeam(null, $data->login, $data->teamId, false);
} else {
$success = $this->forcePlayerToPlay(null, $data->login, true, true, false);
}
return new CommunicationAnswer(array("success" => $success));
});
} }
/** /**
@ -129,26 +153,35 @@ class PlayerActions implements EchoListener, CommunicationListener {
* @param string $adminLogin * @param string $adminLogin
* @param string $targetLogin * @param string $targetLogin
* @param int $teamId * @param int $teamId
* @param bool $calledByAdmin
* @return bool
*/ */
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) { public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId, $calledByAdmin = true) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); if ($calledByAdmin) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM) $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
) { if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_TEAM)
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin); ) {
return; $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
return false;
}
if (!$admin) {
return false;
}
} }
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
if (!$target || !$admin) { if (!$target) {
return; return false;
} }
if ($target->isSpectator) { if ($target->isSpectator) {
try { try {
if (!$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false)) { if (!$this->forcePlayerToPlay($adminLogin, $targetLogin, true, false, $calledByAdmin)) {
return; return false;
} }
} catch (FaultException $exception) { } catch (FaultException $exception) {
$this->maniaControl->getChat()->sendException($exception, $admin); if ($calledByAdmin) {
$this->maniaControl->getChat()->sendException($exception, $admin);
}
} }
} }
@ -156,27 +189,43 @@ class PlayerActions implements EchoListener, CommunicationListener {
$this->maniaControl->getClient()->forcePlayerTeam($target->login, $teamId); $this->maniaControl->getClient()->forcePlayerTeam($target->login, $teamId);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->forcePlayerToPlay($adminLogin, $targetLogin); $this->forcePlayerToPlay($adminLogin, $targetLogin);
return; return false;
} catch (UnknownPlayerException $exception) { } catch (UnknownPlayerException $exception) {
$this->maniaControl->getChat()->sendException($exception, $admin); if ($calledByAdmin) {
return; $this->maniaControl->getChat()->sendException($exception, $admin);
}
return false;
} catch (GameModeException $exception) { } catch (GameModeException $exception) {
$this->maniaControl->getChat()->sendException($exception, $admin); if ($calledByAdmin) {
return; $this->maniaControl->getChat()->sendException($exception, $admin);
}
return false;
} }
$chatMessage = false; $chatMessage = false;
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
if ($teamId === self::TEAM_BLUE) { if ($calledByAdmin) {
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Blue-Team!'; $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
} else if ($teamId === self::TEAM_RED) { if ($teamId === self::TEAM_BLUE) {
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Red-Team!'; $chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Blue-Team!';
} else if ($teamId === self::TEAM_RED) {
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' into the Red-Team!';
}
} else {
if ($teamId === self::TEAM_BLUE) {
$chatMessage = $target->getEscapedNickname() . ' got forced into the Blue-Team!';
} else if ($teamId === self::TEAM_RED) {
$chatMessage = $target->getEscapedNickname() . ' got forced into the Red-Team!';
}
} }
if (!$chatMessage) { if (!$chatMessage) {
return; return false;
} }
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
return true;
} }
/** /**
@ -186,15 +235,19 @@ class PlayerActions implements EchoListener, CommunicationListener {
* @param string $targetLogin * @param string $targetLogin
* @param bool $userIsAbleToSelect * @param bool $userIsAbleToSelect
* @param bool $displayAnnouncement * @param bool $displayAnnouncement
* @param bool $calledByAdmin
* @return bool * @return bool
*/ */
public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true) { public function forcePlayerToPlay($adminLogin, $targetLogin, $userIsAbleToSelect = true, $displayAnnouncement = true, $calledByAdmin = true) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); if ($calledByAdmin) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY) $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
) { if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_PLAY)
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin); ) {
return false; $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
return false;
}
} }
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
if (!$target) { if (!$target) {
return false; return false;
@ -203,7 +256,9 @@ class PlayerActions implements EchoListener, CommunicationListener {
try { try {
$this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_PLAYER); $this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_PLAYER);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat()->sendException($exception, $admin); if ($calledByAdmin) {
$this->maniaControl->getChat()->sendException($exception, $admin);
}
return false; return false;
} }
@ -211,14 +266,22 @@ class PlayerActions implements EchoListener, CommunicationListener {
try { try {
$this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE); $this->maniaControl->getClient()->forceSpectator($target->login, self::SPECTATOR_USER_SELECTABLE);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat()->sendException($exception, $admin); if ($calledByAdmin) {
$this->maniaControl->getChat()->sendException($exception, $admin);
}
return false; return false;
} }
} }
// Announce force // Announce force
if ($displayAnnouncement) { if ($displayAnnouncement) {
$chatMessage = $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Play!'; if ($calledByAdmin) {
$chatMessage = $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Play!';
} else {
$chatMessage = $target->getEscapedNickname() . ' got forced to Play!';
}
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($chatMessage);
} }
@ -232,29 +295,44 @@ class PlayerActions implements EchoListener, CommunicationListener {
* @param string $targetLogin * @param string $targetLogin
* @param int $spectatorState * @param int $spectatorState
* @param bool $releaseSlot * @param bool $releaseSlot
* @param bool $calledByAdmin
* @return bool
*/ */
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) { public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true, $calledByAdmin = true) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); if ($calledByAdmin) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC) $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
) { if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin); ) {
return; $this->maniaControl->getAuthenticationManager()->sendNotAllowed($admin);
return false;
}
if (!$admin) {
return false;
}
} }
$target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin); $target = $this->maniaControl->getPlayerManager()->getPlayer($targetLogin);
if (!$admin || !$target || $target->isSpectator) { if (!$target || $target->isSpectator) {
return; return false;
} }
try { try {
$this->maniaControl->getClient()->forceSpectator($target->login, $spectatorState); $this->maniaControl->getClient()->forceSpectator($target->login, $spectatorState);
} catch (ServerOptionsException $exception) { } catch (ServerOptionsException $exception) {
$this->maniaControl->getChat()->sendException($exception, $admin->login); if ($calledByAdmin) {
return; $this->maniaControl->getChat()->sendException($exception, $admin->login);
}
return false;
} }
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel); if ($calledByAdmin) {
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Spectator!'; $title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' ' . $admin->getEscapedNickname() . ' forced ' . $target->getEscapedNickname() . ' to Spectator!';
} else {
$chatMessage = $target->getEscapedNickname() . ' got forced to Spectator!';
}
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true); Logger::logInfo($chatMessage, true);
@ -266,6 +344,8 @@ class PlayerActions implements EchoListener, CommunicationListener {
} catch (UnknownPlayerException $e) { } catch (UnknownPlayerException $e) {
} }
} }
return true;
} }
/** /**
@ -666,5 +746,5 @@ class PlayerActions implements EchoListener, CommunicationListener {
return $player->isMuted(); return $player->isMuted();
} }
return false; return false;
}
} }
}