updated pause / warmup systems in mc

This commit is contained in:
kremsy 2017-04-13 20:46:23 +02:00
parent 65f179e7a2
commit cffbc6cd89
5 changed files with 99 additions and 68 deletions

View File

@ -212,10 +212,10 @@ class ModeScriptEventManager implements UsageInformationAble {
* Extend the duration of any ongoing warmup. * Extend the duration of any ongoing warmup.
* *
* @api * @api
* @param $milisec < the duration of the extension in milliseconds. * @param $seconds < the duration of the extension in seconds.
*/ */
public function extendManiaPlanetWarmup($milisec) { public function extendManiaPlanetWarmup($seconds) {
$this->maniaControl->getClient()->triggerModeScriptEvent('Maniaplanet.WarmUp.Extend', array($milisec)); $this->maniaControl->getClient()->triggerModeScriptEvent('Maniaplanet.WarmUp.Extend', array($seconds * 1000));
} }
/** /**

View File

@ -2,6 +2,7 @@
namespace ManiaControl\Script; namespace ManiaControl\Script;
use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure;
use ManiaControl\Callbacks\Structures\ManiaPlanet\ModeUseTeamsStructure; use ManiaControl\Callbacks\Structures\ManiaPlanet\ModeUseTeamsStructure;
use ManiaControl\General\UsageInformationAble; use ManiaControl\General\UsageInformationAble;
use ManiaControl\General\UsageInformationTrait; use ManiaControl\General\UsageInformationTrait;
@ -12,6 +13,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
/** /**
* Manager for Game Mode Script related Stuff * Manager for Game Mode Script related Stuff
* *
* @api
* @author ManiaControl Team <mail@maniacontrol.com> * @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team * @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
@ -19,12 +21,16 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
class ScriptManager implements UsageInformationAble { class ScriptManager implements UsageInformationAble {
use UsageInformationTrait; use UsageInformationTrait;
//TODO add CB to MC Website
const CB_PAUSE_STATUS_CHANGED = "ManiaControl.ScriptManager.PauseStatusChanged";
/* /*
* Private properties * Private properties
*/ */
/** @var ManiaControl $maniaControl */ /** @var ManiaControl $maniaControl */
private $maniaControl = null; private $maniaControl = null;
private $isScriptMode = null; private $isScriptMode = null;
private $modeUsesPause = false;
/** /**
* Construct a new script manager instance * Construct a new script manager instance
@ -69,13 +75,53 @@ class ScriptManager implements UsageInformationAble {
} }
}); });
//Checks if the Mode Uses Pause
$this->checkIfTheModeUsesPause();
return true; return true;
} }
/**
* Checks if the Mode Uses Pause Async
*/
private function checkIfTheModeUsesPause() {
try {
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
foreach ($scriptInfos->commandDescs as $param) { //TODO Mp3, can be removed later
if ($param->name === "Command_ForceWarmUp" || $param->name === "Command_SetPause") {
$this->setPauseStatus(true);
return;
}
}
} catch (GameModeException $e) {
}
//Checks if the Script has implemented the Pause Feature and Sets the Information
$this->maniaControl->getModeScriptEventManager()->getPauseStatus()->setCallable(function (StatusCallbackStructure $structure) {
if ($structure->isAvailable()) {
$this->setPauseStatus(true);
}
});
}
/**
* Sets the New Pause Status
*
* @param boolean $status
*/
private function setPauseStatus($status) {
$status = (boolean) $status;
if ($this->modeUsesPause != $status) {
$this->modeUsesPause = $status;
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_PAUSE_STATUS_CHANGED, $status);
}
}
/** /**
* Check whether the Server is running in Script Mode * Check whether the Server is running in Script Mode
* *
* @api
* @return bool * @return bool
*/ */
public function isScriptMode() { public function isScriptMode() {
@ -85,4 +131,24 @@ class ScriptManager implements UsageInformationAble {
} }
return $this->isScriptMode; return $this->isScriptMode;
} }
/**
* Checks if the Mode Can be Forced to a Pause
*
* @api
* @return bool
*/
public function modeUsesPause() {
return $this->modeUsesPause;
}
/**
* Checks if the Mode is in TeamMode
*
* @api
* @return bool
*/
public function modeIsTeamMode() {
return $this->maniaControl->getServer()->isTeamMode();
}
} }

View File

@ -8,6 +8,7 @@ use FML\Controls\Quads\Quad_Icons64x64_1;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\Callbacks;
use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Logger; use ManiaControl\Logger;
@ -38,9 +39,6 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
const SETTING_PERMISSION_SHOW_SYSTEMINFO = 'Show SystemInfo'; const SETTING_PERMISSION_SHOW_SYSTEMINFO = 'Show SystemInfo';
const SETTING_PERMISSION_SHUTDOWN_SERVER = 'Shutdown Server'; const SETTING_PERMISSION_SHUTDOWN_SERVER = 'Shutdown Server';
const SETTING_PERMISSION_CHANGE_SERVERSETTINGS = 'Change ServerSettings'; const SETTING_PERMISSION_CHANGE_SERVERSETTINGS = 'Change ServerSettings';
const COMMAND_EXTEND_WARMUP = 'WarmUp_Extend';
const COMMAND_FORCE_WARMUP = 'Command_ForceWarmUp';
const COMMAND_SET_PAUSE = 'Command_SetPause';
/* /*
* Private properties * Private properties
@ -61,7 +59,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
// Callbacks // Callbacks
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'each5Seconds', 5000); $this->maniaControl->getTimerManager()->registerTimerListening($this, 'each5Seconds', 5000);
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'handleOnInit');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::WARMUPSTATUS, $this, 'handleWarmUpStatus'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::MP_WARMUP_STATUS, $this, 'handleWarmUpStatus');
// Chat commands // Chat commands
$this->maniaControl->getCommandManager()->registerCommandListener('setservername', $this, 'commandSetServerName', true, 'Sets the ServerName.'); $this->maniaControl->getCommandManager()->registerCommandListener('setservername', $this, 'commandSetServerName', true, 'Sets the ServerName.');
@ -92,8 +90,6 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CANCEL_VOTE, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CANCEL_VOTE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_HANDLE_WARMUP, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_HANDLE_WARMUP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->handleWarmUpStatus(true); //TODO dynamic
$this->updateCancelVoteMenuItem(); $this->updateCancelVoteMenuItem();
$this->updateWarmUpMenuItems(); $this->updateWarmUpMenuItems();
} }
@ -112,21 +108,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* Manage the WarmUp related menu items * Manage the WarmUp related menu items
*/ */
private function updateWarmUpMenuItems() { private function updateWarmUpMenuItems() {
$pauseExists = false;
try {
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
foreach ($scriptInfos->commandDescs as $param) {
if ($param->name === self::COMMAND_FORCE_WARMUP || $param->name === self::COMMAND_SET_PAUSE) {
$pauseExists = true;
break;
}
}
$this->maniaControl->getClient()->triggerModeScriptEvent("WarmUp_GetStatus");
} catch (GameModeException $e) {
}
// Add pause menu item // Add pause menu item
if ($pauseExists) { if ($this->maniaControl->getServer()->getScriptManager()->modeUsesPause()) {
$itemQuad = new Quad_Icons128x32_1(); $itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
$itemQuad->setAction(self::ACTION_SET_PAUSE); $itemQuad->setAction(self::ACTION_SET_PAUSE);
@ -140,8 +123,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
* *
* @param $warmupEnabled * @param $warmupEnabled
*/ */
public function handleWarmUpStatus($warmupEnabled) { public function handleWarmUpStatus(StatusCallbackStructure $structure) {
if ($warmupEnabled) { if ($structure->isAvailable()) {
// Extend WarmUp menu item // Extend WarmUp menu item
$itemQuad = new Quad_BgRaceScore2(); $itemQuad = new Quad_BgRaceScore2();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_SendScore); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_SendScore);
@ -193,11 +176,10 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
return; return;
} }
try { //TODO command paprameter for seconds
$this->maniaControl->getClient()->triggerModeScriptEvent('WarmUp_Extend', '10'); $this->maniaControl->getModeScriptEventManager()->extendManiaPlanetWarmup(10);
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!'); $this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' extended the WarmUp by 10 seconds!');
} catch (GameModeException $e) {
}
} }
/** /**
@ -212,13 +194,8 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
return; return;
} }
try {
$this->maniaControl->getClient()->triggerModeScriptEvent('WarmUp_Stop', ''); //TODO remove
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' stopped the WarmUp!');
} catch (GameModeException $e) {
}
$this->maniaControl->getModeScriptEventManager()->stopManiaPlanetWarmup(); $this->maniaControl->getModeScriptEventManager()->stopManiaPlanetWarmup();
$this->maniaControl->getChat()->sendInformation($player->getEscapedNickname() . ' stopped the WarmUp!');
} }
/** /**
@ -249,6 +226,11 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceEndRound' => true)); $this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceEndRound' => true));
} catch (GameModeException $ex) { } catch (GameModeException $ex) {
} }
//TODO verify if not everything is replaced through the new pause
$this->maniaControl->getModeScriptEventManager()->startPause();
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
} }
/** /**

View File

@ -487,6 +487,8 @@ class Server implements CallbackListener, CommandListener, UsageInformationAble
/** /**
* Check if the Server Runs a Team-Based Mode * Check if the Server Runs a Team-Based Mode
* *
* @deprecated
* @see ScriptManager::modeIsTeamMode()
* @return bool * @return bool
*/ */
public function isTeamMode() { public function isTeamMode() {

View File

@ -26,6 +26,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use ManiaControl\Script\ScriptManager;
use ManiaControl\Server\Commands; use ManiaControl\Server\Commands;
use ManiaControl\Server\Server; use ManiaControl\Server\Server;
use ManiaControl\Utils\ColorUtil; use ManiaControl\Utils\ColorUtil;
@ -146,6 +147,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$this->maniaControl->getCallbackManager()->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished'); $this->maniaControl->getCallbackManager()->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished');
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->getCallbackManager()->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu'); $this->maniaControl->getCallbackManager()->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu');
$this->maniaControl->getCallbackManager()->registerCallbackListener(ScriptManager::CB_PAUSE_STATUS_CHANGED, $this, 'constructMenu');
// Settings // Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.); $this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.);
@ -224,27 +226,12 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$itemQuad->setAction(self::ACTION_START_VOTE . 'restartmap'); $itemQuad->setAction(self::ACTION_START_VOTE . 'restartmap');
$this->addVoteMenuItem($itemQuad, 5, 'Vote for Restart-Map'); $this->addVoteMenuItem($itemQuad, 5, 'Vote for Restart-Map');
//Check if Pause exists in current GameMode if ($this->maniaControl->getServer()->getScriptManager()->modeUsesPause()) {
try {
$scriptInfos = $this->maniaControl->getClient()->getModeScriptInfo();
$pauseExists = false;
foreach ($scriptInfos->commandDescs as $param) {
if ($param->name === "Command_ForceWarmUp" || $param->name === "Command_SetPause") {
$pauseExists = true;
break;
}
}
// Menu Pause
if ($pauseExists) {
$itemQuad = new Quad_Icons128x32_1(); $itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_ManiaLinkSwitch);
$itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame'); $itemQuad->setAction(self::ACTION_START_VOTE . 'pausegame');
$this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game'); $this->addVoteMenuItem($itemQuad, 10, 'Vote for a pause of Current Game');
} }
} catch (GameModeException $e) {
}
//Menu SkipMap //Menu SkipMap
$itemQuad = new Quad_Icons64x64_1(); $itemQuad = new Quad_Icons64x64_1();
@ -252,7 +239,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
$itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap'); $itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap');
$this->addVoteMenuItem($itemQuad, 15, 'Vote for a Map Skip'); $this->addVoteMenuItem($itemQuad, 15, 'Vote for a Map Skip');
if ($this->maniaControl->getServer()->isTeamMode()) { if ($this->maniaControl->getServer()->getScriptManager()->modeIsTeamMode()) {
//Menu TeamBalance //Menu TeamBalance
$itemQuad = new Quad_Icons128x32_1(); $itemQuad = new Quad_Icons128x32_1();
$itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team);
@ -551,15 +538,9 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP
} catch (GameModeException $ex) { } catch (GameModeException $ex) {
} }
try { //TODO verify if not everything is replaced through the new pause
//Chase and Combo? $this->maniaControl->getModeScriptEventManager()->startPause();
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_SetPause' => true));
$this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!'); $this->maniaControl->getChat()->sendInformation('$f8fVote to $fffpause the current Game$f8f has been successful!');
//Especially for chase, force end of the round to reach a draw
$this->maniaControl->getClient()->sendModeScriptCommands(array('Command_ForceEndRound' => true));
} catch (GameModeException $ex) {
}
break; break;
case 'replay': case 'replay':
$this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->getMapManager()->getCurrentMap()); $this->maniaControl->getMapManager()->getMapQueue()->addFirstMapToMapQueue($this->currentVote->voter, $this->maniaControl->getMapManager()->getCurrentMap());