Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: IRC klient w php
Forum PHP.pl > Forum > PHP
P4z
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:
  1. #!/usr/bin/php
  2. <?php
  3. echo "[STATUS] Starting the script.\n";
  4. //First lets set the timeout limit to 0 so the page wont time out.
  5. //set_time_limit(0);
  6. //Also inclue our config file
  7. include("cfg.php");
  8. echo "[STATUS] Included configs.\n";
  9.  
  10. //Read the data from STDIN
  11.  
  12. //Now lets connect.
  13. $server = array(); //we will use an array to store all the server data.
  14. //Open the socket connection to the IRC server
  15. $server['SOCKET'] = @fsockopen($server_host, $server_port, $errno, $errstr, $server_timeout);
  16. if($server['SOCKET'])
  17. {
  18.    //Ok, we have connected to the server, now we have to send the login commands.
  19.    SendCommand("PASS $server_pass\nr"); //Sends the password not needed for most servers
  20.    SendCommand("NICK $nickname\nr"); //sends the nickname
  21.    SendCommand("USER $ident\nr"); //sends the user must have 4 paramters
  22.    echo "[STATUS] Logged on the server.\n";
  23.    while(!feof($server['SOCKET'])) //while we are connected to the server
  24.    {
  25.        $server['READ_BUFFER'] = fgets($server['SOCKET'], 1024); //get a line of data from the server
  26.        echo "[RECIVE] ".$server['READ_BUFFER']."\n"; //display the recived data from the server
  27.        
  28.        /*
  29.         IRC Sends a "PING" command to the client which must be anwsered with a "PONG"
  30.         Or the client gets Disconnected
  31.         */
  32.        //Now lets check to see if we have joined the server
  33.        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)
  34.        {
  35.            //If we have joined the server
  36.            
  37.            SendCommand("JOIN $server_chan\nr"); //Join the chanel
  38.            echo "[STATUS] Joined $server_chan.\n";
  39.        }
  40.        if(substr($server['READ_BUFFER'], 0, 6) == "PING :") //If the server has sent the ping command
  41.        {
  42.            SendCommand("PONG :".substr($server['READ_BUFFER'], 6)."\nr"); //Reply with pong
  43.            //As you can see i dont have it reply with just "PONG"
  44.            //It sends PONG and the data recived after the "PING" text on that recived line
  45.            //Reason being is some irc servers have a "No Spoof" feature that sends a key after the PING
  46.            //Command that must be replied with PONG and the same key sent.
  47.            echo "[STATUS] PONG.\n";
  48.        }
  49. //PLAYER_ENTERED |x|_hoax 62.56.79.192 Ś×Ś Hoax
  50. //PLAYER_RENAMED ctxtadd Tadd@crazy-tronners.com 84.57.165.48 1 CTxTadd
  51.        
  52.        while (1) {
  53.            $data = rtrim(fgets(STDIN, 1024));
  54.            $keywords = preg_split("/ /", $data);
  55.            if (preg_match("/^PLAYER_ENTERED /", $data) OR preg_match("/^PLAYER_RENAMED /", $data))
  56.            {    
  57.                $name = $keywords[2];
  58.                foreach($watched as $wPlayer) {
  59.                    if (preg_match($wPlayer,$name)) {
  60.                        $command = "PRIVMSG $server_chan :".$date().": I've just found ".$name." on Open Sumo Server\nr";
  61.                        SendCommand($command);
  62.                        echo "[STATUS] SENT $command TO $server_chan\n";
  63.                    }
  64.                }
  65.  
  66.            }
  67.            flush(); //This flushes the output buffer forcing the text in the while loop to be displayed "On demand"
  68.        }
  69.    }
  70.    @fclose($server['SOCKET']);
  71. }
  72. else {
  73.    die("[STATUS] $errno $errstr\nr");
  74. }
  75.  
  76.  
  77. function SendCommand ($cmd)
  78. {
  79.    global $server; //Extends our $server array to this function
  80.    @fwrite($server['SOCKET'], $cmd, strlen($cmd)); //sends the command to the server
  81.    //echo "[SEND] $cmd <br>"; //displays it on the screen
  82. }
  83. ?>



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
batman
Nie ten dział. Przenoszę na PHP.
Kamson
może zabukowane fsockopen lub porty u dostawcy, testowałeś jakiegoś klienta irc z shela?
P4z
Tak, to nasz VPS, klient dziala, supybot dziala, ww skrypt nie dziala. Debugowac pewnie nie mozna, chyba ze sie myle?
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.