gameServer/HWProtoNEState.hs
changeset 2352 7eaf82cf0890
parent 2349 ba7a0813c532
child 2747 7889a3a9724f
equal deleted inserted replaced
2351:a4a17b8df591 2352:7eaf82cf0890
     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 handleCmd_NotEntered clID clients _ ["NICK", newNick] =
    14 handleCmd_NotEntered clID clients _ ["NICK", newNick]
    15 	if not . null $ nick client then
    15 	| not . null $ nick client = [ProtocolError "Nickname already chosen"]
    16 		[ProtocolError "Nickname already chosen"]
    16 	| haveSameNick = [AnswerThisClient ["WARNING", "Nickname collision"], ByeClient ""]
    17 	else if haveSameNick then
    17 	| illegalName newNick = [ByeClient "Illegal nickname"]
    18 		[AnswerThisClient ["WARNING", "Nickname collision"]]
    18 	| otherwise =
    19 		++ [ByeClient ""]
    19 		ModifyClient (\c -> c{nick = newNick}) :
    20 	else if illegalName newNick then
    20 		AnswerThisClient ["NICK", newNick] :
    21 		[ByeClient "Illegal nickname"]
    21 		[CheckRegistered | clientProto client /= 0]
    22 	else
       
    23 		[ModifyClient (\c -> c{nick = newNick}),
       
    24 		AnswerThisClient ["NICK", newNick]]
       
    25 		++ checkPassword
       
    26 	where
    22 	where
    27 		client = clients IntMap.! clID
    23 		client = clients IntMap.! clID
    28 		haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients
    24 		haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients
    29 		checkPassword = [CheckRegistered | clientProto client /= 0]
       
    30 
    25 
    31 
    26 
    32 handleCmd_NotEntered clID clients _ ["PROTO", protoNum]
    27 handleCmd_NotEntered clID clients _ ["PROTO", protoNum]
    33 	| clientProto client > 0 = [ProtocolError "Protocol already known"]
    28 	| clientProto client > 0 = [ProtocolError "Protocol already known"]
    34 	| parsedProto == 0 = [ProtocolError "Bad number"]
    29 	| parsedProto == 0 = [ProtocolError "Bad number"]
    35 	| otherwise =
    30 	| otherwise =
    36 		[ModifyClient (\ c -> c{clientProto = parsedProto}),
    31 		ModifyClient (\c -> c{clientProto = parsedProto}) :
    37 		AnswerThisClient ["PROTO", show parsedProto]]
    32 		AnswerThisClient ["PROTO", show parsedProto] :
    38 		++ checkPassword
    33 		[CheckRegistered | (not . null) (nick client)]
    39 	where
    34 	where
    40 		client = clients IntMap.! clID
    35 		client = clients IntMap.! clID
    41 		parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16)
    36 		parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16)
    42 		checkPassword = [CheckRegistered | (not . null) (nick client)]
       
    43 
    37 
    44 
    38 
    45 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] =
    39 handleCmd_NotEntered clID clients _ ["PASSWORD", passwd] =
    46 	if passwd == webPassword client then
    40 	if passwd == webPassword client then
    47 		[ModifyClient (\cl -> cl{logonPassed = True}),
    41 		[ModifyClient (\cl -> cl{logonPassed = True}),