forked from gamedig/node-gamedig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mumble.js
39 lines (35 loc) · 1.02 KB
/
mumble.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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, '')
}
}