10 import Utils |
10 import Utils |
11 |
11 |
12 handleCmd_NotEntered :: CmdHandler |
12 handleCmd_NotEntered :: CmdHandler |
13 |
13 |
14 handleCmd_NotEntered clID clients _ ["NICK", newNick] |
14 handleCmd_NotEntered clID clients _ ["NICK", newNick] |
15 | not . null $ nick client = [ProtocolError "Nickname already chosen"] |
15 | not . null $ nick client = [ProtocolError "Nickname already chosen"] |
16 | haveSameNick = [AnswerThisClient ["WARNING", "Nickname already in use"], ByeClient ""] |
16 | haveSameNick = [AnswerThisClient ["WARNING", "Nickname already in use"], ByeClient ""] |
17 | illegalName newNick = [ByeClient "Illegal nickname"] |
17 | illegalName newNick = [ByeClient "Illegal nickname"] |
18 | otherwise = |
18 | otherwise = |
19 ModifyClient (\c -> c{nick = newNick}) : |
19 ModifyClient (\c -> c{nick = newNick}) : |
20 AnswerThisClient ["NICK", newNick] : |
20 AnswerThisClient ["NICK", newNick] : |
21 [CheckRegistered | clientProto client /= 0] |
21 [CheckRegistered | clientProto client /= 0] |
22 where |
22 where |
23 client = clients IntMap.! clID |
23 client = clients IntMap.! clID |
24 haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
24 haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
25 |
25 |
26 |
26 |
27 handleCmd_NotEntered clID clients _ ["PROTO", protoNum] |
27 handleCmd_NotEntered clID clients _ ["PROTO", protoNum] |
28 | clientProto client > 0 = [ProtocolError "Protocol already known"] |
28 | clientProto client > 0 = [ProtocolError "Protocol already known"] |
29 | parsedProto == 0 = [ProtocolError "Bad number"] |
29 | parsedProto == 0 = [ProtocolError "Bad number"] |
30 | otherwise = |
30 | otherwise = |
31 ModifyClient (\c -> c{clientProto = parsedProto}) : |
31 ModifyClient (\c -> c{clientProto = parsedProto}) : |
32 AnswerThisClient ["PROTO", show parsedProto] : |
32 AnswerThisClient ["PROTO", show parsedProto] : |
33 [CheckRegistered | (not . null) (nick client)] |
33 [CheckRegistered | (not . null) (nick client)] |
34 where |
34 where |
35 client = clients IntMap.! clID |
35 client = clients IntMap.! clID |
36 parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
36 parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
37 |
37 |
38 |
38 |
39 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
39 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
40 if passwd == webPassword client then |
40 if passwd == webPassword client then |
41 [ModifyClient (\cl -> cl{logonPassed = True}), |
41 [ModifyClient (\cl -> cl{logonPassed = True}), |
42 MoveToLobby] ++ adminNotice |
42 MoveToLobby] ++ adminNotice |
43 else |
43 else |
44 [ByeClient "Authentication failed"] |
44 [ByeClient "Authentication failed"] |
45 where |
45 where |
46 client = clients IntMap.! clID |
46 client = clients IntMap.! clID |
47 adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client] |
47 adminNotice = [AnswerThisClient ["ADMIN_ACCESS"] | isAdministrator client] |
48 |
48 |
49 |
49 |
50 --handleCmd_NotEntered _ _ _ ["DUMP"] = |
50 --handleCmd_NotEntered _ _ _ ["DUMP"] = |
51 -- [Dump] |
51 -- [Dump] |
52 |
52 |