gameServer/Actions.hs
changeset 2341 408edb2f254c
parent 2337 723f1cbe2ef3
child 2343 3ab763dc14a3
equal deleted inserted replaced
2340:3b35fd5f67c7 2341:408edb2f254c
   191 
   191 
   192 processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient msg) = do
   192 processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient msg) = do
   193 	(_, _, newClients, newRooms) <-
   193 	(_, _, newClients, newRooms) <-
   194 		if roomID client /= 0 then
   194 		if roomID client /= 0 then
   195 			if isMaster client then
   195 			if isMaster client then
   196 				if gameinprogress room then
   196 				if (gameinprogress room) && (playersIn room > 1) then
   197 					processAction (clID, serverInfo, clients, rooms) RemoveRoom
   197 					changeMaster
   198 				else -- not in game
   198 				else -- not in game
   199 					processAction (clID, serverInfo, clients, rooms) RemoveRoom
   199 					processAction (clID, serverInfo, clients, rooms) RemoveRoom
   200 			else -- not master
   200 			else -- not master
   201 				foldM
   201 				foldM
   202 					processAction
   202 					processAction
   216 		rID = roomID client
   216 		rID = roomID client
   217 		client = clients ! clID
   217 		client = clients ! clID
   218 		room = rooms ! rID
   218 		room = rooms ! rID
   219 		resetClientFlags cl = cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined}
   219 		resetClientFlags cl = cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined}
   220 		removeClientFromRoom r = r{
   220 		removeClientFromRoom r = r{
   221 				playersIDs = IntSet.delete clID (playersIDs r),
   221 				playersIDs = otherPlayersSet,
   222 				playersIn = (playersIn r) - 1,
   222 				playersIn = (playersIn r) - 1,
   223 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   223 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   224 				}
   224 				}
   225 		insertClientToRoom r = r{playersIDs = IntSet.insert clID (playersIDs r)}
   225 		insertClientToRoom r = r{playersIDs = IntSet.insert clID (playersIDs r)}
       
   226 		changeMaster = do
       
   227 			processAction (newMasterId, serverInfo, clients, rooms) $ AnswerThisClient ["ROOM_CONTROL_ACCESS", "1"]
       
   228 			return (
       
   229 				clID,
       
   230 				serverInfo,
       
   231 				adjust (\cl -> cl{isMaster = True}) newMasterId clients,
       
   232 				adjust (\r -> r{name = newRoomName}) rID rooms
       
   233 				)
       
   234 		newRoomName = "abandoned"
       
   235 		otherPlayersSet = IntSet.delete clID (playersIDs room)
       
   236 		newMasterId = IntSet.findMin otherPlayersSet
   226 
   237 
   227 
   238 
   228 processAction (clID, serverInfo, clients, rooms) (AddRoom roomName roomPassword) = do
   239 processAction (clID, serverInfo, clients, rooms) (AddRoom roomName roomPassword) = do
   229 	let newServerInfo = serverInfo {nextRoomID = newID}
   240 	let newServerInfo = serverInfo {nextRoomID = newID}
   230 	let room = newRoom{
   241 	let room = newRoom{