added playermute

This commit is contained in:
kremsy 2014-01-02 16:37:52 +01:00
parent 45803ef443
commit f935fa9b43
3 changed files with 205 additions and 107 deletions

View File

@ -60,9 +60,11 @@ class Player {
$this->joinTime = time();
if($this->nickname == '')
if($this->nickname == '') {
$this->nickname = $this->login;
}
}
/**
* Check if player is not a real player

View File

@ -6,7 +6,6 @@ use FML\Controls\Control;
use FML\Controls\Frame;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_BgRaceScore2;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\ManiaLink;
use ManiaControl\Admin\AuthenticationManager;
@ -55,7 +54,9 @@ class PlayerActions {
// TODO: get used by playercommands
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
if (!$admin || !$target) return;
if(!$admin || !$target) {
return;
}
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
if($target->isSpectator) {
@ -75,15 +76,16 @@ class PlayerActions {
$chatMessage = false;
if($teamId == self::BLUE_TEAM) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!';
}
else if ($teamId == self::RED_TEAM) {
} else if($teamId == self::RED_TEAM) {
$chatMessage = $title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-Team!';
}
if (!$chatMessage) return;
if(!$chatMessage)
return;
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
}
/**
* Force a Player to Spectator
*
@ -108,6 +110,60 @@ class PlayerActions {
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
}
/**
* UnMutes a Player
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
*/
public function unMutePlayer($adminLogin, $targetLogin) {
// TODO: playercommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$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());
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
$chatMessage = $title . ' $<' . $admin->nickname . '$> un-muted $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
}
/**
* Mutes a Player
*
* @param string $adminLogin
* @param string $targetLogin
* @param int $spectatorState
*/
public function mutePlayer($adminLogin, $targetLogin) {
// TODO: playercommand
$admin = $this->maniaControl->playerManager->getPlayer($adminLogin);
$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
$title = $this->maniaControl->authenticationManager->getAuthLevelName($admin->authLevel);
$success = $this->maniaControl->client->query('Ignore', $targetLogin);
if(!$success) {
$this->maniaControl->chat->sendError('Error occurred: ' . $this->maniaControl->getClientErrorText(), $admin->login);
return;
}
$chatMessage = $title . ' $<' . $admin->nickname . '$> muted $<' . $target->nickname . '$>!';
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
}
/**
* Warn a Player
*
@ -202,8 +258,7 @@ class PlayerActions {
if($target->isFakePlayer()) {
$success = $this->maniaControl->client->query('DisconnectFakePlayer', $target->login);
}
else {
} else {
$success = $this->maniaControl->client->query('Kick', $target->login, $message);
}
@ -254,16 +309,13 @@ class PlayerActions {
$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);
$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;
}
@ -307,4 +359,19 @@ class PlayerActions {
$this->maniaControl->chat->sendInformation($chatMessage);
$this->maniaControl->log(Formatter::stripCodes($chatMessage));
}
/**
* Checks if a Player is Muted
*
* @param $login
* @return bool
*/
public function isPlayerMuted($login) {
$this->maniaControl->client->query('GetIgnoreList', 100, 0);
foreach($this->maniaControl->client->getResponse() as $ignoredPlayers) {
if($ignoredPlayers["Login"] == $login)
return true;
}
return false;
}
}

View File

@ -38,6 +38,8 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
const ACTION_FORCE_SPEC = 'PlayerList.ForceSpec';
const ACTION_PLAYER_ADV = 'PlayerList.PlayerAdvancedActions';
const ACTION_CLOSE_PLAYER_ADV = 'PlayerList.ClosePlayerAdvWidget';
const ACTION_MUTE_PLAYER = 'PlayerList.MutePlayer';
const ACTION_UNMUTE_PLAYER = 'PlayerList.UnMutePlayer';
const ACTION_WARN_PLAYER = 'PlayerList.WarnPlayer';
const ACTION_KICK_PLAYER = 'PlayerList.KickPlayer';
const ACTION_BAN_PLAYER = 'PlayerList.BanPlayer';
@ -363,7 +365,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
// todo all configurable or as constants
$x = $this->width / 2 + 2.5;
$width = 35;
$height = $this->height * 0.7;
$height = $this->height * 0.75;
$hAlign = Control::LEFT;
$style = Label_Text::STYLE_TextCardSmall;
$textSize = 1.5;
@ -413,15 +415,14 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$label->setText($player->nickname);
$label->setTextColor($textColor);
//Mute Player
$y = $height / 2 - 14;
// Show Warn
$quad = new Quad_BgsPlayerCard();
$frame->add($quad);
$quad->setX(0);
$quad->setY($y);
$quad->setSubStyle($quad::SUBSTYLE_BgPlayerCardBig);
$quad->setSize($quadWidth, 5);
$quad->setAction(self::ACTION_WARN_PLAYER . "." . $login);
$label = new Label_Button();
$frame->add($label);
@ -430,6 +431,26 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
$label->setY($y);
$label->setStyle($style);
$label->setTextSize($textSize);
$label->setTextColor($textColor);
if(!$this->maniaControl->playerManager->playerActions->isPlayerMuted($login)) {
$label->setText("Mute");
$quad->setAction(self::ACTION_MUTE_PLAYER . "." . $login);
} else {
$label->setText("UnMute");
$quad->setAction(self::ACTION_UNMUTE_PLAYER . "." . $login);
}
//Warn Player
$y -= 5;
$quad = clone $quad;
$frame->add($quad);
$quad->setY($y);
$quad->setAction(self::ACTION_KICK_PLAYER . "." . $login);
$label = clone $label;
$frame->add($label);
$label->setY($y);
$label->setText("Warn");
$label->setTextColor($textColor);
@ -565,6 +586,14 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener {
case self::ACTION_FORCE_SPEC:
$this->maniaControl->playerManager->playerActions->forcePlayerToSpectator($adminLogin, $targetLogin, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE);
break;
case self::ACTION_MUTE_PLAYER:
$this->maniaControl->playerManager->playerActions->mutePlayer($adminLogin, $targetLogin);
$this->showPlayerList($this->maniaControl->playerManager->getPlayer($adminLogin));
break;
case self::ACTION_UNMUTE_PLAYER:
$this->maniaControl->playerManager->playerActions->unMutePlayer($adminLogin, $targetLogin);
$this->showPlayerList($this->maniaControl->playerManager->getPlayer($adminLogin));
break;
case self::ACTION_WARN_PLAYER:
$this->maniaControl->playerManager->playerActions->warnPlayer($adminLogin, $targetLogin);
break;