Frage für Prof's | IRCBots [PHP]

Samuel

Erfahrenes Mitglied
frage für pro's

wer kann mir erklären wie ich einen PHP-Irc-Bot mache

ich hoffe das koennen mir einige erklären, ansonsten
sollten wir alle gemeinsam probieren sowas zu realisieren

danke im voraus

daIllu

[Kommentar Kojote]
Kinder, lernt endlich zu layouten .. :)
<input type='text' value='$usersignatur' maxlength='20'>
[/Kommentar Kojote]
 
so etwas wollte ich auch schonmal coden..
ich bin aber nicht soweit gekommen.

man sollte sich im klaren sein das so ein bot extrem hohe traffic
aufkommen verursacht, wenn man ihn mit '!help' befehlen ausrüstet
(beispiel)
aber ich wäre auch interessiert. nur leider kenne ich mich mit den
sockets nicht so gut aus.. also an alle auch von mir einen hilferuf ;)

greetz
 
das hab ich mal zufällig irgendwo gefunden und noch'ne kleinigkeit hinzugefügt:

PHP:
<? 
    // Set the PHP Timeout to 0, so we wont get killed by PHP 
    set_time_limit(0); 

    // define \r\n for easy use 
    define ('CRLF', "\r\n"); 

    // Just some variables we need to connect 
    $nick = 'tester'; // The nick 
    $username = 'me'; // The Username (username@hostname) 
    $localhost = 'localhost'; // The localhost, this dosen't really metter, the server will find the right one, or use your IP. 
    $remotehost = 'irc.quakenet.eu.org'; // The server we are connecting to 
    $realname = 'me myself'; // Your realname, (real my ass;) 
    $channel = '#channel'; // Channel we join to on connect 



    // Open the socket 
    $fp = fsockopen($remotehost,6667, &$err_num, &$err_msg, 30); 

    if(!$fp) { // Error trying to connect 
        print "Sorry, the server is not currently available!"; 
        exit; 
    } 

    // Send the connect data (This is a part of the IRC RCF, read it if you are going to code more irc stuff) 
    $Header = 'NICK ' . $nick . CRLF; 
    $Header .= 'USER ' . $username . ' ' . $localhost . ' ' . $remotehost . ' :' . $realname . CRLF; 
    fputs($fp, $Header); 

    // define response as a variable, so we wont get a error. 
    $response = ''; 
    while (!feof($fp)) { // Make a while loop untill the socket is closed 
        $response .= fgets($fp, 1024); // Append 1024 bytes to $response (if any), from the socket buffer 
        while (substr_count($response,CRLF) != 0) { // Check if there is CRLF (linesplit) in $response, and do that untill none 
            $offset = strpos($response, CRLF); // Just to know where the line ends 
            $data = substr($response,0,$offset); // Split the line from the rest of the data 
            $response = substr($response,$offset+2); // Split the rest from the line 
            if ( substr($data,0,1) == ':' ) { // If the first char is : then go to this loop 
                // Lines starting whit : are in this format 
                // :sender command :text 
                // So we need to split it like that 

                $offsetA = strpos($data, ' '); // Find first space 
                $dFrom = substr($data,1,$offsetA-1); // set $dFrom as the sender 
                $offsetB = strpos($data, ' :'); // Find the first : 
                $dCommand = substr($data,$offsetA+1,$offsetB-$offsetA-1); // Set $dCommand as the command 
                $dText = substr($data,$offsetB+2); // set $dText as the text. 

                if ( substr($dCommand,0,3) == '004' ) { 
                    // This is just a part of the connect headers that the server send. (001,002,003,004,005) 
                    // Some server dont send 005, so i use 004 to know if i´m connected 
                    fputs($fp,'JOIN ' . $channel . CRLF); // Join $channel 
					fputs($fp,'PRIVMSG ' . $master . ' Es funzt!' . CRLF);
                } 
                elseif ( substr($dCommand,0,7) == 'PRIVMSG' ) { 
                    // If somebody msgs us, or if there is some tolk on a channal, this is send. 

                    if ( Ord(substr($dText,0,1)) == 1 ) { 
                        //  If first chars acsii code is 1 then its a CTCP question. 
                        if ( substr($dText,1,4) == 'PING' ) { 
                            // Sombody CTCP pinged us, lets respond 
                            fputs($fp,':' . $nick . ' NOTICE ' . $dFrom . ' :' . chr(1) . 'PING ' . substr($dText,6) . chr(1) . CRLF); 
                        } 
                        elseif ( substr($dText,1,7) == 'VERSION' ) { 
                            // Somebody versiond us, lets respond 
                            fputs($fp,':' . $nick . ' NOTICE ' . $dFrom . ' :' . chr(1) . 'VERSION PHPirc' . chr(1) . CRLF); 
                        } 
						if ( substr($dText,1,5) == 'CLOSE' ) { 
                            // Reaktion auf "/ctcp [botname] close"
                            fclose ($fp); //close socket
                        }                 
				    } 
                    else { 
                        // Else, do this. This is just a relay of all privemsg sent to use, will go right to the server. 
                        // so we can send RAW message for testing:) 
                        fputs($fp,$dText . CRLF); 
                    } 
                } 
                 
            } 
            elseif ( substr($data,0,4) == 'PING' ) { // Else if first 4 chars are PING do this 
                // If the server pings us, respond. This must be done or we will get timeout 
                fputs($fp,'PONG ' . substr($data,5) . CRLF);  
            } 
        } 
    } 
    // If we are here, then the server has disconnected use 
     
    // Close the socket 
    fclose ($fp);     
?>
vllt. hilft's ja ;)
 
script funkt nicht!

Dein Script bringt bei mir folgende Meldung:


Warning: Call-time pass-by-reference has been deprecated - argument
passed by value; If you would like to pass it by reference, modify
the declaration of fsockopen(). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true
in your INI file. However, future versions may not support this any
longer. in /usr/www/users/blub/blab/bot.php on line 19

Warning: Call-time pass-by-reference has been deprecated - argument
passed by value; If you would like to pass it by reference, modify
the declaration of fsockopen(). If you would like to enable call-time
pass-by-reference, you can set allow_call_time_pass_reference to true
in your INI file. However, future versions may not support this any
longer. in /usr/www/users/blub/blab/bot.php on line 19
Sorry, the server is not currently available!

so, was liegt an?
 
Sorry, the server is not currently available!

der server is veraltet, sorry...

wenn du
PHP:
$remotehost = 'irc.quakenet.eu.org';
in
PHP:
$remotehost = 'de.quakenet.org';
änderst, sollte es zumind. auf dem server laufen...


wenn das nichts hilft, dann sorry: kA, von mir is das script nicht
*g* aber bei mir ging's zumindest...
 
bei mir geht das script, also lokal... aber manche server erlauben
nicht des time limit zu verändern..

trotzdem cooles script. man brauch nur nen passenden webserver.

// greetz
 
naja, dann würd ich lieber en richitgen eggdrop nehmen.
der php bot bringt nur was (meiner meinung nach) wenn man
keine andere möglichkeit hat. sprich kein dsl oder keine shell.

sondern nur en freewebspace mit php *FG*

// greetz
 
Zurück