2 |
2 |
3 import qualified Data.IntMap as IntMap |
3 import qualified Data.IntMap as IntMap |
4 import Maybe |
4 import Maybe |
5 import Data.List |
5 import Data.List |
6 import Data.Word |
6 import Data.Word |
|
7 import Control.Monad.Reader |
7 -------------------------------------- |
8 -------------------------------------- |
8 import CoreTypes |
9 import CoreTypes |
9 import Actions |
10 import Actions |
10 import Utils |
11 import Utils |
|
12 import RoomsAndClients |
11 |
13 |
12 handleCmd_NotEntered :: CmdHandler |
14 handleCmd_NotEntered :: CmdHandler |
13 |
15 |
14 {- |
16 handleCmd_NotEntered ["NICK", newNick] = do |
15 handleCmd_NotEntered clID clients _ ["NICK", newNick] |
17 (ci, irnc) <- ask |
16 | not . null $ nick client = [ProtocolError "Nickname already chosen"] |
18 let cl = irnc `client` ci |
17 | haveSameNick = [AnswerThisClient ["WARNING", "Nickname already in use"], ByeClient ""] |
19 if not . null $ nick cl then return [ProtocolError "Nickname already chosen"] |
18 | illegalName newNick = [ByeClient "Illegal nickname"] |
20 else |
19 | otherwise = |
21 if haveSameNick irnc then return [AnswerClients [sendChan cl] ["WARNING", "Nickname already in use"], ByeClient ""] |
20 ModifyClient (\c -> c{nick = newNick}) : |
22 else |
21 AnswerThisClient ["NICK", newNick] : |
23 if illegalName newNick then return [ByeClient "Illegal nickname"] |
22 [CheckRegistered | clientProto client /= 0] |
24 else |
|
25 return $ |
|
26 ModifyClient (\c -> c{nick = newNick}) : |
|
27 AnswerClients [sendChan cl] ["NICK", newNick] : |
|
28 [CheckRegistered | clientProto cl /= 0] |
23 where |
29 where |
24 client = clients IntMap.! clID |
30 haveSameNick irnc = False --isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
25 haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients |
|
26 |
31 |
27 |
32 handleCmd_NotEntered ["PROTO", protoNum] = do |
28 handleCmd_NotEntered clID clients _ ["PROTO", protoNum] |
33 (ci, irnc) <- ask |
29 | clientProto client > 0 = [ProtocolError "Protocol already known"] |
34 let cl = irnc `client` ci |
30 | parsedProto == 0 = [ProtocolError "Bad number"] |
35 if clientProto cl > 0 then return [ProtocolError "Protocol already known"] |
31 | otherwise = |
36 else |
32 ModifyClient (\c -> c{clientProto = parsedProto}) : |
37 if parsedProto == 0 then return [ProtocolError "Bad number"] |
33 AnswerThisClient ["PROTO", show parsedProto] : |
38 else |
34 [CheckRegistered | (not . null) (nick client)] |
39 return $ |
|
40 ModifyClient (\c -> c{clientProto = parsedProto}) : |
|
41 AnswerClients [sendChan cl] ["PROTO", show parsedProto] : |
|
42 [CheckRegistered | (not . null) (nick cl)] |
35 where |
43 where |
36 client = clients IntMap.! clID |
|
37 parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
44 parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
38 |
45 |
|
46 {- |
39 |
47 |
40 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
48 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
41 if passwd == webPassword client then |
49 if passwd == webPassword client then |
42 [ModifyClient (\cl -> cl{logonPassed = True}), |
50 [ModifyClient (\cl -> cl{logonPassed = True}), |
43 MoveToLobby] ++ adminNotice |
51 MoveToLobby] ++ adminNotice |