
21-10-2005, 19:12
|
 |
|
|
חבר מתאריך: 09.04.04
הודעות: 34
|
|
|
מי שתמיד רצה בוט לIRC בPHP
הנה לכם משהו לעזור להתחיל יותר מהר.
קוד PHP:
<?php define('host','irc.nix.co.il'); define('port',6667); define('nick','easybot'); define('user','easybot'); define('real','easybot'); define('debug',true); $connected = false; set_time_limit(0); while (true) { while (!$connected) { l("!! Connecting..."); $connected = connect(); if (!$connected) sleep(1); } if ($connected) $connected = fetch_and_wait(); } function connect() { global $c; $c = @fsockopen(host,port,$errcatch,$errstrcatch,5); if (!$c) { l("Error connecting: $errcatch $errstrcatch"); return false; } send("NICK ".nick); send("USER ".user." localhost ".host." :".real); return true; } function send($line) { global $c; if (debug) l(">> $line"); fputs($c,$line."\r\n"); } function parse($line) { if (debug) l("<< $line"); if ($line{0} == ':') list($source, $command, $params) = explode(' ',$line,3); else list($command, $params) = explode(' ',$line,2); if (!isset($source)) $source = ''; $command = "_$command"; if (function_exists($command)) $command($source,$params); elseif (debug) l("?< Unknown Command $command"); } function fetch_and_wait() { global $c; stream_set_timeout($c,1,0); $res = fgets($c, 10024); $info = stream_get_meta_data($c); if ($info['timed_out']) return $c; parse($res); return true; } function l($logline) { print "$logline\n"; } function _ping($source, $params) { send("PONG $params"); } function _notice($source, $params) { } ?>
_____________________________________
|