Beispiel #1
0
 public function main_loop()
 {
     while (true) {
         timer::loop();
         // this is our timer counting function
         if (self::$end_burst && count(self::$nbuffer) > 0) {
             foreach (self::$nbuffer as $index => $ircdata) {
                 self::$incoming = self::$incoming + strlen(implode(' ', $ircdata));
                 // log our incoming bandwidth
                 if ($this->process(&$ircdata, true)) {
                     continue;
                 }
                 // process the data from the buffer
                 unset(self::$nbuffer[$index], $index, $ircdata);
             }
             // is there any data in the burst buffer?
             self::$nbuffer = array();
         }
         // but only when the burst has finished ^_^
         if (self::$end_burst && count(self::$buffer) > 0) {
             foreach (self::$buffer as $index => $ircdata) {
                 self::$incoming = self::$incoming + strlen(implode(' ', $ircdata));
                 // log our incoming bandwidth
                 if ($this->process(&$ircdata, false)) {
                     continue;
                 }
                 // process normal incoming data
                 unset(self::$buffer[$index], $index, $ircdata);
             }
             // is there any data in the buffer?
             self::$buffer = array();
         }
         // this is for normal data, eg. post burst.
         if ($raw = stream_get_line(self::$socket, 4092, "\r\n")) {
             $raw = trim($raw);
             $ircdata = explode(' ', $raw);
             self::$lines_processed++;
             // grab the data
             self::alog('recv(): ' . $raw, 'SERVER');
             // log SERVER
             if ((self::$config->settings->loglevel != 'off' || !isset(self::$config->settings->loglevel)) && self::$end_burst) {
                 self::save_logs();
             }
             // we also logfile here, and stop logfiling until we've
             // reached the end of the burst, then we do it every 5 mins
             if (ircd::on_capab_start(&$ircdata)) {
                 self::$capab_start = true;
             }
             // if capab has started we set a true flag, just like
             // we do with burst
             if (ircd::on_capab_end(&$ircdata)) {
                 self::$capab_start = false;
                 $this->boot_server();
             }
             // we need to respectivly wait for capab end
             // before we're suppost to boot everything
             // we also set the flag to false cause capab has ended.
             ircd::get_information(&$ircdata);
             // modes and stuff we check for here.
             if (ircd::on_start_burst(&$ircdata)) {
                 self::$end_burst = false;
                 if (self::$config->server->ircd == 'inspircd12') {
                     self::$network_time = $ircdata[2];
                 }
                 self::$burst_time = microtime(true);
                 // how long did the burst take?
             }
             // if we recieve a start burst, we also adopt the time given to us
             if (ircd::on_end_burst(&$ircdata)) {
                 self::$burst_time = round(microtime(true) - self::$burst_time, 4);
                 if (self::$burst_time[0] == '-') {
                     substr(self::$burst_time, 1);
                 }
                 // nasty hack to get rid of minus values.. they are sometimes displayed
                 // i don't know why.. maybe on clock shifts..
                 // how long did the burst take?
                 self::$end_burst = true;
                 ircd::end_burst();
             }
             // here we check if we're recieving an endburst
             if (!self::$end_burst) {
                 self::$nbuffer[] =& $ircdata;
             } else {
                 self::$buffer[] =& $ircdata;
             }
             // we should really only be processing the data if the burst has finished
             // so we add it to a buffer and process it in each main loop :)
             unset($ircdata, $raw);
             // unset the variables on each process loop
         }
         if (self::$debug && count(self::$debug_data) > 0) {
             foreach (self::$debug_data as $line => $message) {
                 if (trim($message) != '' || trim($message) != null) {
                     print "[" . date('H:i:s', self::$network_time) . "] " . $message . "\r\n";
                 }
                 // only print if we have something to print
                 unset(self::$debug_data[$line]);
                 // ALWAYS unset it.
             }
         } elseif (self::$debug && count(self::$debug_data) == 0) {
             self::$debug_data = array();
         }
         // here we output debug data, if there is any.
         usleep(45000);
         // 40000 is the highest i'm willing to go, as 50000
         // breaks the /hop and /cycle, 40000 gives us some time
         // to reprocess and stuff. Still keeping CPU low.
     }
 }