Some support for spectating when some teams removed
authorunc0rr
Sun, 25 Jan 2009 13:57:48 +0000
changeset 1748 27dd2967fc65
parent 1747 44a6a9924c6d
child 1749 7170f626e9d6
Some support for spectating when some teams removed
netserver/HWProto.hs
netserver/Miscutils.hs
--- a/netserver/HWProto.hs	Sun Jan 25 13:48:41 2009 +0000
+++ b/netserver/HWProto.hs	Sun Jan 25 13:57:48 2009 +0000
@@ -99,7 +99,7 @@
 		toAnswer (paramName, paramStrs) =
 			answerClientOnly $ "CONFIG_PARAM" : paramName : paramStrs
 
-answerAllTeams protocol room = concatMap toAnswer (teams room)
+answerAllTeams protocol teams = concatMap toAnswer teams
 	where
 		toAnswer team =
 			(answerClientOnly $ teamToNet protocol team) ++
@@ -246,7 +246,7 @@
 	else if isRestrictedJoins clRoom then
 		(noChangeClients, noChangeRooms, answerRestricted)
 	else
-		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, (answerJoined $ nick client) ++ answerNicks ++ answerReady ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams (protocol client) clRoom ++ watchRound)
+		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, (answerJoined $ nick client) ++ answerNicks ++ answerReady ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerTeams ++ watchRound)
 	where
 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
 		answerNicks = if not $ null sameRoomClients then
@@ -261,6 +261,10 @@
 				else
 					(answerClientOnly  ["RUN_GAME"]) ++
 					answerClientOnly ("GAMEMSG" : toEngineMsg "e$spectate 1" : (toList $ roundMsgs clRoom))
+		answerTeams = if gameinprogress clRoom then
+				answerAllTeams (protocol client) (teamsAtStart clRoom)
+			else
+				answerAllTeams (protocol client) (teams clRoom)
 
 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
@@ -371,7 +375,13 @@
 			if not $ gameinprogress clRoom then
 				(noChangeClients, modifyRoom clRoom{teams = filter (\t -> teamName /= teamname t) $ teams clRoom}, answerRemoveTeam teamName)
 			else
-				(noChangeClients, modifyRoom clRoom{leftTeams = teamName : leftTeams clRoom, roundMsgs = roundMsgs clRoom |> rmTeamMsg}, answerOthersRoom ["GAMEMSG", rmTeamMsg])
+				(noChangeClients,
+				modifyRoom clRoom{
+					teams = filter (\t -> teamName /= teamname t) $ teams clRoom,
+					leftTeams = teamName : leftTeams clRoom,
+					roundMsgs = roundMsgs clRoom |> rmTeamMsg
+					},
+				answerOthersRoom ["GAMEMSG", rmTeamMsg])
 	where
 		noSuchTeam = isNothing findTeam
 		team = fromJust findTeam
@@ -391,7 +401,7 @@
 handleCmd_inRoom client _ rooms ["START_GAME"] =
 	if isMaster client && (playersIn clRoom == readyPlayers clRoom) && (not $ gameinprogress clRoom) then
 		if enoughClans then
-			(noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty, leftTeams = []}, answerRunGame)
+			(noChangeClients, modifyRoom clRoom{gameinprogress = True, roundMsgs = empty, leftTeams = [], teamsAtStart = teams clRoom}, answerRunGame)
 		else
 			(noChangeClients, noChangeRooms, answerTooFewClans)
 	else
@@ -420,7 +430,7 @@
 
 handleCmd_inRoom client clients rooms ["ROUNDFINISHED"] =
 	if isMaster client then
-		(modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty, leftTeams = []}, answerAllNotReady ++ answerRemovedTeams)
+		(modifyRoomClients clRoom (\cl -> cl{isReady = False}), modifyRoom clRoom{gameinprogress = False, readyPlayers = 0, roundMsgs = empty, leftTeams = [], teamsAtStart = []}, answerAllNotReady ++ answerRemovedTeams)
 	else
 		(noChangeClients, noChangeRooms, [])
 	where
--- a/netserver/Miscutils.hs	Sun Jan 25 13:48:41 2009 +0000
+++ b/netserver/Miscutils.hs	Sun Jan 25 13:57:48 2009 +0000
@@ -65,8 +65,10 @@
 		isRestrictedTeams :: Bool,
 		roundMsgs :: Seq String,
 		leftTeams :: [String],
+		teamsAtStart :: [TeamInfo],
 		params :: Map.Map String [String]
 	}
+
 createRoom = (
 	RoomInfo
 		""
@@ -81,6 +83,7 @@
 		False
 		Data.Sequence.empty
 		[]
+		[]
 		Map.empty
 	)
 
@@ -93,6 +96,7 @@
 		loginsNumber :: Int,
 		lastHourUsers :: [UTCTime]
 	}
+
 newServerInfo = (
 	ServerInfo
 		True