cleanup
This commit is contained in:
parent
0390b8794d
commit
a34f47c082
@ -56,6 +56,7 @@ class CallbackManager {
|
|||||||
private $last5Second = -1;
|
private $last5Second = -1;
|
||||||
private $last1Minute = -1;
|
private $last1Minute = -1;
|
||||||
private $mapEnded = false;
|
private $mapEnded = false;
|
||||||
|
private $mapBegan = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Callbacks Manager
|
* Construct a new Callbacks Manager
|
||||||
@ -119,7 +120,9 @@ class CallbackManager {
|
|||||||
$removed = false;
|
$removed = false;
|
||||||
foreach($this->callbackListeners as &$listeners) {
|
foreach($this->callbackListeners as &$listeners) {
|
||||||
foreach($listeners as $key => &$listenerCallback) {
|
foreach($listeners as $key => &$listenerCallback) {
|
||||||
if ($listenerCallback[0] != $listener) continue;
|
if($listenerCallback[0] != $listener) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
unset($listeners[$key]);
|
unset($listeners[$key]);
|
||||||
$removed = true;
|
$removed = true;
|
||||||
}
|
}
|
||||||
@ -137,7 +140,9 @@ class CallbackManager {
|
|||||||
$removed = false;
|
$removed = false;
|
||||||
foreach($this->scriptCallbackListener as &$listeners) {
|
foreach($this->scriptCallbackListener as &$listeners) {
|
||||||
foreach($listeners as $key => &$listenerCallback) {
|
foreach($listeners as $key => &$listenerCallback) {
|
||||||
if ($listenerCallback[0] != $listener) continue;
|
if($listenerCallback[0] != $listener) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
unset($listeners[$key]);
|
unset($listeners[$key]);
|
||||||
$removed = true;
|
$removed = true;
|
||||||
}
|
}
|
||||||
@ -152,7 +157,9 @@ class CallbackManager {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function triggerCallback($callbackName, array $callback) {
|
public function triggerCallback($callbackName, array $callback) {
|
||||||
if (!array_key_exists($callbackName, $this->callbackListeners)) return;
|
if(!array_key_exists($callbackName, $this->callbackListeners)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
foreach($this->callbackListeners[$callbackName] as $listener) {
|
foreach($this->callbackListeners[$callbackName] as $listener) {
|
||||||
call_user_func(array($listener[0], $listener[1]), $callback);
|
call_user_func(array($listener[0], $listener[1]), $callback);
|
||||||
}
|
}
|
||||||
@ -165,7 +172,9 @@ class CallbackManager {
|
|||||||
* @param array $callback
|
* @param array $callback
|
||||||
*/
|
*/
|
||||||
public function triggerScriptCallback($callbackName, array $callback) {
|
public function triggerScriptCallback($callbackName, array $callback) {
|
||||||
if (!array_key_exists($callbackName, $this->scriptCallbackListener)) return;
|
if(!array_key_exists($callbackName, $this->scriptCallbackListener)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
foreach($this->scriptCallbackListener[$callbackName] as $listener) {
|
foreach($this->scriptCallbackListener[$callbackName] as $listener) {
|
||||||
call_user_func(array($listener[0], $listener[1]), $callback);
|
call_user_func(array($listener[0], $listener[1]), $callback);
|
||||||
}
|
}
|
||||||
@ -179,7 +188,9 @@ class CallbackManager {
|
|||||||
$this->manageTimedCallbacks();
|
$this->manageTimedCallbacks();
|
||||||
|
|
||||||
// Server Callbacks
|
// Server Callbacks
|
||||||
if (!$this->maniaControl->client) return;
|
if(!$this->maniaControl->client) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$callbacks = $this->maniaControl->client->executeCallbacks();
|
$callbacks = $this->maniaControl->client->executeCallbacks();
|
||||||
if(!is_array($callbacks)) {
|
if(!is_array($callbacks)) {
|
||||||
@ -192,13 +203,17 @@ class CallbackManager {
|
|||||||
$callbackName = $callback[0];
|
$callbackName = $callback[0];
|
||||||
switch($callbackName) {
|
switch($callbackName) {
|
||||||
case 'ManiaPlanet.BeginMap':
|
case 'ManiaPlanet.BeginMap':
|
||||||
|
if(!$this->mapBegan) {
|
||||||
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
||||||
|
$this->mapBegan = true;
|
||||||
$this->mapEnded = false;
|
$this->mapEnded = false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'ManiaPlanet.EndMap':
|
case 'ManiaPlanet.EndMap':
|
||||||
if(!$this->mapEnded) {
|
if(!$this->mapEnded) {
|
||||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
||||||
$this->mapEnded = true;
|
$this->mapEnded = true;
|
||||||
|
$this->mapBegan = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::CB_MP_MODESCRIPTCALLBACK:
|
case self::CB_MP_MODESCRIPTCALLBACK:
|
||||||
@ -226,25 +241,21 @@ class CallbackManager {
|
|||||||
$scriptCallbackName = $scriptCallbackData[0];
|
$scriptCallbackName = $scriptCallbackData[0];
|
||||||
switch($scriptCallbackName) {
|
switch($scriptCallbackName) {
|
||||||
case 'BeginMap':
|
case 'BeginMap':
|
||||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
|
||||||
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
|
||||||
break;
|
|
||||||
case 'LibXmlRpc_BeginMap':
|
case 'LibXmlRpc_BeginMap':
|
||||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
||||||
|
if(!$this->mapBegan) {
|
||||||
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
||||||
break;
|
$this->mapBegan = true;
|
||||||
case 'EndMap':
|
$this->mapEnded = false;
|
||||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
|
||||||
if (!$this->mapEnded) {
|
|
||||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
|
||||||
$this->mapEnded = true;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'EndMap':
|
||||||
case 'LibXmlRpc_EndMap':
|
case 'LibXmlRpc_EndMap':
|
||||||
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
$this->triggerScriptCallback($scriptCallbackName, $scriptCallbackData);
|
||||||
if(!$this->mapEnded) {
|
if(!$this->mapEnded) {
|
||||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
||||||
$this->mapEnded = true;
|
$this->mapEnded = true;
|
||||||
|
$this->mapBegan = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -258,17 +269,23 @@ class CallbackManager {
|
|||||||
*/
|
*/
|
||||||
private function manageTimedCallbacks() {
|
private function manageTimedCallbacks() {
|
||||||
// 1 second
|
// 1 second
|
||||||
if ($this->last1Second > time() - 1) return;
|
if($this->last1Second > time() - 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->last1Second = time();
|
$this->last1Second = time();
|
||||||
$this->triggerCallback(self::CB_MC_1_SECOND, array(self::CB_MC_1_SECOND));
|
$this->triggerCallback(self::CB_MC_1_SECOND, array(self::CB_MC_1_SECOND));
|
||||||
|
|
||||||
// 5 second
|
// 5 second
|
||||||
if ($this->last5Second > time() - 5) return;
|
if($this->last5Second > time() - 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->last5Second = time();
|
$this->last5Second = time();
|
||||||
$this->triggerCallback(self::CB_MC_5_SECOND, array(self::CB_MC_5_SECOND));
|
$this->triggerCallback(self::CB_MC_5_SECOND, array(self::CB_MC_5_SECOND));
|
||||||
|
|
||||||
// 1 minute
|
// 1 minute
|
||||||
if ($this->last1Minute > time() - 60) return;
|
if($this->last1Minute > time() - 60) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->last1Minute = time();
|
$this->last1Minute = time();
|
||||||
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user