1 module HWProtoCore where |
1 module HWProtoCore where |
2 |
2 |
3 import qualified Data.IntMap as IntMap |
3 import qualified Data.IntMap as IntMap |
|
4 import Data.Foldable |
|
5 import Maybe |
4 -------------------------------------- |
6 -------------------------------------- |
5 import CoreTypes |
7 import CoreTypes |
6 import Actions |
8 import Actions |
7 import Utils |
9 import Utils |
8 import HWProtoNEState |
10 import HWProtoNEState |
9 import HWProtoLobbyState |
11 import HWProtoLobbyState |
10 import HWProtoInRoomState |
12 import HWProtoInRoomState |
11 |
13 |
12 handleCmd:: CmdHandler |
14 handleCmd, handleCmd_loggedin :: CmdHandler |
13 |
15 |
14 handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]] |
16 handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]] |
15 |
17 |
16 handleCmd clID clients rooms ("QUIT" : xs) = |
18 handleCmd clID clients rooms ("QUIT" : xs) = |
17 (if isMaster client then [RemoveRoom] else removeClientTeams) |
19 (if isMaster client then [RemoveRoom] else removeClientTeams) |
22 msg = if not $ null xs then head xs else "" |
24 msg = if not $ null xs then head xs else "" |
23 room = rooms IntMap.! (roomID client) |
25 room = rooms IntMap.! (roomID client) |
24 clientTeams = filter (\t -> teamowner t == nick client) $ teams room |
26 clientTeams = filter (\t -> teamowner t == nick client) $ teams room |
25 removeClientTeams = map (RemoveTeam . teamname) clientTeams |
27 removeClientTeams = map (RemoveTeam . teamname) clientTeams |
26 |
28 |
|
29 |
27 handleCmd clID clients rooms cmd = |
30 handleCmd clID clients rooms cmd = |
28 if not $ logonPassed client then |
31 if not $ logonPassed client then |
29 handleCmd_NotEntered clID clients rooms cmd |
32 handleCmd_NotEntered clID clients rooms cmd |
30 else if roomID client == 0 then |
33 else |
|
34 handleCmd_loggedin clID clients rooms cmd |
|
35 where |
|
36 client = clients IntMap.! clID |
|
37 |
|
38 |
|
39 handleCmd_loggedin clID clients rooms ["INFO", asknick] = |
|
40 if noSuchClient then |
|
41 [] |
|
42 else |
|
43 [AnswerThisClient |
|
44 ["INFO", |
|
45 nick client, |
|
46 "[" ++ host client ++ "]", |
|
47 protoNumber2ver $ clientProto client, |
|
48 roomInfo]] |
|
49 where |
|
50 maybeClient = find (\cl -> asknick == nick cl) clients |
|
51 noSuchClient = isNothing maybeClient |
|
52 client = fromJust maybeClient |
|
53 room = rooms IntMap.! roomID client |
|
54 roomInfo = if roomID client /= 0 then "room " ++ (name room) else "lobby" |
|
55 |
|
56 |
|
57 handleCmd_loggedin clID clients rooms cmd = |
|
58 if roomID client == 0 then |
31 handleCmd_lobby clID clients rooms cmd |
59 handleCmd_lobby clID clients rooms cmd |
32 else |
60 else |
33 handleCmd_inRoom clID clients rooms cmd |
61 handleCmd_inRoom clID clients rooms cmd |
34 where |
62 where |
35 client = clients IntMap.! clID |
63 client = clients IntMap.! clID |
36 |
|