- subfolders for different classes
- Improved file and class naming - "handler"-> "listener" (callbacks, commands)
This commit is contained in:
parent
348db3602a
commit
9e5e444552
@ -19,7 +19,7 @@ if (!is_dir('logs')) {
|
||||
ini_set('error_log', 'logs/ManiaControl_' . getmypid() . '.log');
|
||||
|
||||
// Load ManiaControl class
|
||||
require_once __DIR__ . '/core/maniaControl.php';
|
||||
require_once __DIR__ . '/core/ManiaControl.php';
|
||||
|
||||
// Start ManiaControl
|
||||
error_log('Loading ManiaControl v' . ManiaControl::VERSION . '...');
|
||||
|
13
application/core/Callbacks/CallbackListener.php
Normal file
13
application/core/Callbacks/CallbackListener.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
/**
|
||||
* Interface for CallbackListener
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
interface CallbackListener {
|
||||
}
|
||||
|
||||
?>
|
@ -1,13 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Callbacks;
|
||||
|
||||
require_once __DIR__ . '/CallbackListener.php';
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Class for handling server and controller callbacks
|
||||
* Class for managing server and controller callbacks
|
||||
*
|
||||
* @author steeffeen
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class Callbacks {
|
||||
class CallbackManager {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
@ -23,10 +27,8 @@ class Callbacks {
|
||||
// ManiaPlanet callbacks
|
||||
const CB_MP_SERVERSTART = 'ManiaPlanet.ServerStart';
|
||||
const CB_MP_SERVERSTOP = 'ManiaPlanet.ServerStop';
|
||||
const CB_MP_BEGINMAP = 'ManiaPlanet.BeginMap';
|
||||
const CB_MP_BEGINMATCH = 'ManiaPlanet.BeginMatch';
|
||||
const CB_MP_ENDMATCH = 'ManiaPlanet.EndMatch';
|
||||
const CB_MP_ENDMAP = 'ManiaPlanet.EndMap';
|
||||
const CB_MP_MAPLISTMODIFIED = 'ManiaPlanet.MapListModified';
|
||||
const CB_MP_ECHO = 'ManiaPlanet.Echo';
|
||||
const CB_MP_BILLUPDATED = 'ManiaPlanet.BillUpdated';
|
||||
@ -50,21 +52,19 @@ class Callbacks {
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $callbackHandlers = array();
|
||||
private $callbackListeners = array();
|
||||
private $last1Second = -1;
|
||||
private $last5Second = -1;
|
||||
private $last1Minute = -1;
|
||||
private $last3Minute = -1;
|
||||
|
||||
/**
|
||||
* Construct callbacks handler
|
||||
* Construct callbacks manager
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init values
|
||||
$this->last1Second = time();
|
||||
$this->last5Second = time();
|
||||
$this->last1Minute = time();
|
||||
@ -72,89 +72,24 @@ class Callbacks {
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform OnInit callback
|
||||
* Register a new callback listener
|
||||
*
|
||||
* @param string $callbackName
|
||||
* @param \ManiaControl\Callbacks\CallbackListener $listener
|
||||
* @param string $method
|
||||
* @return bool
|
||||
*/
|
||||
public function onInit() {
|
||||
// On init callback
|
||||
$this->triggerCallback(self::CB_MC_ONINIT, array(self::CB_MC_ONINIT));
|
||||
|
||||
// Simulate begin map
|
||||
$map = $this->maniaControl->server->getCurrentMap();
|
||||
if ($map) {
|
||||
$this->triggerCallback(self::CB_MC_BEGINMAP, array(self::CB_MC_BEGINMAP, array($map)));
|
||||
public function registerCallbackListener($callbackName, CallbackListener $listener, $method) {
|
||||
if (!method_exists($listener, $method)) {
|
||||
trigger_error(
|
||||
"Given listener (" . get_class($listener) . ") can't handle callback '{$callbackName}' (no method '{$method}')!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the given array of callbacks
|
||||
*/
|
||||
public function handleCallbacks() {
|
||||
// Perform ManiaControl callbacks
|
||||
if ($this->last1Second <= time() - 1) {
|
||||
$this->last1Second = time();
|
||||
|
||||
// 1 second
|
||||
$this->triggerCallback(self::CB_MC_1_SECOND, array(self::CB_MC_1_SECOND));
|
||||
|
||||
if ($this->last5Second <= time() - 5) {
|
||||
$this->last5Second = time();
|
||||
|
||||
// 5 second
|
||||
$this->triggerCallback(self::CB_MC_5_SECOND, array(self::CB_MC_5_SECOND));
|
||||
|
||||
if ($this->last1Minute <= time() - 60) {
|
||||
$this->last1Minute = time();
|
||||
|
||||
// 1 minute
|
||||
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
||||
|
||||
if ($this->last3Minute <= time() - 180) {
|
||||
$this->last3Minute = time();
|
||||
|
||||
// 3 minute
|
||||
$this->triggerCallback(self::CB_MC_3_MINUTE, array(self::CB_MC_3_MINUTE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get server callbacks
|
||||
if (!$this->maniaControl->client) {
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->client->resetError();
|
||||
$this->maniaControl->client->readCB();
|
||||
$callbacks = $this->maniaControl->client->getCBResponses();
|
||||
if (!is_array($callbacks) || $this->maniaControl->client->isError()) {
|
||||
trigger_error("Error reading server callbacks. " . $this->maniaControl->getClientErrorText());
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle callbacks
|
||||
foreach ($callbacks as $index => $callback) {
|
||||
$callbackName = $callback[0];
|
||||
switch ($callbackName) {
|
||||
case self::CB_MP_BEGINMAP:
|
||||
{
|
||||
// Map begin
|
||||
$this->triggerCallback($callbackName, $callback);
|
||||
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
||||
break;
|
||||
}
|
||||
case self::CB_MP_ENDMAP:
|
||||
{
|
||||
// Map end
|
||||
$this->triggerCallback($callbackName, $callback);
|
||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
$this->triggerCallback($callbackName, $callback);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!array_key_exists($callbackName, $this->callbackListeners)) {
|
||||
$this->callbackListeners[$callbackName] = array();
|
||||
}
|
||||
array_push($this->callbackListeners[$callbackName], array($listener, $method));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,28 +99,119 @@ class Callbacks {
|
||||
* @param array $data
|
||||
*/
|
||||
public function triggerCallback($callbackName, array $callback) {
|
||||
if (!array_key_exists($callbackName, $this->callbackHandlers)) {
|
||||
if (!array_key_exists($callbackName, $this->callbackListeners)) {
|
||||
return;
|
||||
}
|
||||
foreach ($this->callbackHandlers[$callbackName] as $handler) {
|
||||
call_user_func(array($handler[0], $handler[1]), $callback);
|
||||
foreach ($this->callbackListeners[$callbackName] as $listener) {
|
||||
call_user_func(array($listener[0], $listener[1]), $callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new callback handler
|
||||
* Trigger internal and manage server callbacks
|
||||
*/
|
||||
public function registerCallbackHandler($callback, $handler, $method) {
|
||||
if (!is_object($handler) || !method_exists($handler, $method)) {
|
||||
trigger_error("Given handler can't handle callback '{$callback}' (no method '{$method}')!");
|
||||
public function manageCallbacks() {
|
||||
$this->manageTimedCallbacks();
|
||||
|
||||
// Get server callbacks
|
||||
if (!$this->maniaControl->client) {
|
||||
return;
|
||||
}
|
||||
if (!array_key_exists($callback, $this->callbackHandlers) || !is_array($this->callbackHandlers[$callback])) {
|
||||
// Init callback handler array
|
||||
$this->callbackHandlers[$callback] = array();
|
||||
$this->maniaControl->client->readCB();
|
||||
$callbacks = $this->maniaControl->client->getCBResponses();
|
||||
if (!is_array($callbacks)) {
|
||||
trigger_error("Error reading server callbacks. " . $this->maniaControl->getClientErrorText());
|
||||
return;
|
||||
}
|
||||
// Register callback handler
|
||||
array_push($this->callbackHandlers[$callback], array($handler, $method));
|
||||
|
||||
// Handle callbacks
|
||||
foreach ($callbacks as $index => $callback) {
|
||||
$callbackName = $callback[0];
|
||||
switch ($callbackName) {
|
||||
case 'ManiaPlanet.BeginMap':
|
||||
{
|
||||
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
||||
break;
|
||||
}
|
||||
case 'ManiaPlanet.EndMap':
|
||||
{
|
||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
||||
break;
|
||||
}
|
||||
case self::CB_MP_MODESCRIPTCALLBACK:
|
||||
{
|
||||
$this->handleScriptCallback($callback);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
var_dump($callback);
|
||||
$this->triggerCallback($callbackName, $callback);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the given script callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
private function handleScriptCallback(array $callback) {
|
||||
$scriptCallbackName = $callback[1][0];
|
||||
switch ($scriptCallbackName) {
|
||||
case 'EndMap':
|
||||
{
|
||||
$this->triggerCallback(self::CB_MP_MODESCRIPTCALLBACK, $callback);
|
||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
||||
break;
|
||||
}
|
||||
case 'LibXmlRpc_EndMap':
|
||||
{
|
||||
$this->triggerCallback(self::CB_MP_MODESCRIPTCALLBACK, $callback);
|
||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
var_dump($callback);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage recurring timed callbacks
|
||||
*/
|
||||
private function manageTimedCallbacks() {
|
||||
// 1 second
|
||||
if ($this->last1Second > time() - 1) {
|
||||
return;
|
||||
}
|
||||
$this->last1Second = time();
|
||||
$this->triggerCallback(self::CB_MC_1_SECOND, array(self::CB_MC_1_SECOND));
|
||||
|
||||
// 5 second
|
||||
if ($this->last5Second > time() - 5) {
|
||||
return;
|
||||
}
|
||||
$this->last5Second = time();
|
||||
$this->triggerCallback(self::CB_MC_5_SECOND, array(self::CB_MC_5_SECOND));
|
||||
|
||||
// 1 minute
|
||||
if ($this->last1Minute > time() - 60) {
|
||||
return;
|
||||
}
|
||||
$this->last1Minute = time();
|
||||
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
||||
|
||||
// 3 minute
|
||||
if ($this->last3Minute > time() - 180) {
|
||||
return;
|
||||
}
|
||||
$this->last3Minute = time();
|
||||
$this->triggerCallback(self::CB_MC_3_MINUTE, array(self::CB_MC_3_MINUTE));
|
||||
}
|
||||
}
|
||||
|
13
application/core/Commands/CommandListener.php
Normal file
13
application/core/Commands/CommandListener.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Commands;
|
||||
|
||||
/**
|
||||
* Interface for command listeners
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
interface CommandListener {
|
||||
}
|
||||
|
||||
?>
|
@ -1,6 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Commands;
|
||||
|
||||
require_once __DIR__ . '/CommandListener.php';
|
||||
|
||||
use ManiaControl\Authentication;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Class for handling chat commands
|
||||
@ -8,56 +16,57 @@ namespace ManiaControl;
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
// TODO: settings for command auth levels
|
||||
class Commands {
|
||||
class CommandManager implements CallbackListener, CommandListener {
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $commandHandlers = array();
|
||||
private $commandListeners = array();
|
||||
private $openBills = array();
|
||||
private $serverShutdownTime = -1;
|
||||
private $serverShutdownEmpty = false;
|
||||
|
||||
/**
|
||||
* Construct commands handler
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MC_5_SECOND, $this, 'each5Seconds');
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_BILLUPDATED, $this, 'handleBillUpdated');
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERCHAT, $this, 'handleChatCallback');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_5_SECOND, $this, 'each5Seconds');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_BILLUPDATED, $this, 'handleBillUpdated');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCHAT, $this, 'handleChatCallback');
|
||||
|
||||
// Register basic commands
|
||||
$commands = array('help', 'version', 'shutdown', 'shutdownserver', 'systeminfo', 'setservername', 'getplanets', 'donate',
|
||||
'pay', 'kick', 'nextmap', 'restartmap', 'addmap', 'removemap');
|
||||
foreach ($commands as $command) {
|
||||
$this->registerCommandHandler($command, $this, 'command_' . $command);
|
||||
$this->registerCommandListener($command, $this, 'command_' . $command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a command handler
|
||||
* Register a command listener
|
||||
*
|
||||
* @param string $commandName
|
||||
* @param object $handler
|
||||
* @param CommandListener $listener
|
||||
* @param string $method
|
||||
* @return bool
|
||||
*/
|
||||
public function registerCommandHandler($commandName, $handler, $method) {
|
||||
public function registerCommandListener($commandName, CommandListener $listener, $method) {
|
||||
$command = strtolower($commandName);
|
||||
if (!is_object($handler) || !method_exists($handler, $method)) {
|
||||
trigger_error("Given handler can't handle command '{$command}' (no method '{$method}')!");
|
||||
if (!method_exists($listener, $method)) {
|
||||
trigger_error("Given listener can't handle command '{$command}' (no method '{$method}')!");
|
||||
return false;
|
||||
}
|
||||
if (!array_key_exists($command, $this->commandHandlers) || !is_array($this->commandHandlers[$command])) {
|
||||
// Init handlers array
|
||||
$this->commandHandlers[$command] = array();
|
||||
if (!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
|
||||
// Init listeners array
|
||||
$this->commandListeners[$command] = array();
|
||||
}
|
||||
// Register command handler
|
||||
array_push($this->commandHandlers[$command], array($handler, $method));
|
||||
// Register command listener
|
||||
array_push($this->commandListeners[$command], array($listener, $method));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -68,26 +77,25 @@ class Commands {
|
||||
* @return bool
|
||||
*/
|
||||
public function handleChatCallback(array $callback) {
|
||||
$chat = $callback[1];
|
||||
// Check for command
|
||||
if (!$chat[3]) {
|
||||
if (!$callback[1][3]) {
|
||||
return false;
|
||||
}
|
||||
// Check for valid player
|
||||
$player = $this->maniaControl->playerHandler->getPlayer($login);
|
||||
$player = $this->maniaControl->playerManager->getPlayer($callback[1][1]);
|
||||
if (!$player) {
|
||||
return false;
|
||||
}
|
||||
// Handle command
|
||||
$command = explode(" ", substr($chat[2], 1));
|
||||
$command = explode(" ", substr($callback[1][2], 1));
|
||||
$command = strtolower($command[0]);
|
||||
if (!array_key_exists($command, $this->commandHandlers) || !is_array($this->commandHandlers[$command])) {
|
||||
if (!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
|
||||
// No command handler registered
|
||||
return true;
|
||||
}
|
||||
// Inform command handlers
|
||||
foreach ($this->commandHandlers[$command] as $handler) {
|
||||
call_user_func(array($handler[0], $handler[1]), $callback, $player);
|
||||
foreach ($this->commandListeners[$command] as $listener) {
|
||||
call_user_func(array($listener[0], $listener[1]), $callback, $player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -502,7 +510,7 @@ class Commands {
|
||||
* Handle nextmap command
|
||||
*
|
||||
* @param array $chat
|
||||
* @param Player $player
|
||||
* @param \ManiaControl\Players\Player $player
|
||||
* @return bool
|
||||
*/
|
||||
private function command_nextmap(array $chat, Player $player) {
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
/**
|
||||
* Handler for manialink ids
|
||||
@ -27,4 +27,5 @@ class ManialinkIdHandler {
|
||||
return $mlIds;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Manialinks;
|
||||
|
||||
/**
|
||||
* Manialink utility class
|
84
application/core/Maps/Map.php
Normal file
84
application/core/Maps/Map.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Maps;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Map class
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class Map {
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $mapFetcher = null;
|
||||
public $id = 0;
|
||||
public $name = 'undefined';
|
||||
public $uid = '';
|
||||
public $fileName = '';
|
||||
public $environment = '';
|
||||
public $goldTime; // TODO: format?
|
||||
public $copperPrice = 0;
|
||||
public $mapType = '';
|
||||
public $mapStyle = '';
|
||||
public $mx = null;
|
||||
public $authorLogin = '';
|
||||
public $authorNick = '';
|
||||
public $authorZone = '';
|
||||
public $authorEInfo = '';
|
||||
public $comment = '';
|
||||
public $titleUid = '';
|
||||
public $startTime = 0;
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Create a new map object from rpc data
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
* @param array $rpc_infos
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl, $rpc_infos = null) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->startTime = time();
|
||||
|
||||
if (!$rpc_infos) {
|
||||
return;
|
||||
}
|
||||
$this->name = $rpc_infos['Name']; // in aseco stripped new lines on name
|
||||
$this->uid = $rpc_infos['UId'];
|
||||
$this->fileName = $rpc_infos['FileName'];
|
||||
$this->authorLogin = $rpc_infos['Author'];
|
||||
$this->environment = $rpc_infos['Environnement'];
|
||||
$this->goldTime = $rpc_infos['GoldTime'];
|
||||
$this->copperPrice = $rpc_infos['CopperPrice'];
|
||||
$this->mapType = $rpc_infos['MapType'];
|
||||
$this->mapStyle = $rpc_infos['MapStyle'];
|
||||
|
||||
$mapsDirectory = $this->maniaControl->server->getMapsDirectory();
|
||||
if ($this->maniaControl->server->checkAccess($mapsDirectory)) {
|
||||
$this->mapFetcher = new \GBXChallMapFetcher(true);
|
||||
try {
|
||||
$this->mapFetcher->processFile($mapsDirectory . $this->fileName);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
trigger_error($e->getMessage(), E_USER_WARNING);
|
||||
}
|
||||
$this->authorNick = $this->mapFetcher->authorNick;
|
||||
$this->authorEInfo = $this->mapFetcher->authorEInfo;
|
||||
$this->authorZone = $this->mapFetcher->authorZone;
|
||||
$this->comment = $this->mapFetcher->comment;
|
||||
}
|
||||
|
||||
// TODO: define timeout if mx is down
|
||||
$serverInfo = $this->maniaControl->server->getSystemInfo();
|
||||
$title = strtoupper(substr($serverInfo['TitleId'], 0, 2));
|
||||
$this->mx = new \MXInfoFetcher($title, $this->uid, false);
|
||||
}
|
||||
}
|
77
application/core/Maps/MapManager.php
Normal file
77
application/core/Maps/MapManager.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Maps;
|
||||
|
||||
require_once __DIR__ . '/Map.php';
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
|
||||
/**
|
||||
* Manager for maps
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class MapManager implements CallbackListener {
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $mapList = array();
|
||||
|
||||
/**
|
||||
* Construct map manager
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
|
||||
// TODO: database init
|
||||
// TODO: erasemap from server
|
||||
// TODO: implement of a method which are called by xlist command and results maplists from maniaexcahnge (or extra class for it)
|
||||
// TODO: admin add from maniaexchange, would handle it here
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->initTables();
|
||||
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_BEGINMAP, $this, 'handleBeginMap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize necessary database tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
// TODO: Initialize database table
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a map to the MapList
|
||||
*
|
||||
* @param \ManiaControl\Maps\Map $map
|
||||
* @return bool
|
||||
*/
|
||||
private function addMap(Map $map) {
|
||||
if (!$map) {
|
||||
return false;
|
||||
}
|
||||
// TODO: Save map in database
|
||||
$this->mapList[$map->uid] = $map;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle BeginMap callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function handleBeginMap(array $callback) {
|
||||
$rpcMap = $this->maniaControl->server->getCurrentMap();
|
||||
$map = new Map($this->maniaControl, $rpcMap);
|
||||
$this->addMap($map);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Players;
|
||||
|
||||
/**
|
||||
* Class representing players
|
@ -1,17 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Players;
|
||||
|
||||
require_once __DIR__ . '/Player.php';
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
|
||||
/**
|
||||
* Class managing players
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class PlayerHandler {
|
||||
class PlayerManager implements CallbackListener {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const TABLE_PLAYERS = 'mc_players';
|
||||
const SETTING_LEAVE_JOIN_MESSAGES = 'EnableLeaveJoinMessages';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
@ -22,16 +29,17 @@ class PlayerHandler {
|
||||
/**
|
||||
* Construct player handler
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->initTables();
|
||||
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERDISCONNECT, $this,
|
||||
'playerDisconnect');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -73,17 +81,19 @@ class PlayerHandler {
|
||||
* @param array $callback
|
||||
*/
|
||||
public function onInit(array $callback) {
|
||||
//register settings
|
||||
$this->maniaControl->settingManager->initSetting($this, "Leave Join Messages",true);
|
||||
// register settings
|
||||
$this->maniaControl->settingManager->initSetting($this, "Leave Join Messages", true);
|
||||
|
||||
$this->maniaControl->client->query('GetPlayerList', 300, 0, 2);
|
||||
$playerList = $this->maniaControl->client->getResponse();
|
||||
foreach ($playerList as $player) {
|
||||
if ($player['PlayerId'] <= 0) {
|
||||
foreach ($playerList as $playerItem) {
|
||||
if ($playerItem['PlayerId'] <= 0) {
|
||||
continue;
|
||||
}
|
||||
$callback = array(Callbacks::CB_MP_PLAYERCONNECT, array($player['Login']));
|
||||
$this->playerConnect($callback);
|
||||
$this->maniaControl->client->query('GetDetailedPlayerInfo', $playerItem['Login']);
|
||||
$playerInfo = $this->maniaControl->client->getResponse();
|
||||
$player = new Player($playerInfo);
|
||||
$this->addPlayer($player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,13 +109,17 @@ class PlayerHandler {
|
||||
$player = new Player($playerInfo);
|
||||
$this->addPlayer($player);
|
||||
|
||||
if($this->maniaControl->settingManager->getSetting($this,"Leave Join Messages")){
|
||||
$string = array(0 => 'New Player', 1 => '$0f0Operator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
|
||||
$this->maniaControl->chat->sendChat('$ff0'.$string[$player->authLevel].': '. $player->nickname . '$z $ff0Nation:$fff ' . $player->getCountry() . ' $ff0Ladder: $fff' . $player->ladderRank);
|
||||
if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_LEAVE_JOIN_MESSAGES)) {
|
||||
return;
|
||||
}
|
||||
//TODO: remove $w, $l and stuff out of nick
|
||||
//TODO: postfix playerConnect callBack as soon as needed
|
||||
//Todo: Better style colours of the message or anything else
|
||||
$string = array(0 => 'New Player', 1 => '$0f0Operator', 2 => '$0f0Admin', 3 => '$0f0MasterAdmin', 4 => '$0f0MasterAdmin');
|
||||
$this->maniaControl->chat->sendChat(
|
||||
'$ff0' . $string[$player->authLevel] . ': ' . $player->nickname . '$z $ff0Nation:$fff ' . $player->getCountry() .
|
||||
' $ff0Ladder: $fff' . $player->ladderRank);
|
||||
|
||||
// TODO: remove $w, $l and stuff out of nick
|
||||
// TODO: postfix playerConnect callBack as soon as needed
|
||||
// TODO: Better style colours of the message or anything else
|
||||
}
|
||||
|
||||
/**
|
||||
@ -117,7 +131,7 @@ class PlayerHandler {
|
||||
$login = $callback[1][0];
|
||||
$player = $this->removePlayer($login);
|
||||
|
||||
if($this->maniaControl->settingManager->getSetting($this,"Leave Join Messages")){
|
||||
if ($this->maniaControl->settingManager->getSetting($this, "Leave Join Messages")) {
|
||||
$played = TimeFormatter::formatTime(time() - $player->joinTime);
|
||||
$this->maniaControl->chat->sendChat($player->nickname . '$z $ff0has left the game. Played:$fff ' . $played);
|
||||
}
|
@ -1,27 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Plugins;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Plugin parent class
|
||||
*
|
||||
* @author Lukas Kremsmayr and steeffeen
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
abstract class Plugin {
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
protected $maniaControl;
|
||||
protected $name;
|
||||
protected $version;
|
||||
protected $author;
|
||||
protected $description;
|
||||
protected $maniaControl = null;
|
||||
protected $name = 'undefined';
|
||||
protected $version = 'undefined';
|
||||
protected $author = 'undefined';
|
||||
protected $description = 'undefined';
|
||||
|
||||
/**
|
||||
* Create plugin instance
|
||||
* Create a new plugin
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public abstract function __construct(ManiaControl $maniaControl);
|
||||
|
@ -1,13 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
namespace ManiaControl\Plugins;
|
||||
|
||||
require_once __DIR__ . '/Plugin.php';
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
|
||||
/**
|
||||
* Class handling plugins
|
||||
* Class managing plugins
|
||||
*
|
||||
* @author Lukas Kremsmayr and steeffeen
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class PluginHandler {
|
||||
class PluginManager {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
@ -23,7 +27,7 @@ class PluginHandler {
|
||||
/**
|
||||
* Construct plugin handler
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
43
application/core/Settings/SettingConfigurator.php
Normal file
43
application/core/Settings/SettingConfigurator.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Settings;
|
||||
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
|
||||
/**
|
||||
* Ingame setting configurator class
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
class SettingConfigurator implements CallbackListener {
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
|
||||
/**
|
||||
* Construct setting configurator
|
||||
*
|
||||
* @param \ManiaControl\ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MC_ONINIT, $this, 'onInit');
|
||||
|
||||
$this->maniaControl->manialinkIdHandler->reserveManiaLinkIds(100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle OnInit callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function onInit(array $callback) {
|
||||
// TODO: handle callback
|
||||
// $this->maniaControl->manialinkUtil->
|
||||
// $this->maniaControl->chat->sendChat("test");
|
||||
}
|
||||
}
|
@ -2,6 +2,10 @@
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
require_once __DIR__ . '/SettingConfigurator.php';
|
||||
|
||||
use ManiaControl\Settings\SettingConfigurator;
|
||||
|
||||
/**
|
||||
* Class managing settings and configurations
|
||||
*
|
||||
@ -22,6 +26,7 @@ class SettingManager {
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $configurator = null;
|
||||
private $arrayDelimiter = ';;';
|
||||
|
||||
/**
|
||||
@ -33,6 +38,8 @@ class SettingManager {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->initTables();
|
||||
|
||||
$this->configurator = new SettingConfigurator($maniaControl);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,8 +194,8 @@ class SettingManager {
|
||||
@value := ?,
|
||||
@value
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`type` = VALUE(`type`),
|
||||
`default` = VALUE(`default`);";
|
||||
`type` = VALUES(`type`),
|
||||
`default` = VALUES(`default`);";
|
||||
$settingStatement = $mysqli->prepare($settingQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
use ManiaControl\Players\Player;
|
||||
|
||||
/**
|
||||
* Class handling authentication levels
|
||||
*
|
||||
@ -42,7 +44,7 @@ class Authentication {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
|
||||
// Remove all XSuperadmins
|
||||
$adminQuery = "UPDATE `" . PlayerHandler::TABLE_PLAYERS . "`
|
||||
$adminQuery = "UPDATE `" . Players\PlayerManager::TABLE_PLAYERS . "`
|
||||
SET `authLevel` = ?
|
||||
WHERE `authLevel` = ?;";
|
||||
$adminStatement = $mysqli->prepare($adminQuery);
|
||||
@ -61,7 +63,7 @@ class Authentication {
|
||||
|
||||
// Set XSuperAdmins
|
||||
$xAdmins = $config->xsuperadmins->xpath('login');
|
||||
$adminQuery = "INSERT INTO `" . PlayerHandler::TABLE_PLAYERS . "` (
|
||||
$adminQuery = "INSERT INTO `" . Players\PlayerManager::TABLE_PLAYERS . "` (
|
||||
`login`,
|
||||
`authLevel`
|
||||
) VALUES (
|
||||
@ -138,7 +140,7 @@ class Authentication {
|
||||
/**
|
||||
* Check if the player has enough rights
|
||||
*
|
||||
* @param Player $login
|
||||
* @param \ManiaControl\Players\Player $login
|
||||
* @param int $neededAuthLevel
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -2,31 +2,30 @@
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
/**
|
||||
* Needed includes
|
||||
*
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
require_once __DIR__ . '/authentication.php';
|
||||
require_once __DIR__ . '/callbacks.php';
|
||||
require_once __DIR__ . '/chat.php';
|
||||
require_once __DIR__ . '/commands.php';
|
||||
require_once __DIR__ . '/database.php';
|
||||
require_once __DIR__ . '/fileUtil.php';
|
||||
require_once __DIR__ . '/manialinkIdHandler.php';
|
||||
require_once __DIR__ . '/player.php';
|
||||
require_once __DIR__ . '/playerHandler.php';
|
||||
require_once __DIR__ . '/plugin.php';
|
||||
require_once __DIR__ . '/pluginHandler.php';
|
||||
require_once __DIR__ . '/server.php';
|
||||
require_once __DIR__ . '/settingManager.php';
|
||||
require_once __DIR__ . '/settingConfigurator.php';
|
||||
require_once __DIR__ . '/map.php';
|
||||
require_once __DIR__ . '/mapHandler.php';
|
||||
use ManiaControl\Players\PlayerManager;
|
||||
use ManiaControl\Callbacks\CallbackManager;
|
||||
use ManiaControl\Commands\CommandManager;
|
||||
use ManiaControl\Manialinks\ManialinkIdHandler;
|
||||
use ManiaControl\Maps\MapManager;
|
||||
use ManiaControl\Plugins\PluginManager;
|
||||
|
||||
require_once __DIR__ . '/Authentication.php';
|
||||
require_once __DIR__ . '/Callbacks/CallbackManager.php';
|
||||
require_once __DIR__ . '/Chat.php';
|
||||
require_once __DIR__ . '/Commands/CommandManager.php';
|
||||
require_once __DIR__ . '/Database.php';
|
||||
require_once __DIR__ . '/FileUtil.php';
|
||||
require_once __DIR__ . '/Manialinks/ManialinkIdHandler.php';
|
||||
require_once __DIR__ . '/Manialinks/ManialinkUtil.php';
|
||||
require_once __DIR__ . '/Maps/Map.php';
|
||||
require_once __DIR__ . '/Maps/MapManager.php';
|
||||
require_once __DIR__ . '/Players/PlayerManager.php';
|
||||
require_once __DIR__ . '/Plugins/PluginManager.php';
|
||||
require_once __DIR__ . '/Server.php';
|
||||
require_once __DIR__ . '/Settings/SettingManager.php';
|
||||
require_once __DIR__ . '/GbxDataFetcher/gbxdatafetcher.inc.php';
|
||||
require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php';
|
||||
require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php';
|
||||
|
||||
list($endiantest) = array_values(unpack('L1L', pack('V', 1)));
|
||||
if ($endiantest == 1) {
|
||||
require_once __DIR__ . '/PhpRemote/GbxRemote.inc.php';
|
||||
@ -38,7 +37,7 @@ else {
|
||||
/**
|
||||
* ManiaControl Server Controller for ManiaPlanet Server
|
||||
*
|
||||
* @author steeffeen and Lukas
|
||||
* @author steeffeen & kremsy
|
||||
*/
|
||||
class ManiaControl {
|
||||
/**
|
||||
@ -52,17 +51,19 @@ class ManiaControl {
|
||||
* Public properties
|
||||
*/
|
||||
public $authentication = null;
|
||||
public $callbacks = null;
|
||||
public $callbackManager = null;
|
||||
public $chat = null;
|
||||
public $client = null;
|
||||
public $commands = null;
|
||||
public $commandManager = null;
|
||||
public $database = null;
|
||||
public $manialinkIdHandler = null;
|
||||
public $playerHandler = null;
|
||||
public $pluginHandler = null;
|
||||
public $mapManager = null;
|
||||
public $playerManager = null;
|
||||
public $pluginManager = null;
|
||||
public $server = null;
|
||||
public $settingConfigurator = null;
|
||||
public $settingManager = null;
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
@ -73,17 +74,16 @@ class ManiaControl {
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->database = new Database($this);
|
||||
$this->callbackManager = new CallbackManager($this);
|
||||
$this->manialinkIdHandler = new ManialinkIdHandler();
|
||||
$this->settingManager = new SettingManager($this);
|
||||
$this->chat = new Chat($this);
|
||||
$this->callbacks = new Callbacks($this);
|
||||
$this->server = new Server($this);
|
||||
$this->authentication = new Authentication($this);
|
||||
$this->playerHandler = new PlayerHandler($this);
|
||||
$this->mapHandler = new MapHandler($this);
|
||||
$this->manialinkIdHandler = new ManialinkIdHandler();
|
||||
$this->commands = new Commands($this);
|
||||
$this->pluginHandler = new PluginHandler($this);
|
||||
$this->settingConfigurator = new SettingConfigurator($this);
|
||||
$this->playerManager = new PlayerManager($this);
|
||||
$this->mapManager = new MapManager($this);
|
||||
$this->commandManager = new CommandManager($this);
|
||||
$this->pluginManager = new PluginManager($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +134,7 @@ class ManiaControl {
|
||||
error_log('Starting ManiaControl v' . self::VERSION . '!');
|
||||
|
||||
// Load plugins
|
||||
$this->pluginHandler->loadPlugins();
|
||||
$this->pluginManager->loadPlugins();
|
||||
|
||||
// Connect to server
|
||||
$this->connect();
|
||||
@ -146,7 +146,7 @@ class ManiaControl {
|
||||
$this->chat->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
|
||||
|
||||
// OnInit
|
||||
$this->callbacks->onInit();
|
||||
$this->callbackManager->triggerCallback(CallbackManager::CB_MC_ONINIT, array(CallbackManager::CB_MC_ONINIT));
|
||||
|
||||
// Main loop
|
||||
while (!$this->shutdownRequested) {
|
||||
@ -155,8 +155,8 @@ class ManiaControl {
|
||||
// Disable script timeout
|
||||
set_time_limit(30);
|
||||
|
||||
// Handle server callbacks
|
||||
$this->callbacks->handleCallbacks();
|
||||
// Manager callbacks
|
||||
$this->callbackManager->manageCallbacks();
|
||||
|
||||
// Yield for next tick
|
||||
$loopEnd = microtime(true);
|
||||
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
/**
|
||||
* Map Object
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
|
||||
class Map {
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = 0;
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $mapFetcher = null;
|
||||
|
||||
public $id = 0;
|
||||
public $name = '';
|
||||
public $uid = 0;
|
||||
public $fileName = '';
|
||||
public $environment = '';
|
||||
public $goldTime; //format?
|
||||
public $copperPrice = 0;
|
||||
public $mapType = '';
|
||||
public $mapStyle = '';
|
||||
|
||||
public $mx = null;
|
||||
public $authorLogin = '';
|
||||
public $authorNick = '';
|
||||
public $authorZone = '';
|
||||
public $authorEInfo = '';
|
||||
public $comment = '';
|
||||
public $titleUid = '';
|
||||
|
||||
public $starttime = 0;
|
||||
|
||||
// instantiates the map with an RPC response
|
||||
public function __construct(ManiaControl $maniaControl, $rpc_infos = null) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
if ($rpc_infos) {
|
||||
$this->name = $rpc_infos['Name']; //in aseco stripped new lines on name
|
||||
$this->uid = $rpc_infos['UId'];
|
||||
$this->fileName = $rpc_infos['FileName'];
|
||||
$this->authorLogin = $rpc_infos['Author'];
|
||||
$this->environment = $rpc_infos['Environnement'];
|
||||
$this->goldTime = $rpc_infos['GoldTime'];
|
||||
$this->copperPrice = $rpc_infos['CopperPrice'];
|
||||
$this->mapType = $rpc_infos['MapType'];
|
||||
$this->mapStyle = $rpc_infos['MapStyle'];
|
||||
|
||||
$this->mapFetcher = new \GBXChallMapFetcher(true);
|
||||
|
||||
try{
|
||||
$this->mapFetcher->processFile($this->maniaControl->server->getMapsDirectory() . $this->fileName);
|
||||
} catch (Exception $e){
|
||||
trigger_error($e->getMessage(), E_USER_WARNING);
|
||||
}
|
||||
$this->authorNick = $this->mapFetcher->authorNick;
|
||||
$this->authorEInfo = $this->mapFetcher->authorEInfo;
|
||||
$this->authorZone = $this->mapFetcher->authorZone;
|
||||
$this->comment = $this->mapFetcher->comment;
|
||||
//additional properties anyway in the mapfetcher object
|
||||
|
||||
//TODO: change to SM to gameerkennung
|
||||
//TODO: define timeout if mx is down
|
||||
$this->mx = new \MXInfoFetcher('SM', $this->uid, false); //SM -> change to gameerkennung
|
||||
} else {
|
||||
$this->name = 'undefined';
|
||||
}
|
||||
|
||||
$this->starttime = time();
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Handler for maps
|
||||
*
|
||||
* @author kremsy & steeffeen
|
||||
*/
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
|
||||
class mapHandler {
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $mapList = array();
|
||||
|
||||
/**
|
||||
* Construct map handler
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
|
||||
//TODO: database init
|
||||
//TODO: erasemap from server
|
||||
//TODO: implement of a method which are called by xlist command and results maplists from maniaexcahnge (or extra class for it)
|
||||
//TODO: admin add from maniaexchange, would handle it here
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
$this->initTables();
|
||||
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_BEGINMAP, $this, 'beginMap');
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MP_ENDMAP, $this, 'endMap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all necessary tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
//TODO: Initialize database table
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle OnInit callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function onInit(){
|
||||
$this->maniaControl->client->query('GetMapList', 300, 0);
|
||||
$mapList = $this->maniaControl->client->getResponse();
|
||||
foreach ($mapList as $map) {
|
||||
$map = new Map($this->maniaControl, $map);
|
||||
$this->addMap($map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a map to the MapList
|
||||
*
|
||||
* @param Map $map
|
||||
* @return bool
|
||||
*/
|
||||
private function addMap(Map $map) {
|
||||
//TODO: ADD Maps to database
|
||||
if (!$map) {
|
||||
return false;
|
||||
}
|
||||
$this->mapList[$map->uid] = $map;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Lukas Kremsmayr and steeffeen
|
||||
*/
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
|
||||
class settingConfigurator {
|
||||
private $maniaControl = null;
|
||||
public function __construct(ManiaControl $maniaControl){
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->maniaControl->callbacks->registerCallbackHandler(Callbacks::CB_MC_ONINIT, $this, 'onInit');
|
||||
$this->maniaControl->manialinkIdHandler->reserveManiaLinkIds(100);
|
||||
}
|
||||
|
||||
public function onInit(array $callback){
|
||||
// $this->maniaControl->manialinkUtil->
|
||||
// $this->maniaControl->chat->sendChat("test");
|
||||
}
|
||||
}
|
@ -1,7 +1,12 @@
|
||||
<?php
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Plugins\Plugin;
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
/**
|
||||
* Basic test plugin
|
||||
*
|
||||
* @author steeffeen
|
||||
*/
|
||||
class TestPlugin extends Plugin {
|
||||
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
|
Loading…
Reference in New Issue
Block a user