- removed unnecessary files
- cleaned up database class - plugin and plugin handler class - improved player and player handler classes - other cleanup and improvements
This commit is contained in:
@ -28,7 +28,7 @@ class Authentication {
|
||||
$this->mc = $mc;
|
||||
|
||||
// Load config
|
||||
$this->config = Tools::loadConfig('authentication.ManiaControl.xml');
|
||||
$this->config = Tools::loadConfig('authentication.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3,7 +3,7 @@
|
||||
namespace ManiaControl;
|
||||
|
||||
/**
|
||||
* Class for handling server callbacks
|
||||
* Class for handling server and controller callbacks
|
||||
*
|
||||
* @author steeffeen
|
||||
*/
|
||||
@ -12,14 +12,14 @@ class Callbacks {
|
||||
* Constants
|
||||
*/
|
||||
// ManiaControl callbacks
|
||||
const CB_IC_1_SECOND = 'ManiaControl.1Second';
|
||||
const CB_IC_5_SECOND = 'ManiaControl.5Second';
|
||||
const CB_IC_1_MINUTE = 'ManiaControl.1Minute';
|
||||
const CB_IC_3_MINUTE = 'ManiaControl.3Minute';
|
||||
const CB_IC_ONINIT = 'ManiaControl.OnInit';
|
||||
const CB_IC_CLIENTUPDATED = 'ManiaControl.ClientUpdated';
|
||||
const CB_IC_BEGINMAP = 'ManiaControl.BeginMap';
|
||||
const CB_IC_ENDMAP = 'ManiaControl.EndMap';
|
||||
const CB_MC_1_SECOND = 'ManiaControl.1Second';
|
||||
const CB_MC_5_SECOND = 'ManiaControl.5Second';
|
||||
const CB_MC_1_MINUTE = 'ManiaControl.1Minute';
|
||||
const CB_MC_3_MINUTE = 'ManiaControl.3Minute';
|
||||
const CB_MC_ONINIT = 'ManiaControl.OnInit';
|
||||
const CB_MC_CLIENTUPDATED = 'ManiaControl.ClientUpdated';
|
||||
const CB_MC_BEGINMAP = 'ManiaControl.BeginMap';
|
||||
const CB_MC_ENDMAP = 'ManiaControl.EndMap';
|
||||
// ManiaPlanet callbacks
|
||||
const CB_MP_SERVERSTART = 'ManiaPlanet.ServerStart';
|
||||
const CB_MP_SERVERSTOP = 'ManiaPlanet.ServerStop';
|
||||
@ -45,27 +45,24 @@ class Callbacks {
|
||||
const CB_TM_PLAYERCHECKPOINT = 'TrackMania.PlayerCheckpoint';
|
||||
const CB_TM_PLAYERFINISH = 'TrackMania.PlayerFinish';
|
||||
const CB_TM_PLAYERINCOHERENCE = 'TrackMania.PlayerIncoherence';
|
||||
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $mc = null;
|
||||
|
||||
private $maniaControl = null;
|
||||
private $callbackHandlers = array();
|
||||
|
||||
private $last1Second = -1;
|
||||
|
||||
private $last5Second = -1;
|
||||
|
||||
private $last1Minute = -1;
|
||||
|
||||
private $last3Minute = -1;
|
||||
|
||||
/**
|
||||
* Construct callbacks handler
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct($mc) {
|
||||
$this->mc = $mc;
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Init values
|
||||
$this->last1Second = time();
|
||||
@ -79,12 +76,12 @@ class Callbacks {
|
||||
*/
|
||||
public function onInit() {
|
||||
// On init callback
|
||||
$this->triggerCallback(self::CB_IC_ONINIT, array(self::CB_IC_ONINIT));
|
||||
$this->triggerCallback(self::CB_MC_ONINIT, array(self::CB_MC_ONINIT));
|
||||
|
||||
// Simulate begin map
|
||||
$map = $this->mc->server->getMap();
|
||||
$map = $this->maniaControl->server->getMap();
|
||||
if ($map) {
|
||||
$this->triggerCallback(self::CB_IC_BEGINMAP, array(self::CB_IC_BEGINMAP, array($map)));
|
||||
$this->triggerCallback(self::CB_MC_BEGINMAP, array(self::CB_MC_BEGINMAP, array($map)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,37 +94,39 @@ class Callbacks {
|
||||
$this->last1Second = time();
|
||||
|
||||
// 1 second
|
||||
$this->triggerCallback(self::CB_IC_1_SECOND, array(self::CB_IC_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_IC_5_SECOND, array(self::CB_IC_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_IC_1_MINUTE, array(self::CB_IC_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_IC_3_MINUTE, array(self::CB_IC_3_MINUTE));
|
||||
$this->triggerCallback(self::CB_MC_3_MINUTE, array(self::CB_MC_3_MINUTE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get server callbacks
|
||||
if (!$this->mc->client) return;
|
||||
$this->mc->client->resetError();
|
||||
$this->mc->client->readCB();
|
||||
$callbacks = $this->mc->client->getCBResponses();
|
||||
if (!is_array($callbacks) || $this->mc->client->isError()) {
|
||||
trigger_error("Error reading server callbacks. " . $this->mc->getClientErrorText());
|
||||
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;
|
||||
}
|
||||
|
||||
@ -139,14 +138,14 @@ class Callbacks {
|
||||
{
|
||||
// Map begin
|
||||
$this->triggerCallback($callbackName, $callback);
|
||||
$this->triggerCallback(self::CB_IC_BEGINMAP, $callback);
|
||||
$this->triggerCallback(self::CB_MC_BEGINMAP, $callback);
|
||||
break;
|
||||
}
|
||||
case self::CB_MP_ENDMAP:
|
||||
{
|
||||
// Map end
|
||||
$this->triggerCallback($callbackName, $callback);
|
||||
$this->triggerCallback(self::CB_IC_ENDMAP, $callback);
|
||||
$this->triggerCallback(self::CB_MC_ENDMAP, $callback);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -162,12 +161,14 @@ class Callbacks {
|
||||
* Trigger a specific callback
|
||||
*
|
||||
* @param string $callbackName
|
||||
* @param mixed $data
|
||||
* @param array $data
|
||||
*/
|
||||
public function triggerCallback($callbackName, $data) {
|
||||
if (!array_key_exists($callbackName, $this->callbackHandlers) || !is_array($this->callbackHandlers[$callbackName])) return;
|
||||
public function triggerCallback($callbackName, array $callback) {
|
||||
if (!array_key_exists($callbackName, $this->callbackHandlers)) {
|
||||
return;
|
||||
}
|
||||
foreach ($this->callbackHandlers[$callbackName] as $handler) {
|
||||
call_user_func(array($handler[0], $handler[1]), $data);
|
||||
call_user_func(array($handler[0], $handler[1]), $callback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +177,7 @@ class 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 . "')!");
|
||||
trigger_error("Given handler can't handle callback '{$callback}' (no method '{$method}')!");
|
||||
return;
|
||||
}
|
||||
if (!array_key_exists($callback, $this->callbackHandlers) || !is_array($this->callbackHandlers[$callback])) {
|
||||
|
@ -25,7 +25,7 @@ class Chat {
|
||||
$this->mc = $mc;
|
||||
|
||||
// Load config
|
||||
$this->config = Tools::loadConfig('chat.ManiaControl.xml');
|
||||
$this->config = Tools::loadConfig('chat.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,7 +41,8 @@ class Chat {
|
||||
return $this->mc->client->query('ChatSendServerMessage', '$z' . ($prefix ? $this->prefix : '') . $message . '$z');
|
||||
}
|
||||
else {
|
||||
return $this->mc->client->query('ChatSendServerMessageToLogin', '$z' . ($prefix ? $this->prefix : '') . $message . '$z', $login);
|
||||
return $this->mc->client->query('ChatSendServerMessageToLogin', '$z' . ($prefix ? $this->prefix : '') . $message . '$z',
|
||||
$login);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,10 @@ class Commands {
|
||||
$this->mc = $mc;
|
||||
|
||||
// Load config
|
||||
$this->config = Tools::loadConfig('commands.ManiaControl.xml');
|
||||
$this->config = Tools::loadConfig('commands.xml');
|
||||
|
||||
// Register for callbacks
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_IC_5_SECOND, $this, 'each5Seconds');
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MC_5_SECOND, $this, 'each5Seconds');
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_BILLUPDATED, $this, 'handleBillUpdated');
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERCHAT, $this, 'handleChatCallback');
|
||||
|
||||
@ -345,7 +345,7 @@ class Commands {
|
||||
$this->mc->authentication->sendNotAllowed($login);
|
||||
return;
|
||||
}
|
||||
$this->mc->quit("ManiaControl shutdown requested by '" . $login . "'");
|
||||
$this->mc->quit("ManiaControl shutdown requested by '{$login}'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,32 +11,28 @@ class Database {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const TABLE_PLAYERS = 'ic_players';
|
||||
const TABLE_MAPS = 'ic_maps';
|
||||
|
||||
const TABLE_PLAYERS = 'mc_players';
|
||||
const TABLE_MAPS = 'mc_maps';
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $mysqli = null;
|
||||
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $mc = null;
|
||||
|
||||
private $maniaControl = null;
|
||||
private $config = null;
|
||||
|
||||
private $multiQueries = '';
|
||||
|
||||
/**
|
||||
* Construct database connection
|
||||
*/
|
||||
public function __construct($mc) {
|
||||
$this->mc = $mc;
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Load config
|
||||
$this->config = Tools::loadConfig('database.ManiaControl.xml');
|
||||
$this->mc->checkConfig($this->config, array("host", "user"), 'database.ManiaControl.xml');
|
||||
$this->config = Tools::loadConfig('database.xml');
|
||||
|
||||
// Get mysql server information
|
||||
$host = $this->config->xpath('host');
|
||||
@ -58,23 +54,12 @@ class Database {
|
||||
// Open database connection
|
||||
$this->mysqli = new \mysqli($host, $user, $pass, null, $port);
|
||||
if ($this->mysqli->connect_error) {
|
||||
// Connection error
|
||||
throw new \Exception(
|
||||
"Error on connecting to mysql server. " . $this->mysqli->connect_error . " (" . $this->mysqli->connect_errno . ")");
|
||||
trigger_error($this->mysqli->connect_error, E_USER_ERROR);
|
||||
}
|
||||
|
||||
// Set charset
|
||||
$this->mysqli->set_charset("utf8");
|
||||
|
||||
// Create/Connect database
|
||||
$this->initDatabase();
|
||||
|
||||
// Init tables
|
||||
$this->initTables();
|
||||
|
||||
// Register for callbacks
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_IC_5_SECOND, $this, 'handle5Second');
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_IC_BEGINMAP, $this, 'handleBeginMap');
|
||||
$this->optimizeTables();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,6 +71,8 @@ class Database {
|
||||
|
||||
/**
|
||||
* Connect to the defined database (create it if needed)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initDatabase() {
|
||||
$dbname = $this->config->xpath('database');
|
||||
@ -94,307 +81,67 @@ class Database {
|
||||
|
||||
// Try to connect
|
||||
$result = $this->mysqli->select_db($dbname);
|
||||
if (!$result) {
|
||||
// Create database
|
||||
$query = "CREATE DATABASE `" . $this->escape($dbname) . "`;";
|
||||
$result = $this->mysqli->query($query);
|
||||
if (!$result) {
|
||||
trigger_error(
|
||||
"Couldn't create database '" . $dbname . "'. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')',
|
||||
E_USER_ERROR);
|
||||
}
|
||||
else {
|
||||
// Connect to database
|
||||
$result = $this->mysqli->select_db($dbname);
|
||||
if (!$result) {
|
||||
trigger_error(
|
||||
"Couldn't select database '" . $dbname . "'. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')',
|
||||
E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the needed tables
|
||||
*/
|
||||
private function initTables() {
|
||||
$query = "";
|
||||
|
||||
// Players table
|
||||
$query .= "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERS . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`Login` varchar(100) NOT NULL,
|
||||
`NickName` varchar(250) NOT NULL,
|
||||
`PlayerId` int(11) NOT NULL,
|
||||
`LadderRanking` int(11) NOT NULL,
|
||||
`Flags` varchar(50) NOT NULL,
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `Login` (`Login`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Store player metadata' AUTO_INCREMENT=1;";
|
||||
|
||||
// Maps table
|
||||
$query .= "CREATE TABLE IF NOT EXISTS `ic_maps` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`UId` varchar(100) NOT NULL,
|
||||
`Name` varchar(100) NOT NULL,
|
||||
`FileName` varchar(200) NOT NULL,
|
||||
`Author` varchar(150) NOT NULL,
|
||||
`Environnement` varchar(50) NOT NULL,
|
||||
`Mood` varchar(50) NOT NULL,
|
||||
`BronzeTime` int(11) NOT NULL DEFAULT '-1',
|
||||
`SilverTime` int(11) NOT NULL DEFAULT '-1',
|
||||
`GoldTime` int(11) NOT NULL DEFAULT '-1',
|
||||
`AuthorTime` int(11) NOT NULL DEFAULT '-1',
|
||||
`CopperPrice` int(11) NOT NULL DEFAULT '-1',
|
||||
`LapRace` tinyint(1) NOT NULL,
|
||||
`NbLaps` int(11) NOT NULL DEFAULT '-1',
|
||||
`NbCheckpoints` int(11) NOT NULL DEFAULT '-1',
|
||||
`MapType` varchar(100) NOT NULL,
|
||||
`MapStyle` varchar(100) NOT NULL,
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `UId` (`UId`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Store map metadata' AUTO_INCREMENT=1;";
|
||||
|
||||
// Perform queries
|
||||
if (!$this->multiQuery($query)) {
|
||||
trigger_error("Creating basic tables failed. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')', E_USER_ERROR);
|
||||
}
|
||||
|
||||
// Optimize all existing tables
|
||||
$query = "SHOW TABLES;";
|
||||
$result = $this->query($query);
|
||||
if (!$result || !is_object($result)) {
|
||||
trigger_error("Couldn't select tables. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')');
|
||||
}
|
||||
else {
|
||||
$query = "OPTIMIZE TABLE ";
|
||||
$count = $result->num_rows;
|
||||
$index = 0;
|
||||
while ($row = $result->fetch_row()) {
|
||||
$query .= "`" . $row[0] . "`";
|
||||
if ($index < $count - 1) $query .= ", ";
|
||||
$index++;
|
||||
}
|
||||
$query .= ";";
|
||||
if (!$this->query($query)) {
|
||||
trigger_error("Couldn't optimize tables. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for performing a simple query
|
||||
*
|
||||
* @param string $query
|
||||
* @return mixed query result
|
||||
*/
|
||||
public function query($query) {
|
||||
if (!is_string($query)) return false;
|
||||
if (strlen($query) <= 0) return true;
|
||||
return $this->mysqli->query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform multi query
|
||||
*
|
||||
* @param
|
||||
* string multi_query
|
||||
* @return bool whether no error occured during executing the multi query
|
||||
*/
|
||||
public function multiQuery($query) {
|
||||
if (!is_string($query)) return false;
|
||||
if (strlen($query) <= 0) return true;
|
||||
$noError = true;
|
||||
$this->mysqli->multi_query($query);
|
||||
if ($this->mysqli->error) {
|
||||
trigger_error("Executing multi query failed. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')');
|
||||
$noError = false;
|
||||
}
|
||||
while ($this->mysqli->more_results() && $this->mysqli->next_result()) {
|
||||
if ($this->mysqli->error) {
|
||||
trigger_error("Executing multi query failed. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')');
|
||||
$noError = false;
|
||||
}
|
||||
}
|
||||
return $noError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 5Second callback
|
||||
*/
|
||||
public function handle5Second($callback = null) {
|
||||
// Save current players in database
|
||||
$players = $this->mc->server->getPlayers();
|
||||
if ($players) {
|
||||
$query = "";
|
||||
foreach ($players as $player) {
|
||||
if (!Tools::isPlayer($player)) continue;
|
||||
$query .= $this->composeInsertPlayer($player);
|
||||
}
|
||||
$this->multiQuery($query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle BeginMap callback
|
||||
*/
|
||||
public function handleBeginMap($callback) {
|
||||
$map = $callback[1][0];
|
||||
$query = $this->composeInsertMap($map);
|
||||
$result = $this->query($query);
|
||||
if ($this->mysqli->error) {
|
||||
trigger_error("Couldn't save map. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player index for the given login
|
||||
*
|
||||
* @param string $login
|
||||
* @return int null
|
||||
*/
|
||||
public function getPlayerIndex($login) {
|
||||
$query = "SELECT `index` FROM `" . self::TABLE_PLAYERS . "` WHERE `Login` = '" . $this->escape($login) . "';";
|
||||
$result = $this->query($query);
|
||||
$result = $result->fetch_assoc();
|
||||
if ($result) {
|
||||
return $result['index'];
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map index for the given UId
|
||||
*
|
||||
* @param string $uid
|
||||
* @return int null
|
||||
*/
|
||||
public function getMapIndex($uid) {
|
||||
$query = "SELECT `index` FROM `" . self::TABLE_MAPS . "` WHERE `UId` = '" . $this->escape($uid) . "';";
|
||||
$result = $this->query($query);
|
||||
$result = $result->fetch_assoc();
|
||||
if ($result) {
|
||||
return $result['index'];
|
||||
|
||||
// Create database
|
||||
$databaseQuery = "CREATE DATABASE ?;";
|
||||
$databaseStatement = $this->mysqli->prepare($databaseQuery);
|
||||
if ($this->mysqli->error) {
|
||||
trigger_error($this->mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a query string for inserting the given player
|
||||
*
|
||||
* @param array $player
|
||||
*/
|
||||
private function composeInsertPlayer($player) {
|
||||
if (!Tools::isPlayer($player)) return "";
|
||||
return "INSERT INTO `" . self::TABLE_PLAYERS . "` (
|
||||
`Login`,
|
||||
`NickName`,
|
||||
`PlayerId`,
|
||||
`LadderRanking`,
|
||||
`Flags`
|
||||
) VALUES (
|
||||
'" . $this->escape($player['Login']) . "',
|
||||
'" . $this->escape($player['NickName']) . "',
|
||||
" . $player['PlayerId'] . ",
|
||||
" . $player['LadderRanking'] . ",
|
||||
'" . $this->escape($player['Flags']) . "'
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`NickName` = VALUES(`NickName`),
|
||||
`PlayerId` = VALUES(`PlayerId`),
|
||||
`LadderRanking` = VALUES(`LadderRanking`),
|
||||
`Flags` = VALUES(`Flags`);";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a query string for inserting the given map
|
||||
*
|
||||
* @param array $map
|
||||
*/
|
||||
private function composeInsertMap($map) {
|
||||
if (!$map) return "";
|
||||
return "INSERT INTO `" . self::TABLE_MAPS . "` (
|
||||
`UId`,
|
||||
`Name`,
|
||||
`FileName`,
|
||||
`Author`,
|
||||
`Environnement`,
|
||||
`Mood`,
|
||||
`BronzeTime`,
|
||||
`SilverTime`,
|
||||
`GoldTime`,
|
||||
`AuthorTime`,
|
||||
`CopperPrice`,
|
||||
`LapRace`,
|
||||
`NbLaps`,
|
||||
`NbCheckpoints`,
|
||||
`MapType`,
|
||||
`MapStyle`
|
||||
) VALUES (
|
||||
'" . $this->escape($map['UId']) . "',
|
||||
'" . $this->escape($map['Name']) . "',
|
||||
'" . $this->escape($map['FileName']) . "',
|
||||
'" . $this->escape($map['Author']) . "',
|
||||
'" . $this->escape($map['Environnement']) . "',
|
||||
'" . $this->escape($map['Mood']) . "',
|
||||
" . $map['BronzeTime'] . ",
|
||||
" . $map['SilverTime'] . ",
|
||||
" . $map['GoldTime'] . ",
|
||||
" . $map['AuthorTime'] . ",
|
||||
" . $map['CopperPrice'] . ",
|
||||
" . Tools::boolToInt($map['LapRace']) . ",
|
||||
" . $map['NbLaps'] . ",
|
||||
" . $map['NbCheckpoints'] . ",
|
||||
'" . $this->escape($map['MapType']) . "',
|
||||
'" . $this->escape($map['MapStyle']) . "'
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`Name` = VALUES(`Name`),
|
||||
`FileName` = VALUES(`FileName`),
|
||||
`Author` = VALUES(`Author`),
|
||||
`Environnement` = VALUES(`Environnement`),
|
||||
`Mood` = VALUES(`Mood`),
|
||||
`BronzeTime` = VALUES(`BronzeTime`),
|
||||
`SilverTime` = VALUES(`SilverTime`),
|
||||
`GoldTime` = VALUES(`GoldTime`),
|
||||
`AuthorTime` = VALUES(`AuthorTime`),
|
||||
`CopperPrice` = VALUES(`CopperPrice`),
|
||||
`LapRace` = VALUES(`LapRace`),
|
||||
`NbLaps` = VALUES(`NbLaps`),
|
||||
`NbCheckpoints` = VALUES(`NbCheckpoints`),
|
||||
`MapType` = VALUES(`MapType`),
|
||||
`MapStyle` = VALUES(`MapStyle`);";
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all information about the player with the given login
|
||||
*/
|
||||
public function getPlayer($login) {
|
||||
if (!$login) return null;
|
||||
$query = "SELECT * FROM `" . self::TABLE_PLAYERS . "` WHERE `Login` = '" . $this->escape($login) . "';";
|
||||
$result = $this->mysqli->query($query);
|
||||
if ($this->mysqli->error || !$result) {
|
||||
trigger_error(
|
||||
"Couldn't select player with login '" . $login . "'. " . $this->mysqli->error . ' (' . $this->mysqli->errno . ')');
|
||||
return null;
|
||||
$databaseStatement->bind_param('s', $dbname);
|
||||
$databaseStatement->execute();
|
||||
if ($databaseStatement->error) {
|
||||
trigger_error($databaseStatement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
while ($player = $result->fetch_assoc()) {
|
||||
return $player;
|
||||
$databaseStatement->close();
|
||||
|
||||
// Connect to new database
|
||||
$this->mysqli->select_db($dbname);
|
||||
if ($this->mysqli->error) {
|
||||
trigger_error("Couldn't select database '{$dbname}'. " . $this->mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimize all existing tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function optimizeTables() {
|
||||
$showQuery = "SHOW TABLES;";
|
||||
$result = $this->mysqli->query($showQuery);
|
||||
if ($this->mysqli->error) {
|
||||
trigger_error($this->mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$count = $result->num_rows;
|
||||
if ($count <= 0) {
|
||||
return true;
|
||||
}
|
||||
$optimizeQuery = "OPTIMIZE TABLE ";
|
||||
$index = 0;
|
||||
while ($row = $result->fetch_row()) {
|
||||
$tableName = $row[0];
|
||||
$optimizeQuery .= "`{$tableName}`";
|
||||
if ($index < $count - 1) {
|
||||
$optimizeQuery .= ", ";
|
||||
}
|
||||
return null;
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes the given string for a mysql query
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public function escape($string) {
|
||||
return $this->mysqli->escape_string($string);
|
||||
$optimizeQuery .= ";";
|
||||
$this->mysqli->query($optimizeQuery);
|
||||
if ($this->mysqli->error) {
|
||||
trigger_error($this->mysqli->error);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,9 @@ require_once __DIR__ . '/chat.php';
|
||||
require_once __DIR__ . '/commands.php';
|
||||
require_once __DIR__ . '/database.php';
|
||||
require_once __DIR__ . '/server.php';
|
||||
require_once __DIR__ . '/stats.php';
|
||||
require_once __DIR__ . '/tools.php';
|
||||
require_once __DIR__ . '/pluginHandler.php';
|
||||
require_once __DIR__ . '/plugin.php';
|
||||
require_once __DIR__ . '/playerHandler.php';
|
||||
require_once __DIR__ . '/player.php';
|
||||
require_once __DIR__ . '/manialinkIdHandler.php';
|
||||
list($endiantest) = array_values(unpack('L1L', pack('V', 1)));
|
||||
if ($endiantest == 1) {
|
||||
@ -38,90 +35,40 @@ class ManiaControl {
|
||||
const VERSION = '0.1';
|
||||
const API_VERSION = '2013-04-16';
|
||||
const DATE = 'd-m-y h:i:sa T';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $version = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $authentication = null;
|
||||
|
||||
public $callbacks = null;
|
||||
|
||||
public $client = null;
|
||||
|
||||
public $chat = null;
|
||||
|
||||
public $config = null;
|
||||
|
||||
public $commands = null;
|
||||
|
||||
public $database = null;
|
||||
|
||||
public $debug = false;
|
||||
|
||||
public $server = null;
|
||||
|
||||
public $startTime = -1;
|
||||
|
||||
public $stats = null;
|
||||
|
||||
public $manialinkIdHandler = null;
|
||||
public $pluginHandler = null;
|
||||
|
||||
public $manialinkIdHandler = null;
|
||||
public $pluginHandler = null;
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
//private $plugins = array();
|
||||
|
||||
private $shutdownRequested = false;
|
||||
private $config = null;
|
||||
|
||||
/**
|
||||
* Construct ManiaControl
|
||||
*/
|
||||
public function __construct() {
|
||||
// Load core
|
||||
$this->config = Tools::loadConfig('core.ManiaControl.xml');
|
||||
$this->startTime = time();
|
||||
|
||||
// Load chat tool
|
||||
$this->config = Tools::loadConfig('core.xml');
|
||||
$this->chat = new Chat($this);
|
||||
|
||||
// Load callbacks handler
|
||||
$this->callbacks = new Callbacks($this);
|
||||
|
||||
// Load database
|
||||
$this->database = new Database($this);
|
||||
|
||||
// Load server
|
||||
$this->server = new Server($this);
|
||||
|
||||
// Load authentication
|
||||
$this->authentication = new Authentication($this);
|
||||
|
||||
// Load playerHandler
|
||||
$this->playerHandler = new PlayerHandler($this);
|
||||
|
||||
// Load manialinkidHandler
|
||||
$this->manialinkIdHandler = new ManialinkIdHandler();
|
||||
|
||||
// Load pluginHandler
|
||||
$this->pluginHandler = new PluginHandler($this);
|
||||
|
||||
// Load commands handler
|
||||
$this->playerHandler = new PlayerHandler($this);
|
||||
$this->manialinkIdHandler = new ManialinkIdHandler();
|
||||
$this->commands = new Commands($this);
|
||||
|
||||
// Load stats manager
|
||||
$this->stats = new Stats($this);
|
||||
|
||||
// Register for core callbacks
|
||||
$this->callbacks->registerCallbackHandler(Callbacks::CB_MP_ENDMAP, $this, 'handleEndMap');
|
||||
|
||||
// Set ManiaControl version
|
||||
$this->version = self::VERSION;
|
||||
$this->pluginHandler = new PluginHandler($this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,8 +88,6 @@ class ManiaControl {
|
||||
* Quit ManiaControl and log the given message
|
||||
*/
|
||||
public function quit($message = false) {
|
||||
if ($this->shutdownRequested) return;
|
||||
|
||||
if ($this->client) {
|
||||
// Announce quit
|
||||
$this->chat->sendInformation('ManiaControl shutting down.');
|
||||
@ -157,7 +102,9 @@ class ManiaControl {
|
||||
}
|
||||
|
||||
// Shutdown
|
||||
if ($this->client) $this->client->Terminate();
|
||||
if ($this->client) {
|
||||
$this->client->Terminate();
|
||||
}
|
||||
|
||||
error_log("Quitting ManiaControl!");
|
||||
exit();
|
||||
@ -166,14 +113,12 @@ class ManiaControl {
|
||||
/**
|
||||
* Run ManiaControl
|
||||
*/
|
||||
public function run($debug = false) {
|
||||
public function run() {
|
||||
error_log('Starting ManiaControl v' . self::VERSION . '!');
|
||||
$this->debug = (bool) $debug;
|
||||
|
||||
// Load plugins
|
||||
//$this->loadPlugins();
|
||||
$this->pluginHandler->loadPlugins();
|
||||
|
||||
|
||||
// Connect to server
|
||||
$this->connect();
|
||||
|
||||
@ -181,14 +126,8 @@ class ManiaControl {
|
||||
error_log("Loading completed!");
|
||||
|
||||
// Announce ManiaControl
|
||||
if (!$this->chat->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!')) {
|
||||
trigger_error("Couldn't announce ManiaControl. " . $this->getClientErrorText());
|
||||
}
|
||||
|
||||
//get PlayerList
|
||||
$this->client->query('GetPlayerList', 300, 0, 2);
|
||||
$this->playerHandler->addPlayerList($this->client->getResponse());
|
||||
|
||||
$this->chat->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
|
||||
|
||||
// OnInit
|
||||
$this->callbacks->onInit();
|
||||
|
||||
@ -202,14 +141,6 @@ class ManiaControl {
|
||||
// Handle server callbacks
|
||||
$this->callbacks->handleCallbacks();
|
||||
|
||||
// Loop plugins
|
||||
/*foreach ($this->plugins as $plugin) {
|
||||
if (!method_exists($plugin, 'loop')) {
|
||||
continue;
|
||||
}
|
||||
$plugin->loop();
|
||||
}*/
|
||||
|
||||
// Yield for next tick
|
||||
$loopEnd = microtime(true);
|
||||
$sleepTime = 300000 - $loopEnd + $loopStart;
|
||||
@ -243,13 +174,11 @@ class ManiaControl {
|
||||
if (!$timeout) trigger_error("Invalid core configuration (timeout).", E_USER_ERROR);
|
||||
$timeout = (int) $timeout[0];
|
||||
|
||||
error_log("Connecting to server at " . $host . ":" . $port . "...");
|
||||
error_log("Connecting to server at {$host}:{$port}...");
|
||||
|
||||
// Connect
|
||||
if (!$this->client->InitWithIp($host, $port, $timeout)) {
|
||||
trigger_error(
|
||||
"Couldn't connect to server! " . $this->client->getErrorMessage() . "(" . $this->client->getErrorCode() . ")",
|
||||
E_USER_ERROR);
|
||||
trigger_error("Couldn't connect to server! " . $this->getClientErrorText(), E_USER_ERROR);
|
||||
}
|
||||
|
||||
$login = $this->server->config->xpath('login');
|
||||
@ -261,15 +190,12 @@ class ManiaControl {
|
||||
|
||||
// Authenticate
|
||||
if (!$this->client->query('Authenticate', $login, $pass)) {
|
||||
trigger_error(
|
||||
"Couldn't authenticate on server with user '" . $login . "'! " . $this->client->getErrorMessage() . "(" .
|
||||
$this->client->getErrorCode() . ")", E_USER_ERROR);
|
||||
trigger_error("Couldn't authenticate on server with user '{$login}'! " . $this->getClientErrorText(), E_USER_ERROR);
|
||||
}
|
||||
|
||||
// Enable callback system
|
||||
if (!$this->client->query('EnableCallbacks', true)) {
|
||||
trigger_error("Couldn't enable callbacks! " . $this->client->getErrorMessage() . "(" . $this->client->getErrorCode() . ")",
|
||||
E_USER_ERROR);
|
||||
trigger_error("Couldn't enable callbacks! " . $this->getClientErrorText(), E_USER_ERROR);
|
||||
}
|
||||
|
||||
// Wait for server to be ready
|
||||
@ -280,18 +206,12 @@ class ManiaControl {
|
||||
// Set api version
|
||||
if (!$this->client->query('SetApiVersion', self::API_VERSION)) {
|
||||
trigger_error(
|
||||
"Couldn't set API version '" . self::API_VERSION . "'! This might cause problems. " .
|
||||
$this->getClientErrorText());
|
||||
"Couldn't set API version '" . self::API_VERSION . "'! This might cause problems. " . $this->getClientErrorText());
|
||||
}
|
||||
|
||||
// Connect finished
|
||||
error_log("Server connection succesfully established!");
|
||||
|
||||
// Enable service announces
|
||||
if (!$this->client->query("DisableServiceAnnounces", false)) {
|
||||
trigger_error("Couldn't enable service announces. " . $this->getClientErrorText());
|
||||
}
|
||||
|
||||
// Enable script callbacks if needed
|
||||
if ($this->server->getGameMode() === 0) {
|
||||
if (!$this->client->query('GetModeScriptSettings')) {
|
||||
@ -302,8 +222,7 @@ class ManiaControl {
|
||||
if (array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
||||
$scriptSettings['S_UseScriptCallbacks'] = true;
|
||||
if (!$this->client->query('SetModeScriptSettings', $scriptSettings)) {
|
||||
trigger_error(
|
||||
"Couldn't set mode script settings to enable script callbacks. " . $this->getClientErrorText());
|
||||
trigger_error("Couldn't set mode script settings to enable script callbacks. " . $this->getClientErrorText());
|
||||
}
|
||||
else {
|
||||
error_log("Script callbacks successfully enabled.");
|
||||
@ -312,84 +231,6 @@ class ManiaControl {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load ManiaControl plugins
|
||||
*/
|
||||
//private function loadPlugins() {
|
||||
/* $pluginsConfig = Tools::loadConfig('plugins.ManiaControl.xml');
|
||||
if (!$pluginsConfig || !isset($pluginsConfig->plugin)) {
|
||||
trigger_error('Invalid plugins config.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Load plugin classes
|
||||
$classes = get_declared_classes();
|
||||
foreach ($pluginsConfig->xpath('plugin') as $plugin) {
|
||||
$fileName = ManiaControlDir . '/plugins/' . $plugin;
|
||||
if (!file_exists($fileName)) {
|
||||
trigger_error("Couldn't load plugin '" . $plugin . "'! File doesn't exist. (/plugins/" . $plugin . ")");
|
||||
}
|
||||
else {
|
||||
require_once $fileName;
|
||||
error_log("Loading plugin: " . $plugin);
|
||||
}
|
||||
}
|
||||
$plugins = array_diff(get_declared_classes(), $classes);
|
||||
|
||||
// Create plugins
|
||||
foreach ($plugins as $plugin) {
|
||||
$nameIndex = stripos($plugin, 'plugin');
|
||||
if ($nameIndex === false) continue;
|
||||
array_push($this->plugins, new $plugin($this));
|
||||
}*/
|
||||
//}
|
||||
|
||||
/**
|
||||
* Handle EndMap callback
|
||||
*/
|
||||
public function handleEndMap($callback) {
|
||||
// Autosave match settings
|
||||
$autosaveMatchsettings = $this->config->xpath('autosave_matchsettings');
|
||||
if ($autosaveMatchsettings) {
|
||||
$autosaveMatchsettings = (string) $autosaveMatchsettings[0];
|
||||
if ($autosaveMatchsettings) {
|
||||
if (!$this->client->query('SaveMatchSettings', 'MatchSettings/' . $autosaveMatchsettings)) {
|
||||
trigger_error("Couldn't autosave match settings. " . $this->getClientErrorText());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check config settings
|
||||
*/
|
||||
public function checkConfig($config, $settings, $name = 'Config XML') {
|
||||
if (!is_array($settings)) $settings = array($settings);
|
||||
foreach ($settings as $setting) {
|
||||
$settingTags = $config->xpath('//' . $setting);
|
||||
if (empty($settingTags)) {
|
||||
trigger_error("Missing property '" . $setting . "' in config '" . $name . "'!", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $version
|
||||
*/
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,111 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Lukas
|
||||
* Date: 09.11.13
|
||||
* Time: 19:32
|
||||
*/
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
|
||||
/**
|
||||
* Class representing players
|
||||
*
|
||||
* @author Kremsy & Steff
|
||||
*/
|
||||
class Player {
|
||||
/**
|
||||
* public properties
|
||||
*/
|
||||
public $id; //Internal Id from ManiaControl
|
||||
public $pid; //Id from dedicated Server
|
||||
public $login;
|
||||
public $nickname;
|
||||
public $teamname;
|
||||
public $ip;
|
||||
public $client;
|
||||
public $ipport;
|
||||
public $zone;
|
||||
public $continent;
|
||||
public $nation;
|
||||
//public $prevstatus;
|
||||
public $isSpectator;
|
||||
public $isOfficial;
|
||||
public $language;
|
||||
public $avatar;
|
||||
public $teamid;
|
||||
public $unlocked;
|
||||
public $ladderrank;
|
||||
public $ladderscore;
|
||||
public $created;
|
||||
|
||||
public $rightLevel;
|
||||
|
||||
|
||||
//TODO: usefull construct player without rpc info?
|
||||
//TODO: isBot properti
|
||||
//TODO: add all attributes like, allies, clublink ... just make vardump on rpc infos
|
||||
//TODO: READ ADDITIONAL INFOS FROM DATABASE
|
||||
public function __construct($rpc_infos = null){
|
||||
|
||||
if ($rpc_infos) {
|
||||
$this->login = $rpc_infos['Login'];
|
||||
$this->nickname = $rpc_infos['NickName'];
|
||||
$this->pid = $rpc_infos['PlayerId'];
|
||||
$this->teamid = $rpc_infos['TeamId'];
|
||||
$this->ipport = $rpc_infos['IPAddress'];
|
||||
$this->ip = preg_replace('/:\d+/', '', $rpc_infos['IPAddress']); // strip port
|
||||
//$this->prevstatus = false;
|
||||
$this->isSpectator = $rpc_infos['IsSpectator'];
|
||||
$this->isOfficial = $rpc_infos['IsInOfficialMode'];
|
||||
$this->teamname = $rpc_infos['LadderStats']['TeamName'];
|
||||
$this->zone = substr($rpc_infos['Path'], 6); // strip 'World|'
|
||||
$zones = explode('|', $rpc_infos['Path']);
|
||||
if (isset($zones[1])) {
|
||||
switch ($zones[1]) {
|
||||
case 'Europe':
|
||||
case 'Africa':
|
||||
case 'Asia':
|
||||
case 'Middle East':
|
||||
case 'North America':
|
||||
case 'South America':
|
||||
case 'Oceania':
|
||||
$this->continent = $zones[1];
|
||||
$this->nation = $zones[2];
|
||||
break;
|
||||
default:
|
||||
$this->continent = '';
|
||||
$this->nation = $zones[1];
|
||||
}
|
||||
} else {
|
||||
$this->continent = '';
|
||||
$this->nation = '';
|
||||
}
|
||||
$this->ladderrank = $rpc_infos['LadderStats']['PlayerRankings'][0]['Ranking'];
|
||||
$this->ladderscore = round($rpc_infos['LadderStats']['PlayerRankings'][0]['Score'], 2);
|
||||
$this->client = $rpc_infos['ClientVersion'];
|
||||
$this->language = $rpc_infos['Language'];
|
||||
$this->avatar = $rpc_infos['Avatar']['FileName'];
|
||||
$this->created = time();
|
||||
} else {
|
||||
// set defaults
|
||||
$this->pid = 0;
|
||||
$this->login = '';
|
||||
$this->nickname = '';
|
||||
$this->ipport = '';
|
||||
$this->ip = '';
|
||||
//$this->prevstatus = false;
|
||||
$this->isSpectator = false;
|
||||
$this->isOfficial = false;
|
||||
$this->teamname = '';
|
||||
$this->zone = '';
|
||||
$this->continent = '';
|
||||
$this->nation = '';
|
||||
$this->ladderrank = 0;
|
||||
$this->ladderscore = 0;
|
||||
$this->created = 0;
|
||||
}
|
||||
|
||||
|
||||
//rightlevels, 0 = user, 1 = operator, 2 = admin, 3 = superadmin, 4 = headadmin (from config)
|
||||
$this->rightLevel = 0;
|
||||
}
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $index = -1;
|
||||
public $pid = -1;
|
||||
public $login = '';
|
||||
public $nickname = '';
|
||||
public $isFakePlayer = false;
|
||||
public $teamName = '';
|
||||
public $ip = '';
|
||||
public $ipFull = '';
|
||||
public $clientVersion = '';
|
||||
public $zone = '';
|
||||
public $continent = '';
|
||||
public $nation = '';
|
||||
public $isSpectator = false;
|
||||
public $isOfficial = false;
|
||||
public $language = '';
|
||||
public $avatar = '';
|
||||
public $teamId; // TODO: default value
|
||||
public $unlocked; // TODO: default value
|
||||
public $ladderRank = -1;
|
||||
public $ladderScore = -1;
|
||||
public $created = -1;
|
||||
public $rightLevel = 0;
|
||||
|
||||
// TODO: usefull construct player without rpc info?
|
||||
// TODO: add all attributes like, allies, clublink ... just make vardump on rpc infos
|
||||
// TODO: READ ADDITIONAL INFOS FROM DATABASE
|
||||
/**
|
||||
* Construct a player
|
||||
*
|
||||
* @param array $rpcInfos
|
||||
*/
|
||||
public function __construct($rpcInfos) {
|
||||
$this->created = time();
|
||||
if (!$rpcInfos) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->login = $rpcInfos['Login'];
|
||||
$this->isFakePlayer = (stripos($this->login, '*') !== false);
|
||||
$this->nickname = $rpcInfos['NickName'];
|
||||
$this->pid = $rpcInfos['PlayerId'];
|
||||
$this->teamId = $rpcInfos['TeamId'];
|
||||
$this->ipFull = $rpcInfos['IPAddress'];
|
||||
$this->ip = preg_replace('/:\d+/', '', $this->ipFull);
|
||||
$this->isSpectator = $rpcInfos['IsSpectator'];
|
||||
$this->isOfficial = $rpcInfos['IsInOfficialMode'];
|
||||
$this->teamName = $rpcInfos['LadderStats']['TeamName'];
|
||||
$this->zone = substr($rpcInfos['Path'], 6);
|
||||
$zones = explode('|', $rpcInfos['Path']);
|
||||
if (isset($zones[1])) {
|
||||
if (isset($zones[2])) {
|
||||
$this->continent = $zones[1];
|
||||
$this->nation = $zones[2];
|
||||
}
|
||||
else {
|
||||
$this->nation = $zones[1];
|
||||
}
|
||||
}
|
||||
$this->ladderRank = $rpcInfos['LadderStats']['PlayerRankings'][0]['Ranking'];
|
||||
$this->ladderScore = round($rpcInfos['LadderStats']['PlayerRankings'][0]['Score'], 2);
|
||||
$this->clientVersion = $rpcInfos['ClientVersion'];
|
||||
$this->language = $rpcInfos['Language'];
|
||||
$this->avatar = $rpcInfos['Avatar']['FileName'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,113 +1,156 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Lukas
|
||||
* Date: 09.11.13
|
||||
* Time: 19:44
|
||||
*/
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
require_once __DIR__ . '/player.php';
|
||||
|
||||
/**
|
||||
* Class playerHandler
|
||||
* Class managing players
|
||||
*
|
||||
* @package ManiaControl
|
||||
*/
|
||||
class playerHandler {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const TABLE_PLAYERS = 'mc_players';
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $rightLevels = array(0 => 'Player', 1 => 'Operator', 2 => 'Admin', 3 => 'MasterAdmin', 4 => 'Owner');
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $playerList = array();
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $playerList;
|
||||
private $mc;
|
||||
/**
|
||||
* Construct player handler
|
||||
*
|
||||
* @param 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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Public properties
|
||||
*/
|
||||
public $rightLevels = array(0 => 'Player', 1 => 'Operator', 2 => 'Admin', 3 => 'MasterAdmin', 4 => 'MasterAdmin');
|
||||
/**
|
||||
* Initialize all necessary tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$playerTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLAYERS . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`pid` int(11) NOT NULL DEFAULT '-1',
|
||||
`login` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`ipFull` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`clientVersion` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`zone` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`language` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`avatar` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`),
|
||||
UNIQUE KEY `login` (`login`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Player data' AUTO_INCREMENT=1;";
|
||||
$playerTableStatement = $mysqli->prepare($playerTableQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$playerTableStatement->execute();
|
||||
if ($playerTableStatement->error) {
|
||||
trigger_error($playerTableStatement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$playerTableStatement->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __construct(ManiaControl $mc){
|
||||
$this->mc = $mc;
|
||||
$this->playerList = array();
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERCONNECT, $this, 'playerConnect');
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MP_PLAYERDISCONNECT, $this, 'playerDisconnect');
|
||||
}
|
||||
/**
|
||||
* Handle OnInit callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function onInit(array $callback) {
|
||||
$this->maniaControl->client->query('GetPlayerList', 300, 0, 2);
|
||||
$playerList = $this->maniaControl->client->getResponse();
|
||||
foreach ($playerList as $player) {
|
||||
$callback = array(Callbacks::CB_MP_PLAYERCONNECT, array($player['Login']));
|
||||
$this->playerConnect($callback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle playerConnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerConnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
$this->maniaControl->client->query('GetDetailedPlayerInfo', $login);
|
||||
$playerInfo = $this->maniaControl->client->getResponse();
|
||||
$player = new Player($playerInfo);
|
||||
$this->addPlayer($player);
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes a Whole PlayerList
|
||||
* @param $players
|
||||
*/
|
||||
public function addPlayerList($players){
|
||||
foreach($players as $player){
|
||||
$this->playerConnect(array($player['Login'], ''));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handles a playerConnect
|
||||
* @param $player
|
||||
*/
|
||||
public function playerConnect($player){
|
||||
//TODO: Welcome Message?, on mc restart not all players listed, no relay support yet
|
||||
//TODO: Add Rights
|
||||
//TODO: Database
|
||||
$this->mc->client->query('GetDetailedPlayerInfo', $player[0]);
|
||||
$this->addPlayer(new Player($this->mc->client->getResponse()));
|
||||
$player = $this->playerList[$player[0]];
|
||||
if($player->pid != 0){ //Player 0 = server
|
||||
$string = array(0 => 'New Player', 1 => 'Operator', 2 => 'Admin', 3 => 'MasterAdmin', 4 => 'MasterAdmin');
|
||||
$this->mc->chat->sendChat('$ff0'.$string[$player->rightLevel].': '. $player->nickname . '$z $ff0Nation:$fff ' . $player->nation . ' $ff0Ladder: $fff' . $player->ladderrank);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Handle playerDisconnect callback
|
||||
*
|
||||
* @param array $callback
|
||||
*/
|
||||
public function playerDisconnect(array $callback) {
|
||||
$login = $callback[1][0];
|
||||
$player = $this->removePlayer($login);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a playerDisconnect
|
||||
* @param $player
|
||||
*/
|
||||
public function playerDisconnect($player){
|
||||
$player = $this->removePlayer($player[0]);
|
||||
$played = TOOLS::formatTime(time() - $player->created);
|
||||
$this->mc->chat->sendChat($player->nickname . '$z $ff0has left the game. Played:$fff ' . $played);
|
||||
}
|
||||
/**
|
||||
* Get a Player from the PlayerList
|
||||
*
|
||||
* @param string $login
|
||||
* @return Player
|
||||
*/
|
||||
public function getPlayer($login) {
|
||||
if (!isset($this->playerList[$login])) {
|
||||
return null;
|
||||
}
|
||||
return $this->playerList[$login];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the PlayerList
|
||||
*
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
private function addPlayer(Player $player) {
|
||||
if (!$player) {
|
||||
return false;
|
||||
}
|
||||
$this->playerList[$player->login] = $player;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Player from the Playerlist
|
||||
* @param $login
|
||||
* @return null
|
||||
*/
|
||||
public function getPlayer($login){
|
||||
if (isset($this->playerList[$login]))
|
||||
return $this->playerList[$login];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a player to the PlayerList
|
||||
* @param Player $player
|
||||
* @return bool
|
||||
*/
|
||||
private function addPlayer(Player $player){
|
||||
if($player != null){
|
||||
$this->playerList[$player->login] = $player;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes a Player from the PlayerList
|
||||
* @param $login
|
||||
* @return Player $player
|
||||
*/
|
||||
private function removePlayer($login){
|
||||
if(isset($this->playerList[$login])){
|
||||
$player = $this->playerList[$login];
|
||||
unset($this->playerList[$login]);
|
||||
} else {
|
||||
$player = null;
|
||||
}
|
||||
return $player;
|
||||
}
|
||||
/**
|
||||
* Remove a Player from the PlayerList
|
||||
*
|
||||
* @param string $login
|
||||
* @return Player $player
|
||||
*/
|
||||
private function removePlayer($login) {
|
||||
if (!isset($this->playerList[$login])) {
|
||||
return null;
|
||||
}
|
||||
$player = $this->playerList[$login];
|
||||
unset($this->playerList[$login]);
|
||||
return $player;
|
||||
}
|
||||
}
|
@ -3,152 +3,55 @@
|
||||
namespace ManiaControl;
|
||||
|
||||
/**
|
||||
* Class plugin parent class for all plugins
|
||||
* Plugin parent class
|
||||
*
|
||||
* @author Lukas Kremsmayr and steeffeen
|
||||
*/
|
||||
|
||||
|
||||
class Plugin {
|
||||
|
||||
abstract class Plugin {
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $mc;
|
||||
private $version;
|
||||
private $author;
|
||||
private $updateUrl;
|
||||
private $name;
|
||||
private $description;
|
||||
private $active;
|
||||
|
||||
public function __construct($mc, $name, $version = 0, $author = '', $description = '', $updateUrl = ''){
|
||||
$this->mc = $mc;
|
||||
$this->name = $name;
|
||||
$this->version = $version;
|
||||
$this->author = $author;
|
||||
$this->description = $description;
|
||||
$this->updateUrl = $updateUrl;
|
||||
|
||||
$this->mc->pluginHandler->registerPlugin($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserves manialinks on the ManialinkIdHandler
|
||||
*
|
||||
* @param int $count
|
||||
* @return array with manialink Ids
|
||||
* Private properties
|
||||
*/
|
||||
public function reserveManialinkIds($count){
|
||||
return $this->mc->manialinkIdHandler->reserveManialikIds($count);
|
||||
}
|
||||
protected $maniaControl;
|
||||
protected $name;
|
||||
protected $version;
|
||||
protected $author;
|
||||
protected $description;
|
||||
|
||||
public function checkUpdate(){
|
||||
|
||||
}
|
||||
/**
|
||||
* Create plugin instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public abstract function __construct(ManiaControl $maniaControl);
|
||||
|
||||
/**
|
||||
* Enables the Plugin
|
||||
*/
|
||||
public function enablePlugin()
|
||||
{
|
||||
$this->active = true;
|
||||
}
|
||||
/**
|
||||
* Get plugin author
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public abstract function getAuthor();
|
||||
|
||||
/**
|
||||
* Disable the Plugin
|
||||
*/
|
||||
public function disablePlugin()
|
||||
{
|
||||
$this->active = false;
|
||||
}
|
||||
/**
|
||||
* Get plugin version
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public abstract function getVersion();
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function isActive()
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
/**
|
||||
* Get plugin name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public abstract function getName();
|
||||
|
||||
/**
|
||||
* @param mixed $author
|
||||
*/
|
||||
public function setAuthor($author)
|
||||
{
|
||||
$this->author = $author;
|
||||
}
|
||||
/**
|
||||
* Get plugin description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public abstract function getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAuthor()
|
||||
{
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $updateUrl
|
||||
*/
|
||||
public function setUpdateUrl($updateUrl)
|
||||
{
|
||||
$this->updateUrl = $updateUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUpdateUrl()
|
||||
{
|
||||
return $this->updateUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $version
|
||||
*/
|
||||
public function setVersion($version)
|
||||
{
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getVersion()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
/**
|
||||
* @param mixed $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $description
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
@ -2,32 +2,163 @@
|
||||
|
||||
namespace ManiaControl;
|
||||
|
||||
require_once __DIR__ . '/plugin.php';
|
||||
|
||||
/**
|
||||
* Class handles plugins
|
||||
* Class handling plugins
|
||||
*
|
||||
* @author Lukas Kremsmayr and steeffeen
|
||||
*/
|
||||
class PluginHandler {
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
const TABLE_PLUGINS = 'mc_plugins';
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $maniaControl = null;
|
||||
private $activePlugins = array();
|
||||
private $pluginClasses = array();
|
||||
|
||||
/**
|
||||
* Construct plugin handler
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
$this->initTables();
|
||||
}
|
||||
|
||||
class PluginHandler {
|
||||
/**
|
||||
* Initialize necessary database tables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function initTables() {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$pluginsTableQuery = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_PLUGINS . "` (
|
||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`className` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`active` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`index`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ManiaControl plugin status' AUTO_INCREMENT=1;";
|
||||
$tableStatement = $mysqli->prepare($pluginsTableQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$tableStatement->execute();
|
||||
if ($tableStatement->error) {
|
||||
trigger_error($tableStatement->error, E_USER_ERROR);
|
||||
return false;
|
||||
}
|
||||
$tableStatement->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private properties
|
||||
*/
|
||||
private $mc;
|
||||
private $plugins;
|
||||
/**
|
||||
* Save plugin status in database
|
||||
*
|
||||
* @param string $className
|
||||
* @param bool $active
|
||||
* @return bool
|
||||
*/
|
||||
private function savePluginStatus($className, $active) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$pluginStatusQuery = "INSERT INTO `" . self::TABLE_PLUGINS . "` (
|
||||
`className`,
|
||||
`active`
|
||||
) VALUES (
|
||||
?, ?
|
||||
) ON DUPLICATE KEY UPDATE
|
||||
`active` = VALUES(`active`);";
|
||||
$pluginStatement = $mysqli->prepare($pluginStatusQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$activeInt = ($active ? 1 : 0);
|
||||
$pluginStatement->bind_param('si', $className, $activeInt);
|
||||
$pluginStatement->execute();
|
||||
if ($pluginStatement->error) {
|
||||
trigger_error($pluginStatement->error);
|
||||
return false;
|
||||
}
|
||||
$pluginStatement->close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __construct($mc){
|
||||
$this->mc = $mc;
|
||||
$this->plugins = array();
|
||||
}
|
||||
/**
|
||||
* Get plugin status from database
|
||||
*
|
||||
* @param string $className
|
||||
* @return bool
|
||||
*/
|
||||
private function getPluginStatus($className) {
|
||||
$mysqli = $this->maniaControl->database->mysqli;
|
||||
$pluginStatusQuery = "SELECT `active` FROM `" . self::TABLE_PLUGINS . "`
|
||||
WHERE `className` = ?;";
|
||||
$pluginStatement = $mysqli->prepare($pluginStatusQuery);
|
||||
if ($mysqli->error) {
|
||||
trigger_error($mysqli->error);
|
||||
return false;
|
||||
}
|
||||
$pluginStatement->bind_param('s', $className);
|
||||
$pluginStatement->execute();
|
||||
if ($pluginStatement->error) {
|
||||
trigger_error($pluginStatement->error);
|
||||
$pluginStatement->close();
|
||||
return false;
|
||||
}
|
||||
$pluginStatement->store_result();
|
||||
if ($pluginStatement->num_rows <= 0) {
|
||||
$pluginStatement->free_result();
|
||||
$pluginStatement->close();
|
||||
return false;
|
||||
}
|
||||
$pluginStatement->bind_result($activeInt);
|
||||
$pluginStatement->fetch();
|
||||
$active = ($activeInt === 1);
|
||||
$pluginStatement->free_result();
|
||||
$pluginStatement->close();
|
||||
return $active;
|
||||
}
|
||||
|
||||
public function registerPlugin($plugin){
|
||||
array_push($this->plugins, $plugin);
|
||||
}
|
||||
/**
|
||||
* Load complete plugins directory and start all configured plugins
|
||||
*/
|
||||
public function loadPlugins() {
|
||||
$pluginsDirectory = ManiaControlDir . '/plugins/';
|
||||
$pluginFiles = scandir($pluginsDirectory, 0);
|
||||
foreach ($pluginFiles as $pluginFile) {
|
||||
if (stripos($pluginFile, '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
$classesBefore = get_declared_classes();
|
||||
$success = include_once $pluginsDirectory . $pluginFile;
|
||||
if (!$success) {
|
||||
continue;
|
||||
}
|
||||
$classesAfter = get_declared_classes();
|
||||
$newClasses = array_diff($classesAfter, $classesBefore);
|
||||
foreach ($newClasses as $className) {
|
||||
if (!is_subclass_of($className, 'ManiaControl\Plugin')) {
|
||||
continue;
|
||||
}
|
||||
array_push($this->pluginClasses, $className);
|
||||
$active = $this->getPluginStatus($className);
|
||||
if (!$active) {
|
||||
continue;
|
||||
}
|
||||
$plugin = new $className($this->maniaControl);
|
||||
array_push($this->activePlugins, $plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loadPlugins(){
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
@ -31,11 +31,10 @@ class Server {
|
||||
$this->mc = $mc;
|
||||
|
||||
// Load config
|
||||
$this->config = Tools::loadConfig('server.ManiaControl.xml');
|
||||
$this->mc->checkConfig($this->config, array('host', 'port', 'login', 'pass'), 'server');
|
||||
$this->config = Tools::loadConfig('server.xml');
|
||||
|
||||
// Register for callbacks
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_IC_1_SECOND, $this, 'eachSecond');
|
||||
$this->mc->callbacks->registerCallbackHandler(Callbacks::CB_MC_1_SECOND, $this, 'eachSecond');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,8 +225,8 @@ class Server {
|
||||
}
|
||||
return $gameMode;
|
||||
}
|
||||
|
||||
//TODO: remove getPlayer / getPlayers -> methods now in playerHandler handeld, but should be improved more
|
||||
|
||||
// TODO: remove getPlayer / getPlayers -> methods now in playerHandler handeld, but should be improved more
|
||||
/**
|
||||
* Fetch player info
|
||||
*
|
||||
|
@ -140,15 +140,15 @@ class Tools {
|
||||
return $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the given time (seconds) to hh:mm:ss
|
||||
*
|
||||
* @param int $time
|
||||
* @return string
|
||||
*/
|
||||
public static function formatTimeH($seconds) {
|
||||
return gmdate("H:i:s", $seconds);
|
||||
}
|
||||
/**
|
||||
* Formats the given time (seconds) to hh:mm:ss
|
||||
*
|
||||
* @param int $time
|
||||
* @return string
|
||||
*/
|
||||
public static function formatTimeH($seconds) {
|
||||
return gmdate("H:i:s", $seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert given data to real boolean
|
||||
|
Reference in New Issue
Block a user