game search bot

By ODD on Dec 26, 2008

This is my first irc bot made with PHP: idea is simple playing a game that forces you into searching for peopld just type !search bla and it will post in anotehr channel
note : $search_channel cld be turned into an array then while loop it to search into more than one channel

<?php
// Prevent PHP from stopping the script after 30 sec
set_time_limit(0);
//identifying vars
$host = "network";
$nick="php-bot";
$chan="#channel name";
$search_channel = "#channel to search in";
$no_talking = 0;
// Opening the socket
$socket = fsockopen($host, 6667);
// Send auth info
fputs($socket,"USER PHP_BOT bla MHB :bla PHP IRC BOT\n");
fputs($socket,"NICK $nick\n");
// WAIT FOR SIGN IN
while($logincount < 10) {
$logincount++;
 $data = fgets($socket, 128);
      echo nl2br($data);

      // Separate all data
      $ex = explode(' ', $data);

      // Send PONG back to the server
      if($ex[0] == "PING"){
         fputs($socket, "PONG ".$ex[1]."\n");
      }
      flush();
}   
//sleep 10 seconds before joining
sleep(10);
// Join channel
fputs($socket, "JOIN :".$chan."\n");
// Force an endless while
while(1) {
   // Continue the rest of the script here
   while($data = fgets($socket, 128)) {

      echo nl2br($data);
      // Separate all data
      $ex = explode(' ', $data);
      // Send PONG back to the server
      if($ex[0] == "PING"){
         fputs($socket, "PONG ".$ex[1]."\n");
      }
      //seperate username and hostname
      preg_match('/^:(.*?)!(.*?)$/i', $ex[0], $matches);
     $hostname = "!".$matches[2];
     $username = $matches[1];
       //placing what user says in a variable
      $command = str_replace(array(chr(10), chr(13)), '', $ex[3]);
      switch ($command) {
        //welcome message
        case ":!welc":
       fputs($socket, "PRIVMSG ".$chan." :welcome to my channel channel...Soon we are going to have our new set of services here keep checking:) \n");
       break;
       //ending the script
       case ":!end":
       fputs($socket, "QUIT\n");
       break;
       //search for a game through !search
       case ":!search":
       //put what user says in a raw called $say_raw
       $c=4;
       $say_raw = "";
       while (isset($ex[$c])){
       $say_raw .= $ex[$c]." ";
       $c++;
     }
     //send msg to another channel
     fputs($socket, "PRIVMSG ".$search_channel." : ".$username." : searching".$say_raw."\n");
     break;
     default:
     $no_talking++;
     if ($no_talking % 60 == 0){
       fputs($socket, "PRIVMSG ".$chan." :you can use search \n");
     }
     break;
                        }
           flush();
       }
 sleep(1);
 }

?>

Comments

Sign in to comment.
ODD   -  Jan 06, 2009

Actually i did some research.
If you are behind a firewall please allow port 6667 in quakenet or any other necessary port and i think it shall work for you

 Respond  
ODD   -  Jan 06, 2009

about the upper code that was the part i added to fix the problem...

 Respond  
ODD   -  Jan 06, 2009

well i was facing the same situation with quake net but when i added the sign in part it was fixed and i use my bot on quakenet please try it on some other network to see if its just quake or the bot

while($logincount < 10) {
$logincount++;
$data = fgets($socket, 128);
echo nl2br($data);

  // Separate all data
  $ex = explode(' ', $data);

  // Send PONG back to the server
  if($ex[0] == "PING"){
     fputs($socket, "PONG ".$ex[1]."\n");
  }
  flush();

}

 Respond  
axelwai   -  Jan 06, 2009

It shows :
NOTICE AUTH : Looking up your hostname
NOTICE AUTH :
Checking Ident
NOTICE AUTH : Found your hostname
NOTICE AUTH :
No ident respons
ERROR :Closing Link: by port80c.se.quakenet.org (Registration Timeout)

What should I do ?

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.