match settings manager

This commit is contained in:
Steffen Schröder 2014-05-11 15:28:53 +02:00
parent 52be0fab10
commit 0834d2c587
11 changed files with 154 additions and 82 deletions

View File

@ -2,8 +2,6 @@
namespace ManiaControl\Bills;
use ManiaControl\Players\Player;
/**
* ManiaControl BillData Structure
*
@ -26,7 +24,7 @@ class BillData {
* Construct new BillData
*
* @param mixed $function
* @param Player/string $player
* @param Player /string $player
* @param int $amount
* @param bool $pay
* @param string $receiverLogin

View File

@ -33,6 +33,7 @@ class Database implements TimerListener {
$this->maniaControl = $maniaControl;
// Get mysql server information
/** @var \SimpleXMLElement $databaseXmlTag */
$databaseXmlTag = $this->maniaControl->config->database;
$host = $databaseXmlTag->xpath('host');
if (!$host) {

View File

@ -9,7 +9,7 @@ use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Server\Server;
use ManiaControl\Server\MatchSettingsManager;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
@ -62,7 +62,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_TEAM_BALANCE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
//CallbackManager
$this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'teamStatusChanged');
$this->maniaControl->callbackManager->registerCallbackListener(MatchSettingsManager::CB_TEAM_MODE_CHANGED, $this, 'teamStatusChanged');
// Action Open Playerlist
$this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList');

View File

@ -326,7 +326,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer
$playerQuad->addTooltipLabelFeature($descriptionLabel, $description);
}
if ($this->maniaControl->server->isTeamMode()) {
if ($this->maniaControl->server->matchSettingsManager->isTeamMode()) {
if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) {
// Force to Red-Team Quad
$redQuad = new Quad_Emblems();

View File

@ -122,7 +122,7 @@ class PlayerManager implements CallbackListener, TimerListener {
//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);
$this->maniaControl->server->matchSettingsManager->setTeamMode(true);
}
$player = new Player($this->maniaControl, true);
@ -321,7 +321,7 @@ class PlayerManager implements CallbackListener, TimerListener {
//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);
$this->maniaControl->server->matchSettingsManager->setTeamMode(true);
}
$prevJoinState = $player->hasJoinedGame;

View File

@ -135,6 +135,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
return strcmp($a::getName(), $b::getName());
});
$pageFrame = null;
foreach ($pluginClasses as $index => $pluginClass) {
/** @var Plugin $pluginClass */
if ($index % $pageMaxCount === 0) {
@ -253,6 +254,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$y = 0;
$index = 0;
$settingHeight = 5.;
$pageFrame = null;
foreach ($settings as $setting) {
if ($index % $pageSettingsMaxCount === 0) {
$pageFrame = new Frame();

View File

@ -0,0 +1,96 @@
<?php
namespace ManiaControl\Server;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\ManiaControl;
/**
* Class managing the current Match Settings of the Server
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class MatchSettingsManager implements CallbackListener {
/*
* Constants
*/
const CB_TEAM_MODE_CHANGED = 'MatchSettings.TeamModeChanged';
/*
* Private Properties
*/
private $maniaControl = null;
private $teamMode = null;
/**
* Construct a new Match Settings Manager
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
}
/**
* Set whether the Server Runs a Team-Based Mode or not
*
* @param bool $teamMode
*/
public function setTeamMode($teamMode = true) {
$oldStatus = $this->teamMode;
$this->teamMode = (bool)$teamMode;
// Trigger callback
if ($oldStatus !== $this->teamMode | $oldStatus === null) {
$this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode);
}
}
/**
* Check if the Server Runs a Team-Based Mode
*
* @return bool
*/
public function isTeamMode() {
return $this->teamMode;
}
/**
* Fetch the current Game Mode
*
* @param bool $stringValue
* @param int $parseValue
* @return int | string
*/
public function getGameMode($stringValue = false, $parseValue = null) {
if (is_int($parseValue)) {
$gameMode = $parseValue;
} else {
$gameMode = $this->maniaControl->client->getGameMode();
}
if ($stringValue) {
switch ($gameMode) {
case 0:
return 'Script';
case 1:
return 'Rounds';
case 2:
return 'TimeAttack';
case 3:
return 'Team';
case 4:
return 'Laps';
case 5:
return 'Cup';
case 6:
return 'Stunts';
default:
return 'Unknown';
}
}
return $gameMode;
}
}

View File

@ -20,7 +20,6 @@ class Server implements CallbackListener {
* Constants
*/
const TABLE_SERVERS = 'mc_servers';
const CB_TEAM_MODE_CHANGED = 'ServerCallback.TeamModeChanged';
/*
* Public Properties
@ -38,12 +37,12 @@ class Server implements CallbackListener {
public $usageReporter = null;
public $rankingManager = null;
public $scriptManager = null;
public $matchSettingsManager = null;
/*
* Private Properties
*/
private $maniaControl = null;
private $teamMode = false;
/**
* Construct a new Server
@ -58,6 +57,7 @@ class Server implements CallbackListener {
$this->usageReporter = new UsageReporter($maniaControl);
$this->rankingManager = new RankingManager($maniaControl);
$this->scriptManager = new ScriptManager($maniaControl);
$this->matchSettingsManager = new MatchSettingsManager($maniaControl);
// Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
@ -223,30 +223,6 @@ class Server implements CallbackListener {
$statement->close();
}
/**
* Set if the Server Runs a Team-Mode or not
*
* @param bool $teamMode
*/
public function setTeamMode($teamMode = true) {
$oldStatus = $this->teamMode;
$this->teamMode = $teamMode;
// Trigger callback
if ($oldStatus != $this->teamMode) {
$this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode);
}
}
/**
* Check if the Server Runs a TeamMode
*
* @return bool
*/
public function isTeamMode() {
return $this->teamMode;
}
/**
* Fetch Maps Directory
*
@ -314,7 +290,7 @@ class Server implements CallbackListener {
// Build file name
$map = $this->maniaControl->mapManager->getCurrentMap();
$gameMode = $this->getGameMode();
$gameMode = $this->matchSettingsManager->getGameMode();
$time = time();
$fileName = "GhostReplays/Ghost.{$login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx";
@ -351,42 +327,6 @@ class Server implements CallbackListener {
return (is_dir($directory) && is_writable($directory));
}
/**
* Fetch current Game Mode
*
* @param bool $stringValue
* @param int $parseValue
* @return int | string
*/
public function getGameMode($stringValue = false, $parseValue = null) {
if (is_int($parseValue)) {
$gameMode = $parseValue;
} else {
$gameMode = $this->maniaControl->client->getGameMode();
}
if ($stringValue) {
switch ($gameMode) {
case 0:
return 'Script';
case 1:
return 'Rounds';
case 2:
return 'TimeAttack';
case 3:
return 'Team';
case 4:
return 'Laps';
case 5:
return 'Cup';
case 6:
return 'Stunts';
default:
return 'Unknown';
}
}
return $gameMode;
}
/**
* Wait for the Server to have the given Status
*
@ -420,4 +360,38 @@ class Server implements CallbackListener {
}
return true;
}
/**
* Set whether the Server Runs a Team-Based Mode or not
*
* @deprecated Use MatchSettingsManager instead
* @param bool $teamMode
*/
public function setTeamMode($teamMode = true) {
$this->matchSettingsManager->setTeamMode($teamMode);
}
/**
* Check if the Server Runs a Team-Based Mode
*
* @deprecated Use MatchSettingsManager instead
* @return bool
*/
public function isTeamMode() {
$this->matchSettingsManager->isTeamMode();
}
/**
* Fetch the current Game Mode
*
* @deprecated Use MatchSettingsManager instead
* @param bool $stringValue
* @param int $parseValue
* @return int | string
*/
public function getGameMode($stringValue = false, $parseValue = null) {
$this->matchSettingsManager->getGameMode($stringValue, $parseValue);
}
}

View File

@ -25,7 +25,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin;
use ManiaControl\Server\Server;
use ManiaControl\Server\MatchSettingsManager;
use ManiaControl\Server\ServerCommands;
use Maniaplanet\DedicatedServer\Structures\VoteRatio;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
@ -139,7 +139,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
$this->maniaControl->callbackManager->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
$this->maniaControl->callbackManager->registerCallbackListener(MatchSettingsManager::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
//Settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
@ -243,7 +243,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap');
$this->addVoteMenuItem($itemQuad, 15, 'Vote for a Mapskip');
if ($this->maniaControl->server->isTeamMode()) {
if ($this->maniaControl->server->matchSettingsManager->isTeamMode()) {
//Menu TeamBalance
$itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);

View File

@ -358,7 +358,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene
* @return String
*/
private function getGameModeString() {
$gameMode = $this->maniaControl->server->getGameMode();
$gameMode = $this->maniaControl->server->matchSettingsManager->getGameMode();
$scriptNameResponse = $this->maniaControl->client->getScriptName();
$scriptName = str_replace('.Script.txt', '', $scriptNameResponse["CurrentValue"]);
if ($gameMode === null) {

View File

@ -335,7 +335,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
$properties = array();
$gameMode = $this->maniaControl->server->getGameMode(true);
$gameMode = $this->maniaControl->server->matchSettingsManager->getGameMode(true);
if ($gameMode == 'Script') {
$scriptName = $this->maniaControl->client->getScriptName();
$properties['gamemode'] = $scriptName["CurrentValue"];
@ -444,7 +444,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
return;
}
$gameMode = $this->maniaControl->server->getGameMode(true);
$gameMode = $this->maniaControl->server->matchSettingsManager->getGameMode(true);
if (count($votes) == 0) {
return;