2 /* NeonServ_QServer.class.php - NeonServ v5
3 * Copyright (C) 2011-2012 Philipp Kreil (pk910)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 class NeonServ_QServer {
20 private $admin, $socket, $numeric;
22 function NeonServ_QServer() {
23 $this->admin['pass']='*'; // QServer Passwort
24 $this->admin['host']='127.0.0.1';
25 $this->admin['port']=7499;
28 public function disconnect() {
29 fclose($this->socket);
33 public function connect() {
37 $this->socket=@fsockopen($this->admin['host'], $this->admin['port'], $errno, $errstr, 3);
39 stream_set_timeout($this->socket, 2);
40 fputs($this->socket, "A ".$this->admin['pass']."\n");
41 $data = $this->parseLine(@fgets($this->socket));
44 $this->disconnect(); //not logged in...
49 public function connected() {
50 if($this->socket) return true;
54 private function parseLine($line) {
55 $line = str_replace(array("\r", "\n"), array("", ""), $line);
56 $highExplode = explode(" :", $line, 2);
57 $tokens = explode(" ", $highExplode[0]);
58 if(count($highExplode) > 1)
59 $tokens[] = $highExplode[1];
63 /* Get IRC User Information
64 * returns array: nick, ident, host, auth, realname
66 public function getUser($nick) {
67 fputs($this->socket, "U ".$nick."\n");
68 $data = $this->parseLine(@fgets($this->socket));
69 if($data[0] != "U") return NULL;
70 if($data[1] == "0") return NULL; //User not found
72 $user['nick'] = $data[2];
73 $user['ident'] = $data[3];
74 $user['host'] = $data[4];
75 $user['auth'] = ($data[5] == "0" ? NULL : $data[5]);
76 $user['realname'] = $data[6];
80 /* Get IRC Channel Information
81 * returns array: name, usercount, modes, topic
83 public function getChannel($name) {
84 fputs($this->socket, "C ".$name."\n");
85 $data = $this->parseLine(@fgets($this->socket));
86 if($data[0] != "C") return NULL;
87 if($data[1] == "0") return NULL; //Channel not found
89 $chan['name'] = $data[2];
90 $chan['usercount'] = $data[3];
91 $chan['modes'] = implode(" ", array_slice($data, 4, (count($data) - 5)));
92 $chan['topic'] = $data[count($data)-1];
96 /* Get All IRC Channels
97 * returns array with subarrays: name, usercount, modes, topic
99 public function getChannels() {
100 fputs($this->socket, "AC\n");
103 $data = $this->parseLine(@fgets($this->socket));
104 if($data[0] == "E") return NULL;
105 if($data[0] == "ACE") break;
106 if($data[0] == "AC") {
108 $chan['name'] = $data[1];
109 $chan['usercount'] = $data[2];
110 $chan['modes'] = implode(" ", array_slice($data, 3, (count($data) - 4)));
111 $chan['topic'] = $data[count($data)-1];
118 /* Get IRC Channel Users
119 * returns array with subarrays: nick, auth, flags
121 public function getChannelUsers($name, $invisibles = false) {
122 fputs($this->socket, "ACU ".$name." ".($invisibles ? "1" : "0")."\n");
123 $chanusers = array();
125 $data = $this->parseLine(@fgets($this->socket));
126 if($data[0] == "E") return NULL;
127 if($data[0] == "ACUE") break;
128 if($data[0] == "ACU") {
130 $chanuser['nick'] = $data[1];
131 $chanuser['auth'] = ($data[2] == "0" ? NULL : $data[2]);
132 $chanuser['flags'] = $data[3];
133 $chanusers[] = $chanuser;
140 * returns true / false
142 public function sendRAW($class, $raw, $classIsNick = false) {
143 fputs($this->socket, "R ".($classIsNick ? "1" : "0")." ".$class." :".$raw."\n");
144 $data = $this->parseLine(@fgets($this->socket));
145 if($data[0] == "R" && $data[1] == "1") return true;