Ejemplo n.º 1
0
 public function loadInstances()
 {
     $newInstances = $this->getNewInstancesInDir("./core");
     foreach ($newInstances as $name => $className) {
         Registry::setInstance($name, new $className());
     }
     $this->loadCoreModules();
     $this->loadUserModules();
     $this->logger->log('DEBUG', "Inject dependencies for all instances");
     foreach (Registry::getAllInstances() as $instance) {
         Registry::injectDependencies($instance);
     }
 }
Ejemplo n.º 2
0
 /**
  * @HandlesCommand("reloadinstance")
  * @Matches("/^reloadinstance all$/i")
  */
 public function reloadinstanceAllCommand($message, $channel, $sender, $sendto, $args)
 {
     $instances = Registry::getAllInstances();
     $count = count($instances);
     $blob = '';
     foreach ($instances as $name => $instance) {
         $blob .= $name . ' (' . get_class($instance) . ")\n";
         Registry::importChanges($instance);
         Registry::injectDependencies($instance);
     }
     $msg = $this->text->make_blob("All instances have been reloaded ({$count})", $blob);
     $sendto->reply($msg);
 }
Ejemplo n.º 3
0
 public static function getInstance($name, $reload = false)
 {
     $name = strtolower($name);
     LegacyLogger::log("DEBUG", "Registry", "Requesting instance for '{$name}'");
     $instance = Registry::$repo[$name];
     if ($instance == null) {
         LegacyLogger::log("WARN", "Registry", "Could not find instance for '{$name}'");
     }
     if ($instance !== null && (USE_RUNKIT_CLASS_LOADING === true || $reload === true)) {
         Registry::importChanges($instance);
         Registry::injectDependencies($instance);
     }
     return $instance;
 }
Ejemplo n.º 4
0
 public function run()
 {
     // set default timezone
     date_default_timezone_set("UTC");
     echo $this->getInitialInfoMessage();
     $this->loadPhpExtensions();
     // these must happen first since the classes that are loaded may be used by processes below
     $this->loadPhpLibraries();
     $this->loadEssentialCoreClasses();
     // load $vars
     global $vars;
     $vars = $this->getConfigVars();
     $logFolderName = $vars['name'] . '.' . $vars['dimension'];
     $this->setErrorHandling($logFolderName);
     $this->showSetupDialog();
     $this->canonicalizeBotCharacterName();
     $this->configureLogger($logFolderName);
     $this->setWindowTitle();
     LegacyLogger::log('INFO', 'StartUp', "Starting {$vars['name']} ({$this->version}) on RK{$vars['dimension']}...");
     $classLoader = new ClassLoader($vars['module_load_paths']);
     Registry::injectDependencies($classLoader);
     $classLoader->loadInstances();
     $this->connectToDatabase();
     $this->clearDatabaseInformation();
     $this->runUpgradeScripts();
     list($server, $port) = $this->getServerAndPort($vars);
     $chatBot = Registry::getInstance('chatBot');
     // startup core systems and load modules
     $chatBot->init($vars);
     // when using AOChatProxy, wait 10s before connecting to give AOChatProxy time to reset
     if ($vars['use_proxy'] == 1) {
         LegacyLogger::log('INFO', 'StartUp', "Waiting 10 seconds for AOChatProxy to reset...");
         sleep(10);
     }
     // connect to ao chat server
     $chatBot->connectAO($vars['login'], $vars['password'], $server, $port);
     // clear login credentials
     unset($vars['login']);
     unset($vars['password']);
     // pass control to Budabot class
     $chatBot->run();
 }
Ejemplo n.º 5
0
 /**
  * Waits until response is fully received from remote server and returns
  * the response. Note that this blocks execution, but does not freeze the bot
  * as the execution will return to event loop while waiting.
  *
  * @return mixed
  */
 public function waitAndReturnResponse()
 {
     // run in event loop, waiting for loop->quit()
     $this->loop = new EventLoop();
     Registry::injectDependencies($this->loop);
     while (!$this->finished) {
         $this->loop->execSingleLoop();
     }
     return $this->buildResponse();
 }
Ejemplo n.º 6
0
 public function getSettingHandler($row)
 {
     $handler = null;
     switch ($row->type) {
         case 'color':
             $handler = new ColorSettingHandler($row);
             break;
         case 'text':
             $handler = new TextSettingHandler($row);
             break;
         case 'number':
             $handler = new NumberSettingHandler($row);
             break;
         case 'options':
             $handler = new OptionsSettingHandler($row);
             break;
         case 'time':
             $handler = new TimeSettingHandler($row);
             break;
         default:
             $this->loggger->log('ERROR', "Could not find setting handler for setting type: '{$row->type}'");
     }
     Registry::injectDependencies($handler);
     return $handler;
 }
Ejemplo n.º 7
0
 public function run()
 {
     $loop = new EventLoop();
     Registry::injectDependencies($loop);
     while (true) {
         $loop->execSingleLoop();
     }
 }