Jump to content


Irc Php bot


5 replies to this topic

#1 Frozen_W

    Young Padawan

  • Members
  • Pip
  • 186 posts
  • Gender:Male
  • Location:Belgium, Gistel
  • Interests:Just gimme a PC and i'm happy!<br />Also my friends, some concerts, parties,...<br />After the pc, the usual stuff;)

Posted 18 July 2007 - 02:32 PM

Here's the code

<?php
$config = array();
$config['nickname'] = 'Cocktail';
$config['realname'] = 'Frozen Bot';
$config['ident']    = 'cocktailbot';
$config['hostname'] = 0;
$config['server']   = 'irc.krey.net';
$config['poort']    = 6667;
$config['kanalen']  = array('#Frozen');

if(!$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) {
    die('error, unable to create socket');
}
echo 'Socket created'."\n";

if(!socket_bind($socket,$config['hostname'])) {
    die('error connection couldn't be bind on hostname '.$config['hostname'].'.');
}
echo 'connection binded'."\n";

if(!socket_connect($socket,$config['server'],$config['poort'])) {
    die('Unable to connect to server');
}
echo 'Connecting'."\n";

function schrijf($data) {
    global $socket;
    socket_write($socket,$data."\r\n");
}
function zeg($bericht,$ontvanger) {
    schrijf('PRIVMSG '.$ontvanger.' :'.$bericht);
}

schrijf('USER '.$config['ident'].' '.$config['hostname'].' '.$config['server'].' :'.$config['realname']);
schrijf('NICK '.$config['nickname']);

$inKanaal = false;
while($data = @socket_read($socket,65000,PHP_NORMAL_READ)) { 
    if($data == "\n") continue; 
     
    // If $inKanaal still is false, we still have to join
    // We're only able to join if there is a MOTD command.
    if($inKanaal == false && strstr($data,'MOTD')) { 
        for($i = 0; isset($config['kanaal'][$i]); $i++) { 
            schrijf('JOIN '.$config['kanaal'][$i]); 
            zeg('Ik ben een überbot!',$config['kanaal'][$i]); 
        } 
        $inKanaal = true; 
    } 
 
    // IRC-server will send a ping that needs to be answerd with pong (so you wouldn't be kicked => ghost client)
    $eData = explode(' ',$data); 
    if($eData[0] == 'PING') { 
        schrijf('PONG '.$eData[1]); 
    } 
 
// Code here (bot commands)
}
 
?>

So, my browser says it does it's connections (using xampp) and so on, but the bot just doesn't join the channel :P
Anybody knows why this is?

Thx
Greetz

Edited by Frozen_W, 20 July 2007 - 05:16 AM.


#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 19 July 2007 - 12:32 PM

Hm,

Is your PHP configured to handle 'global' variables? Most hostings don't allow it by default... (just a guess)


dotbart

#3 Frozen_W

    Young Padawan

  • Members
  • Pip
  • 186 posts
  • Gender:Male
  • Location:Belgium, Gistel
  • Interests:Just gimme a PC and i'm happy!<br />Also my friends, some concerts, parties,...<br />After the pc, the usual stuff;)

Posted 19 July 2007 - 03:40 PM

don't think it's due the global, It should be configured to use globals
Pff really don't get it :)

Other suggestions

#4 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 19 July 2007 - 03:59 PM

View Postdotbart, on Jul 19 2007, 12:32 PM, said:

Hm,

Is your PHP configured to handle 'global' variables? Most hostings don't allow it by default... (just a guess)


dotbart

What are you talking about? You may be getting that confused with register_globals, which simply means that (if set 'On'), all $_POST and $_GET variable are automatically parsed into their own variables ($_POST['foo'] and $_GET['bar'] get parsed into $foo and $bar... you can see how much of a security risk this is obviously).

Anyways, sorry I can't really help because I don't know much when it comes to sockets, and I can't read the comments because I can only read English and French.
I just had to ask what dotbart was talking about really.

#5 Frozen_W

    Young Padawan

  • Members
  • Pip
  • 186 posts
  • Gender:Male
  • Location:Belgium, Gistel
  • Interests:Just gimme a PC and i'm happy!<br />Also my friends, some concerts, parties,...<br />After the pc, the usual stuff;)

Posted 20 July 2007 - 05:12 AM

Now you say it:p
Indeed global vars is about that.

Err sorry about the lang:p it's dutch, I'll change it just for you:p (and for anyone who's intrested:p)

Greetz

#6 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 20 July 2007 - 05:37 AM

Oh I tought it was about the use of global variables.
I guess you learn something every day :D

In that case, can't help





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users