-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnmgr.pony
39 lines (30 loc) · 933 Bytes
/
connmgr.pony
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
use "net"
use "collections"
actor ConnectionManager
let _out: OutStream
let _players: MapIs[TCPConnection, Player]
new create(out: OutStream) =>
_players = MapIs[TCPConnection, Player]
_out = out
_out.print("connection manager created")
be accepted(conn: TCPConnection tag) =>
_out.print("[CM] Connection accepted.")
let p = Player(this, conn)
_players(conn) = p
_out.print(_players.size().string() + " players online.")
be closed(conn: TCPConnection tag) =>
try
_players.remove(conn)
end
_out.print("[CM] Connection closed.")
be cmdreceived(conn: TCPConnection, cmd: String) =>
_out.print("[CM] received command text.")
try
_players(conn).parsecommand(cmd)
end
be broadcast(msg: String) =>
_bcast(msg)
fun _bcast(msg: String) =>
for player in _players.values() do
player.tell(msg)
end