Witam,
mam problem z fsockopen.
Mój skrypt dostaje na wejściu dane z tail -n0 -f /log/serwera. Ma to być przetwarzane i ewentualnie wysyłane na kanał IRC.
Utknąlem podczas podłączania. Co może być nie tak?
tu kod:
#!/usr/bin/php
<?php
echo "[STATUS] Starting the script.\n"; //First lets set the timeout limit to 0 so the page wont time out.
//set_time_limit(0);
//Also inclue our config file
include("cfg.php");
echo "[STATUS] Included configs.\n";
//Read the data from STDIN
//Now lets connect.
$server = array(); //we will use an array to store all the server data. //Open the socket connection to the IRC server
$server['SOCKET'] = @fsockopen($server_host, $server_port, $errno, $errstr, $server_timeout); if($server['SOCKET'])
{
//Ok, we have connected to the server, now we have to send the login commands.
SendCommand("PASS $server_pass\nr"); //Sends the password not needed for most servers
SendCommand("NICK $nickname\nr"); //sends the nickname
SendCommand("USER $ident\nr"); //sends the user must have 4 paramters
echo "[STATUS] Logged on the server.\n"; while(!feof($server['SOCKET'])) //while we are connected to the server {
$server['READ_BUFFER'] = fgets($server['SOCKET'], 1024
); //get a line of data from the server echo "[RECIVE] ".$server['READ_BUFFER']."\n"; //display the recived data from the server
/*
IRC Sends a "PING" command to the client which must be anwsered with a "PONG"
Or the client gets Disconnected
*/
//Now lets check to see if we have joined the server
if(strpos($server['READ_BUFFER'], "422")) //422 is the message number of the MOTD for the server (The last thing displayed after a successful connection) {
//If we have joined the server
SendCommand("JOIN $server_chan\nr"); //Join the chanel
echo "[STATUS] Joined $server_chan.\n"; }
if(substr($server['READ_BUFFER'], 0, 6) == "PING :") //If the server has sent the ping command {
SendCommand
("PONG :".substr($server['READ_BUFFER'], 6)."\nr"); //Reply with pong //As you can see i dont have it reply with just "PONG"
//It sends PONG and the data recived after the "PING" text on that recived line
//Reason being is some irc servers have a "No Spoof" feature that sends a key after the PING
//Command that must be replied with PONG and the same key sent.
}
//PLAYER_ENTERED |x|_hoax 62.56.79.192 Ś×Ś Hoax
//PLAYER_RENAMED ctxtadd Tadd@crazy-tronners.com 84.57.165.48 1 CTxTadd
while (1) {
{
$name = $keywords[2];
foreach($watched as $wPlayer) {
$command = "PRIVMSG $server_chan :".$date().": I've just found ".$name." on Open Sumo Server\nr";
SendCommand($command);
echo "[STATUS] SENT $command TO $server_chan\n"; }
}
}
flush(); //This flushes the output buffer forcing the text in the while loop to be displayed "On demand" }
}
}
else {
die("[STATUS] $errno $errstr\nr"); }
function SendCommand ($cmd)
{
global $server; //Extends our $server array to this function @fwrite($server['SOCKET'], $cmd, strlen($cmd)); //sends the command to the server //echo "[SEND] $cmd <br>"; //displays it on the screen
}
?>
a tu odpowiedź:
Kod
codezone@joy:~/P4$ ./start_bot.sh
[STATUS] Starting the script.
[STATUS] Included configs.
[STATUS] 110 Connection timed out
serwer na pingi odpowiada, nalezy dodac ze to irc.freenode.net port 6667
pingi z shella dochodza
Ten post edytował P4z 30.11.2008, 08:53:47