gameServer/HWProtoNEState.hs
author unc0rr
Wed, 25 Feb 2009 17:12:32 +0000
changeset 1841 fba7210b438b
parent 1834 71cb978dc85f
child 1844 81abed9d4c11
permissions -rw-r--r--
Retrieve client password from web database and ask for it

module HWProtoNEState where

import qualified Data.IntMap as IntMap
import Maybe
import Data.List
import Data.Word
--------------------------------------
import CoreTypes
import Actions
import Utils

handleCmd_NotEntered :: CmdHandler

handleCmd_NotEntered clID clients _ ["NICK", newNick] =
	if not . null $ nick client then
		[ProtocolError "Nick already chosen"]
	else if haveSameNick then
		[AnswerThisClient ["WARNING", "Nick collision"]]
		++ [ByeClient ""]
	else
		[ModifyClient (\c -> c{nick = newNick}),
		AnswerThisClient ["NICK", newNick]]
		++ checkPassword
	where
		client = clients IntMap.! clID
		haveSameNick = isJust $ find (\cl -> newNick == nick cl) $ IntMap.elems clients
		checkPassword = if clientProto client /= 0 then [CheckRegistered] else []


handleCmd_NotEntered clID clients _ ["PROTO", protoNum] =
	if clientProto client > 0 then
		[ProtocolError "Protocol already known"]
	else if parsedProto == 0 then
		[ProtocolError "Bad number"]
	else
		[ModifyClient (\c -> c{clientProto = parsedProto}),
		AnswerThisClient ["PROTO", show parsedProto]]
		++ checkPassword
	where
		client = clients IntMap.! clID
		parsedProto = fromMaybe 0 (maybeRead protoNum :: Maybe Word16)
		checkPassword = if (not . null) (nick client) then [CheckRegistered] else []

handleCmd_NotEntered clID clients _ ["PASSWORD"] =
	[ModifyClient (\cl -> cl{logonPassed = True}),
	MoveToLobby]


handleCmd_NotEntered _ _ _ ["DUMP"] =
	[Dump]


handleCmd_NotEntered clID _ _ _ = [ProtocolError "Incorrect command (state: not entered)"]