Follow us on Twitter!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Sunday, April 20, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 30
Guests Online: 27
Members Online: 3

Registered Members: 82850
Newest Member: hardstylurr
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

irc bot help in PHP

t0xikc0mputer
Member



Posts: 112
Location: t0xik waste dump
Joined: 07.01.11
Rank:
Newbie
Posted on 19-05-11 00:37
Hello all,
I have recently been trying to create an irc bot for an irc channel that I (and m4rc0p0l0) have at irc.psych0tik.net. (#t0x0p0l0) I wanted to create an irc bot so that whoever entered, it would say hello, and if you said certain words, it would respond with certain things. I was just looking into some tuts and I found a few and copied the code.

Code
<?php
set_time_limit(0);
ini_set('desplay_errors', 'on');
$configure = array(
   'server' => 'ssl://irc.psych0tik.net',
   'port' => 6697,
   'nick' => 't0x0b0t',
   'name' => 'Bot',
   'channel' => '#t0x0p0l0',
   'pass' => null
);
class Bot{
   //TCP connection holder.
   public $socket;
   
   //Message holder.
   public $msg = array();
   
   /*
    * Constucter.
    * Opens the server connection, and logs in the bot.
    *
    * @param array.
    */
   function __construct($configure){
       $this->socket = fsockopen($configure['server'], $configure['port']);
       $this->login($configure);
       $this->main();
       $this->send_data('JOIN', $this->configure['channel']);
   }
   
   /*
    * Logs bot in to server
    *
    * @param array.
    */
   
   function login($configure){
      $this->send_data('USER', $configure['nick'] . ' t0xiksite.herobo.com ' . $configure['nick'] . ' :' . $configure['name']);
      $this->send_data('NICK', $configure['nick']);
   }
   
   /*
    * Main function, used to grab all data.
    *
    */
   
   function main(){
      $data = fgets($this->socket, 128);
      flush();
      $this->ex = explode(' ', $data);
      
      if($this->ex[0] == 'PING'){
         //Plays ping-pong with the server..
         $this->send_data('PONG', $this->ex[1]);
      }
      $command = str_replace(array(chr(10), chr(13)), '', $this->ex[3]);
      
      //List of commands the bot responds to.
      switch($command){
         case ':!say':
            $this->say();
         break;
         case ':!join':
            $this->join_channel($this->ex[4]);
         break;
         
         case ':!quit':
            $this->send_data('QUIT', $this->ex[4]);
         break;
         
         case ':!op':
            $this->op_user();
         break;   
         
         case ':!deop':
            $this->op_user('','', false);
         break;

         case ':!time':
            $this->send_data("PRIVMSG", "Time" . date("F j, Y, g:i a" . time()));
         break;
         
         case 'Hello':
            fputs($socket,"PRIVMSG " . $this->ex[2] . " : Hi!\n");
         break;
         
      }
      $this->main();
   }
   function say(){
      $arraysize = sizeof($this->ex);
      //1,2,3 are just nick and chan, 4 is where text starts
      $count = 4;
      while($count <= $arraysize) {
         $text = $text . " " . $this->ex[$count];
         $count++;
      }
      $this->privmsg($text, $this->ex[2]);
      unset($text);
   }
   
   function privmsg($message, $to){
      fputs($socket,"PRIVMSG " . $to . " :" . $message . "\n");
   }
               
   
   /*
    * Sends data to the server.
    */
   function send_data($cmd, $msg = null){
       if($msg == null){
          fputs($this->socket, $cmd . "\n");
          echo "<b>$cmd</b>";
       }else{
         fputs($this->socket, $cmd.' '.$msg."\n");
         echo "<b>$cmd $msg</b>";
       }
   }
   
   /*
    * Joins a channel.
    *
    * @param text
    */
   function join_channel($channel){
      $this->send_data('JOIN', $channel);
   }
   /*
    * Give/Take operator status.
    */
   function op_user($channel = '', $user = '', $op = true){
      if($channel == '' || $user == ''){
         if($channel == ''){
            $channel = $this->ex[2];
         }
         if($user == ''){
             $user = strstr($this->ex[0], '!', true);
         };
         if($op){
            $this->send_data('MODE', $channel . ' +o ' . $user);
         }else{
            $this->send_data('MODE', $channel . ' -o ' . $user);
         }
      }
   }
}
$bot = new Bot($configure);      
      
         


      
      
?>






I am running it on my EasyPHP server. (I use EasyPHP because XAMPP doesn't work on my pc, also when I began this stuff, it was very useful because it was so simple.)

Anyways, it comes up with this error (after loading for a very very very very long time):

Code
USER t0x0b0t t0xiksite.herobo.com t0x0b0t :BotNICK t0x0b0t
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net
Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
PONG :natalya.psych0tik.net





I have fiddled with it a while, and I remembered that I needed to enable ssl to use the irc and so then I typed ssl:// before the host part in the $config array. Then it said I needed to enable Openssl so I went into php.ini and removed the semi-colon from in front of

Code
;extension=php_openssl.dll




So that it now says

Code
extension=php_openssl.dll




Is this bad? (I was instructed to do this by a website where another guy had to enable openssl)

So basically, I just need the answer to a few questions:

1. How can I fix up the code so that it doesn't load forever
2. Is what I did to try and enable Openssl bad
3. How can I make the code better, or make a better irc bot

Thanks very much in advance,

~t0xik

EDIT: Line 57 is this:

Code
$command = str_replace(array(chr(10), chr(13)), '', $this->ex[3]);




just so's ya know.




Edited by t0xikc0mputer on 19-05-11 01:36
Author

RE: irc bot help in PHP

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 19-05-11 02:36
Just took a quick glance at your code, but have you checked for situations in which ex might not contain 4 elements? That would make your statement fail if it wasn't caught by the 'PING' if statement, no?


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .

Edited by stealth- on 19-05-11 02:36
http://www.stealth-x.com
Author

RE: irc bot help in PHP

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
Posted on 19-05-11 10:21
I believe you also need a "\r\n" after everything you send to the irc server, not just the "\n".


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: irc bot help in PHP

t0xikc0mputer
Member



Posts: 112
Location: t0xik waste dump
Joined: 07.01.11
Rank:
Newbie
Posted on 19-05-11 12:12
Thanks for your responses!

stealth- wrote:
Just took a quick glance at your code, but have you checked for situations in which ex might not contain 4 elements? That would make your statement fail if it wasn't caught by the 'PING' if statement, no?

Is that possible? And now that I look at it, ex[3] would be different if there was no ex[4], right?

techb wrote:
I believe you also need a "\r\n" after everything you send to the irc server, not just the "\n".

Can you give an example so that I get the syntaxes right?

Thanks,

~t0xik

EDIT: I looked up this error and found people having this issue, but they needed to do a "var_dump" with something or other, and I have no idea how this would apply to me.




Edited by t0xikc0mputer on 19-05-11 12:27
Author

RE: irc bot help in PHP

techb
Member



Posts: 384
Location:
Joined: 15.02.09
Rank:
Moderate
Posted on 19-05-11 12:59
Everywhere in your code you see "\n", change it to "\r\n"

I don't really know PHP, but I believe the IRC protocol requires a carriage return character followed by the newline character after every statement sent to the server.


www.userbars.com/74460/665255/337-7865-ubda3219.gif
kbcarte.wordpress.com
Author

RE: irc bot help in PHP


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 19-05-11 15:16
techb wrote:
Everywhere in your code you see "\n", change it to "\r\n"

I don't really know PHP, but I believe the IRC protocol requires a carriage return character followed by the newline character after every statement sent to the server.


Correct, everything TCP related requires CRLF for that matter.
Author

RE: irc bot help in PHP

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 19-05-11 16:10
t0xikc0mputer wrote:
Is that possible? And now that I look at it, ex[3] would be different if there was no ex[4], right?


Well, since you use the function explode(), it will fill the array "ex" with whatever the content is. But what if the server sent you this:

":guy NICK guy1"

The server is telling you "guy" just changed his name to "guy1". How many elements would be in "ex"? Only 3, and since "ex[3]" addresses the fourth element your program would fail.

EDIT: I looked up this error and found people having this issue, but they needed to do a "var_dump" with something or other, and I have no idea how this would apply to me.


var_dump() is a function that outputs the contents of a variable. It's incredibly useful for debugging purposes.

For example, the code:

Code
$test = array(10-19*5/(5+1), 'hi');
var_dump($test);





Will produce this output:

Code

array(2) {
  [0]=>
  float(-5.83333333333)
  [1]=>
  string(2) "hi"
}





It basically lets you see what is going on in your program just by throwing var_dump() statements into various parts.

Hope that helps,
Stealth-


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .

Edited by stealth- on 19-05-11 16:10
http://www.stealth-x.com
Author

RE: irc bot help in PHP

t0xikc0mputer
Member



Posts: 112
Location: t0xik waste dump
Joined: 07.01.11
Rank:
Newbie
Posted on 19-05-11 21:17
I thank you all for your helpful responses.


stealth- wrote:
t0xikc0mputer wrote:
Is that possible? And now that I look at it, ex[3] would be different if there was no ex[4], right?


Well, since you use the function explode(), it will fill the array "ex" with whatever the content is. But what if the server sent you this:

":guy NICK guy1"

The server is telling you "guy" just changed his name to "guy1". How many elements would be in "ex"? Only 3, and since "ex[3]" addresses the fourth element your program would fail.

Any ideas on how I could fix this issue, so that it works better?

Also, thanks for the info on var_dump()!

In response to techb's helpful post, I have done that and am waiting to see if the same error message is obtained with that changed.

Thanks a lot!

~t0xik


Author

RE: irc bot help in PHP

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 19-05-11 23:53
A great way to fix this would be to use var_dump($ex) before you try to call the index [3] of that array, and that way you can see what unexpected data is being passed to your program and work in a method of handling it.


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .
http://www.stealth-x.com
Author

RE: irc bot help in PHP

t0xikc0mputer
Member



Posts: 112
Location: t0xik waste dump
Joined: 07.01.11
Rank:
Newbie
Posted on 20-05-11 01:37
stealth- wrote:
A great way to fix this would be to use var_dump($ex) before you try to call the index [3] of that array, and that way you can see what unexpected data is being passed to your program and work in a method of handling it.

Okay, in that case, then how do I work with if statements that can go into var dump and extract what was or was not encountered?

Also, I know this is glitch fixing, but I just want the initial program to work as well, so any additional ideas for that would be great!

~t0xik


Author

RE: irc bot help in PHP

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 20-05-11 09:24
t0xikc0mputer wrote:
Okay, in that case, then how do I work with if statements that can go into var dump and extract what was or was not encountered?


I'm not sure you understood what I meant. Just insert the var_dump() call like this:

Code
/* ........ */
$data = fgets($this->socket, 128);
flush();
$this->ex = explode(' ', $data);
echo var_dump($this->ex);
/* ....... */




Then run it, and it will do pretty much identical to what it did before, however this time you will be able to see what is exactly contained in ex and you can see what data is causing your program to be behaving incorrectly. That way, you can alter your program afterwards so that it will correctly handle those cases.

var_dump() calls should never be in the final code, it's just useful for inserting there temporarily so the programmer can get some direct feedback of the variables in his program.


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .
http://www.stealth-x.com
Author

RE: irc bot help in PHP

t0xikc0mputer
Member



Posts: 112
Location: t0xik waste dump
Joined: 07.01.11
Rank:
Newbie
Posted on 20-05-11 12:27
stealth- wrote:
t0xikc0mputer wrote:
Okay, in that case, then how do I work with if statements that can go into var dump and extract what was or was not encountered?


I'm not sure you understood what I meant. Just insert the var_dump() call like this:

Code
/* ........ */
$data = fgets($this->socket, 128);
flush();
$this->ex = explode(' ', $data);
echo var_dump($this->ex);
/* ....... */




Then run it, and it will do pretty much identical to what it did before, however this time you will be able to see what is exactly contained in ex and you can see what data is causing your program to be behaving incorrectly. That way, you can alter your program afterwards so that it will correctly handle those cases.

var_dump() calls should never be in the final code, it's just useful for inserting there temporarily so the programmer can get some direct feedback of the variables in his program.

Oh, oh! I thought it would also store it so that you could work with whether there was more than $ex[3]. Now I get it!

Thanks

~t0xik

EDIT: It returned this:

Code
USER t0x0b0t t0xiksite.herobo.com t0x0b0t :BotNICK t0x0b0t
string ':***' (length=4)
string 't0x0b0t' (length=7)
string '(t0x0b0t@0::ffff:173.77.220.171)' (length=32)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 57
string '' (length=0)


Fatal error: Maximum function nesting level of '100' reached, aborting! in \EasyPHP\www\ircbot\index.php on line 49




Also, I believe that I forgot to mention the fatal error earlier, because I didn't see it. The fatal error (above) is referring to line 49 which is this line:

Code
$data = fgets($this->socket, 128);




Should I put the var_dump() there as well? Also, I don't know what the first part of the top part of the var_dump() meant.

Code
string ':***' (length=4)




Is that the real name, because I didn't enter a password.


SECOND EDIT: I put a var_dump() in part of the main() function
(
Code
function main(){
      $data = fgets($this->socket, 128);
      var_dump($data);
      flush();
      $this->ex = explode(' ', $data);
      


) highlighting the $data variable. (the one that we were having the error with on line 49)
and this is what it came out with:

Code
USER t0xb0t t0xiksite.herobo.com t0xb0t :BotNICK t0xb0t
string ':natalya.psych0tik.net NOTICE Auth :*** Looking up your hostname...

' (length=69)
string ':natalya.psych0tik.net NOTICE Auth :*** Found your hostname (*******************************) -- cached

' (length=117)
string ':natalya.psych0tik.net 439 t0xb0t :This server has anti-spambot mechanisms enabled.

' (length=85)
string ':natalya.psych0tik.net 931 t0xb0t :Malicious bots, spammers, and other automated systems of dubious origin are NOT welcome here' (length=127)
string '.

' (length=3)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
string ':natalya.psych0tik.net PRIVMSG t0xb0t :TIME

' (length=47)
string ':natalya.psych0tik.net NOTICE Auth :Welcome to psych0tik!

' (length=61)
string ':natalya.psych0tik.net 001 t0xb0t :Welcome to the psych0tik IRC Network t0xb0t!t0xb0t@***********************************' (length=127)

(length=4)

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
string ':natalya.psych0tik.net 002 t0xb0t :Your host is natalya.psych0tik.net, running version InspIRCd-1.1

' (length=101)
string ':natalya.psych0tik.net 003 t0xb0t :This server was created 18:03:03 Jun 22 2009

' (length=81)
string ':natalya.psych0tik.net 004 t0xb0t natalya.psych0tik.net InspIRCd-1.1 HRinorswx MORbehiklmnoprstv behklov

' (length=106)
string ':natalya.psych0tik.net 005 t0xb0t WALLCHOPS WALLVOICES MODES=19 CHANTYPES=# PREFIX=(ohv)@%+ MAP MAXCHANNELS=20 MAXBANS=60 VBANL' (length=127)
string 'IST NICKLEN=31 CASEMAPPING=rfc1459 STATUSMSG=@%+ CHARSET=ascii :are supported by this server

' (length=94)
string ':natalya.psych0tik.net 005 t0xb0t TOPICLEN=307 KICKLEN=255 MAXTARGETS=20 AWAYLEN=200 CHANMODES=be,k,l,MORimnprst FNC NETWORK=ps' (length=127)
string 'ych0tik MAXPARA=32 ELIST=MU SSL=*:6697; EXCEPTS=e :are supported by this server

' (length=81)
string ':natalya.psych0tik.net 375 t0xb0t :natalya.psych0tik.net message of the day

' (length=77)
string ':natalya.psych0tik.net 372 t0xb0t :-                                     888       .d8888b.  888    d8b 888     

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :-                                     888      d88P  Y88b 888    Y8P 888     

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :-                                     888      888   8888 888        888     

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 88888b.  .d8888b  888  888  .d8888b 88888b.  888  8 888 888888 888 888  888

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 888 "88b 88K      888  888 d88P"    888 "88b 888 8  888 888    888 888 .88P

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 888  888 "Y8888b. 888  888 888      888  888 8888   888 888    888 888888K 

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 888 d88P      X88 Y88b 888 Y88b.    888  888 Y88b  d88P Y88b.  888 888 "88b

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 88888P"   88888P'  "Y88888  "Y8888P 888  888  "Y8888P"   "Y888 888 888  888

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 888                    888                                                 

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 888               Y8b d88P             {www,blog,irc,gsproxy}.psych0tik.net

' (length=114)
string ':natalya.psych0tik.net 372 t0xb0t :- 888                "Y88P"                                                   

' (length=115)
string ':natalya.psych0tik.net 372 t0xb0t :- 

' (length=40)
string ':natalya.psych0tik.net 372 t0xb0t :-                                                             USE A HAMMER!!!

' (length=114)
string ':natalya.psych0tik.net 372 t0xb0t :- I HAERD YOU LIEK MUDKIPZ                           

' (length=91)
string ':natalya.psych0tik.net 372 t0xb0t :- 

' (length=40)
string ':natalya.psych0tik.net 376 t0xb0t :End of message of the day.

' (length=63)
string ':natalya.psych0tik.net 251 t0xb0t :There are 18 users and 17 invisible on 4 servers

' (length=85)
string ':natalya.psych0tik.net 252 t0xb0t 2 :operator(s) online

' (length=57)
string ':natalya.psych0tik.net 254 t0xb0t 21 :channels formed

' (length=55)
string ':natalya.psych0tik.net 255 t0xb0t :I have 27 clients and 3 servers

' (length=68)
string ':natalya.psych0tik.net 265 t0xb0t :Current Local Users: 27  Max: 33

' (length=69)




Then I refreshed it and this is what came up.

EDIT: Scratch what I wrote below, I just restart the server and it works again.

Code
USER t0x0b0t t0xiksite.herobo.com t0x0b0t :BotNICK t0x0b0t
string ':natalya.psych0tik.net NOTICE Auth :*** Looking up your hostname...

' (length=69)
string ':natalya.psych0tik.net 433 * t0x0b0t :Nickname is already in use.

' (length=67)
string 'ERROR :Closing link (t0x0b0t@0::ffff:***.***.***.***) [Registration timeout]

' (length=77)
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58
boolean false

Notice: Undefined offset: 3 in \EasyPHP\www\ircbot\index.php on line 58

Fatal error: Maximum function nesting level of '100' reached, aborting! in \EasyPHP\www\ircbot\index.php on line 49




I know that I am throwing a lot at one time, but I keep finding new things to ask about. I am glad that it connected to the server the first time, but what about the second time? Also, I am not sure why it didn't connect to the specified channel, and I think that may be one of the only things still standing in my way.

Thank you so much for following me through this, and I will be so happy when my final task is accomplished! :happy:

~t0xik




Edited by t0xikc0mputer on 20-05-11 13:59
Author

RE: irc bot help in PHP

stealth-
Member



Posts: 1003
Location: Eh?
Joined: 10.04.09
Rank:
Mad User
Posted on 20-05-11 22:10
Okay, there's a lot to work with here so excuse if this is hard to follow.

I know that I am throwing a lot at one time, but I keep finding new things to ask about. I am glad that it connected to the server the first time, but what about the second time? Also, I am not sure why it didn't connect to the specified channel, and I think that may be one of the only things still standing in my way.


It didn't connect the second time because the server thought you were still logged in from your first program run. It told you the nick was already in use, and waited for you to provide another nick. When you didn't reply, it disconnected you. If you look at the output of the second run you can see what I mean.

Code
Fatal error: Maximum function nesting level of '100' reached, aborting! in \EasyPHP\www\ircbot\index.php on line 49




Also, I believe that I forgot to mention the fatal error earlier, because I didn't see it. The fatal error (above) is referring to line 49 which is this line:


Yeah, you really should have mentioned that error earlier :P
If you look at your function $this->main, look at the very last line of the code. The function calls itself. That's very bad to do it that way, because PHP has a limit to how deep you can go. Every function is still running another instance of itself, and eventually you will reach the limit and PHP will cancel the execution of your program. What your doing is called function recursion, but it's not supposed to be used in that manner. Even if your program successfully connects, it will constantly crash if you use function recursion because as more and more messages are spoken in the IRC, the function will continue to initiate another instance of itself and the old instance stays running and taking up resources. Does that make sense? I can explain it in more depth if necessary.

Your second run crashes because the IRC closes the connection (because you didn't identify a name, like I mentioned above) and you continue to try and get data from it (via fgets()), but it simply returns "false" (because you are disconnected). However your program has no checks for that and will continue to initiate another instance of itself until all the resources are used up.

As for why you are seeing that original warning about ex[3], there are two reasons I noticed right off the bat:

1) When you are disconnected and it returns "false", that's a boolean value that can't be explode()'d and ex[3] won't exist, raising that error.

2) There are a couple of cases where the IRC server returns data that doesn't include spaces. In your first run it returned ".\r\n" at one point, which, when explode()'d, would not have a value at ex[3] and would raise the error as well.

As for why it wasn't joining the channel on the first run, I think we should worry about that later and wait to figure out the immediate problems first.

Thank you so much for following me through this, and I will be so happy when my final task is accomplished! :happy:


I'm glad to help, personally I think you are taking on a project a little over your head at the moment, but you seem genuinely interested in learning from this so I don't mind helping :happy:


The irony of man's condition is that the deepest need is to be free of the anxiety of death and annihilation; but it is life itself which awakens it, and so we must shrink from being fully alive.
http://www.stealt. . .
http://www.stealth-x.com