1804
|
1 |
module HWProtoCore where
|
|
2 |
|
|
3 |
import qualified Data.IntMap as IntMap
|
|
4 |
--------------------------------------
|
|
5 |
import CoreTypes
|
|
6 |
import Actions
|
|
7 |
import Utils
|
|
8 |
import HWProtoNEState
|
|
9 |
import HWProtoLobbyState
|
|
10 |
import HWProtoInRoomState
|
|
11 |
|
|
12 |
handleCmd:: CmdHandler
|
|
13 |
|
|
14 |
handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]]
|
|
15 |
|
1814
|
16 |
handleCmd clID clients rooms ("QUIT" : xs) =
|
|
17 |
(if isMaster client then [RemoveRoom] else removeClientTeams)
|
1804
|
18 |
++ [ByeClient msg]
|
|
19 |
where
|
|
20 |
client = clients IntMap.! clID
|
|
21 |
clientNick = nick client
|
|
22 |
msg = if not $ null xs then head xs else ""
|
1814
|
23 |
room = rooms IntMap.! (roomID client)
|
|
24 |
clientTeams = filter (\t -> teamowner t == nick client) $ teams room
|
|
25 |
removeClientTeams = map (RemoveTeam . teamname) clientTeams
|
1804
|
26 |
|
|
27 |
handleCmd clID clients rooms cmd =
|
|
28 |
if null (nick client) || clientProto client == 0 then
|
|
29 |
handleCmd_NotEntered clID clients rooms cmd
|
|
30 |
else if roomID client == 0 then
|
|
31 |
handleCmd_lobby clID clients rooms cmd
|
|
32 |
else
|
|
33 |
handleCmd_inRoom clID clients rooms cmd
|
|
34 |
where
|
|
35 |
client = clients IntMap.! clID
|
|
36 |
|