# HG changeset patch
# User unc0rr
# Date 1224853386 0
# Node ID 08b9c28419f16511c5549a76c23b2f853b5312a5
# Parent  ee4b28a1861dfc2b8ab954a01844314c6e43f1bd
Send readiness information on join

diff -r ee4b28a1861d -r 08b9c28419f1 netserver/HWProto.hs
--- a/netserver/HWProto.hs	Fri Oct 24 13:00:53 2008 +0000
+++ b/netserver/HWProto.hs	Fri Oct 24 13:03:06 2008 +0000
@@ -54,7 +54,7 @@
 answerMap mapName = [(othersInRoom, ["MAP", mapName])]
 answerRunGame = [(sameRoom, ["RUN_GAME"])]
 answerCannotCreateRoom = [(clientOnly, ["WARNING", "Cannot create more rooms"])]
-answerReady nick = [(sameRoom, ["READY", nick])]
+answerIsReady nick = [(sameRoom, ["READY", nick])]
 answerNotReady nick = [(sameRoom, ["NOT_READY", nick])]
 
 
@@ -141,10 +141,12 @@
 	else if roomPassword /= password clRoom then
 		(noChangeClients, noChangeRooms, answerWrongPassword)
 	else
-		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ (answerJoined $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
+		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ answerReady ++ (answerJoined $ nick client) ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
 	where
 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
-		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
+		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ sameRoomClients))]
+		answerReady = map (\c -> (clientOnly, [if isReady c then "READY" else "NOT_READY", nick c])) sameRoomClients
+		sameRoomClients = filter (\ci -> room ci == roomName) clients
 		clRoom = roomByName roomName rooms
 
 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
@@ -236,9 +238,9 @@
 		(modifyClient client{isReady = False}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, (answerNotReady $ nick client))
 	else
 		if (playersIn clRoom) == newReadyPlayers then
-			(modifyClient client{isReady = True}, modifyRoom clRoom{gameinprogress = True, readyPlayers = newReadyPlayers}, (answerReady $ nick client) ++ answerRunGame)
+			(modifyClient client{isReady = True}, modifyRoom clRoom{gameinprogress = True, readyPlayers = newReadyPlayers}, (answerIsReady $ nick client) ++ answerRunGame)
 		else
-			(modifyClient client{isReady = True}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, answerReady $ nick client)
+			(modifyClient client{isReady = True}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, answerIsReady $ nick client)
 	where
 		clRoom = roomByName (room client) rooms
 		newReadyPlayers = (readyPlayers clRoom) + if isReady client then -1 else 1