9 import Actions |
9 import Actions |
10 import Utils |
10 import Utils |
11 |
11 |
12 handleCmd_NotEntered :: CmdHandler |
12 handleCmd_NotEntered :: CmdHandler |
13 |
13 |
14 onLoginFinished :: Int -> String -> Word16 -> Clients -> [Action] |
|
15 onLoginFinished clID clientNick clProto clients = |
|
16 if (null $ clientNick) || (clProto == 0) then |
|
17 [] |
|
18 else |
|
19 (RoomAddThisClient 0) |
|
20 : CheckRegistered |
|
21 : answerLobbyNicks |
|
22 -- ++ (answerServerMessage client clients) |
|
23 where |
|
24 lobbyNicks = filter (\n -> (not (null n))) $ map nick $ IntMap.elems clients |
|
25 answerLobbyNicks = if not $ null lobbyNicks then |
|
26 [AnswerThisClient (["LOBBY:JOINED"] ++ lobbyNicks)] |
|
27 else |
|
28 [] |
|
29 |
|
30 |
|
31 handleCmd_NotEntered clID clients _ ["NICK", newNick] = |
14 handleCmd_NotEntered clID clients _ ["NICK", newNick] = |
32 if not . null $ nick client then |
15 if not . null $ nick client then |
33 [ProtocolError "Nick already chosen"] |
16 [ProtocolError "Nick already chosen"] |
34 else if haveSameNick then |
17 else if haveSameNick then |
35 [AnswerThisClient ["WARNING", "Nick collision"]] |
18 [AnswerThisClient ["WARNING", "Nick collision"]] |
36 ++ [ByeClient ""] |
19 ++ [ByeClient ""] |
37 else |
20 else |
38 [ModifyClient (\c -> c{nick = newNick}), |
21 [ModifyClient (\c -> c{nick = newNick}), |
39 AnswerThisClient ["NICK", newNick]] |
22 AnswerThisClient ["NICK", newNick]] |
40 ++ (onLoginFinished clID newNick (clientProto client) clients) |
23 ++ checkPassword |
41 where |
24 where |
42 client = clients IntMap.! clID |
25 client = clients IntMap.! clID |
43 haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
26 haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
|
27 checkPassword = if clientProto client /= 0 then [CheckRegistered] else [] |
44 |
28 |
45 |
29 |
46 handleCmd_NotEntered clID clients _ ["PROTO", protoNum] = |
30 handleCmd_NotEntered clID clients _ ["PROTO", protoNum] = |
47 if clientProto client > 0 then |
31 if clientProto client > 0 then |
48 [ProtocolError "Protocol already known"] |
32 [ProtocolError "Protocol already known"] |
49 else if parsedProto == 0 then |
33 else if parsedProto == 0 then |
50 [ProtocolError "Bad number"] |
34 [ProtocolError "Bad number"] |
51 else |
35 else |
52 [ModifyClient (\c -> c{clientProto = parsedProto}), |
36 [ModifyClient (\c -> c{clientProto = parsedProto}), |
53 AnswerThisClient ["PROTO", show parsedProto]] |
37 AnswerThisClient ["PROTO", show parsedProto]] |
54 ++ (onLoginFinished clID (nick client) parsedProto clients) |
38 ++ checkPassword |
55 where |
39 where |
56 client = clients IntMap.! clID |
40 client = clients IntMap.! clID |
57 parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
41 parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
|
42 checkPassword = if (not . null) (nick client) then [CheckRegistered] else [] |
|
43 |
|
44 handleCmd_NotEntered clID clients _ ["PASSWORD"] = |
|
45 [ModifyClient (\cl -> cl{logonPassed = True}), |
|
46 MoveToLobby] |
58 |
47 |
59 |
48 |
60 handleCmd_NotEntered _ _ _ ["DUMP"] = |
49 handleCmd_NotEntered _ _ _ ["DUMP"] = |
61 [Dump] |
50 [Dump] |
62 |
51 |