server teammode property

This commit is contained in:
kremsy 2014-02-01 19:06:21 +01:00 committed by Steffen Schröder
parent 00529d111d
commit e792c706c7
5 changed files with 83 additions and 31 deletions

View File

@ -5,16 +5,18 @@ namespace ManiaControl\Players;
use FML\Controls\Quads\Quad_Icons128x32_1;
use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Server\Server;
/**
* Class offering various Admin Commands related to Players
*
* @author steeffeen & kremsy
*/
class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
/**
* Constants
*/
@ -61,12 +63,8 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_BOT, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_TEAM_BALANCE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
// Action Balance Teams
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance');
$itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
$itemQuad->setAction(self::ACTION_BALANCE_TEAMS);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 40, 'Balance Teams');
//CallbackManager
$this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_STATUS_CHANGED, $this, 'teamStatusChanged');
// Action Open Playerlist
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList');
@ -76,6 +74,22 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener {
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 15, 'Open Playerlist');
}
/**
* Handle TeamStatusChanged
* @param array $callback
*/
public function teamStatusChanged(array $callback) {
$status = $callback[1];
//Add Balance Team Icon if it's a teamMode
if ($status) {
// Action Balance Teams
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance');
$itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
$itemQuad->setAction(self::ACTION_BALANCE_TEAMS);
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 40, 'Balance Teams');
}
}
/**
* Handle //teambalance command

View File

@ -277,6 +277,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
// Description Label
$script->addTooltip($playerQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Advanced Player Actions on " . $listPlayer->nickname));
if($this->maniaControl->server->isTeamMode()){
// Force to Red-Team Quad
$redQuad = new Quad_Emblems();
$playerFrame->add($redQuad);
@ -300,6 +301,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
// Force to Blue-Team Description Label
$script->addTooltip($blueQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force " . $listPlayer->nickname . '$z to Blue Team!'));
}
// Force to Spectator Quad
$spectatorQuad = new Quad_BgRaceScore2();

View File

@ -128,6 +128,11 @@ class PlayerManager implements CallbackListener {
$playerItem->hoursSinceZoneInscription = $detailedPlayerInfo->hoursSinceZoneInscription;
//Check if the Player is in a Team, to notify if its a TeamMode or not
if ($playerItem->teamId != -1) {
$this->maniaControl->server->setTeamMode(true);
}
$player = new Player($playerItem);
$player->hasJoinedGame = true;
$this->addPlayer($player);
@ -186,8 +191,14 @@ class PlayerManager implements CallbackListener {
return;
}
$player->teamId = $callback[1][0]["TeamId"];
$player->ladderRank = $callback[1][0]["LadderRanking"];
$player->teamId = $callback[1][0]["TeamId"];
//Check if the Player is in a Team, to notify if its a TeamMode or not
if ($player->teamId != -1) {
$this->maniaControl->server->setTeamMode(true);
}
$prevJoinState = $player->hasJoinedGame;

View File

@ -19,6 +19,7 @@ class Server implements CallbackListener {
* Constants
*/
const TABLE_SERVERS = 'mc_servers';
const CB_TEAM_STATUS_CHANGED = 'ServerCallback.TeamStatusChanged';
/**
* Public Properties
@ -33,10 +34,12 @@ class Server implements CallbackListener {
public $serverCommands = null;
public $usageReporter = null;
/**
* Private Properties
*/
private $maniaControl = null;
private $teamMode = false;
/**
* Construct a new Server
@ -126,6 +129,28 @@ class Server implements CallbackListener {
$this->updateProperties();
}
/**
* Set if the Server Runs a Team-Mode or not
*
* @param bool $teamMode
*/
public function setTeamMode($teamMode = true) {
$this->teamMode = $teamMode;
// Trigger callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_STATUS_CHANGED, array(self::CB_TEAM_STATUS_CHANGED, $teamMode));
}
/**
* Check if the Server Runs a TeamMode
*
* @return bool
*/
public function isTeamMode() {
return $this->teamMode;
}
/**
* Fetch Game Data Directory
*

View File

@ -83,7 +83,6 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
//Check if Pause exists in current GameMode
$scriptInfos = $this->maniaControl->client->getModeScriptInfo();
$pauseExists = false;
foreach($scriptInfos->commandDescs as $param) {
if ($param->name == "Command_ForceWarmUp") {
@ -122,6 +121,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage
$this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 30, 'Cancel Vote');
}
/**
* Handle //cancelvote command
*