Esempio n. 1
0
 public static function dispatch(Event $event)
 {
     $eventClass = get_class($event);
     if (isset(self::$listeners[$eventClass]) && isset(self::$listeners[$eventClass][$event->getMethod()])) {
         foreach (self::$listeners[$eventClass][$event->getMethod()] as $listener) {
             try {
                 $event->fireDo($listener);
             } catch (\Exception $e) {
                 ErrorHandling::processModuleException($e);
             }
         }
     }
 }
Esempio n. 2
0
 function onServerStart()
 {
     foreach ($this->delayedPlugins as $pluginId => $plugin) {
         try {
             $this->loadedPlugins[$pluginId] = $plugin;
             $this->prepare($plugin);
         } catch (\Exception $e) {
             $this->unload($pluginId);
             unset($this->delayedPlugins[$pluginId]);
             ErrorHandling::processRuntimeException($e);
         }
     }
     foreach ($this->delayedPlugins as $plugin) {
         $plugin->onReady();
     }
     $this->delayedPlugins = array();
 }
 final function run()
 {
     try {
         $this->init();
         Dispatcher::dispatch(new Event(Event::ON_RUN));
         self::$startTime = microtime(true);
         $nextCycleStart = self::$startTime;
         $cycleTime = 1 / static::CYCLES_PER_SECOND;
     } catch (\Exception $e) {
         ErrorHandling::processRuntimeException($e);
     }
     try {
         while ($this->running) {
             Dispatcher::dispatch(new Event(Event::ON_PRE_LOOP));
             $calls = $this->connection->executeCallbacks();
             if (!empty($calls)) {
                 foreach ($calls as $call) {
                     $method = preg_replace('/^[[:alpha:]]+\\./', '', $call[0]);
                     // remove trailing "Whatever."
                     $params = (array) $call[1];
                     Dispatcher::dispatch(new \ManiaLive\DedicatedApi\Callback\Event($method, $params));
                 }
             }
             $this->connection->executeMulticall();
             Dispatcher::dispatch(new Event(Event::ON_POST_LOOP));
             $endCycleTime = microtime(true) + $cycleTime / 10;
             do {
                 $nextCycleStart += $cycleTime;
             } while ($nextCycleStart < $endCycleTime);
             @time_sleep_until($nextCycleStart);
         }
     } catch (\Exception $e) {
         ErrorHandling::processRuntimeException($e);
     }
     Dispatcher::dispatch(new Event(Event::ON_TERMINATE));
 }
Esempio n. 4
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);
     }
 }