gameServer/Actions.hs
changeset 1811 1b9e33623b7e
parent 1804 4e78ad846fb6
child 1813 cfe1481e0247
equal deleted inserted replaced
1810:4059cafd1da7 1811:1b9e33623b7e
    16 	| AnswerOthersInRoom [String]
    16 	| AnswerOthersInRoom [String]
    17 	| AnswerLobby [String]
    17 	| AnswerLobby [String]
    18 	| RoomAddThisClient Int -- roomID
    18 	| RoomAddThisClient Int -- roomID
    19 	| RoomRemoveThisClient
    19 	| RoomRemoveThisClient
    20 	| RemoveRoom
    20 	| RemoveRoom
       
    21 	| UnreadyRoomClients
    21 	| ProtocolError String
    22 	| ProtocolError String
    22 	| Warning String
    23 	| Warning String
    23 	| ByeClient String
    24 	| ByeClient String
    24 	| ModifyClient (ClientInfo -> ClientInfo)
    25 	| ModifyClient (ClientInfo -> ClientInfo)
    25 	| ModifyRoom (RoomInfo -> RoomInfo)
    26 	| ModifyRoom (RoomInfo -> RoomInfo)
   177 		newID = (nextRoomID serverInfo) - 1
   178 		newID = (nextRoomID serverInfo) - 1
   178 		client = clients ! clID
   179 		client = clients ! clID
   179 
   180 
   180 
   181 
   181 processAction (clID, serverInfo, clients, rooms) (RemoveRoom) = do
   182 processAction (clID, serverInfo, clients, rooms) (RemoveRoom) = do
   182 	processAction (clID, serverInfo, clients, rooms) $ AnswerLobby ["ROOM", "DEL", name clRoom]
   183 	processAction (clID, serverInfo, clients, rooms) $ AnswerLobby ["ROOM", "DEL", name room]
   183 	processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["ROOMABANDONED", name clRoom]
   184 	processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["ROOMABANDONED", name room]
   184 	return (clID,
   185 	return (clID,
   185 		serverInfo,
   186 		serverInfo,
   186 		Data.IntMap.map (\cl -> if roomID cl == rID then cl{roomID = 0, isMaster = False} else cl) clients,
   187 		Data.IntMap.map (\cl -> if roomID cl == rID then cl{roomID = 0, isMaster = False} else cl) clients,
   187 		delete rID $ adjust (\r -> r{playersIDs = IntSet.union (playersIDs clRoom) (playersIDs r)}) 0 rooms
   188 		delete rID $ adjust (\r -> r{playersIDs = IntSet.union (playersIDs room) (playersIDs r)}) 0 rooms
   188 		)
   189 		)
   189 	where
   190 	where
   190 		clRoom = rooms ! rID
   191 		room = rooms ! rID
   191 		rID = roomID client
   192 		rID = roomID client
   192 		client = clients ! clID
   193 		client = clients ! clID
       
   194 
       
   195 processAction (clID, serverInfo, clients, rooms) (UnreadyRoomClients) = do
       
   196 	processAction (clID, serverInfo, clients, rooms) $ AnswerThisRoom ("NOT_READY" : roomPlayers)
       
   197 	return (clID,
       
   198 		serverInfo,
       
   199 		Data.IntMap.map (\cl -> if roomID cl == rID then cl{isReady = False} else cl) clients,
       
   200 		rooms)
       
   201 	where
       
   202 		room = rooms ! rID
       
   203 		rID = roomID client
       
   204 		client = clients ! clID
       
   205 		roomPlayers = Prelude.map (nick . (clients !)) roomPlayersIDs
       
   206 		roomPlayersIDs = IntSet.elems $ playersIDs room
       
   207 
   193 
   208 
   194 processAction (clID, serverInfo, clients, rooms) (Dump) = do
   209 processAction (clID, serverInfo, clients, rooms) (Dump) = do
   195 	writeChan (sendChan $ clients ! clID) ["DUMP", show serverInfo, showTree clients, showTree rooms]
   210 	writeChan (sendChan $ clients ! clID) ["DUMP", show serverInfo, showTree clients, showTree rooms]
   196 	return (clID, serverInfo, clients, rooms)
   211 	return (clID, serverInfo, clients, rooms)
   197 
   212