5 // Timeout avant une reconnexion
6 public $socketTimeout = 280;
9 static public $instance = FALSE;
11 static $botVersion = 1.0;
20 private function __construct() {
21 $this->connect(self
::$server, self
::$port);
24 static function Init($server, $port, $channel, $myBotName='XboT', $ip='127.0.0.1', $domain='localhost') {
25 self
::$server = $server;
27 self
::$channel = $channel;
28 self
::$myBotName = preg_replace('`[^_[:alnum:]\`\\\\[\]^-]`', '', $myBotName);
30 self
::$domain = $domain;
33 static function GetInstance() {
34 if(!IRCConn
::$instance) {
35 IRCConn
::$instance = new IRCConn();
37 return IRCConn
::$instance;
40 public function disconnect($msg='EOL ;') {
41 $this->put('QUIT :'.$msg);
42 if(is_resource($this->C
)) {
47 protected function connect() {
48 $this->C
= @fsockopen
(self
::$server, self
::$port, $errno, $errstr, 10);
50 die('Impossible de se connecter au server IRC !'."\n");
53 $this->put('USER '.self
::$myBotName.' '.self
::$myBotName.'@'.self
::$ip.' '.self
::$domain.' :XBOT');
55 $this->put('NICK '.self
::$myBotName);
58 public function joinChannel($channel) {
59 $this->put('JOIN '.$channel);
62 public function newNick() {
63 self
::$myBotName .= '_';
66 public function put($command) {
67 if (!is_resource($this->C
)) {
69 die("Connection lost...\n");
71 echo '[-> ' . $command . "\n";
72 fputs($this->C
, $command . "\n");
75 public function get() {
77 stream_set_timeout($this->C
, $this->socketTimeout
);
79 $content = fgets($this->C
, 1024);
85 if (time()-$tmp1 >= $this->socketTimeout
) {