Player Actions and Commands Improvements

This commit is contained in:
Steffen Schröder 2014-01-06 17:33:45 +01:00
parent 3df6407a33
commit 3d9362724a
4 changed files with 156 additions and 103 deletions

View File

@ -149,7 +149,6 @@ class ActionsMenu implements CallbackListener, ManialinkPageAnswerListener {
* @return ManiaLink
*/
private function buildMenuIconsManialink(Player $player) {
// TODO: close popoutframe on click
$posX = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSX);
$posY = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_POSY);
$itemSize = $this->maniaControl->settingManager->getSetting($this, self::SETTING_MENU_ITEMSIZE);

View File

@ -54,10 +54,7 @@ class PlayerActions {
// 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 (!$admin || !$target) return;
if ($target->isSpectator) {
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, self::SPECTATOR_PLAYER);
@ -74,6 +71,7 @@ class PlayerActions {
}
$chatMessage = false;
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if ($teamId == self::BLUE_TEAM) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!';
}
@ -82,7 +80,7 @@ class PlayerActions {
}
if (!$chatMessage) return;
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
}
/**
@ -91,67 +89,77 @@ class PlayerActions {
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
* @param bool $releaseSlot
*/
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) {
// TODO: get used by playercommands
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState);
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $spectatorState);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to Spectator!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
// free player slot
if ($releaseSlot) $this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login);
if ($releaseSlot) {
// Free player slot
$this->maniaControl->client->query('SpectatorReleasePlayerSlot', $target->login);
}
}
/**
* UnMutes a Player
* UnMute a Player
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
*/
public function unMutePlayer($adminLogin, $targetLogin) {
// TODO: playercommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('UnIgnore', $targetLogin);
var_dump($success);
var_dump($this->maniaControl->client->getResponse());
$success = $this->maniaControl->client->query('UnIgnore', $target->login);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> un-muted $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
}
/**
* Mutes a Player
* Mute a Player
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
*/
public function mutePlayer($adminLogin, $targetLogin) {
// TODO: playercommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('Ignore', $targetLogin);
if (!$success) {
@ -159,9 +167,10 @@ class PlayerActions {
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
}
/**
@ -171,81 +180,78 @@ class PlayerActions {
* @param string $targetLogin
*/
public function warnPlayer($adminLogin, $targetLogin) {
// TODO: chatcommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if (!$target) return;
// display warning message
// Display warning message
$message = '$s$f00This is an administrative warning.{br}{br}$gWhatever you wrote or you have done is against {br} our server\'s policy.
{br}Not respecting other players, or{br}using offensive language might result in a{br}$f00kick, or ban $ff0the next time.
{br}{br}$gThe server administrators.';
$message = preg_split('/{br}/', $message);
// Build Manialink
$width = 80;
$height = 50;
$quadStyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
$quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
// mainframe
$frame = new Frame();
$maniaLink->add($frame);
$frame->setSize($width, $height);
$frame->setPosition(0, 10);
// Background Quad
// Background
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// Add Close Quad (X)
// Close Quad (X)
$closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad);
$closeQuad->setPosition($width * 0.473, $height * 0.457, 3);
$closeQuad->setSize(6, 6);
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
$closeQuad->setSubStyle($closeQuad::SUBSTYLE_QuitRace);
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
// Headline Label
// Headline
$label = new Label_Text();
$frame->add($label);
$label->setHAlign(Control::CENTER);
$label->setX(0);
$label->setY($height / 2 - 5);
$label->setStyle(Label_Text::STYLE_TextCardMedium);
$label->setStyle($label::STYLE_TextCardMedium);
$label->setTextSize(4);
$label->setText('Administrative Warning');
$label->setTextColor('F00');
$label->setTextColor('f00');
$y = $height / 2 - 15;
foreach ($message as &$line) {
// Warn Labels
foreach ($message as $line) {
// Message lines
$label = new Label_Text();
$frame->add($label);
$label->setHAlign(Control::CENTER);
// $label->setX(-$width / 2 + 5);
$label->setX(0);
$label->setY($y);
$label->setStyle(Label_Text::STYLE_TextCardMedium);
$label->setTextSize(1.6);
$label->setText($line);
$label->setTextColor('FF0');
$label->setTextColor('ff0');
$y -= 4;
}
// Display manialink
$this->maniaControl->manialinkManager->displayWidget($maniaLink, $target);
// Announce warning
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> warned $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
}
/**
* Kicks a Player
* Kick a Player
*
* @param string $adminLogin
* @param string $targetLogin
@ -253,8 +259,12 @@ class PlayerActions {
*/
public function kickPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_MODERATOR)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if (!$target) return;
if ($target->isFakePlayer()) {
$success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login);
@ -262,19 +272,20 @@ class PlayerActions {
else {
$success = $this->maniaControl->client->query('Kick', $target->login, $message);
}
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
// Announce kick
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
}
/**
* Bans a Player
* Ban a Player
*
* @param string $adminLogin
* @param string $targetLogin
@ -282,19 +293,24 @@ class PlayerActions {
*/
public function banPlayer($adminLogin, $targetLogin, $message = '') {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
if (!$this->maniaControl->authenticationManager->checkRight($admin, AuthenticationManager::AUTH_LEVEL_ADMIN)) {
$this->maniaControl->authenticationManager->sendNotAllowed($admin);
return;
}
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if (!$target) return;
$success = $this->maniaControl->client->query('Ban', $target->login, $message);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
// Announce ban
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
}
/**
@ -307,32 +323,29 @@ class PlayerActions {
public function grandAuthLevel($adminLogin, $targetLogin, $authLevel) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError(
'This Player is already ' . $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel), $admin->login);
return;
}
if (!$admin || !$target) return;
$authLevelName = $this->maniaControl->authenticationManager->getAuthLevelName($authLevel);
if ($this->maniaControl->authenticationManager->checkRight($admin, $authLevel + 1)) {
$this->maniaControl->chat->sendError("You don't have the permission to add a {$authLevelName}!", $admin->login);
}
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);
if ($this->maniaControl->authenticationManager->checkRight($target, $authLevel)) {
$this->maniaControl->chat->sendError("This Player is already {$authLevelName}!", $admin->login);
return;
}
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, $authLevel);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred.', $admin->login);
return;
}
// Announce granting
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> added $<' . $target->nickname . '$> as $< ' . $authLevelName . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
}
/**
@ -344,29 +357,36 @@ class PlayerActions {
public function revokeAuthLevel($adminLogin, $targetLogin) {
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if (!$admin || !$target) return;
if ($this->maniaControl->authenticationManager->checkRight($admin, $target->authLevel + 1)) {
$title = $this->maniaControl->authenticationManager->getAuthLevelName($target->authLevel);
$this->maniaControl->chat->sendError("You can't revoke the Rights of a {$title}!", $admin->login);
return;
}
if ($this->maniaControl->authenticationManager->checkRight($target, AuthenticationManager::AUTH_LEVEL_MASTERADMIN)) {
$this->maniaControl->chat->sendError('MasterAdmins can\'t be removed ', $admin->login);
$this->maniaControl->chat->sendError("MasterAdmins can't be removed!", $admin->login);
return;
}
$success = $this->maniaControl->authenticationManager->grantAuthLevel($target, AuthenticationManager::AUTH_LEVEL_PLAYER);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
$this->maniaControl->chat->sendError('Error occurred.', $admin->login);
return;
}
$chatMessage = $title . ' $<' . $admin->nickname . '$> revokes the Rights of $<' . $target->nickname . '$>!';
// Announce revoke
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$chatMessage = $title . ' $<' . $admin->nickname . '$> revoked the Rights of $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
$this->maniaControl->log($chatMessage, true);
}
/**
* Checks if a Player is Muted
* Check if a Player is muted
*
* @param $login
* @param string $login
* @return bool
*/
public function isPlayerMuted($login) {

View File

@ -50,6 +50,8 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->commandManager->registerCommandListener('removebot', $this, 'command_RemoveFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('addbots', $this, 'command_AddFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('removebots', $this, 'command_RemoveFakePlayers', true);
$this->maniaControl->commandManager->registerCommandListener('mute', $this, 'command_MutePlayer', true);
$this->maniaControl->commandManager->registerCommandListener('unmute', $this, 'command_UnmutePlayer', true);
// TODO: Move into another class
$this->maniaControl->commandManager->registerCommandListener('cancel', $this, 'command_CancelVote', true);
@ -129,22 +131,32 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
return;
}
$params = explode(' ', $chat[1][2], 3);
if (!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //kick login', $player->login);
return;
}
$target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target);
if (!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
if (count($params) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//kick login'", $player->login);
return;
}
$targetLogin = $params[1];
$message = '';
if (isset($params[2])) {
$message = $params[2];
}
$this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $target, $message);
$this->maniaControl->playerManager->playerActions->kickPlayer($player->login, $targetLogin, $message);
}
/**
* Handle //warn Command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_Warn(array $chatCallback, Player $player) {
$params = explode(' ', $chat[1][2], 3);
if (count($params) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//kick login'", $player->login);
return;
}
$targetLogin = $params[1];
$this->maniaControl->playerManager->playerActions->warnPlayer($player->login, $targetLogin);
}
/**
@ -159,29 +171,19 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
return;
}
$params = explode(' ', $chat[1][2]);
if (!isset($params[1])) {
$this->maniaControl->chat->sendUsageInfo('Usage example: //forcespec login', $player->login);
if (count($params) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No Login given! Example: '//forcespec login'", $player->login);
return;
}
$target = $params[1];
$target = $this->maniaControl->playerManager->getPlayer($target);
if (!$target) {
$this->maniaControl->chat->sendError("Invalid player login.", $player->login);
return;
}
$type = 3;
$targetLogin = $params[1];
if (isset($params[2]) && is_numeric($params[2])) {
$type = intval($params[2]);
$type = (int) $params[2];
$this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($player->login, $targetLogin, $type);
}
$success = $this->maniaControl->client->query('ForceSpectator', $target->login, $type);
if (!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $player->login);
return;
else {
$this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($player->login, $targetLogin);
}
if ($type != 1) {
$this->maniaControl->client->query('ForceSpectator', $target->login, 0);
}
$this->maniaControl->chat->sendInformation('$<' . $player->nickname . '$> forced $<' . $target->nickname . '$> to spectator!');
}
/**
@ -269,6 +271,38 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->chat->sendSuccess('Fake players disconnected!', $player->login);
}
/**
* Handle //mute Command
*
* @param array $chatCallback
* @param Player $admin
*/
public function command_MutePlayer(array $chatCallback, Player $admin) {
$commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No login specified! Example: '//mute login'");
return;
}
$targetLogin = $commandParts[1];
$this->maniaControl->playerManager->playerActions->mutePlayer($admin->login, $targetLogin);
}
/**
* Handle //unmute Command
*
* @param array $chatCallback
* @param Player $admin
*/
public function command_UnmutePlayer(array $chatCallback, Player $admin) {
$commandParts = explode(' ', $chatCallback[1][2]);
if (count($commandParts) <= 1) {
$this->maniaControl->chat->sendUsageInfo("No login specified! Example: '//unmute login'");
return;
}
$targetLogin = $commandParts[1];
$this->maniaControl->playerManager->playerActions->unMutePlayer($admin->login, $targetLogin);
}
/**
* Handle Player list command
*

View File

@ -214,7 +214,7 @@ class PlayerManager implements CallbackListener {
* Get a Player by Login
*
* @param string $login
* @return Player
* @return \ManiaControl\Players\Player
*/
public function getPlayer($login) {
if (!isset($this->players[$login])) {