Esempio n. 1
0
 protected function __construct()
 {
     $this->identifier = 'ManiaLive ' . \ManiaLiveApplication\Version;
     $config = Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
     Dispatcher::register(Event::getClass(), $this, Event::ON_ECHO);
 }
Esempio n. 2
0
 protected function __construct()
 {
     Dispatcher::register(ServerEvent::getClass(), $this, ServerEvent::ON_PLAYER_CHAT);
     $command = new Command('help', 0);
     $command->addLoginAsFirstParameter = true;
     $command->log = false;
     $command->help = 'Display all visible commands to a player it takes no parameter';
     $command->callback = array($this, 'help');
     $this->register($command);
     $command = new Command('man', 1);
     $command->addLoginAsFirstParameter = true;
     $command->help = 'Display help for every commands you give as parameter' . "\n" . 'exemple of usage: /man man';
     $command->isPublic = true;
     $command->log = false;
     $command->callback = array($this, 'man');
     $this->register($command);
     $command = new Command('man', 2);
     $command->addLoginAsFirstParameter = true;
     $command->help = 'Display help for the command with the corresponding parameters' . "\n" . 'exemple of usage: /man man 2';
     $command->isPublic = true;
     $command->log = false;
     $command->callback = array($this, 'man');
     $this->register($command);
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
 }
Esempio n. 3
0
 final function __construct()
 {
     $this->dependencies = array();
     $this->methods = array();
     $this->id = "\\" . get_class($this);
     $this->setVersion(1);
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
     $this->pluginHandler = PluginHandler::getInstance();
     $this->storage = Storage::getInstance();
     $this->chatCommands = array();
 }
Esempio n. 4
0
 protected function __construct()
 {
     $this->modalBg = new Bgs1(340, 200);
     $this->modalBg->setSubStyle(Bgs1::BgDialogBlur);
     $this->modalBg->setAlign('center', 'center');
     $this->modalBg->setPosZ(Window::Z_MODAL);
     $this->modalBg->setScriptEvents();
     $this->nextLoop = microtime(true);
     Dispatcher::register(AppEvent::getClass(), $this, AppEvent::ALL & ~AppEvent::ON_POST_LOOP);
     Dispatcher::register(PlayerEvent::getClass(), $this, PlayerEvent::ON_PLAYER_CHANGE_SIDE);
     Dispatcher::register(ServerEvent::getClass(), $this, ServerEvent::ON_PLAYER_CONNECT | ServerEvent::ON_PLAYER_DISCONNECT);
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
 }
 protected function init()
 {
     new \ManiaLive\Features\Tick\Ticker();
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
     $this->connection->enableCallbacks(true);
     \ManiaLive\Data\Storage::getInstance();
     \ManiaLive\Features\ChatCommand\Interpreter::getInstance();
     \ManiaLive\Features\EchoHandler::getInstance();
     \ManiaLive\Gui\GuiHandler::getInstance();
     \ManiaLive\PluginHandler\PluginHandler::getInstance();
     \ManiaLive\Threading\ThreadHandler::getInstance();
     Dispatcher::dispatch(new Event(Event::ON_INIT));
 }
Esempio n. 6
0
 final function __construct()
 {
     $this->dependencies = array();
     $this->methods = array();
     $items = explode('\\', get_class($this));
     $this->author = $items[1];
     $this->name = $items[2];
     $this->id = $this->author . '\\' . $this->name;
     $this->setVersion(1);
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
     $this->pluginHandler = PluginHandler::getInstance();
     $this->storage = Storage::getInstance();
     $this->chatCommands = array();
 }
Esempio n. 7
0
 protected function __construct()
 {
     $this->enabled = extension_loaded('mysql') && Config::getInstance()->enabled;
     if ($this->enabled) {
         $this->setUpDatabase();
         $this->setData('config', \ManiaLive\Config\Config::getInstance());
         $this->setData('wsapi', \ManiaLive\Features\WebServices\Config::getInstance());
         $this->setData('manialive', \ManiaLive\Application\Config::getInstance());
         $this->setData('server', \ManiaLive\DedicatedApi\Config::getInstance());
         $this->setData('threading', \ManiaLive\Threading\Config::getInstance());
     } else {
         Logger::debug('Application started with threading disabled!', true, array('Process #' . getmypid()));
         $this->buffers[0] = array();
     }
     Dispatcher::register(TickEvent::getClass(), $this);
 }
Esempio n. 8
0
 private function initDatabase()
 {
     $options = getopt(null, array('dbHost::', 'dbPort::', 'dbUsername::', 'dbPassword::', 'dbDatabase::'));
     $dbConfig = \ManiaLive\Database\Config::getInstance();
     foreach ($options as $key => $value) {
         $dbConfig->{lcfirst(substr($key, 2))} = $value;
     }
     $this->database = Connection::getConnection($dbConfig->host, $dbConfig->username, $dbConfig->password, $dbConfig->database, 'MySQL', $dbConfig->port);
     // load configs from DB
     $configs = array('config' => \ManiaLive\Config\Config::getInstance(), 'wsapi' => \ManiaLive\Features\WebServices\Config::getInstance(), 'manialive' => \ManiaLive\Application\Config::getInstance(), 'server' => \ManiaLive\DedicatedApi\Config::getInstance(), 'threading' => Config::getInstance());
     foreach ($configs as $dbName => $instance) {
         $data = $this->getData($dbName, array());
         foreach ((array) $data as $key => $value) {
             $instance->{$key} = $value;
         }
     }
 }
 /**
  * @return \ManiaLive\DedicatedApi\Connection
  */
 protected function getServerConnection()
 {
     if ($this->connection) {
         return $this->connection;
     }
     $service = new \ManiaHost\Services\ServerService();
     $server = end($service->getList(0, 1));
     if (!$server) {
         throw new \Exception('No server launched');
     }
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $config->host = $server->hostname;
     $config->port = $server->port;
     $config->user = '******';
     $config->password = $server->superAdminPassword;
     $this->connection = \ManiaLive\DedicatedApi\Connection::getInstance();
     return $this->connection;
 }
 static function postConfigLoad()
 {
     $options = getopt(null, array('rpcport::', 'address::', 'password::', 'dedicated_cfg::', 'user::', 'logsPrefix::', 'debug::'));
     $serverConfig = \ManiaLive\DedicatedApi\Config::getInstance();
     if (isset($options['logsPrefix'])) {
         \ManiaLive\Config\Config::getInstance()->logsPrefix = $options['logsPrefix'];
     }
     if (isset($options['debug'])) {
         \ManiaLive\Config\Config::getInstance()->debug = true;
     }
     if (isset($options['user'])) {
         if ($options['user'] != 'SuperAdmin' && $options['user'] != 'Admin' && $options['user'] != 'User') {
             echo 'Invalid Username' . PHP_EOL . $help;
             exit;
         }
         $serverConfig->user = $options['user'];
     }
     if (isset($options['dedicated_cfg'])) {
         $filename = \ManiaLive\Config\Config::getInstance()->dedicatedPath . '/UserData/Config/' . $options['dedicated_cfg'];
         if (file_exists($filename)) {
             //Load the config file
             $config = simplexml_load_file($filename);
             $serverConfig->port = (int) $config->system_config->xmlrpc_port;
             foreach ($config->authorization_levels->children() as $level) {
                 if ($serverConfig->user == (string) $level->name) {
                     $serverConfig->password = (string) $level->password;
                     break;
                 }
             }
         } else {
             throw new Exception('Configuration file not found...' . PHP_EOL . 'stopping software...');
         }
     } else {
         if (isset($options['rpcport'])) {
             $serverConfig->port = $options['rpcport'];
         }
         if (isset($options['password'])) {
             $serverConfig->password = $options['password'];
         }
     }
     if (isset($options['address'])) {
         $serverConfig->host = $options['address'];
     }
 }
Esempio n. 11
0
 function onClickMode($login, $mode)
 {
     try {
         $config = \ManiaLive\DedicatedApi\Config::getInstance();
         Connection::factory($config->host, $config->port)->setGameMode($mode);
         $dialog = Dialog::Create($login, false);
         $dialog->setSize(125, 40);
         $dialog->setTitle('Game Mode Changed!');
         $dialog->setText('You have selected ' . self::$modes[$mode][0] . ",\n" . 'New game mode will be set on map change!' . "\n" . 'Do you want to restart now?');
         $dialog->setButtons(Dialog::YES | Dialog::NO);
         $dialog->addCloseCallback(array($this, 'onDialogClosed'));
         $dialog->centerOnScreen();
         $dialog->showModal();
         $this->show();
     } catch (\Exception $ex) {
         $win = Info::Create($login, false);
         $win->setSize(40, 23);
         $win->setTitle('Error');
         $win->setText($ex->getMessage());
         $win->centerOnScreen();
         $win->showModal();
     }
 }
Esempio n. 12
0
 function onInit()
 {
     $config = \ManiaLive\DedicatedApi\Config::getInstance();
     $this->connection = Connection::factory($config->host, $config->port, $config->timeout, $config->user, $config->password);
     $this->serverStatus = $this->connection->getStatus();
     $players = $this->connection->getPlayerList(-1, 0);
     foreach ($players as $player) {
         try {
             $details = $this->connection->getDetailedPlayerInfo($player->login);
             foreach ($details as $key => $value) {
                 if ($value) {
                     $player->{$key} = $value;
                 }
             }
             if ($player->spectatorStatus % 10 == 0) {
                 $this->players[$player->login] = $player;
             } else {
                 $this->spectators[$player->login] = $player;
             }
         } catch (\Exception $e) {
         }
     }
     try {
         $this->maps = $this->connection->getMapList(-1, 0);
         $this->nextMap = $this->maps[$this->connection->getNextMapIndex()];
         $this->currentMap = $this->connection->getCurrentMapInfo();
         Console::printlnFormatted('Current map: ' . Formatting::stripStyles($this->currentMap->name));
     } catch (\Exception $e) {
         $this->maps = array();
         $this->nextMap = null;
         $this->currentMap = null;
     }
     $this->server = $this->connection->getServerOptions();
     $this->gameInfos = $this->connection->getCurrentGameInfo();
     try {
         $this->serverLogin = $this->connection->getSystemInfo()->serverLogin;
     } catch (\Exception $e) {
         $this->serverLogin = null;
     }
 }
Esempio n. 13
0
 function clearFiles()
 {
     try {
         $login = $this->db->query('SELECT playerLogin FROM Servers S ' . 'INNER JOIN Rents R ON S.idRent = R.id ' . 'WHERE hostname = %s AND port = %d', $this->db->quote(Config::getInstance()->host), Config::getInstance()->port)->fetchScalar();
         $count = $this->db->query('SELECT count(*) ' . 'FROM Rents ' . 'WHERE DATE_ADD(rentDate, INTERVAL duration HOUR) > NOW() ' . 'AND playerLogin = %s', $this->db->quote($login))->fetchScalar();
         $filesPath = realpath(\ManiaLive\Config\Config::getInstance()->dedicatedPath) . DIRECTORY_SEPARATOR . 'UserData' . DIRECTORY_SEPARATOR . 'Maps' . DIRECTORY_SEPARATOR;
         if ($count && file_exists($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login)) {
             $maps = scandir($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login);
             foreach ($maps as $map) {
                 if ($map != '..' && $map != '.') {
                     unlink($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login . DIRECTORY_SEPARATOR . $map);
                 }
             }
             rmdir($filesPath . '$uploaded' . DIRECTORY_SEPARATOR . $login);
         }
     } catch (\Exception $e) {
         \ManiaLive\Application\ErrorHandling::displayAndLogError($e);
     }
 }