2017-08-09 11:05:55 +02:00
|
|
|
class Mumble extends require('./core') {
|
2017-08-09 12:32:09 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
2018-01-31 11:03:13 +01:00
|
|
|
this.options.socketTimeout = 5000;
|
2017-08-09 12:32:09 +02:00
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
run(state) {
|
|
|
|
this.tcpSend('json', (buffer) => {
|
|
|
|
if(buffer.length < 10) return;
|
2017-08-09 11:05:55 +02:00
|
|
|
const str = buffer.toString();
|
2017-08-09 12:32:09 +02:00
|
|
|
let json;
|
|
|
|
try {
|
|
|
|
json = JSON.parse(str);
|
|
|
|
} catch(e) {
|
|
|
|
// probably not all here yet
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
state.raw = json;
|
|
|
|
state.name = json.name;
|
2017-08-09 11:05:55 +02:00
|
|
|
|
|
|
|
let channelStack = [state.raw.root];
|
2017-08-09 12:32:09 +02:00
|
|
|
while(channelStack.length) {
|
2017-08-09 11:05:55 +02:00
|
|
|
const channel = channelStack.shift();
|
2017-08-09 12:32:09 +02:00
|
|
|
channel.description = this.cleanComment(channel.description);
|
|
|
|
channelStack = channelStack.concat(channel.channels);
|
|
|
|
for(const user of channel.users) {
|
|
|
|
user.comment = this.cleanComment(user.comment);
|
|
|
|
state.players.push(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.finish(state);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
cleanComment(str) {
|
|
|
|
return str.replace(/<.*>/g,'');
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Mumble;
|