gameServer/HWProtoNEState.hs
author koda
Thu, 09 Jul 2009 00:56:26 +0000
changeset 2244 853a1db1cff6
parent 2155 d897222d3339
child 2349 ba7a0813c532
permissions -rw-r--r--
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general

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 "Nickname already chosen"]
	else if haveSameNick then
		[AnswerThisClient ["WARNING", "Nickname collision"]]
		++ [ByeClient ""]
	else if illegalName newNick then
		[ByeClient "Illegal nickname"]
	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", passwd] =
	if passwd == webPassword client then
		[ModifyClient (\cl -> cl{logonPassed = True}),
		MoveToLobby] ++ adminNotice
	else
		[ByeClient "Authentication failed"]
	where
		client = clients IntMap.! clID
		adminNotice = if isAdministrator client then [AnswerThisClient ["ADMIN_ACCESS"]] else []


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


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