示例#1
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));
 }