Web Hosting Talk







View Full Version : fsockopen() Connecting to irc, need help!


[eXtract] William
11-02-2004, 01:42 AM
<?php

$irc_server = "irc.us.gamesurge.net";
$irc_port = "6667";
$irc_nick = "William2004";
$irc_channel = "#test";
$irc_quiet = "Session Ended";

$irc_connection = fsockopen("$irc_server",$irc_port);
fputs($irc_connection, "USER n");
fputs($irc_connection, "NICK $irc_nick n");
fputs($irc_connection, "JOIN #irc_channel n");
fputs($irc_connection, "QUIT $irc_quiet n");

while (!feof($irc_connection) OR !$irc_connection) {
$data = fgets($irc_connection, 1024);
echo str_replace(" ", "<br>", $data);
$match = explode(" ", $data);

if ($match[1] == "001") {
fclose($irc_connection);
exit;
}
}

?>


There is the script so far, It outputs this:

NOTICE
AUTH
:***
Looking
up
your
hostname NOTICE
AUTH
:***
Found
your
hostname,
cached NOTICE
AUTH
:***
Checking
Ident ERROR
:Closing
Link:

by
Kanzi.CA.US.GameSurge.net
(Registration
Timeout)

Im guesing that meens that the USER part is the problem so I cleared it, Does anyone know what the USER part needs in attrubutes? Thanks

[eXtract] William
11-02-2004, 02:11 AM
<?php

$irc_server = "irc.us.gamesurge.net";
$irc_port = "6667";
$localhost = "localhost";
$irc_nick = "William2004";
$irc_realname = "[eXtract] IRC Bot";
$irc_channel = "#test";
$irc_quiet = "Session Ended";

$irc_connection = fsockopen("$irc_server",$irc_port);
fputs($irc_connection, "USER $irc_nick $localhost $irc_server : $irc_realname n");
fputs($irc_connection, "NICK $irc_nick n");
fputs($irc_connection, "JOIN #irc_channel n");
fputs($irc_connection, "QUIT $irc_quiet n");

while (!feof($irc_connection) OR !$irc_connection) {
$data = fgets($irc_connection, 1024);
echo str_replace(" ", "<br>", $data);
$match = explode(" ", $data);

if ($match[1] == "001") {
fclose($irc_connection);
exit;
}
}

?>

Is a update, But it still don't work!

[eXtract] William
11-02-2004, 03:07 AM
<?php

$irc_server = "irc.us.gamesurge.net";
$irc_port = "6667";
$localhost = "localhost";
$irc_nick = "William2004";
$irc_realname = "[eXtract] IRC Bot";
$irc_channel = "#test";
$irc_quiet = "Session Ended";

$irc_connection = fsockopen("$irc_server",$irc_port);
fputs($irc_connection, "USER $irc_nick $localhost $irc_server : $irc_realname \n");
fputs($irc_connection, "NICK $irc_nick \n");
fputs($irc_connection, "JOIN #irc_channel \n");
fputs($irc_connection, "QUIT $irc_quiet \n");

while (!feof($irc_connection) OR !$irc_connection) {
$data = fgets($irc_connection, 1024);
echo str_replace(" ", "<br>", $data);
$match = explode(" ", $data);

if ($match[1] == "001") {
fclose($irc_connection);
exit;
}
}

?>


Now there is this error:
NOTICE
AUTH
:***
Looking
up
your
hostname NOTICE
AUTH
:***
Checking
Ident NOTICE
AUTH
:***
Found
your
hostname PING
:970343986 :NetFire.TX.US.GameSurge.net
451
William2004
William2004
:Register
first.

Alan @ CIT
11-02-2004, 05:41 AM
Just one point ...

fputs($irc_connection, "JOIN #irc_channel \n");

You have a # where you should have a $...

fputs($irc_connection, "JOIN $irc_channel \n");

[eXtract] William
11-02-2004, 05:34 PM
Ya, I noticed that I fixed everything even the USER problem, Now my problem is, (This has nothing to do with sockets is: How do I parse it toget a certian amoun tof data. Heer is new code:



<?php

$irc_server = "irc.us.gamesurge.net";
$irc_port = "6667";
$localhost = "localhost";
$irc_username = "TheHiddenViper";
$irc_nick = "[PHP-IRC-Bot]";
$irc_realname = "[eXtract] IRC Bot";
$irc_channel = "#eXtractbot";
$irc_quiet = "Session Ended";

$irc_connection = fsockopen("$irc_server",$irc_port);

fputs($irc_connection, "NICK $irc_nick \r\n");
sleep(4);
fputs($irc_connection, "USER $irc_username $localhost $irc_server :$irc_realname \r\n");
sleep(4);
fputs($irc_connection, "JOIN $irc_channel \r\n");
sleep(4);
fputs($irc_connection, "QUIT $irc_quiet \r\n");

while (!feof($irc_connection) OR !$irc_connection) {

$data = fgets($irc_connection, 1024);
echo str_replace("\n", "<br>", $data);
$match = explode(" ", $data);

if ($match[1] == "001") {
fclose($irc_connection);
exit;
}
}

?>

Ill end up making a new post sence this one is so old.
But see, In the $data = fgets($irc_connection, 1024); somewhere in there my script is going to recieve PING :18259021861261 i need the script to Parse it so it makes the numbers a varible. :P, Thanks.

Burhan
11-03-2004, 03:14 AM
Just use http://pear.php.net/package/Net_IRC