-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverQuery.jsmod
More file actions
56 lines (43 loc) · 1.73 KB
/
serverQuery.jsmod
File metadata and controls
56 lines (43 loc) · 1.73 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
/* ***** BEGIN LICENSE BLOCK *****
* Version: GNU GPL 3.0
*
* The contents of this file are subject to the
* GNU General Public License Version 3.0; you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://www.gnu.org/licenses/gpl.html
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
* ***** END LICENSE BLOCK ***** */
(function tremulousServerStatus($D, $A) {
this.name = this.constructor.name;
this.disabled = true;
this.moduleListener = {
botcmd: {
state: function( modCmd, cmdName, cmdData, command, from, to, msg ) {
var nick = from.split('!',1);
var replyTo = to[0] == '#' ? to : nick;
UDPGet( 'master.tremulous.net', 30710, '\xFF\xFF\xFF\xFFgetservers 69', 5*SECOND, function(status, response) {
if ( status != OK ) {
$A.Privmsg( replyTo, 'failed' );
} else {
var serverList = [];
var buffer = new Buffer();
buffer.Write(response);
buffer.Match('\xFF\xFF\xFF\xFFgetserversResponse\\', true) || Failed('Invalid server response');
var p = new Pack(buffer);
while ( buffer.length >= 7 ) {
var ip = p.ReadInt(1, false) + '.' + p.ReadInt(1, false) + '.' + p.ReadInt(1, false) + '.' + p.ReadInt(1, false);
var port = p.ReadInt(2, false, true);
buffer.Match('\\', true) || Failed('Protocol error');
serverList.push([ip,port]);
}
$A.Privmsg( replyTo, 'got '+serverList.length+' tremulous servers' );
}
});
}
}
}
})