Some preparation for room control delegation support
authorunc0rr
Sun, 30 Aug 2009 08:04:59 +0000
changeset 2337 723f1cbe2ef3
parent 2336 66c751f7a28e
child 2338 8f6508c97f3f
Some preparation for room control delegation support
gameServer/Actions.hs
gameServer/HWProtoInRoomState.hs
--- a/gameServer/Actions.hs	Fri Aug 28 02:52:26 2009 +0000
+++ b/gameServer/Actions.hs	Sun Aug 30 08:04:59 2009 +0000
@@ -122,8 +122,7 @@
 	infoM "Clients" ((show $ clientUID client) ++ " quits: " ++ msg)
 	(_, _, newClients, newRooms) <-
 			if roomID client /= 0 then
-				processAction  (clID, serverInfo, clients, rooms)
-					(if isMaster client then RemoveRoom else RemoveClientTeams clID)
+				processAction  (clID, serverInfo, clients, rooms) $ RoomRemoveThisClient "quit"
 				else
 					return (clID, serverInfo, clients, rooms)
 
@@ -192,29 +191,38 @@
 
 processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient msg) = do
 	(_, _, newClients, newRooms) <-
-			if roomID client /= 0 then
+		if roomID client /= 0 then
+			if isMaster client then
+				if gameinprogress room then
+					processAction (clID, serverInfo, clients, rooms) RemoveRoom
+				else -- not in game
+					processAction (clID, serverInfo, clients, rooms) RemoveRoom
+			else -- not master
 				foldM
 					processAction
 						(clID, serverInfo, clients, rooms)
 						[AnswerOthersInRoom ["LEFT", nick client, msg],
 						RemoveClientTeams clID]
-				else
-					return (clID, serverInfo, clients, rooms)
+		else -- in lobby
+			return (clID, serverInfo, clients, rooms)
 	
 	return (
 		clID,
 		serverInfo,
-		adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined}) clID newClients,
-		adjust (\r -> r{
-				playersIDs = IntSet.delete clID (playersIDs r),
-				playersIn = (playersIn r) - 1,
-				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
-				}) rID $
-			adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r)}) 0 newRooms
+		adjust resetClientFlags clID newClients,
+		adjust removeClientFromRoom rID $ adjust insertClientToRoom 0 newRooms
 		)
 	where
 		rID = roomID client
 		client = clients ! clID
+		room = rooms ! rID
+		resetClientFlags cl = cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined}
+		removeClientFromRoom r = r{
+				playersIDs = IntSet.delete clID (playersIDs r),
+				playersIn = (playersIn r) - 1,
+				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
+				}
+		insertClientToRoom r = r{playersIDs = IntSet.insert clID (playersIDs r)}
 
 
 processAction (clID, serverInfo, clients, rooms) (AddRoom roomName roomPassword) = do
--- a/gameServer/HWProtoInRoomState.hs	Fri Aug 28 02:52:26 2009 +0000
+++ b/gameServer/HWProtoInRoomState.hs	Sun Aug 30 08:04:59 2009 +0000
@@ -27,9 +27,6 @@
 
 
 handleCmd_inRoom clID clients rooms ["PART"] =
-	if isMaster client then
-		[RemoveRoom]
-	else
 		[RoomRemoveThisClient "part"]
 	where
 		client = clients IntMap.! clID