mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-03 13:01:04 +01:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
var async = require('async');
|
|
|
|
module.exports = require('./protocols/core').extend({
|
|
init: function() {
|
|
this._super();
|
|
this.pretty = 'Mumble';
|
|
this.options.port = 27800;
|
|
this.options.tcpTimeout = 5000;
|
|
},
|
|
run: function(state) {
|
|
var self = this;
|
|
|
|
this.tcpSend('json', function(buffer) {
|
|
if(buffer.length < 10) return;
|
|
var str = buffer.toString();
|
|
var json;
|
|
try {
|
|
json = JSON.parse(str);
|
|
} catch(e) {
|
|
// probably not all here yet
|
|
return;
|
|
}
|
|
|
|
state.raw = json;
|
|
state.name = json.name;
|
|
|
|
var channelStack = [state.raw.root];
|
|
while(channelStack.length) {
|
|
var channel = channelStack.shift();
|
|
channel.description = self.cleanComment(channel.description);
|
|
channelStack = channelStack.concat(channel.channels);
|
|
for(var i = 0; i < channel.users.length; i++) {
|
|
var user = channel.users[i];
|
|
user.comment = self.cleanComment(user.comment);
|
|
state.players.push(user);
|
|
}
|
|
}
|
|
|
|
self.finish(state);
|
|
return true;
|
|
});
|
|
},
|
|
cleanComment: function(str) {
|
|
return str.replace(/<.*>/g,'');
|
|
}
|
|
});
|