Esempio n. 1
0
 public function Start()
 {
     $IRC = $GLOBALS['IRC'];
     $i = 0;
     while (!$IRC->IsConnected() and isset($this->Config['server'][$i])) {
         $GLOBALS['Log']->Sys('---------------------------------------------------------------------------');
         $GLOBALS['Log']->Sys('Trying connect with ' . $this->Config['server'][$i]['url'] . ':' . $this->Config['server'][$i]['port'] . "\n");
         if (!$IRC->Connect($this->Config['server'][$i]['url'], $this->Config['server'][$i]['port'], $ErrNo, $ErrStr, $this->Config['timeout']['connect'])) {
             $GLOBALS['Log']->Sys('!! Connect with IRC server fails !!');
             $GLOBALS['Log']->Sys('Server: ' . $this->Config['server'][$i]['url'] . ':' . $this->Config['server'][$i]['port'] . ', timeout: ' . $this->Config['timeout']['connect']);
             $GLOBALS['Log']->Sys('Error: ' . $ErrNo . ' - ' . $ErrStr);
         }
         $i++;
     }
     if (!$IRC->IsConnected()) {
         $GLOBALS['Log']->Sys('All connections (' . $i . ') fails. Please try to add some servers in your IRC network, or check your server settings.');
         return false;
     } else {
         // Now we have got a opened socket with IRC server
         $GLOBALS['Log']->Sys('Connected ...');
         // USER Message -----------------------
         $GLOBALS['Log']->Sys('Sending USER Message ...');
         $IRC->ScWrite('USER ' . $this->Config['user_message'][0], false);
         $regexps_user_fails = array(':[^ ]+ ' . ERR_NEEDMOREPARAMS . '( [^ ]*)? USER .*');
         $code_user_fails = "\t\$GLOBALS['Log']->Sys(\"User message error\nTrying other message...\");\r\n\t\t\t\t\t\$this->TTL = (Time() + 5);\r\n\t\t\t\t\t\$this->Data++;\r\n\t\t\t\t\t\$Config=\$GLOBALS['Bot']->GetConfig();\r\n\t\t\t\t\tif (isset(\$Config['user_message'][\$this->Data]))\r\n\t\t\t\t\t   {\$user_message=\$Config['user_message'][\$this->Data];}\r\n\t\t\t\t\telse\r\n                       {\$user_message=\$Config['user_message']['default'];} \r\n\t\t\t\t\t\$GLOBALS['IRC']->ScWrite('USER '.\$user_message,false);\r\n\t\t\t\t\t\$GLOBALS['Log']->Sys('Sending NICK Message ...');\r\n      \t\t\t\t\$GLOBALS['IRC']->ScWrite('NICK '.\$Config['nick'][0],false);\t\r\n\t\t\t\t\t";
         $regexps_user_ok = array(':[^ ]+ ' . RPL_WELCOME . '.*', ':[^ ]+ ' . ERR_ALREADYREGISTRED . '.*');
         // becouse of if server send welcome message we muss be logged in
         $code_user_ok = "\$Config=\$GLOBALS['Bot']->GetConfig();\r\n\t\t\t\t\t   if (!isset(\$Config['user_message'][\$this->Data]))\r\n\t\t\t\t\t      {\$user_message=\$Config['user_message'][\$this->Data];}\r\n\t\t\t\t\t   else\r\n                          {\$user_message=\$Config['user_message']['default'];} \r\n\t\t\t\t\t  \$GLOBALS['Log']->Sys('Used USER message : '.\$user_message);\r\n\t\t\t\t\t  \$this->DestroyAllTriggers(); // free nick messages\r\n\t\t\t\t\t";
         // USER message event
         $tmp = new CodeEvent($this->Config['timeout']['user_message']);
         $tmp->SetData(0);
         $tmp->AddTrigger($regexps_user_ok, $code_user_ok);
         $tmp->AddTrigger($regexps_user_fails, $code_user_fails);
         $this->NewRunningEvent($tmp);
         unset($tmp);
         // NICK Message -----------------------------------------------------
         $GLOBALS['Log']->Sys('Sending NICK Message ...' . "\n");
         $IRC->ScWrite('NICK ' . $this->Config['nick'][0], false);
         $IRC->SetAttrib('Nick', $this->Config['nick'][0]);
         $regexps_nick_fails = array(':[^ ]+ ' . ERR_NONICKNAMEGIVEN . '.*', ':[^ ]+ ' . ERR_ERRONEUSNICKNAME . '( [^ ]*)? ' . $this->Config['nick'][0] . '.*', ':[^ ]+ ' . ERR_NICKCOLLISION . '( [^ ]*)? ' . $this->Config['nick'][0] . '.*', ':[^ ]+ ' . ERR_UNAVAILRESOURCE . '( [^ ]*)? ' . $this->Config['nick'][0] . '.*', ':[^ ]+ ' . ERR_RESTRICTED . '.*', ':[^ ]+ ' . ERR_NICKNAMEINUSE . '( [^ ]*)? ' . $this->Config['nick'][0] . '.*');
         $code_nick_fails = "\r\n\t\t\t\t   \$GLOBALS['Log']->Sys(\"Nick error\nTrying other nick...\");\r\n\t\t\t\t   \$this->TTL = (Time() + 5);\r\n\t\t\t\t   \$this->Data++;\r\n\t\t\t\t   \$Config=\$GLOBALS['Bot']->GetConfig();\r\n\t\t\t\t   if (!isset(\$Config['nick'][\$this->Data])) \r\n\t\t\t\t\t\t{\$Nick=\$Config['nick'][0].strval(rand(0,1000));}\r\n\t\t\t\t   else \$Nick=\$Config['nick'][\$this->Data];\r\n\t\t\t\t   // change regexps \r\n\t\t\t\t   foreach(\$this->Trigger as &\$Exp)\r\n\t\t\t\t\t {\$Exp['RegExp']=str_replace(\$GLOBALS['IRC']->GetNick(),\$Nick,\$Exp['RegExp']);}\r\n\t\t\t\t   \$GLOBALS['IRC']->SetAttrib('Nick',\$Nick);\r\n\t\t\t\t   \$GLOBALS['IRC']->ScWrite('NICK '.\$Nick,false);\r\n\t\t\t  \t ";
         $regexp_nick_ok = ':[^ ]+ ' . RPL_WELCOME . '.*';
         $code_nick_ok = "\$GLOBALS['Log']->Sys('Used Nick is '.\$GLOBALS['IRC']->GetNick());\r\n\t\t\t\t\t \$this->DestroyAllTriggers(); // free nick messages\r\n\t\t\t\t\t//prepare this server hosmask\r\n\t\t\t\t\teregi(':([^ ]+).*',\$GLOBALS['IRC']->GetLastLine(),\$tmp);\r\n\t\t\t\t\t\$GLOBALS['IRC']->SetAttrib('Server',\$tmp[1]);\r\n\t\t\t\t\t\$GLOBALS['Log']->Sys('Get server\\'s hostname: '.\$tmp[1]);\r\n\t\t\t\t\t// join to all channels form list\r\n\t\t\t\t\t\$Config=\$GLOBALS['Bot']->GetConfig();\r\n\t\t\t\t\tforeach ((\$Config['channel']) as \$value)\r\n\t\t \t\t\t{\r\n\t\t   \t\t\t\t\$GLOBALS['Log']->Sys('Trying join to '.\$value.'... ');\r\n\t\t\t\t\t\t\$GLOBALS['IRC']->Join(\$value);\r\n\t\t \t\t\t}\r\n\t\t\t\t\t";
         // NICK message Event
         $timeout = $this->Config['timeout']['user_message'] * count($this->Config['user_message']) + $this->Config['timeout']['nick_message'];
         $tmp = new CodeEvent($timeout);
         $tmp->SetData(0);
         $tmp->AddTrigger($regexps_nick_fails, $code_nick_fails);
         $tmp->AddTrigger($regexp_nick_ok, $code_nick_ok);
         $this->NewRunningEvent($tmp);
         unset($tmp);
         //------------------------------------------------------------
         $this->LoadEvents();
     }
     unset($IRC);
 }
Esempio n. 2
0
 public function SetNick($Nick)
 {
     // Try to change Nick
     $this->ScWrite('NICK ' . $Nick, false);
     $code_fails = '$this->DestroyAllTriggers();';
     $regexps_fails = array(':[^ ]+ ' . ERR_NONICKNAMEGIVEN . '.*', ':[^ ]+ ' . ERR_ERRONEUSNICKNAME . '( [^ ]*)? ' . $Nick . '.*', ':[^ ]+ ' . ERR_NICKCOLLISION . '( [^ ]*)? ' . $Nick . '.*', ':[^ ]+ ' . ERR_UNAVAILRESOURCE . '( [^ ]*)? ' . $Nick . '.*', ':[^ ]+ ' . ERR_RESTRICTED . '.*', ':[^ ]+ ' . ERR_NICKNAMEINUSE . '( [^ ]*)? ' . $Nick . '.*');
     $regexp_ok = ':' . $this->Nick . '![^ ]+ NICK :?' . $Nick;
     $code_ok = '$GLOBALS[\'IRC\']->SetAttrib(\'Nick\',\'' . $Nick . '\');$this->DestroyAllTriggers();';
     $tmp = new CodeEvent(5);
     // valid for 5 second
     $tmp->AddTrigger($regexp_ok, $code_ok);
     $tmp->AddTrigger($regexps_fails, $code_fails);
     $GLOBALS['Bot']->NewRunningEvent($tmp);
 }