From 68a0c493aee27fa78a222213341eb9e644f439da Mon Sep 17 00:00:00 2001 From: kremsy Date: Wed, 21 Jun 2017 19:25:58 +0200 Subject: [PATCH] Resolved #152 updated callbacks / modescript updates, dedimania seems to be fine --- core/Callbacks/Callbacks.php | 3 + core/Callbacks/ShootManiaCallbacks.php | 11 ++- .../ShootMania/OnAFKPropertiesStructure.php | 74 +++++++++++++++++++ .../ShootMania/OnPlayersAFKStructure.php | 58 +++++++++++++++ core/Script/ModeScriptEventManager.php | 27 ++++++- 5 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 core/Callbacks/Structures/ShootMania/OnAFKPropertiesStructure.php create mode 100644 core/Callbacks/Structures/ShootMania/OnPlayersAFKStructure.php diff --git a/core/Callbacks/Callbacks.php b/core/Callbacks/Callbacks.php index fdc0b0e5..2eb37e74 100644 --- a/core/Callbacks/Callbacks.php +++ b/core/Callbacks/Callbacks.php @@ -84,6 +84,9 @@ interface Callbacks { const SM_ONFALLDAMAGE = "Shootmania.Event.OnFallDamage"; const SM_ONCOMMAND = "Shootmania.Event.OnCommand"; + const SM_PLAYERSAFK = "Shootmania.AFK.IsAfk"; + const SM_AFKPROPERTIES = "Shootmania.AFK.GetProperties"; + /** * Use the PlayerManager Callback in favour of this * diff --git a/core/Callbacks/ShootManiaCallbacks.php b/core/Callbacks/ShootManiaCallbacks.php index e760838f..23abae1b 100644 --- a/core/Callbacks/ShootManiaCallbacks.php +++ b/core/Callbacks/ShootManiaCallbacks.php @@ -6,7 +6,10 @@ use ManiaControl\Callbacks\Structures\Common\BasePlayerTimeStructure; use ManiaControl\Callbacks\Structures\Common\UIPropertiesBaseStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnActionCustomEventStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnActionEvent; +use ManiaControl\Callbacks\Structures\ShootMania\OnAFKProperties; +use ManiaControl\Callbacks\Structures\ShootMania\OnAFKPropertiesStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnArmorEmptyStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnBasePlayerObjectTimeStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnCaptureStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnCommandStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnDefaultEventStructure; @@ -17,9 +20,9 @@ use ManiaControl\Callbacks\Structures\ShootMania\OnJoustReloadStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnJoustRoundResultsStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnJoustSelectedPlayersStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnNearMissStructure; -use ManiaControl\Callbacks\Structures\ShootMania\OnBasePlayerObjectTimeStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestActionChange; use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerRequestRespawnStructure; +use ManiaControl\Callbacks\Structures\ShootMania\OnPlayersAFKStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnPlayerTriggersSectorStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnRoyalPlayerSpawnStructure; use ManiaControl\Callbacks\Structures\ShootMania\OnRoyalPointsStructure; @@ -156,6 +159,12 @@ class ShootManiaCallbacks implements CallbackListener { case Callbacks::SM_ROYAL_ROUNDWINNER: $this->maniaControl->getCallbackManager()->triggerCallback($name, new OnRoyalRoundWinnerStructure($this->maniaControl, $data)); break; + case Callbacks::SM_AFKPROPERTIES: + $this->maniaControl->getCallbackManager()->triggerCallback($name, new OnAFKPropertiesStructure($this->maniaControl, $data)); + break; + case Callbacks::SM_PLAYERSAFK: + $this->maniaControl->getCallbackManager()->triggerCallback($name, new OnPlayersAFKStructure($this->maniaControl, $data)); + break; } } } diff --git a/core/Callbacks/Structures/ShootMania/OnAFKPropertiesStructure.php b/core/Callbacks/Structures/ShootMania/OnAFKPropertiesStructure.php new file mode 100644 index 00000000..a79814bb --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnAFKPropertiesStructure.php @@ -0,0 +1,74 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnAFKPropertiesStructure extends BaseResponseStructure { + protected $idleTimeLimit; + protected $spawnTimeLimit; + protected $checkInterval; + protected $forceSpec; + + /** + * Construct a new On Hit Structure + * + * @param ManiaControl $maniaControl + * @param array $data + */ + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $jsonObj = $this->getPlainJsonObject(); + $this->idleTimeLimit = $jsonObj->idletimelimit; + $this->spawnTimelimit = $jsonObj->spawntimelimit; + $this->checkInterval = $jsonObj->checkinterval; + $this->forceSpec = $jsonObj->forcespec; + } + + /** + * Time after which a player is considered to be AFK (ms) + * + * @api + * @return int + */ + public function getIdleTimeLimit() { + return (int) $this->idleTimeLimit; + } + + /** + * Time after spawn before which a player can't be considered to be + * + * @return int + */ + public function getSpawnTimeLimit() { + return (int) $this->spawnTimeLimit; + } + + /** + * Time between each AFK check (ms) + * + * @return int + */ + public function getCheckInterval() { + return (int) $this->checkInterval; + } + + /** + * Let the library force the AFK player into spectator mode + * + * @return bool + */ + public function getForceSpec() { + return $this->forceSpec; + } +} \ No newline at end of file diff --git a/core/Callbacks/Structures/ShootMania/OnPlayersAFKStructure.php b/core/Callbacks/Structures/ShootMania/OnPlayersAFKStructure.php new file mode 100644 index 00000000..20f7d272 --- /dev/null +++ b/core/Callbacks/Structures/ShootMania/OnPlayersAFKStructure.php @@ -0,0 +1,58 @@ + + * @copyright 2014-2017 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class OnPlayersAFKStructure extends BaseStructure { + protected $logins; + + /** + * Construct a new On Hit Structure + * + * @param ManiaControl $maniaControl + * @param array $data + */ + public function __construct(ManiaControl $maniaControl, $data) { + parent::__construct($maniaControl, $data); + + $jsonObj = $this->getPlainJsonObject(); + $this->logins = $jsonObj->logins; + } + + /** + * Returns a Login Array of the defenders + * + * @api + * @return array + */ + public function getAFKPlayerLogins() { + return $this->logins; + } + + /** + * Gets an Array of the Players + * + * @api + * @return \ManiaControl\Players\Player[] + */ + public function getAFKPlayers() { + $afkPlayers = array(); + foreach ($this->logins as $login) { + $player = $this->maniaControl->getPlayerManager()->getPlayer($login); + if ($player) { + $afkPlayers[$login] = $player; + } + } + return $afkPlayers; + } +} \ No newline at end of file diff --git a/core/Script/ModeScriptEventManager.php b/core/Script/ModeScriptEventManager.php index bd13ca82..722850a4 100644 --- a/core/Script/ModeScriptEventManager.php +++ b/core/Script/ModeScriptEventManager.php @@ -23,7 +23,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException; class ModeScriptEventManager implements UsageInformationAble { use UsageInformationTrait; - const API_VERSION = "2.1.0"; + const API_VERSION = "2.2.0"; /** @var ManiaControl $maniaControl */ private $maniaControl; @@ -416,6 +416,31 @@ class ModeScriptEventManager implements UsageInformationAble { return new InvokeScriptCallback($this->maniaControl, Callbacks::SM_SCORES, $responseId); } + /** + * Request the current properties of the AFK libraries. + * + * @api + * @return \ManiaControl\Script\InvokeScriptCallback You can directly set a callable on it via setCallable() + */ + public function getShootmaniaAFKProperties() { + $responseId = $this->generateResponseId(); + $this->triggerModeScriptEvent(' Shootmania.AFK.GetProperties', array($responseId)); + return new InvokeScriptCallback($this->maniaControl, Callbacks::SM_AFKPROPERTIES, $responseId); + } + + /** + * Set the properties of the AFK library. + * + * @api + * @param int $idleTimeLimit + * @param int $spawnTimeLimit + * @param int $checkInterval + * @param int $forceSpec + */ + public function setShootmaniaAFKProperties($idleTimeLimit, $spawnTimeLimit, $checkInterval, $forceSpec) { + $this->triggerModeScriptEvent('Shootmania.AFK.SetProperties', array(strval($idleTimeLimit), strval($spawnTimeLimit), strval($checkInterval), strval($forceSpec))); + } + /** * Request the current ui properties. This method will trigger the "Shootmania.UIProperties" callback. *