equal
deleted
inserted
replaced
|
1 {-# LANGUAGE OverloadedStrings #-} |
1 module HWProtoNEState where |
2 module HWProtoNEState where |
2 |
3 |
3 import qualified Data.IntMap as IntMap |
4 import qualified Data.IntMap as IntMap |
4 import Maybe |
5 import Maybe |
5 import Data.List |
6 import Data.List |
6 import Data.Word |
7 import Data.Word |
7 import Control.Monad.Reader |
8 import Control.Monad.Reader |
|
9 import qualified Data.ByteString.Char8 as B |
8 -------------------------------------- |
10 -------------------------------------- |
9 import CoreTypes |
11 import CoreTypes |
10 import Actions |
12 import Actions |
11 import Utils |
13 import Utils |
12 import RoomsAndClients |
14 import RoomsAndClients |
14 handleCmd_NotEntered :: CmdHandler |
16 handleCmd_NotEntered :: CmdHandler |
15 |
17 |
16 handleCmd_NotEntered ["NICK", newNick] = do |
18 handleCmd_NotEntered ["NICK", newNick] = do |
17 (ci, irnc) <- ask |
19 (ci, irnc) <- ask |
18 let cl = irnc `client` ci |
20 let cl = irnc `client` ci |
19 if not . null $ nick cl then return [ProtocolError "Nickname already chosen"] |
21 if not . B.null $ nick cl then return [ProtocolError "Nickname already chosen"] |
20 else |
22 else |
21 if haveSameNick irnc then return [AnswerClients [sendChan cl] ["WARNING", "Nickname already in use"], ByeClient ""] |
23 if haveSameNick irnc then return [AnswerClients [sendChan cl] ["WARNING", "Nickname already in use"], ByeClient ""] |
22 else |
24 else |
23 if illegalName newNick then return [ByeClient "Illegal nickname"] |
25 if illegalName newNick then return [ByeClient "Illegal nickname"] |
24 else |
26 else |
36 else |
38 else |
37 if parsedProto == 0 then return [ProtocolError "Bad number"] |
39 if parsedProto == 0 then return [ProtocolError "Bad number"] |
38 else |
40 else |
39 return $ |
41 return $ |
40 ModifyClient (\c -> c{clientProto = parsedProto}) : |
42 ModifyClient (\c -> c{clientProto = parsedProto}) : |
41 AnswerClients [sendChan cl] ["PROTO", show parsedProto] : |
43 AnswerClients [sendChan cl] ["PROTO", B.pack $ show parsedProto] : |
42 [CheckRegistered | (not . null) (nick cl)] |
44 [CheckRegistered | not . B.null $ nick cl] |
43 where |
45 where |
44 parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16) |
46 parsedProto = case B.readInt protoNum of |
|
47 Just (i, t) | B.null t -> fromIntegral i |
|
48 otherwise -> 0 |
45 |
49 |
46 {- |
50 {- |
47 |
51 |
48 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
52 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] = |
49 if passwd == webPassword client then |
53 if passwd == webPassword client then |