--- a/netserver/HWProto.hs Wed Oct 22 21:41:00 2008 +0000
+++ b/netserver/HWProto.hs Thu Oct 23 15:12:38 2008 +0000
@@ -54,6 +54,10 @@
answerMap mapName = [(othersInRoom, ["MAP", mapName])]
answerRunGame = [(sameRoom, ["RUN_GAME"])]
answerCannotCreateRoom = [(clientOnly, ["WARNING", "Cannot create more rooms"])]
+answerReady nick = [(sameRoom, ["READY", nick])]
+answerNotReady nick = [(sameRoom, ["NOT_READY", nick])]
+
+
-- Main state-independent cmd handler
handleCmd :: CmdHandler
handleCmd client _ rooms ("QUIT":xs) =
@@ -62,11 +66,12 @@
else if isMaster client then
(noChangeClients, removeRoom (room client), answerQuit ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
else
- (noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
+ (noChangeClients, modifyRoom clRoom{teams = othersTeams, playersIn = (playersIn clRoom) - 1, readyPlayers = newReadyPlayers}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
where
clRoom = roomByName (room client) rooms
answerRemoveClientTeams = map (\tn -> (othersInRoom, ["REMOVE_TEAM", teamname tn])) clientTeams
(clientTeams, othersTeams) = partition (\t -> teamowner t == nick client) $ teams clRoom
+ newReadyPlayers = if isReady client then (readyPlayers clRoom) - 1 else readyPlayers clRoom
-- check state and call state-dependent commmand handlers
@@ -226,13 +231,17 @@
findTeam = find (\t -> teamName == teamname t) $ teams clRoom
clRoom = roomByName (room client) rooms
-handleCmd_inRoom client _ rooms ["READY"] =
- if not $ isMaster client then
- (noChangeClients, noChangeRooms, answerNotMaster)
+handleCmd_inRoom client _ rooms ["TOGGLE_READY"] =
+ if isReady client then
+ (modifyClient client{isReady = False}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, (answerNotReady $ nick client))
else
- (noChangeClients, modifyRoom clRoom{gameinprogress = True}, answerRunGame)
+ if (playersIn clRoom) == newReadyPlayers then
+ (modifyClient client{isReady = True}, modifyRoom clRoom{gameinprogress = True, readyPlayers = newReadyPlayers}, (answerReady $ nick client) ++ answerRunGame)
+ else
+ (modifyClient client{isReady = True}, modifyRoom clRoom{readyPlayers = newReadyPlayers}, answerReady $ nick client)
where
clRoom = roomByName (room client) rooms
+ newReadyPlayers = (readyPlayers clRoom) + if isReady client then 1 else -1
handleCmd_inRoom client _ rooms ["ROUNDFINISHED"] =
if isMaster client then
--- a/netserver/Miscutils.hs Wed Oct 22 21:41:00 2008 +0000
+++ b/netserver/Miscutils.hs Thu Oct 23 15:12:38 2008 +0000
@@ -17,6 +17,7 @@
protocol :: Word16,
room :: String,
isMaster :: Bool,
+ isReady :: Bool,
forceQuit :: Bool
}
@@ -49,9 +50,10 @@
gamemap :: String,
gameinprogress :: Bool,
playersIn :: Int,
+ readyPlayers :: Int,
params :: Map.Map String [String]
}
-createRoom = (RoomInfo "" "" 0 [] "+rnd+" False 1 Map.empty)
+createRoom = (RoomInfo "" "" 0 [] "+rnd+" False 1 0 Map.empty)
type ClientsTransform = [ClientInfo] -> [ClientInfo]
type RoomsTransform = [RoomInfo] -> [RoomInfo]
--- a/netserver/hedgewars-server.hs Wed Oct 22 21:41:00 2008 +0000
+++ b/netserver/hedgewars-server.hs Thu Oct 23 15:12:38 2008 +0000
@@ -25,7 +25,7 @@
hFlush cHandle
cChan <- atomically newTChan
forkIO $ clientLoop cHandle cChan
- atomically $ writeTChan acceptChan (ClientInfo cChan cHandle "" 0 "" False False)
+ atomically $ writeTChan acceptChan (ClientInfo cChan cHandle "" 0 "" False False False)
acceptLoop servSock acceptChan