node-gamedig/protocols/mumble.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

const Core = require('./core');
class Mumble extends Core {
2019-01-10 13:03:07 +01:00
async run(state) {
const json = await this.withTcp(async socket => {
return await this.tcpSend(socket, 'json', (buffer) => {
if (buffer.length < 10) return;
const str = buffer.toString();
let json;
try {
json = JSON.parse(str);
} catch (e) {
// probably not all here yet
return;
}
return json;
});
});
2017-08-09 12:32:09 +02:00
2019-01-10 13:03:07 +01:00
state.raw = json;
state.name = json.name;
2019-01-12 12:45:09 +01:00
state.gamePort = json.x_gtmurmur_connectport || 64738;
2019-01-10 13:03:07 +01:00
let channelStack = [state.raw.root];
while(channelStack.length) {
const channel = channelStack.shift();
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);
2017-08-09 12:32:09 +02:00
}
2019-01-10 13:03:07 +01:00
}
2017-08-09 12:32:09 +02:00
}
2017-08-09 12:32:09 +02:00
cleanComment(str) {
return str.replace(/<.*>/g,'');
}
}
module.exports = Mumble;