Improved Player Actions

This commit is contained in:
Steffen Schröder 2013-12-31 16:01:22 +01:00
parent eeb2a89c4f
commit 96eda851df
2 changed files with 160 additions and 141 deletions

View File

@ -2,7 +2,6 @@
namespace ManiaControl\Players; namespace ManiaControl\Players;
use FML\Controls\Control; use FML\Controls\Control;
use FML\Controls\Frame; use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text; use FML\Controls\Labels\Label_Text;
@ -26,84 +25,97 @@ class PlayerActions {
*/ */
const BLUE_TEAM = 0; const BLUE_TEAM = 0;
const RED_TEAM = 1; const RED_TEAM = 1;
const SPECTATOR_USER_SELECTABLE = 0; const SPECTATOR_USER_SELECTABLE = 0;
const SPECTATOR_SPECTATOR = 1; const SPECTATOR_SPECTATOR = 1;
const SPECTATOR_PLAYER = 2; const SPECTATOR_PLAYER = 2;
const SPECTATOR_BUT_KEEP_SELECTABLE = 3; const SPECTATOR_BUT_KEEP_SELECTABLE = 3;
/** /**
* Private properties * Private Properties
*/ */
private $maniaControl = null; private $maniaControl = null;
/**
* Create a PlayerActions Instance
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) { public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl; $this->maniaControl = $maniaControl;
} }
/** /**
* Forces a Player to a certain team * Force a Player to a certain Team
* @param $adminLogin *
* @param $targetLogin * @param string $adminLogin
* @param $teamId * @param string $targetLogin
* @param int $teamId
*/ */
public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId){ //TODO get used by playercommands public function forcePlayerToTeam($adminLogin, $targetLogin, $teamId) {
// TODO: get used by playercommands
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$admin || !$target) return;
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if ($target->isSpectator) { if ($target->isSpectator) {
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, self::SPECTATOR_PLAYER); $success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER);
if (!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
} }
$success = $this->maniaControl->client->query('ForcePlayerTeam', $targetLogin, $teamId); //TODO bestätigung $success = $this->maniaControl->client->query('ForcePlayerTeam', $target->login, $teamId);
if (!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
$chatMessage = false;
if ($teamId == self::BLUE_TEAM) { if ($teamId == self::BLUE_TEAM) {
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!'); $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!';
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' forced player '. Formatter::stripCodes($target->nickname) . ' into the Blue-Team');
}else if($teamId == self::RED_TEAM){
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!');
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' forced player '. Formatter::stripCodes($target->nickname) . ' into the Red-Team');
} }
else if ($teamId == self::RED_TEAM) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!';
}
if (!$chatMessage) return;
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
} }
/** /**
* Forces a Player to spectator * Force a Player to Spectator
* @param $adminLogin *
* @param $targetLogin * @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState * @param int $spectatorState
*/ */
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE){ //TODO get used by playercommands public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE) {
// TODO: get used by playercommands
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); //TODO bestätigung $success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState);
if (!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); $chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Spectator!';
$this->maniaControl->chat->sendInformation($chatMessage);
// log console message $this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' forced player '. Formatter::stripCodes($target->nickname) . ' to Spectator');
} }
/** /**
* Warn a Player * Warn a Player
* @param $adminLogin *
* @param $targetLogin * @param string $adminLogin
* @param string $targetLogin
*/ */
public function warnPlayer($adminLogin, $targetLogin){ //TODO chatcommand public function warnPlayer($adminLogin, $targetLogin) {
// TODO: chatcommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
@ -114,7 +126,6 @@ class PlayerActions {
{br}{br}$gThe server administrators.'; {br}{br}$gThe server administrators.';
$message = preg_split('/{br}/', $message); $message = preg_split('/{br}/', $message);
$width = 80; $width = 80;
$height = 50; $height = 50;
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle(); $quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
@ -169,22 +180,19 @@ class PlayerActions {
$y -= 4; $y -= 4;
} }
// Display manialink
//render and display xml
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $target); $this->maniaControl->manialinkManager->displayWidget($maniaLink, $target);
// log console message $chatMessage = $title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!';
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' warned player '. Formatter::stripCodes($target->nickname)); $this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
// show chat message
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!');
} }
/** /**
* Kicks a Player * Kicks a Player
* @param $adminLogin *
* @param $targetLogin * @param string $adminLogin
* @param string $targetLogin
* @param string $message * @param string $message
*/ */
public function kickPlayer($adminLogin, $targetLogin, $message = '') { public function kickPlayer($adminLogin, $targetLogin, $message = '') {
@ -192,24 +200,28 @@ class PlayerActions {
$target = $this->maniaControl->playerManager->getPlayer($targetLogin); $target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if($target->isFakePlayer()) if ($target->isFakePlayer()) {
$success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login); $success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login);
else }
$success = $this->maniaControl->client->query('Kick', $target->login, $message); //TODO bestätigung else {
$success = $this->maniaControl->client->query('Kick', $target->login, $message);
}
if (!$success) { if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!');
// log console message $chatMessage = $title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!';
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' kicked player '. Formatter::stripCodes($target->nickname)); $this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
} }
/** /**
* Bans a Player * Bans a Player
* @param $adminLogin *
* @param $targetLogin * @param string $adminLogin
* @param string $targetLogin
* @param string $message * @param string $message
*/ */
public function banPlayer($adminLogin, $targetLogin, $message = '') { public function banPlayer($adminLogin, $targetLogin, $message = '') {
@ -223,17 +235,18 @@ class PlayerActions {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login); $this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return; return;
} }
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!');
// log console message $chatMessage = $title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!';
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' banned player '. Formatter::stripCodes($target->nickname)); $this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
} }
/** /**
* Grands Player an authorization level * Grands the Player an Authorization Level
* @param $adminLogin *
* @param $targetLogin * @param string $adminLogin
* @param $authLevel * @param string $targetLogin
* @param int $authLevel
*/ */
public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) { public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
@ -241,13 +254,16 @@ class PlayerActions {
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel); $title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) { if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError('This admin is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login); $this->maniaControl->chat->sendError(
'This Player is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel),
$admin->login);
return; return;
} }
$authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel); $authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel);
if($this->maniaControl->authenticationManager->checkRight($admin,$authLevel) <= $this->maniaControl->authenticationManager->checkRight($target,$authLevel)){ if ($this->maniaControl->authenticationManager->checkRight($admin, $authLevel) <=
$this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError('You don\'t have the permission to add a ' . $authLevelName . '!', $admin->login); $this->maniaControl->chat->sendError('You don\'t have the permission to add a ' . $authLevelName . '!', $admin->login);
return; return;
} }
@ -259,16 +275,16 @@ class PlayerActions {
return; return;
} }
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName. '$>!'); $chatMessage = $title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
// log console message $this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' added player '. Formatter::stripCodes($target->nickname) . ' as ' . $authLevelName);
} }
/** /**
* Revokes all rights from a Admin * Revokes all Rights from the Player
* @param $adminLogin *
* @param $targetLogin * @param string $adminLogin
* @param string $targetLogin
*/ */
public function revokeAuthLevel($adminLogin, $targetLogin) { public function revokeAuthLevel($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
@ -287,9 +303,8 @@ class PlayerActions {
return; return;
} }
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> revokes $<' . $target->nickname . '$> rights!'); $chatMessage = $title . ' $<' . $admin->nickname . '$> revokes the Rights of $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
// log console message $this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' revokes '. Formatter::stripCodes($target->nickname) . ' rights');
} }
} }

View File

@ -239,7 +239,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->authenticationManager->getAuthLevelName($listPlayer->authLevel) . " " . $listPlayer->nickname); $this->maniaControl->authenticationManager->getAuthLevelName($listPlayer->authLevel) . " " . $listPlayer->nickname);
$script->addTooltip($rightQuad, $descriptionLabel); $script->addTooltip($rightQuad, $descriptionLabel);
// Player Profile Quad // Player Profile Quad
$playerQuad = new Quad_UIConstruction_Buttons(); $playerQuad = new Quad_UIConstruction_Buttons();
$playerFrame->add($playerQuad); $playerFrame->add($playerQuad);
@ -278,7 +277,6 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) { if ($this->maniaControl->authenticationManager->checkRight($player, AuthenticationManager::AUTH_LEVEL_OPERATOR)) {
// Further Player actions Quad // Further Player actions Quad
$playerQuad = new Quad_Icons64x64_1(); $playerQuad = new Quad_Icons64x64_1();
$playerFrame->add($playerQuad); $playerFrame->add($playerQuad);
@ -380,6 +378,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
* @param $login * @param $login
*/ */
public function advancedPlayerWidget(Player $caller, $login) { public function advancedPlayerWidget(Player $caller, $login) {
if (!$caller) return;
$this->playersListShown[$caller->login] = $login; // Show a certain player $this->playersListShown[$caller->login] = $login; // Show a certain player
$this->showPlayerList($caller); // reopen playerlist $this->showPlayerList($caller); // reopen playerlist
} }
@ -622,48 +621,53 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
public function handleManialinkPageAnswer(array $callback) { public function handleManialinkPageAnswer(array $callback) {
$actionId = $callback[1][2]; $actionId = $callback[1][2];
$actionArray = explode(".", $actionId); $actionArray = explode(".", $actionId);
if (count($actionArray) <= 2) {
return;
}
$action = $actionArray[0] . "." . $actionArray[1];
$adminLogin = $callback[1][1];
$targetLogin = $actionArray[2];
// TODO maybe with ids instead of logins, lower network traffic switch ($action) {
switch ($actionArray[0] . "." . $actionArray[1]) {
case self::ACTION_FORCE_BLUE: case self::ACTION_FORCE_BLUE:
$this->maniaControl->playerManager->playerActions->forcePlayerToTeam($callback[1][1], $actionArray[2], $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($adminLogin, $targetLogin,
playerActions::BLUE_TEAM); PlayerActions::BLUE_TEAM);
break; break;
case self::ACTION_FORCE_RED: case self::ACTION_FORCE_RED:
$this->maniaControl->playerManager->playerActions->forcePlayerToTeam($callback[1][1], $actionArray[2], $this->maniaControl->playerManager->playerActions->forcePlayerToTeam($adminLogin, $targetLogin,
playerActions::RED_TEAM); PlayerActions::RED_TEAM);
break; break;
case self::ACTION_FORCE_SPEC: case self::ACTION_FORCE_SPEC:
$this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($callback[1][1], $actionArray[2], $this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($adminLogin, $targetLogin,
playerActions::SPECTATOR_BUT_KEEP_SELECTABLE); PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
break; break;
case self::ACTION_WARN_PLAYER: case self::ACTION_WARN_PLAYER:
$this->maniaControl->playerManager->playerActions->warnPlayer($callback[1][1], $actionArray[2]); $this->maniaControl->playerManager->playerActions->warnPlayer($adminLogin, $targetLogin);
break; break;
case self::ACTION_KICK_PLAYER: case self::ACTION_KICK_PLAYER:
$this->maniaControl->playerManager->playerActions->kickPlayer($callback[1][1], $actionArray[2]); $this->maniaControl->playerManager->playerActions->kickPlayer($adminLogin, $targetLogin);
break; break;
case self::ACTION_BAN_PLAYER: case self::ACTION_BAN_PLAYER:
$this->maniaControl->playerManager->playerActions->banPlayer($callback[1][1], $actionArray[2]); $this->maniaControl->playerManager->playerActions->banPlayer($adminLogin, $targetLogin);
break; break;
case self::ACTION_PLAYER_ADV: case self::ACTION_PLAYER_ADV:
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]); $admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$this->advancedPlayerWidget($player, $actionArray[2]); $this->advancedPlayerWidget($admin, $targetLogin);
break; break;
case self::ACTION_ADD_AS_MASTER: case self::ACTION_ADD_AS_MASTER:
$this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], $this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin,
AuthenticationManager::AUTH_LEVEL_SUPERADMIN); AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
break; break;
case self::ACTION_ADD_AS_ADMIN: case self::ACTION_ADD_AS_ADMIN:
$this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], $this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin,
AuthenticationManager::AUTH_LEVEL_ADMIN); AuthenticationManager::AUTH_LEVEL_ADMIN);
break; break;
case self::ACTION_ADD_AS_MOD: case self::ACTION_ADD_AS_MOD:
$this->maniaControl->playerManager->playerActions->grandAuthLevel($callback[1][1], $actionArray[2], $this->maniaControl->playerManager->playerActions->grandAuthLevel($adminLogin, $targetLogin,
AuthenticationManager::AUTH_LEVEL_OPERATOR); AuthenticationManager::AUTH_LEVEL_OPERATOR);
break; break;
case self::ACTION_REVOKE_RIGHTS: case self::ACTION_REVOKE_RIGHTS:
$this->maniaControl->playerManager->playerActions->revokeAuthLevel($callback[1][1], $actionArray[2]); $this->maniaControl->playerManager->playerActions->revokeAuthLevel($adminLogin, $targetLogin);
break; break;
} }
} }