gameServer/HWProtoCore.hs
author unc0rr
Wed, 18 Feb 2009 15:04:40 +0000
changeset 1804 4e78ad846fb6
child 1811 1b9e33623b7e
permissions -rw-r--r--
New game server: - Incomplete implementation - More robust, no memory leaks, better architecture for easy features addition - Incompatible with current client
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