-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMumbleReader.class.php
More file actions
192 lines (179 loc) · 5.87 KB
/
MumbleReader.class.php
File metadata and controls
192 lines (179 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
* Copyright 2010 Pimmetje
* contact Pimmetje (at) gmail (dot) com
*
* Past of the PHP code is based on what i leared from the mumble viewer
* http://sourceforge.net/projects/mumbleviewer/ this code is GPL licenced
* All code i have used is refactored and commented.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
mumblereader::$useNewAPI = version_compare(Ice_stringVersion(), '3.4', '>=');
if(mumblereader::$useNewAPI) {
//This is because of a bug in ICE. It's wont work if a method includes those files. This should happen in init ice if the bug is fixed in a later version
require_once 'Ice.php';
require_once 'Murmur.php';
}
class mumblereader {
public static $useNewAPI;
private $port;
private $ice;
public function mumblereader($port) {
$this->ice = $this->init_ICE();
$this->port = $port;
}
/**
* Create's a ICE object
*
* @return ice object
*/
private function init_ICE() {
if(!self::$useNewAPI) {
global $ICE;
Ice_loadProfile();
$base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502");
return $base->ice_checkedCast("::Murmur::Meta");
} else {
$ICE = Ice_initialize();
return Murmur_MetaPrxHelper::checkedCast($ICE->stringToProxy('Meta:tcp -h 127.0.0.1 -p 6502'));
}
}
/**
* Converts recursively an Ice-Channel to an array.
*
* @param IceObject $iceChannel
* @return Channel-Array
*/
private function loadChannel($iceChannel) {
$channel = array();
$channel['id'] = $iceChannel->c->id;
$channel['name'] = $iceChannel->c->name;
$channel['parent'] = $iceChannel->c->parent;
$channel['channels'] = array();
$channel['users'] = array();
$channel['links'] = array();
foreach ($iceChannel->children as $_channel) {
$channel['channels'][] = $this->loadChannel($_channel);
}
// for mumble 1.1.x compability!
if (isset($iceChannel->players) && $iceChannel->players != null) {
foreach ($iceChannel->players as $_player) {
$channel['users'][] = $this->loadUser($_player);
}
} else if ($iceChannel->users != null) {
foreach ($iceChannel->users as $_user) {
$channel['users'][] = $this->loadUser($_user);
}
}
return $channel;
}
/**
* Converts recursively an Ice-User to an array.
*
* @param IceObject $iceUser
* @return User-Array
*/
private function loadUser($iceUser) {
$user = array();
$user['session'] = $iceUser->session;
$user['userid'] = isset($iceUser->playerid) ? $iceUser->playerid : isset($iceUser->userid) ? $iceUser->userid : '';
$user['mute'] = $iceUser->mute;
$user['deaf'] = $iceUser->deaf;
$user['suppressed'] = isset($iceUser->suppressed) ? $iceUser->suppressed : '';
$user['selfMute'] = $iceUser->selfMute;
$user['selfDeaf'] = $iceUser->selfDeaf;
$user['channel'] = $iceUser->channel;
$user['name'] = $iceUser->name;
$user['onlinesecs'] = $iceUser->onlinesecs;
$user['idlesecs'] = $iceUser->idlesecs;
$user['os'] = $iceUser->os;
$user['release'] = $iceUser->release;
$user['bytespersec'] = $iceUser->bytespersec;
return $user;
}
/**
* Load all data to a array
*
* @return array of the server
*/
private function loadData() {
$servers = $this->ice->getBootedServers();
$default = $this->ice->getDefaultConf();
foreach ($servers as $id => $iceServer) {
if($iceServer->getConf('port') == $this->port) {
$port = $iceServer->getConf('port');
$servername = $iceServer->getConf("registername");
$tree = $iceServer->getTree();
$uptime = $iceServer->getUptime();
$server['root'] = $this->loadChannel($tree);
$server['name'] = $servername;
$server['id'] = $tree->c->id;
$server['uptime'] = $uptime;
$server['x_connecturl'] = "conurl";
return $server;
}
}
return null;
}
/**
* Load all data from a server tree to a array
*
* @return array of the server
*/
private function loadTree() {
$servers = $this->ice->getBootedServers();
$default = $this->ice->getDefaultConf();
foreach ($servers as $id => $iceServer) {
if($iceServer->getConf('port') == $this->port) {
$tree = $iceServer->getTree();
$array = get_object_vars($tree);
return $array;
}
}
return null;
}
/**
* Render JSON(P) output for this server
*
* @return JSON(P) representing the server
*/
public function renderTree() {
return $this->renderJsonP($this->loadTree());
}
/**
* Render JSON(P) output for this server
*
* @return JSON(P) representing the server
*/
public function render() {
return $this->renderJsonP($this->loadData());
}
/**
* Make from a array a json or jsonp string (depending on is $_GET['callback'] is set)
*
* @param $d the array that needs to be converted
* @return json(p) string
*/
private function renderJsonP($d) {
$data = json_encode($d);
$callback = '';
if(isset($_GET['callback'])) {$callback = $_GET['callback'];}
if(!empty($callback)) {
return $callback . '(' . $data . ');';
} else {
return $data;
}
}
}