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;
86 * Envoie une notice a un salon / utilisateur
89 * @param string $message
91 public function notice ($to,$message) {
92 self
::put('NOTICE '.$to.' :'.$message."\n");
96 * Envoie un message (PRIVMSG) a un salon / utilisateur
99 * @param string $message
101 public function privmsg ($to,$message) {
102 self
::put('PRIVMSG '.$to.' :'.$message."\n");
105 public function put($command) {
106 if (!is_resource($this->C
)) {
107 die("Connection lost...\n");
109 echo debug() ?
'[->' . $command . "" : '';
110 fputs($this->C
, $command . "\n");
113 public function get() {
115 stream_set_timeout($this->C
, $this->socketTimeout
);
117 $content = fgets($this->C
, 1024);
118 echo debug() ?
"<-]$content" : '';
123 if (time()-$tmp1 >= $this->socketTimeout
) {