php bot cant connect

Talk about pretty much anything here, but DO NOT USE FOR SUPPORT.

Moderator: Supporters

Locked
wescooldude3
Posts: 6
Joined: Wed Feb 20, 2008 6:15 pm

php bot cant connect

Post by wescooldude3 »

i am using a php bot

<?php
// No execution Time limit
set_time_limit(0);

// Opening the socket to the Rizon network
$socket = fsockopen("wes.dnsdojo.com", 6667) or die('Could not connect to the server');

// Send auth info
$nick = 'ellis-bot2';

fputs($socket,"USER CMbot combined-minds.net CM :CM bot\n");
fputs($socket,"NICK $nick\n");

// Join a channel
fputs($socket,"JOIN #wes\n");

// Endless loop until exit.
while(1)
{
// Continue the rest of the script here
while($data = fgets($socket, 128))
{
echo nl2br($data);
flush();

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

// Respond to PING W/ PONG
if($ex[0] == "PING")
{
fputs($socket, "PONG ".$ex[1]."\n");
}

// Say something in the channel
$command = str_replace(array(chr(10), chr(13)), '', $ex[3]);

switch($command)
{
case ':!sayit':
if($ex[2] != $nick)
{
$to = $ex[2];
}
else
{
$arr = explode('!', $ex[0]);
$to = ltrim($arr[0],':');
}

fputs($socket, "PRIVMSG $to :Combined-Minds.net irc bot tutorial!\n");
break;

case ':!dienow':
fputs($socket,"PRIVMSG ".$ex[2]." Goodbye cruel world!\n");

die('Session ended.');
break;

default:

}
echo '<pre>';
print_r($ex);
echo '</pre>';
}
usleep(100000);
}
?>




But it wont connect to my unreal ircd but it will conect to another unreal ircd
sometimes it will connect or try to connect to mine but it wont go to channel #wes
and i can connect to it with a irc client and i got it where you can connect with 5 instances from the same ip PLEASE HELP!!! :evil: :cry: :evil:
Jobe
Official supporter
Posts: 1180
Joined: Wed May 03, 2006 7:09 pm
Location: United Kingdom

Re: php bot cant connect

Post by Jobe »

Firstly, you'll need to wait until AFTER you've received numeric 001 before sending the JOIN. Otherwise, if the server gets it before the PONG for the PING cookie, the server will ignore it.

If JOIN is sent too early the server will respond:

Code: Select all

:server.name 451 JOIN :You have not registered
In this example -> is to the server and <- is from the server

Code: Select all

-> NICK Eboj
<- PING :778B6886
-> USER Eboj localhost * :Eboj
-> PONG :778B6886
<- :server.name 001 Eboj :Welcome to the network IRC Network Eboj!Eboj@localhost
-> JOIN #test
On a side note, you're supposed to send NICK before USER.

Also are you aware there is a pre-written PHP class for IRC bots? available on http://pear.php.net
Your IP: Image
Your Country: Image
wescooldude3
Posts: 6
Joined: Wed Feb 20, 2008 6:15 pm

Re: php bot cant connect

Post by wescooldude3 »

I wont to make my own php bot can someone help me with the code for connecting to an irc server? I can do the rest. :shock: :shock:
nate
Posts: 148
Joined: Fri Jul 29, 2005 10:12 am
Location: Johnstown, Pa
Contact:

Re: php bot cant connect

Post by nate »

You should look up technical specifications on how connections to an IRC server are meant to be made, step by step per protocol, do that and it won't be hard to understand what you need to do in PHP.
wescooldude3
Posts: 6
Joined: Wed Feb 20, 2008 6:15 pm

Re: php bot cant connect

Post by wescooldude3 »

Where could I learn all about that? :|
Jobe
Official supporter
Posts: 1180
Joined: Wed May 03, 2006 7:09 pm
Location: United Kingdom

Re: php bot cant connect

Post by Jobe »

Your IP: Image
Your Country: Image
Locked