gameServer/HWProtoLobbyState.hs
changeset 3541 f4f90987e0fa
parent 3536 7d99655130ff
child 3540 b602a57ba0fb
equal deleted inserted replaced
3535:9e78c1f3d8d8 3541:f4f90987e0fa
    72 
    72 
    73 
    73 
    74 handleCmd_lobby ["CREATE_ROOM", newRoom] =
    74 handleCmd_lobby ["CREATE_ROOM", newRoom] =
    75     handleCmd_lobby ["CREATE_ROOM", newRoom, ""]
    75     handleCmd_lobby ["CREATE_ROOM", newRoom, ""]
    76 
    76 
       
    77 
       
    78 handleCmd_lobby ["JOIN_ROOM", roomName, roomPassword] = do
       
    79     (ci, irnc) <- ask
       
    80     let ris = allRooms irnc
       
    81     let cl =  irnc `client` ci
       
    82     let maybeRI = find (\ri -> roomName == name (irnc `room` ri)) ris
       
    83     let jRI = fromJust maybeRI
       
    84     let jRoom = irnc `room` jRI
       
    85     let jRoomClients = map (client irnc) $! roomClients irnc jRI -- no lazyness here!
       
    86     return $
       
    87         if isNothing maybeRI then 
       
    88             [Warning "No such rooms"]
       
    89             else if isRestrictedJoins jRoom then
       
    90             [Warning "Joining restricted"]
       
    91             else if roomPassword /= password jRoom then
       
    92             [Warning "Wrong password"]
       
    93             else
       
    94             [
       
    95                 MoveToRoom jRI,
       
    96                 AnswerClients (map sendChan $ cl : jRoomClients) ["NOT_READY", nick cl]
       
    97             ]
       
    98             ++ [ AnswerClients [sendChan cl] $ "JOINED" : map nick jRoomClients | playersIn jRoom /= 0]
       
    99             ++ (map (readynessMessage cl) jRoomClients)
       
   100 
       
   101     where
       
   102         readynessMessage cl c = AnswerClients [sendChan cl] [if isReady c then "READY" else "NOT_READY", nick c]
       
   103 
       
   104 
       
   105 
    77 {-
   106 {-
    78 
   107 
    79 handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName, roomPassword]
   108 handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName, roomPassword]
    80     | noSuchRoom = [Warning "No such room"]
   109     | noSuchRoom = [Warning "No such room"]
    81     | isRestrictedJoins jRoom = [Warning "Joining restricted"]
   110     | isRestrictedJoins jRoom = [Warning "Joining restricted"]
    88         ++ [AnswerThisRoom ["NOT_READY", nick client]]
   117         ++ [AnswerThisRoom ["NOT_READY", nick client]]
    89         ++ answerFullConfig
   118         ++ answerFullConfig
    90         ++ answerTeams
   119         ++ answerTeams
    91         ++ watchRound
   120         ++ watchRound
    92     where
   121     where
    93         noSuchRoom = isNothing mbRoom
       
    94         mbRoom = find (\r -> roomName == name r && roomProto r == clientProto client) $ IntMap.elems rooms
       
    95         jRoom = fromJust mbRoom
       
    96         rID = roomUID jRoom
       
    97         client = clients IntMap.! clID
       
    98         roomClientsIDs = IntSet.elems $ playersIDs jRoom
       
    99         answerNicks =
   122         answerNicks =
   100             [AnswerThisClient $ "JOINED" :
   123             [AnswerThisClient $ "JOINED" :
   101             map (\clID -> nick $ clients IntMap.! clID) roomClientsIDs | playersIn jRoom /= 0]
   124             map (\clID -> nick $ clients IntMap.! clID) roomClientsIDs | playersIn jRoom /= 0]
   102         answerReady = map
   125         answerReady = map
   103             ((\ c ->
   126             ((\ c ->
   119 
   142 
   120         answerTeams = if gameinprogress jRoom then
   143         answerTeams = if gameinprogress jRoom then
   121                 answerAllTeams (clientProto client) (teamsAtStart jRoom)
   144                 answerAllTeams (clientProto client) (teamsAtStart jRoom)
   122             else
   145             else
   123                 answerAllTeams (clientProto client) (teams jRoom)
   146                 answerAllTeams (clientProto client) (teams jRoom)
   124 
   147 -}
   125 
   148 
   126 handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName] =
   149 handleCmd_lobby ["JOIN_ROOM", roomName] =
   127     handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName, ""]
   150     handleCmd_lobby ["JOIN_ROOM", roomName, ""]
   128 
   151 
   129 
   152 {-
   130 handleCmd_lobby clID clients rooms ["FOLLOW", asknick] =
   153 handleCmd_lobby clID clients rooms ["FOLLOW", asknick] =
   131     if noSuchClient || roomID followClient == 0 then
   154     if noSuchClient || roomID followClient == 0 then
   132         []
   155         []
   133     else
   156     else
   134         handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName]
   157         handleCmd_lobby clID clients rooms ["JOIN_ROOM", roomName]