node-gamedig/protocols/mumble.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

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 12:32:09 +02:00
run(state) {
this.tcpSend('json', (buffer) => {
if(buffer.length < 10) return;
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;
let channelStack = [state.raw.root];
2017-08-09 12:32:09 +02:00
while(channelStack.length) {
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 12:32:09 +02:00
cleanComment(str) {
return str.replace(/<.*>/g,'');
}
}
module.exports = Mumble;