gameServer/HWProtoCore.hs
author unc0rr
Thu, 19 Feb 2009 14:52:32 +0000
changeset 1810 4059cafd1da7
parent 1804 4e78ad846fb6
child 1811 1b9e33623b7e
permissions -rw-r--r--
Frontend look fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1804
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     1
module HWProtoCore where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     2
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     3
import qualified Data.IntMap as IntMap
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     4
--------------------------------------
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     5
import CoreTypes
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     6
import Actions
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     7
import Utils
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     8
import Answers
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
     9
import HWProtoNEState
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    10
import HWProtoLobbyState
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    11
import HWProtoInRoomState
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    12
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    13
handleCmd:: CmdHandler
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    14
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    15
handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    16
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    17
handleCmd clID clients _ ("QUIT" : xs) =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    18
	(if isMaster client then [RemoveRoom] else [])
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    19
	++ [ByeClient msg]
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    20
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    21
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    22
		clientNick = nick client
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    23
		msg = if not $ null xs then head xs else ""
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    24
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    25
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    26
handleCmd clID clients rooms cmd =
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    27
	if null (nick client) || clientProto client == 0 then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    28
		handleCmd_NotEntered clID clients rooms cmd
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    29
	else if roomID client == 0 then
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    30
		handleCmd_lobby clID clients rooms cmd
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    31
	else
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    32
		handleCmd_inRoom clID clients rooms cmd
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    33
	where
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    34
		client = clients IntMap.! clID
4e78ad846fb6 New game server:
unc0rr
parents:
diff changeset
    35