added dumpable interface, implemented all ManiaPlanet Callbacks

This commit is contained in:
kremsy 2017-03-24 22:08:51 +01:00
parent 7c01319a4a
commit 7a668b53ba
9 changed files with 158 additions and 46 deletions

View File

@ -35,15 +35,15 @@ interface Callbacks {
const MP_STARTSERVEREND = 'Callbacks.ManiaPlanetStartServerEnd';
const MP_STARTMATCHSTART = 'Callbacks.ManiaPlanetStartMatchStart';
const MP_STARTMATCHEND = 'Callbacks.ManiaPlanetStartMatchEnd';
const MP_STARTMAPSTART = 'Callbacks.ManiaPlanetStartMapStart';
const MP_STARTMAPEND = 'Callbacks.ManiaPlanetStartMapEnd';
//const MP_STARTMAPSTART = 'Callbacks.ManiaPlanetStartMapStart';
//const MP_STARTMAPEND = 'Callbacks.ManiaPlanetStartMapEnd';
const MP_STARTROUNDSTART = 'Callbacks.ManiaPlanetStartRoundStart';
const MP_STARTROUNDEND = 'Callbacks.ManiaPlanetStartRoundEnd';
const MP_STARTTURNSTART = 'Callbacks.ManiaPlanetStartTurnStart';
const MP_STARTTURNEND = 'Callbacks.ManiaPlanetStartTurnEnd';
const MP_STARTPLAYLOOPSTART = 'Callbacks.ManiaPlanetStartPlayLoopStart';
const MP_STARTPLAYLOOPEND = 'Callbacks.ManiaPlanetStartPlayLoopEnd';
const MP_ENDTTURNSTART = 'Callbacks.ManiaPlanetEndTurnStart';
const MP_ENDTURNSTART = 'Callbacks.ManiaPlanetEndTurnStart';
const MP_ENDTURNEND = 'Callbacks.ManiaPlanetEndTurnEnd';
const MP_ENDROUNDSTART = 'Callbacks.ManiaPlanetEndRoundStart';
const MP_ENDROUNDEND = 'Callbacks.ManiaPlanetEndRoundEnd';
@ -60,13 +60,16 @@ interface Callbacks {
const MP_PODIUMSTART = 'Callbacks.ManiaPlanetPodiumStart';
const MP_PODIUMEND = 'Callbacks.ManiaPlanetPodiumEnd';
//ManiaControl Callbacks
/** BeginMap Callback: Map */
const BEGINMAP = 'Callbacks.BeginMap';
//OLD Callbacks
/** BeginMatch Callback: MatchNumber */
const BEGINMATCH = 'Callbacks.BeginMatch';
/** LoadingMap Callback: MapNumber */
const LOADINGMAP = 'Callbacks.LoadingMap';
/** BeginMap Callback: Map */
const BEGINMAP = 'Callbacks.BeginMap';
/** BeginSubMatch Callback: SubmatchNumber */
const BEGINSUBMATCH = 'Callbacks.BeginSubmatch';
/** BeginRound Callback: RoundNumber */

View File

@ -60,6 +60,88 @@ class LibXmlRpcCallbacks implements CallbackListener {
case 'ManiaPlanet.StartMatch_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTMATCHSTART, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.StartMatch_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTMATCHEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'Maniaplanet.StartMap_Start': //Use the MapManager Callback
//No use for this Implementation right now (as the MapManager Callback should be used
break;
case 'Maniaplanet.StartMap_End': //Use the MapManager Callback
$jsonData = json_decode($data[0]);
$this->maniaControl->getMapManager()->handleScriptBeginMap($jsonData->map->uid, 'False');
//TODO Test if json is correctly parsed
break;
case 'ManiaPlanet.StartRound_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTROUNDSTART, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.StartRound_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTROUNDEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.StartTurn_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTTURNSTART, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.StartTurn_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTTURNEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.StartPlayLoop_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTPLAYLOOPSTART, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.StartPlayLoop_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_STARTPLAYLOOPEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.EndTurn_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDTURNSTART, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.EndTurn_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDTURNEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.EndRound_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDROUNDSTART, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.EndRound_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDROUNDEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'Maniaplanet.EndMap_Start':
//no need for this implementation, callback handled by Map Manager
break;
case 'Maniaplanet.EndMap_End': //Use the MapManager Callback
$this->maniaControl->getMapManager()->handleScriptEndMap(); //Verify if better here or at EndMap_End
break;
case 'ManiaPlanet.EndMatch_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDMATCHSTART, new StartEndStructure($this->maniaControl, $data));
break;
case 'ManiaPlanet.EndMatch_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDMATCHEND, new StartEndStructure($this->maniaControl, $data));
break;
case 'Maniaplanet.EndServer_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDSERVERSTART, new StartServerStructure($this->maniaControl, $data));
break;
case 'Maniaplanet.EndServer_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_ENDSERVEREND, new StartServerStructure($this->maniaControl, $data));
break;
case 'Maniaplanet.LoadingMap_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPSTART);
break;
case 'Maniaplanet.LoadingMap_End':
$jsonData = json_decode($data[0]);
$map = $this->maniaControl->getMapManager()->getMapByUid($jsonData->map->uid); //Verify Json
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPEND, $map);
break;
case 'Maniaplanet.UnloadingMap_Start':
$jsonData = json_decode($data[0]);
$map = $this->maniaControl->getMapManager()->getMapByUid($jsonData->map->uid); //Verify Json
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPSTART, $map);
break;
case 'Maniaplanet.UnloadingMap_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_LOADINGMAPEND);
break;
case 'Maniaplanet.Podium_Start':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_PODIUMSTART);
break;
case 'Maniaplanet.Podium_End':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::MP_PODIUMEND);
break;
//OLD Callbacks
case 'LibXmlRpc_BeginMatch':
$this->maniaControl->getCallbackManager()->triggerCallback(Callbacks::BEGINMATCH, $data[0]);

View File

@ -3,6 +3,7 @@
namespace ManiaControl\Callbacks\Structures;
use ManiaControl\General\Dumpable;
use ManiaControl\ManiaControl;
/**
@ -12,7 +13,7 @@ use ManiaControl\ManiaControl;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
abstract class BaseStructure {
abstract class BaseStructure implements Dumpable {
/** @var ManiaControl $maniaControl */
protected $maniaControl;
private $plainJsonObject;

View File

@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: Lukas
* Date: 24. Mär. 2017
* Time: 21:59
*/
namespace ManiaControl\General;
trait DumpTrait {
/**
* Var_Dump Public Properties of the Object
*/
public function dump() {
var_dump(json_decode(json_encode($this)));
}
}

14
core/General/Dumpable.php Normal file
View File

@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: Lukas
* Date: 24. Mär. 2017
* Time: 21:58
*/
namespace ManiaControl\General;
interface Dumpable {
public function dump();
}

View File

@ -26,7 +26,7 @@ use ManiaControl\Maps\MapManager;
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\PluginManager;
use ManiaControl\Server\ModeScriptEventManager;
use ManiaControl\Script\ModeScriptEventManager;
use ManiaControl\Server\Server;
use ManiaControl\Settings\SettingManager;
use ManiaControl\Statistics\StatisticManager;

View File

@ -2,6 +2,8 @@
namespace ManiaControl\Maps;
use ManiaControl\General\Dumpable;
use ManiaControl\General\DumpTrait;
use ManiaControl\ManiaExchange\MXMapInfo;
use ManiaControl\Utils\Formatter;
@ -12,34 +14,36 @@ use ManiaControl\Utils\Formatter;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Map {
class Map implements Dumpable {
use DumpTrait;
/*
* Public properties
*/
public $index = -1;
public $name = 'undefined';
public $rawName = null;
public $uid = null;
public $fileName = null;
public $environment = null;
public $authorTime = -1;
public $goldTime = -1;
public $copperPrice = -1;
public $mapType = null;
public $mapStyle = null;
public $index = -1;
public $name = 'undefined';
public $rawName = null;
public $uid = null;
public $fileName = null;
public $environment = null;
public $authorTime = -1;
public $goldTime = -1;
public $copperPrice = -1;
public $mapType = null;
public $mapStyle = null;
public $nbCheckpoints = -1;
public $nbLaps = -1;
public $nbLaps = -1;
/** @var MXMapInfo $mx */
public $mx = null;
public $mx = null;
public $authorLogin = null;
public $authorNick = null;
public $authorZone = null;
public $authorNick = null;
public $authorZone = null;
public $authorEInfo = null;
public $comment = null;
public $titleUid = null;
public $startTime = -1;
public $lastUpdate = 0;
public $karma = null;
public $comment = null;
public $titleUid = null;
public $startTime = -1;
public $lastUpdate = 0;
public $karma = null;
/**
* Construct a new map instance from xmlrpc data
@ -104,10 +108,4 @@ class Map {
return ($this->mx && ($this->lastUpdate < strtotime($this->mx->updated) || $this->uid !== $this->mx->uid));
}
/**
* Var_Dump the Map
*/
public function dump() {
var_dump(json_decode(json_encode($this)));
}
}

View File

@ -2,6 +2,8 @@
namespace ManiaControl\Players;
use ManiaControl\General\Dumpable;
use ManiaControl\General\DumpTrait;
use ManiaControl\ManiaControl;
use ManiaControl\Utils\ClassUtil;
use ManiaControl\Utils\Formatter;
@ -14,7 +16,9 @@ use Maniaplanet\DedicatedServer\Structures\LadderStats;
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class Player {
class Player implements Dumpable {
use DumpTrait;
/*
* Public Properties
*/
@ -346,13 +350,6 @@ class Player {
return false;
}
/**
* Var_Dump the Player
*/
public function dump() {
var_dump(json_decode(json_encode($this)));
}
/**
* Var_Dump the Players Cache
*/

View File

@ -6,9 +6,7 @@
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
namespace ManiaControl\Server;
//TODO maybe own folder
namespace ManiaControl\Script;
use ManiaControl\ManiaControl;