advanced callback structure
This commit is contained in:
parent
8ab5d384da
commit
2faa78c8e2
@ -11,7 +11,7 @@
|
|||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
// Run configuration
|
// Run configuration
|
||||||
define('DEV_MODE', false); // Development mode to not send error reports etc.
|
define('DEV_MODE', true); // Development mode to not send error reports etc.
|
||||||
define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder
|
define('LOG_NAME_USE_DATE', true); // Use current date as suffix for log file name in logs folder
|
||||||
define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder
|
define('LOG_NAME_USE_PID', true); // Use current process id as suffix for log file name in logs folder
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ class LibXmlRpcCallbacks implements CallbackListener {
|
|||||||
*/
|
*/
|
||||||
public function handleScriptCallback($name, $data) {
|
public function handleScriptCallback($name, $data) {
|
||||||
var_dump($name);
|
var_dump($name);
|
||||||
|
//var_dump($data);
|
||||||
switch ($name) {
|
switch ($name) {
|
||||||
//New callbacks
|
//New callbacks
|
||||||
case 'XmlRpc.CallbacksList':
|
case 'XmlRpc.CallbacksList':
|
||||||
|
@ -14,12 +14,38 @@ use ManiaControl\ManiaControl;
|
|||||||
abstract class BaseStructure {
|
abstract class BaseStructure {
|
||||||
/** @var ManiaControl $maniaControl */
|
/** @var ManiaControl $maniaControl */
|
||||||
protected $maniaControl;
|
protected $maniaControl;
|
||||||
|
private $plainJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets ManiaControl
|
||||||
|
*
|
||||||
|
* @param \ManiaControl\ManiaControl $maniaControl
|
||||||
|
*/
|
||||||
|
protected function setManiaControl(ManiaControl $maniaControl) {
|
||||||
|
$this->maniaControl = $maniaControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes the Data and Sets the Json
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
protected function setJson($data) {
|
||||||
|
$this->plainJson = json_decode($data[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Plain Json
|
||||||
|
*/
|
||||||
|
public function getJson() {
|
||||||
|
return $this->plainJson;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Var_Dump the Structure
|
* Var_Dump the Structure
|
||||||
*/
|
*/
|
||||||
public function dump() {
|
public function dump() {
|
||||||
|
var_dump($this->getJson());
|
||||||
var_dump(json_decode(json_encode($this)));
|
var_dump(json_decode(json_encode($this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,9 +14,9 @@ use ManiaControl\ManiaControl;
|
|||||||
*/
|
*/
|
||||||
class CallbacksListStructure extends BaseStructure {
|
class CallbacksListStructure extends BaseStructure {
|
||||||
/** @var string $responseId */
|
/** @var string $responseId */
|
||||||
private $responseId;
|
public $responseId;
|
||||||
/** @var array $callbacks */
|
/** @var array $callbacks */
|
||||||
private $callbacks;
|
public $callbacks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Armor Empty Structure
|
* Construct a new Armor Empty Structure
|
||||||
@ -25,13 +25,13 @@ class CallbacksListStructure extends BaseStructure {
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
*/
|
*/
|
||||||
public function __construct(ManiaControl $maniaControl, $data) {
|
public function __construct(ManiaControl $maniaControl, $data) {
|
||||||
$this->maniaControl = $maniaControl;
|
parent::setManiaControl($maniaControl);
|
||||||
|
parent::setJson($data);
|
||||||
|
|
||||||
//Not tested yet, TODO test
|
$this->responseId = $this->getJson()->responseid;
|
||||||
$json = json_decode($data);
|
$this->callbacks = $this->getJson()->callbacks;
|
||||||
|
|
||||||
$this->responseId = $json->responseId;
|
//$this->dump();
|
||||||
$this->callbacks = $json->callbacks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,6 +13,8 @@ namespace ManiaControl\Server;
|
|||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
|
|
||||||
class ModeScriptEventManager {
|
class ModeScriptEventManager {
|
||||||
|
const API_VERSION = "2.0.0";
|
||||||
|
|
||||||
/** @var ManiaControl $maniaControl */
|
/** @var ManiaControl $maniaControl */
|
||||||
private $maniaControl;
|
private $maniaControl;
|
||||||
|
|
||||||
@ -31,12 +33,11 @@ class ModeScriptEventManager {
|
|||||||
public function enableCallbacks() {
|
public function enableCallbacks() {
|
||||||
$this->maniaControl->getClient()->triggerModeScriptEvent('XmlRpc.EnableCallbacks', array('true'));
|
$this->maniaControl->getClient()->triggerModeScriptEvent('XmlRpc.EnableCallbacks', array('true'));
|
||||||
|
|
||||||
$this->setApiVersion();
|
$this->setApiVersion(self::API_VERSION);
|
||||||
|
|
||||||
$this->getAllApiVersions();
|
$this->getAllApiVersions();
|
||||||
|
|
||||||
$this->getCallbacksList(); //TODO verify why this does not work
|
$this->getCallbacksList(); //TODO verify why this does not work
|
||||||
var_dump("test");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +59,7 @@ class ModeScriptEventManager {
|
|||||||
* Sets the Api Version
|
* Sets the Api Version
|
||||||
* @param string $version
|
* @param string $version
|
||||||
*/
|
*/
|
||||||
public function setApiVersion($version = "1.2.3-beta.4.5.6+build789"){ //TODO constant of API Versions
|
public function setApiVersion($version = self::API_VERSION){
|
||||||
$this->maniaControl->getClient()->triggerModeScriptEvent('XmlRpc.SetApiVersion', array($version));
|
$this->maniaControl->getClient()->triggerModeScriptEvent('XmlRpc.SetApiVersion', array($version));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,17 +44,15 @@ class ScriptManager {
|
|||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||||
} catch (GameModeException $e) {
|
} catch (GameModeException $e) {
|
||||||
|
var_dump("test");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO remove later, than only the last 2 lines are needed in future
|
//TODO remove later, than only the last 2 lines are needed in future
|
||||||
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
if (array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
||||||
return false;
|
$scriptSettings['S_UseScriptCallbacks'] = true;
|
||||||
|
$this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
|
||||||
}
|
}
|
||||||
$scriptSettings['S_UseScriptCallbacks'] = true;
|
|
||||||
$this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->maniaControl->getModeScriptEventManager()->enableCallbacks();
|
$this->maniaControl->getModeScriptEventManager()->enableCallbacks();
|
||||||
Logger::logInfo("Script Callbacks successfully enabled!");
|
Logger::logInfo("Script Callbacks successfully enabled!");
|
||||||
|
Loading…
Reference in New Issue
Block a user