gameServer/HWProtoCore.hs
changeset 3435 4e4f88a7bdf2
parent 2961 3e057dfa601f
child 3458 11cd56019f00
equal deleted inserted replaced
3434:6af73e7f2438 3435:4e4f88a7bdf2
     1 module HWProtoCore where
     1 module HWProtoCore where
     2 
     2 
     3 import qualified Data.IntMap as IntMap
     3 import qualified Data.IntMap as IntMap
     4 import Data.Foldable
     4 import Data.Foldable
     5 import Maybe
     5 import Maybe
       
     6 import Control.Monad.Reader
     6 --------------------------------------
     7 --------------------------------------
     7 import CoreTypes
     8 import CoreTypes
     8 import Actions
     9 import Actions
     9 import Utils
    10 import Utils
    10 import HWProtoNEState
    11 import HWProtoNEState
    11 import HWProtoLobbyState
    12 import HWProtoLobbyState
    12 import HWProtoInRoomState
    13 import HWProtoInRoomState
       
    14 import HandlerUtils
       
    15 import RoomsAndClients
    13 
    16 
    14 handleCmd, handleCmd_loggedin :: CmdHandler
    17 handleCmd, handleCmd_loggedin :: CmdHandler
    15 
    18 
    16 handleCmd clID _ _ ["PING"] = [AnswerThisClient ["PONG"]]
       
    17 
    19 
    18 handleCmd clID clients rooms ("QUIT" : xs) =
    20 handleCmd ["PING"] = answerClient ["PONG"]
    19     [ByeClient msg]
    21 
       
    22 
       
    23 handleCmd ("QUIT" : xs) = return [ByeClient msg]
    20     where
    24     where
    21         msg = if not $ null xs then head xs else ""
    25         msg = if not $ null xs then head xs else ""
    22 
    26 
    23 
    27 {-
    24 handleCmd clID clients _ ["PONG"] =
    28 handleCmd clID clients _ ["PONG"] =
    25     if pingsQueue client == 0 then
    29     if pingsQueue client == 0 then
    26         [ProtocolError "Protocol violation"]
    30         [ProtocolError "Protocol violation"]
    27     else
    31     else
    28         [ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})]
    32         [ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})]
    29     where
    33     where
    30         client = clients IntMap.! clID
    34         client = clients IntMap.! clID
       
    35 -}
    31 
    36 
       
    37 handleCmd cmd = do
       
    38     (ci, irnc) <- ask
       
    39     if logonPassed (irnc `client` ci) then
       
    40         handleCmd_NotEntered cmd
       
    41         else
       
    42         handleCmd_loggedin cmd
    32 
    43 
    33 handleCmd clID clients rooms cmd =
    44 {-
    34     if not $ logonPassed client then
       
    35         handleCmd_NotEntered clID clients rooms cmd
       
    36     else
       
    37         handleCmd_loggedin clID clients rooms cmd
       
    38     where
       
    39         client = clients IntMap.! clID
       
    40 
       
    41 
       
    42 handleCmd_loggedin clID clients rooms ["INFO", asknick] =
    45 handleCmd_loggedin clID clients rooms ["INFO", asknick] =
    43     if noSuchClient then
    46     if noSuchClient then
    44         []
    47         []
    45     else
    48     else
    46         [AnswerThisClient
    49         [AnswerThisClient
    60         roomStatus =
    63         roomStatus =
    61             if gameinprogress room
    64             if gameinprogress room
    62             then if teamsInGame client > 0 then "(playing)" else "(spectating)"
    65             then if teamsInGame client > 0 then "(playing)" else "(spectating)"
    63             else ""
    66             else ""
    64 
    67 
       
    68 -}
    65 
    69 
    66 handleCmd_loggedin clID clients rooms cmd =
    70 
    67     if roomID client == 0 then
    71 handleCmd_loggedin cmd = do
    68         handleCmd_lobby clID clients rooms cmd
    72     (ci, rnc) <- ask
    69     else
    73     if clientRoom rnc ci == lobbyId then
    70         handleCmd_inRoom clID clients rooms cmd
    74         handleCmd_lobby cmd
    71     where
    75         else
    72         client = clients IntMap.! clID
    76         handleCmd_inRoom cmd