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

View File

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