improved player action class
This commit is contained in:
parent
5926a06654
commit
8827251738
@ -10,6 +10,7 @@ use ManiaControl\ManiaControl;
|
|||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\CallbackManager;
|
use ManiaControl\Callbacks\CallbackManager;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||||
|
|
||||||
require_once __DIR__ . '/StyleManager.php';
|
require_once __DIR__ . '/StyleManager.php';
|
||||||
require_once __DIR__ . '/../FML/autoload.php';
|
require_once __DIR__ . '/../FML/autoload.php';
|
||||||
@ -19,9 +20,13 @@ require_once __DIR__ . '/../FML/autoload.php';
|
|||||||
*
|
*
|
||||||
* @author steeffeen & kremsy
|
* @author steeffeen & kremsy
|
||||||
*/
|
*/
|
||||||
class ManialinkManager implements CallbackListener {
|
class ManialinkManager implements ManialinkPageAnswerListener,CallbackListener {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants
|
||||||
|
*/
|
||||||
const MAIN_MLID = 'Main.ManiaLinkId';
|
const MAIN_MLID = 'Main.ManiaLinkId';
|
||||||
|
const ACTION_CLOSEWIDGET = 'ManiaLinkManager.CloseWidget';
|
||||||
/**
|
/**
|
||||||
* Public properties
|
* Public properties
|
||||||
*/
|
*/
|
||||||
@ -43,6 +48,8 @@ class ManialinkManager implements CallbackListener {
|
|||||||
$this->styleManager = new StyleManager($maniaControl);
|
$this->styleManager = new StyleManager($maniaControl);
|
||||||
|
|
||||||
// Register for callbacks
|
// Register for callbacks
|
||||||
|
$this->registerManialinkPageAnswerListener(self::ACTION_CLOSEWIDGET , $this,
|
||||||
|
'closeWidgetCallback');
|
||||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this,
|
||||||
'handleManialinkPageAnswer');
|
'handleManialinkPageAnswer');
|
||||||
}
|
}
|
||||||
@ -179,6 +186,16 @@ class ManialinkManager implements CallbackListener {
|
|||||||
$this->maniaControl->manialinkManager->disableAltMenu($player);
|
$this->maniaControl->manialinkManager->disableAltMenu($player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a widget via the callback
|
||||||
|
* @param array $callback
|
||||||
|
* @param Player $player
|
||||||
|
*/
|
||||||
|
public function closeWidgetCallback(array $callback, Player $player) {
|
||||||
|
$this->closeWidget($player);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the Manialink Widget and enables the Alt Menu
|
* Closes the Manialink Widget and enables the Alt Menu
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
|
@ -3,8 +3,17 @@
|
|||||||
namespace ManiaControl\Players;
|
namespace ManiaControl\Players;
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
|
use ManiaControl\Formatter;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
|
use ManiaControl\Manialinks\ManialinkManager;
|
||||||
|
|
||||||
class PlayerActions {
|
class PlayerActions {
|
||||||
/**
|
/**
|
||||||
@ -35,6 +44,8 @@ class PlayerActions {
|
|||||||
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);
|
||||||
|
$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', $targetLogin, self::SPECTATOR_PLAYER);
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
@ -43,17 +54,20 @@ class PlayerActions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('ForcePlayerTeam', $targetLogin, $teamId); //TODO bestätigung und chatnachricht
|
$success = $this->maniaControl->client->query('ForcePlayerTeam', $targetLogin, $teamId); //TODO bestätigung
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($teamId == self::BLUE_TEAM)
|
if($teamId == self::BLUE_TEAM){
|
||||||
$this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!');
|
$this->maniaControl->chat->sendInformation($title . ' $<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Blue-Team!');
|
||||||
else if($teamId == self::RED_TEAM)
|
$this->maniaControl->log($title .' ' . Formatter::stripCodes($admin->nickname) . ' forced player '. Formatter::stripCodes($target->nickname) . ' into the Blue-Team');
|
||||||
$this->maniaControl->chat->sendInformation('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> into the Red-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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,24 +79,100 @@ class PlayerActions {
|
|||||||
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);
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); //TODO bestätigung und chatnachricht
|
$success = $this->maniaControl->client->query('ForceSpectator', $targetLogin, $spectatorState); //TODO bestätigung
|
||||||
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('$<' . $admin->nickname . '$> forced $<' . $target->nickname . '$> to spectator!'); //TODO add admin title
|
$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');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Warn a Player
|
* Warn a Player
|
||||||
* @param $adminLogin
|
* @param $adminLogin
|
||||||
* @param $login
|
* @param $targetLogin
|
||||||
* @param string $message
|
|
||||||
*/
|
*/
|
||||||
public function warnPlayer($adminLogin, $login, $message = ''){
|
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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
|
||||||
|
$width = 80;
|
||||||
|
$height = 50;
|
||||||
|
$quadStyle = Quad_BgRaceScore2::STYLE; //TODO add default menu style to style manager
|
||||||
|
$quadSubstyle = Quad_BgRaceScore2::SUBSTYLE_HandleSelectable;
|
||||||
|
|
||||||
|
$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
|
||||||
|
|
||||||
|
//mainframe
|
||||||
|
$frame = new Frame();
|
||||||
|
$maniaLink->add($frame);
|
||||||
|
$frame->setSize($width,$height);
|
||||||
|
$frame->setPosition(0, 10);
|
||||||
|
|
||||||
|
//Background Quad
|
||||||
|
$backgroundQuad = new Quad();
|
||||||
|
$frame->add($backgroundQuad);
|
||||||
|
$backgroundQuad->setSize($width,$height);
|
||||||
|
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
|
||||||
|
|
||||||
|
// Add 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->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
|
||||||
|
|
||||||
|
//Headline Label
|
||||||
|
$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->setTextSize(4);
|
||||||
|
$label->setText('Administrative Warning');
|
||||||
|
$label->setTextColor('F00');
|
||||||
|
|
||||||
|
$y = $height / 2 - 15;
|
||||||
|
foreach ($message as &$line){
|
||||||
|
//Warn Labels
|
||||||
|
$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');
|
||||||
|
$y -= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//render and display xml
|
||||||
|
$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 . '$>!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -95,13 +185,17 @@ class PlayerActions {
|
|||||||
public function kickPlayer($adminLogin, $targetLogin, $message = ''){
|
public function kickPlayer($adminLogin, $targetLogin, $message = ''){
|
||||||
$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);
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('Kick', $target->login, $message); //TODO bestätigung und chatnachricht
|
$success = $this->maniaControl->client->query('Kick', $target->login, $message); //TODO bestätigung
|
||||||
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('$<' . $admin->nickname . '$> kicked $<' . $target->nickname . '$>!'); //TODO add admin title
|
$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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,13 +207,17 @@ class PlayerActions {
|
|||||||
public function banPlayer($adminLogin, $targetLogin, $message = ''){
|
public function banPlayer($adminLogin, $targetLogin, $message = ''){
|
||||||
$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);
|
||||||
|
|
||||||
$success = $this->maniaControl->client->query('Ban', $target->login, $message); //TODO bestätigung und chatnachricht
|
$success = $this->maniaControl->client->query('Ban', $target->login, $message); //TODO bestätigung
|
||||||
|
|
||||||
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('$<' . $admin->nickname . '$> banned $<' . $target->nickname . '$>!'); //TODO add admin title
|
$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));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -125,10 +125,6 @@ class PlayerManager implements CallbackListener {
|
|||||||
$playerInfo = $this->maniaControl->client->getResponse();
|
$playerInfo = $this->maniaControl->client->getResponse();
|
||||||
$player = new Player($playerInfo);
|
$player = new Player($playerInfo);
|
||||||
|
|
||||||
var_dump($player);
|
|
||||||
//if($player->isFakePlayer())
|
|
||||||
//return;
|
|
||||||
|
|
||||||
$this->addPlayer($player);
|
$this->addPlayer($player);
|
||||||
|
|
||||||
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
if ($this->maniaControl->settingManager->getSetting($this, self::SETTING_JOIN_LEAVE_MESSAGES)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user