gameServer/HWProtoLobbyState.hs
branchwebgl
changeset 9521 8054d9d775fd
parent 9448 04e0acfa7c2c
child 9702 27006953d901
equal deleted inserted replaced
9282:92af50454cf2 9521:8054d9d775fd
     2 module HWProtoLobbyState where
     2 module HWProtoLobbyState where
     3 
     3 
     4 import Data.Maybe
     4 import Data.Maybe
     5 import Data.List
     5 import Data.List
     6 import Control.Monad.Reader
     6 import Control.Monad.Reader
       
     7 import qualified Data.ByteString.Char8 as B
     7 --------------------------------------
     8 --------------------------------------
     8 import CoreTypes
     9 import CoreTypes
     9 import Actions
    10 import Actions
    10 import Utils
    11 import Utils
    11 import HandlerUtils
    12 import HandlerUtils
    12 import RoomsAndClients
    13 import RoomsAndClients
    13 import EngineInteraction
    14 import EngineInteraction
    14 
       
    15 
       
    16 answerAllTeams :: ClientInfo -> [TeamInfo] -> [Action]
       
    17 answerAllTeams cl = concatMap toAnswer
       
    18     where
       
    19         clChan = sendChan cl
       
    20         toAnswer team =
       
    21             [AnswerClients [clChan] $ teamToNet team,
       
    22             AnswerClients [clChan] ["TEAM_COLOR", teamname team, teamcolor team],
       
    23             AnswerClients [clChan] ["HH_NUM", teamname team, showB $ hhnum team]]
       
    24 
    15 
    25 
    16 
    26 handleCmd_lobby :: CmdHandler
    17 handleCmd_lobby :: CmdHandler
    27 
    18 
    28 
    19 
    75     return $
    66     return $
    76         if isNothing maybeRI || not sameProto then
    67         if isNothing maybeRI || not sameProto then
    77             [Warning $ loc "No such room"]
    68             [Warning $ loc "No such room"]
    78             else if isRestrictedJoins jRoom then
    69             else if isRestrictedJoins jRoom then
    79             [Warning $ loc "Joining restricted"]
    70             [Warning $ loc "Joining restricted"]
    80             else if isRegisteredOnly jRoom then
    71             else if isRegisteredOnly jRoom && (B.null . webPassword $ cl) then
    81             [Warning $ loc "Registered users only"]
    72             [Warning $ loc "Registered users only"]
    82             else if isBanned then
    73             else if isBanned then
    83             [Warning $ loc "You are banned in this room"]
    74             [Warning $ loc "You are banned in this room"]
    84             else if roomPassword /= password jRoom then
    75             else if roomPassword /= password jRoom then
    85             [NoticeMessage WrongPassword]
    76             [NoticeMessage WrongPassword]
   112         answerTeams cl jRoom = let f = if isJust $ gameInfo jRoom then teamsAtStart . fromJust . gameInfo else teams in answerAllTeams cl $ f jRoom
   103         answerTeams cl jRoom = let f = if isJust $ gameInfo jRoom then teamsAtStart . fromJust . gameInfo else teams in answerAllTeams cl $ f jRoom
   113 
   104 
   114         watchRound cl jRoom chans = if isNothing $ gameInfo jRoom then
   105         watchRound cl jRoom chans = if isNothing $ gameInfo jRoom then
   115                     []
   106                     []
   116                 else
   107                 else
   117                     [AnswerClients [sendChan cl]  ["RUN_GAME"]
   108                     AnswerClients [sendChan cl]  ["RUN_GAME"]
   118                     , AnswerClients chans ["CLIENT_FLAGS", "+g", nick cl]
   109                     : AnswerClients chans ["CLIENT_FLAGS", "+g", nick cl]
   119                     , ModifyClient (\c -> c{isInGame = True})
   110                     : ModifyClient (\c -> c{isInGame = True})
   120                     , AnswerClients [sendChan cl] $ "EM" : toEngineMsg "e$spectate 1" : (reverse . roundMsgs . fromJust . gameInfo $ jRoom)]
   111                     : [AnswerClients [sendChan cl] $ "EM" : toEngineMsg "e$spectate 1" : (reverse . roundMsgs . fromJust . gameInfo $ jRoom)]
   121 
   112 
   122 
   113 
   123 handleCmd_lobby ["JOIN_ROOM", roomName] =
   114 handleCmd_lobby ["JOIN_ROOM", roomName] =
   124     handleCmd_lobby ["JOIN_ROOM", roomName, ""]
   115     handleCmd_lobby ["JOIN_ROOM", roomName, ""]
   125 
   116