gameServer/Actions.hs
changeset 1977 2284d7fefe4f
parent 1972 e7a7c5eb5d86
child 1994 990f341a2332
equal deleted inserted replaced
1976:be2db1272ed2 1977:2284d7fefe4f
    24 	| RoomAddThisClient Int -- roomID
    24 	| RoomAddThisClient Int -- roomID
    25 	| RoomRemoveThisClient
    25 	| RoomRemoveThisClient
    26 	| RemoveTeam String
    26 	| RemoveTeam String
    27 	| RemoveRoom
    27 	| RemoveRoom
    28 	| UnreadyRoomClients
    28 	| UnreadyRoomClients
    29 		Derek Pomery <nemo@m8y.org>
       
    30 		Daniel Martin <elhombresinremedio@gmail.com>
       
    31 		"Nils Lück" and email: "nils.luck.design@gmail.com"
       
    32 	| MoveToLobby
    29 	| MoveToLobby
    33 	| ProtocolError String
    30 	| ProtocolError String
    34 	| Warning String
    31 	| Warning String
    35 	| ByeClient String
    32 	| ByeClient String
    36 	| KickClient Int -- clID
    33 	| KickClient Int -- clID
   189 			else
   186 			else
   190 				AnswerThisRoom ["JOINED", nick client]
   187 				AnswerThisRoom ["JOINED", nick client]
   191 
   188 
   192 
   189 
   193 processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient) = do
   190 processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient) = do
   194 	when (rID /= 0) $ (processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["LEFT", nick client, "part"]) >> return ()
   191 	(_, _, newClients, newRooms) <-
       
   192 			if roomID client /= 0 then
       
   193 				foldM
       
   194 					processAction
       
   195 						(clID, serverInfo, clients, rooms)
       
   196 						[AnswerOthersInRoom ["LEFT", nick client, "part"],
       
   197 						RemoveClientTeams clID]
       
   198 				else
       
   199 					return (clID, serverInfo, clients, rooms)
       
   200 	
   195 	return (
   201 	return (
   196 		clID,
   202 		clID,
   197 		serverInfo,
   203 		serverInfo,
   198 		adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False}) clID clients,
   204 		adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False}) clID newClients,
   199 		adjust (\r -> r{
   205 		adjust (\r -> r{
   200 				playersIDs = IntSet.delete clID (playersIDs r),
   206 				playersIDs = IntSet.delete clID (playersIDs r),
   201 				playersIn = (playersIn r) - 1,
   207 				playersIn = (playersIn r) - 1,
   202 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   208 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   203 				}) rID $
   209 				}) rID $
   204 			adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r)}) 0 rooms
   210 			adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r)}) 0 newRooms
   205 		)
   211 		)
   206 	where
   212 	where
   207 		rID = roomID client
   213 		rID = roomID client
   208 		client = clients ! clID
   214 		client = clients ! clID
   209 
   215 
   347 processAction (clID, serverInfo, clients, rooms) (AddClient client) = do
   353 processAction (clID, serverInfo, clients, rooms) (AddClient client) = do
   348 	let updatedClients = insert (clientUID client) client clients
   354 	let updatedClients = insert (clientUID client) client clients
   349 	infoM "Clients" ((show $ clientUID client) ++ ": New client. Time: " ++ (show $ connectTime client))
   355 	infoM "Clients" ((show $ clientUID client) ++ ": New client. Time: " ++ (show $ connectTime client))
   350 	writeChan (sendChan $ client) ["CONNECTED", "Hedgewars server http://www.hedgewars.org/"]
   356 	writeChan (sendChan $ client) ["CONNECTED", "Hedgewars server http://www.hedgewars.org/"]
   351 
   357 
   352 	let newLogins = takeWhile (\(_ , time) -> (connectTime client) `diffUTCTime` time <= 20) $ lastLogins serverInfo
   358 	let newLogins = takeWhile (\(_ , time) -> (connectTime client) `diffUTCTime` time <= 11) $ lastLogins serverInfo
   353 
   359 
   354 	if isJust $ host client `Prelude.lookup` newLogins then
   360 	if isJust $ host client `Prelude.lookup` newLogins then
   355 		processAction (clID, serverInfo{lastLogins = newLogins}, updatedClients, rooms) $ ByeClient "Reconnected too fast"
   361 		processAction (clID, serverInfo{lastLogins = newLogins}, updatedClients, rooms) $ ByeClient "Reconnected too fast"
   356 		else
   362 		else
   357 		return (clID, serverInfo{lastLogins = (host client, connectTime client) : newLogins}, updatedClients, rooms)
   363 		return (clID, serverInfo{lastLogins = (host client, connectTime client) : newLogins}, updatedClients, rooms)