HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

HELP!

Post by bla5e »

Code: Select all

<?php 
set_time_limit(0);

$channels = '#testddt'; 
$nick = 'hereiam'; 
$server = 'irc.gamersrealm.org'; 
//$username = 'username';
//$password = 'password';
$resource = @fsockopen($server, 6667, $errno, $errstr, 30);
if (!$resource) { 
echo 'There was an error with the connection! Error ' . $errstr . ' - Number: ' . $errno; 
} 
else { 
fwrite($resource, 'NICK ' . $nick . "\r\n");
fwrite($resource, 'USER ' . $nick . ' "adelphia.net" "127.0.0.1" :botr' . "\r\n");
while (!feof($resource)) { 
$data = fgets($resource, 1000);
$parray = explode(' ', $data); 

$na = explode('!', $parray[0]);

$address = explode(' ', $na[1]); 
$address = explode('@', $address[0]); 
$address = $address[1];

$channel = $parray[2];
if ($parray[0] == 'PING') { 
fwrite($resource, 'PONG ' . $parray[1] . "\r\n"); 
}
if (eregi("END OF MESSAGE", $data)) {
fwrite($resource, 'MODE ' . $nick . ' +xB' . "\r\n");
//fwrite($resource, 'AUTHSERV auth ' . $username . ' ' . $password . "\r\n");
sleep(5);
fwrite($resource, 'JOIN ' . $channels . "\r\n"); 
}
if (trim($parray[3]) == ':.test') { 
fwrite($resource, 'PRIVMSG ' . $channel . ' :What is it that you want to test?' . "\r\n"); 
}
if (trim($parray[3]) == ':.quit') 
   { 
   fclose($resource); 
   } 

} 
} 
?>
Error I get:
There was an error with the connection! Error The operation completed successfully. - Number: 0
or ill get
There was an error with the connection! Error Success - Number: 0

anyone see any problems?
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Im bumping this post incase someone didnt read it who might beable to help.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Try either putting the port number in a var, or surround it with quotes. I always use:

Code: Select all

$fp = fsockopen($this->serveraddress,$this->serverport, &$err_num, &$err_msg, 30);
And it works fine - as long as the server info is correct or course, and its online.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Theres my full IRC bot class in the code snippet section.
Post Reply