mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-09-27 21:01:34 +02:00
ad9adff06c
* Redo imports and exports for lib * Redo imports and exports for bim * Redo imports and exports for games * Remove remaining module.exports * Use export default in lib * Use export default in protocols * Fix import in genreadme.js * Make package module and solve __dirname * Fix minecraft protocol imports * Fix imports on games and make binary runnable * Renamed protocol class exports to lowercase * Export promises class as default * Update README.md to use imports instead of require * Update CHANGELOG to mention the changes. * Remove Valve unused imports * Fix iconv import
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import Core from './core.js';
|
|
|
|
export default class mumble extends Core {
|
|
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;
|
|
});
|
|
});
|
|
|
|
state.raw = json;
|
|
state.name = json.name;
|
|
state.gamePort = json.x_gtmurmur_connectport || 64738;
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
cleanComment(str) {
|
|
return str.replace(/<.*>/g,'');
|
|
}
|
|
}
|