-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayerList.js
44 lines (36 loc) · 833 Bytes
/
playerList.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
40
41
42
43
44
const Player = require('./player.js')
const log = require('loglevel')
class PlayerList {
constructor() {
this.players = {}
}
createPlayer(username, socket) {
var player = new Player(username, socket)
this.addPlayer(player)
return player
}
addPlayer(player) {
this.players[player.uuid] = player
}
deletePlayer(player) {
delete this.players[player.uuid]
}
notify(packet, exceptEid) {
this.forEach(player => player.notify(packet), exceptEid)
}
forEach(f, exceptEid) {
for(var uuid in this.players) {
if(!exceptEid || this.players[uuid].eid != exceptEid) {
f(this.players[uuid])
}
}
}
print(f) {
var str = ''
for(var uuid in this.players) {
str += this.players[uuid].username + ','
}
f(str)
}
}
module.exports = PlayerList