3 // old file, will be deleted
7 // Timeout avant une reconnexion
8 public $socketTimeout = 280;
11 static public $instance = FALSE;
13 static $botVersion = '1.0';
20 static $connection_password;
23 private function __construct() {
24 $this->connect(self
::$server, self
::$port);
27 static function Init($server, $port, $channel, $myBotName='XboT', $ip='127.0.0.1', $domain='localhost', $connection_password=false) {
28 self
::$server = $server;
30 self
::$channel = $channel;
31 self
::$myBotName = preg_replace('`[^_[:alnum:]\`\\\\[\]^-]`', '', $myBotName);
33 self
::$domain = $domain;
34 self
::$connection_password = $connection_password;
37 static function GetInstance() {
38 if (!IRCConn
::$instance) {
39 IRCConn
::$instance = new IRCConn();
41 return IRCConn
::$instance;
44 public function disconnect($msg='EOL ;') {
45 echo 'Closing Link...'."\n";
46 $this->put('QUIT :'.$msg);
47 if (is_resource($this->C
)) {
53 protected function connect() {
54 $this->C
= @fsockopen
(self
::$server, self
::$port, $errno, $errstr, 10);
56 echo "Impossible de se connecter au server IRC !\n";
59 if (self
::$connection_password!==false) {
60 $this->put('PASS '.self
::$connection_password);
62 // TODO : be sure for the validity of the connection password
64 $this->put('USER '.self
::$myBotName.' '.self
::$myBotName.'@'.self
::$ip.' '.self
::$domain.' :XBOT');
66 $this->put('NICK '.self
::$myBotName);
69 public function joinChannel($channel) {
70 $this->put('JOIN '.$channel);
71 echo "Join channel $channel ...\n";
74 private function nick_change() {
75 echo "New nick : ".self
::$myBotName."\n";
76 $this->put('NICK :'.self
::$myBotName);
79 public function newNick($new=false) {
81 case self
::$myBotName:
82 echo "New nick : [ERR] no changes :". self
::$myBotName . ' == ' . $new ."\n";
85 self
::$myBotName .= '_';
89 self
::$myBotName = $new;
96 * Envoie une notice a un salon / utilisateur
99 * @param string $message
101 public function notice ($to,$message) {
102 echo "ERROR : deprecated use of notice function. Please use IRCMain::notice\n";
103 return self
::put('NOTICE '.$to.' :'.$message."\n");
107 * Envoie un message (PRIVMSG) a un salon / utilisateur
110 * @param string $message
112 public function privmsg ($to,$message) {
113 echo "ERROR : deprecated use of privmsg function. Please use IRCMain::privmsg\n";
114 return self
::put('PRIVMSG '.$to.' :'.$message."\n");
117 public function put($command) {
118 if (!is_resource($this->C
)) {
119 self
::error(1,'Connection lost...');
122 echo debug() ?
'[->' . $command . "" : '';
123 fputs($this->C
, $command . "\n");
127 public function get() {
129 stream_set_timeout($this->C
, $this->socketTimeout
);
131 $content = fgets($this->C
, 1024);
132 echo debug() ?
"<-]$content" : '';
133 if ($content != '') {
137 if (time()-$tmp1 >= $this->socketTimeout
) {
138 self
::error(0,'TIMEOUT');