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 echo 'Closing Link...'."\n";
42 $this->put('QUIT :'.$msg);
43 if(is_resource($this->C
)) {
48 protected function connect() {
49 $this->C
= @fsockopen
(self
::$server, self
::$port, $errno, $errstr, 10);
51 die('Impossible de se connecter au server IRC !'."\n");
54 $this->put('USER '.self
::$myBotName.' '.self
::$myBotName.'@'.self
::$ip.' '.self
::$domain.' :XBOT');
56 $this->put('NICK '.self
::$myBotName);
59 public function joinChannel($channel) {
60 $this->put('JOIN '.$channel);
61 echo "Join channel $channel ...\n";
64 private function nick_change() {
65 echo "New nick : ".self
::$myBotName."\n";
66 $this->put('NICK :'.self
::$myBotName);
69 public function newNick($new=false) {
71 case self
::$myBotName:
72 echo "New nick : [ERR] no changes :". self
::$myBotName . ' == ' . $new ."\n";
75 self
::$myBotName .= '_';
79 self
::$myBotName = $new;
85 public function put($command) {
86 if (!is_resource($this->C
)) {
87 die("Connection lost...\n");
89 echo '[->' . $command . "\n";
90 fputs($this->C
, $command . "\n");
93 public function get() {
95 stream_set_timeout($this->C
, $this->socketTimeout
);
97 $content = fgets($this->C
, 1024);
103 if (time()-$tmp1 >= $this->socketTimeout
) {