X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=QServer%2FNeonServ_QServer.class.php;fp=QServer%2FNeonServ_QServer.class.php;h=e3fb4b03194d017f45e4a17abd0e41bd36315891;hp=0000000000000000000000000000000000000000;hb=82f0cd1f3c2c0160944b0c627581f1994583e2b2;hpb=c361012eac11cfc2dc1c7426f7ad1146cebd594f diff --git a/QServer/NeonServ_QServer.class.php b/QServer/NeonServ_QServer.class.php new file mode 100644 index 0000000..e3fb4b0 --- /dev/null +++ b/QServer/NeonServ_QServer.class.php @@ -0,0 +1,150 @@ +. + */ + +class NeonServ_QServer { + private $admin, $socket, $numeric; + + function NeonServ_QServer() { + $this->admin['pass']='*'; // QServer Passwort + $this->admin['host']='127.0.0.1'; + $this->admin['port']=7499; + } + + public function disconnect() { + fclose($this->socket); + $this->socket=false; + } + + public function connect() { + if($this->socket) { + $this->disconnect(); + } + $this->socket=@fsockopen($this->admin['host'], $this->admin['port'], $errno, $errstr, 3); + if ($this->socket) { + stream_set_timeout($this->socket, 2); + fputs($this->socket, "A ".$this->admin['pass']."\n"); + $data = $this->parseLine(@fgets($this->socket)); + if($data[0] == "A") + return true; + $this->disconnect(); //not logged in... + return false; + } + } + + public function connected() { + if($this->socket) return true; + return false; + } + + private function parseLine($line) { + $line = str_replace(array("\r", "\n"), array("", ""), $line); + $highExplode = explode(" :", $line, 2); + $tokens = explode(" ", $highExplode[0]); + if(count($highExplode) > 1) + $tokens[] = $highExplode[1]; + return $tokens; + } + + /* Get IRC User Information + * returns array: nick, ident, host, auth, realname + */ + public function getUser($nick) { + fputs($this->socket, "U ".$nick."\n"); + $data = $this->parseLine(@fgets($this->socket)); + if($data[0] != "U") return NULL; + if($data[1] == "0") return NULL; //User not found + $user = array(); + $user['nick'] = $data[2]; + $user['ident'] = $data[3]; + $user['host'] = $data[4]; + $user['auth'] = ($data[5] == "0" ? NULL : $data[5]); + $user['realname'] = $data[6]; + return $user; + } + + /* Get IRC Channel Information + * returns array: name, usercount, modes, topic + */ + public function getChannel($name) { + fputs($this->socket, "C ".$name."\n"); + $data = $this->parseLine(@fgets($this->socket)); + if($data[0] != "C") return NULL; + if($data[1] == "0") return NULL; //Channel not found + $chan = array(); + $chan['name'] = $data[2]; + $chan['usercount'] = $data[3]; + $chan['modes'] = implode(" ", array_slice($data, 4, (count($data) - 5))); + $chan['topic'] = $data[count($data)-1]; + return $chan; + } + + /* Get All IRC Channels + * returns array with subarrays: name, usercount, modes, topic + */ + public function getChannels() { + fputs($this->socket, "AC\n"); + $channels = array(); + while(true) { + $data = $this->parseLine(@fgets($this->socket)); + if($data[0] == "E") return NULL; + if($data[0] == "ACE") break; + if($data[0] == "AC") { + $chan = array(); + $chan['name'] = $data[1]; + $chan['usercount'] = $data[2]; + $chan['modes'] = implode(" ", array_slice($data, 3, (count($data) - 4))); + $chan['topic'] = $data[count($data)-1]; + $channels[] = $chan; + } + } + return $channels; + } + + /* Get IRC Channel Users + * returns array with subarrays: nick, auth, flags + */ + public function getChannelUsers($name, $invisibles = false) { + fputs($this->socket, "ACU ".$name." ".($invisibles ? "1" : "0")."\n"); + $chanusers = array(); + while(true) { + $data = $this->parseLine(@fgets($this->socket)); + if($data[0] == "E") return NULL; + if($data[0] == "ACUE") break; + if($data[0] == "ACU") { + $chanuser = array(); + $chanuser['nick'] = $data[1]; + $chanuser['auth'] = ($data[2] == "0" ? NULL : $data[2]); + $chanuser['flags'] = $data[3]; + $chanusers[] = $chanuser; + } + } + return $chanusers; + } + + /* send IRC RAW + * returns true / false + */ + public function sendRAW($class, $raw, $classIsNick = false) { + fputs($this->socket, "R ".($classIsNick ? "1" : "0")." ".$class." :".$raw."\n"); + $data = $this->parseLine(@fgets($this->socket)); + if($data[0] == "R" && $data[1] == "1") return true; + return false; + } +} + +?>