示例#1
0
文件: Clones.php 项目: bonan/neotor
 public function makeClone()
 {
     global $networkList;
     global $ircNetworks;
     if (count($this->bots) >= $this->amount) {
         return;
     }
     do {
         $nick = chr(rand(ord('a'), ord('z'))) . chr(rand(ord('a'), ord('z'))) . chr(rand(ord('a'), ord('z'))) . chr(rand(ord('a'), ord('z'))) . chr(rand(ord('a'), ord('z'))) . chr(rand(ord('a'), ord('z'))) . rand(0, 9) . rand(0, 9) . rand(0, 9) . rand(0, 9);
     } while (isset($this->bots[$nick]));
     $i = array('network' => 'net-' . $nick, 'servers' => $this->server, 'nickname' => $nick, 'altnick' => $nick . '_', 'username' => $nick, 'realname' => $nick, 'autojoin' => $this->chan, 'active' => 1, 'perform' => '', 'vhost' => '', 'ssl' => 0, 'pass' => '');
     if (count($this->bots) < $this->amount) {
         Timer::add2('makeClone', $this->interval, array($this, 'makeClone'));
     }
     $networkList['clone-' . $nick] = $i;
     $ircNetworks['clone-' . $nick] = $this->bots[$nick] = new Irc('clone-' . $nick);
 }
示例#2
0
文件: irc.php 项目: bonan/neotor
 /**
  * Pings the server to check if it's still alive
  * 
  * @return void
  */
 public function pingServer()
 {
     if (empty($this->lastPing)) {
         $this->lastPing = time();
     }
     if ($this->lastPing < time() - 130) {
         unset($this->lastPing);
         $this->errorConnectionReset();
         return;
     }
     $this->pingTime = utime();
     $this->raw("PING :" . $this->pingTime);
     $this->attach('pongServer', array($this, 'pongServer'), array('PONG'));
     Timer::add2('ping' . $this->network, 120, array($this, 'pingServer'));
     return;
 }
示例#3
0
 /**
  * @return resource
  */
 public function newSms()
 {
     $q = $this->query("SELECT 'inbox' AS tblname,id,number,text,insertdate FROM inbox WHERE processed = 0 UNION SELECT 'multipartinbox' as tblname,id,number,text,insertdate FROM multipartinbox WHERE processed = 0");
     $id = array('inbox' => array(), 'multipartinbox' => array());
     while ($r = mysql_fetch_object($q)) {
         logWrite(L_DEBUG, "[SMS] New SMS from {$r->number}: {$r->text}");
         $number = preg_replace('/^(\\+|00)46/', '0', $r->number);
         if (preg_match(SMS::$number, $number) == 0) {
             if (isset($this->network[SMS::$unknownTarget[0]])) {
                 $this->network[SMS::$unknownTarget[0]]->unknownMessage($r->number, $r->text);
                 $id[$r->tblname][] = $r->id;
             }
             continue;
         }
         $user = $this->getUserByNumber($number);
         if (count($user) == 0) {
             if (isset($this->network[SMS::$unknownTarget[0]])) {
                 $this->network[SMS::$unknownTarget[0]]->unknownMessage($r->number, $r->text);
                 $id[$r->tblname][] = $r->id;
             }
             continue;
         }
         $ch = $r->text;
         $text = '';
         if (strpos($r->text, ' ') !== false) {
             list($ch, $text) = explode(' ', $r->text, 2);
         }
         $fromNick = '';
         $toNetwork = '';
         $toChannel = '';
         $msg = $r->text;
         foreach ($user as $u) {
             if (empty($fromNick)) {
                 $fromNick = $u['nick'];
                 $toChannel = $u['channel'];
                 $toNetwork = $u['network'];
             }
             $matchChan = strtolower(ltrim($u['channel'], '#'));
             $matchWord = strtolower(ltrim($ch, '#'));
             if (strlen($matchWord) > 0 && substr($matchChan, 0, strlen($matchWord)) == $matchWord) {
                 $fromNick = $u['nick'];
                 $toChannel = $u['channel'];
                 $toNetwork = $u['network'];
                 $msg = $text;
                 break;
             }
         }
         if (isset($this->network[strtolower($toNetwork)])) {
             if ($this->network[strtolower($toNetwork)]->newSms($fromNick, $toChannel, $msg)) {
                 $this->insertHistory($fromNick, '', $toChannel, $toNetwork, $number, 0);
             }
             $id[$r->tblname][] = $r->id;
         } else {
             logWrite(L_DEBUG, "[SMS] New SMS for {$toNetwork}/{$toChannel}: Network not found");
         }
     }
     foreach ($id as $table => $ids) {
         if (count($ids) > 0) {
             $this->query("UPDATE {$table} SET processed=1 WHERE id IN (" . implode(',', $ids) . ")");
         }
     }
     Timer::add2('smsservice', 2, array($this, 'newSms'));
 }
示例#4
0
文件: idlerpg.php 项目: bonan/neotor
 /**
  * Checks the idletime and much more
  *
  * @return none
  */
 public function checkIdle()
 {
     $minus = 3;
     $q = $this->query("SELECT `nickname` FROM `" . CONFIG_mysql_prefix . "idlerpg`");
     while ($row = mysql_fetch_array($q)) {
         $nickname = $row["nickname"];
         /**
          * See if the nickname is logged in
          */
         $login = $this->checkLogin($nickname);
         if ($login == 1) {
             /**
              * Get the level for nickname
              */
             $level = $this->settings[$nickname]["level"];
             /**
              * Get the idletime for nickname
              */
             $idletime = $this->settings[$nickname]["time"];
             $this->settings[$nickname]["time"] = $idletime - $minus;
             printf("Idletime: %s\n", $this->settings[$nickname]["time"]);
             /**
              * Check if the nickname has any active quest
              */
             $quest = $this->checkQuest($nickname);
             /**
              * Check if the nickname has any active battles
              */
             $battle = $this->checkBattle($nickname);
             /**
              * Here comes the magic code
              */
             if ($idletime <= 0) {
                 $this->settings[$nickname]["level"] = $level + 1;
                 $this->Pmath($nickname, $this->settings[$nickname]["time"], $this->settings[$nickname]["level"]);
                 $this->parent->privmsg(CONFIG_idlerpg_channel, sprintf("[LEVELUP] %s The %s has reached level %d", $nickname, $this->settings[$nickname]["class"], $this->settings[$nickname]["level"]));
                 $this->query("UPDATE `" . CONFIG_mysql_prefix . "idlerpg` SET `time` = " . $this->settings[$nickname]['time'] . " WHERE nickname = '{$nickname}'");
                 $this->query("UPDATE `" . CONFIG_mysql_prefix . "idlerpg` SET `level` = " . $this->settings[$nickname]['level'] . " WHERE nickname = '{$nickname}'");
             } else {
                 printf("%s - %s - %d - %d\n", $nickname, $this->settings[$nickname]["class"], $this->settings[$nickname]["level"], $this->settings[$nickname]["time"]);
             }
         }
     }
     Timer::add2('Idlecheck_' . uniqid(), CONFIG_idlerpg_interval, array($this, 'checkIdle'));
 }
示例#5
0
 /**
  * Checks for new revisions in the repository
  *
  * @return none
  */
 public function getNewRevisions()
 {
     $this->LatestEntry = $this->_getLatestFromDB();
     if ($this->LatestEntry == 0) {
         if ($XMLObject = $this->_getAllXMLFromSVN()) {
             foreach ($XMLObject->children() as $LogEntry) {
                 $LogMessage = $this->_fixText((string) $LogEntry->msg);
                 $this->_insertToDB($LogEntry);
                 $this->parent->privmsg(CONFIG_SVNCONTROLLER_CHANNEL, sprintf("[SVN] New commit | r%d | %s | %s", (int) $LogEntry->attributes()->revision, (string) $LogEntry->author, stripslashes($LogMessage)));
             }
         }
     } else {
         if ($XMLObject = $this->_getXMLObjectFromRevision($this->LatestEntry)) {
             if (count($XMLObject->children()) != 1) {
                 foreach ($XMLObject->children() as $LogEntry) {
                     $LogMessage = $this->_fixText((string) $LogEntry->msg);
                     if ($LogEntry->attributes()->revision == $this->LatestEntry) {
                         continue;
                     } else {
                         $this->_insertToDB($LogEntry);
                         $this->parent->privmsg(CONFIG_SVNCONTROLLER_CHANNEL, sprintf("[SVN] New commit | r%d | %s | %s", (int) $LogEntry->attributes()->revision, (string) $LogEntry->author, stripslashes($LogMessage)));
                     }
                 }
             }
         }
     }
     Timer::add2('SVNController_' . uniqid(), CONFIG_SVNCONTROLLER_INTERVAL, array($this, 'getNewRevisions'));
 }