- Reverse the order of client list
- Add 'game in progress' room state to implement support of in-game disconnects notification
--- a/netserver/HWProto.hs Mon Oct 13 14:52:29 2008 +0000
+++ b/netserver/HWProto.hs Mon Oct 13 18:37:59 2008 +0000
@@ -58,11 +58,14 @@
else if isMaster client then
(noChangeClients, removeRoom (room client), answerQuit ++ answerAbandoned) -- core disconnects clients on ROOMABANDONED answer
else
- (noChangeClients, modifyRoom clRoom{teams = othersTeams}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
+ (noChangeClients, modifyRoom clRoom{teams = othersTeams}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams ++ answerLostTeams)
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
+ answerLostTeams = if gameinprogress clRoom then answerInGameLostTeams clientTeams else []
+ answerInGameLostTeams teams = []
+
-- check state and call state-dependent commmand handlers
@@ -109,7 +112,7 @@
if haveSameRoom then
(noChangeClients, noChangeRooms, answerRoomExists)
else
- (modifyClient client{room = newRoom, isMaster = True}, addRoom (RoomInfo newRoom roomPassword (protocol client) [] "+rnd+" Map.empty), answerJoined $ nick client)
+ (modifyClient client{room = newRoom, isMaster = True}, addRoom createRoom{name = newRoom, password = roomPassword, roomProto = (protocol client)}, answerJoined $ nick client)
where
haveSameRoom = isJust $ find (\room -> newRoom == name room) rooms
@@ -212,15 +215,17 @@
findTeam = find (\t -> teamName == teamname t) $ teams clRoom
clRoom = roomByName (room client) rooms
-handleCmd_inRoom client _ _ ["READY"] =
+handleCmd_inRoom client _ rooms ["READY"] =
if not $ isMaster client then
(noChangeClients, noChangeRooms, answerNotMaster)
else
- (noChangeClients, noChangeRooms, answerRunGame)
+ (noChangeClients, modifyRoom clRoom{gameinprogress = True}, answerRunGame)
+ where
+ clRoom = roomByName (room client) rooms
handleCmd_inRoom client _ rooms ["ROUNDFINISHED"] =
if isMaster client then
- (noChangeClients, modifyRoom clRoom{teams = []}, [])
+ (noChangeClients, modifyRoom clRoom{teams = [], gameinprogress = False}, [])
else
(noChangeClients, noChangeRooms, [])
where
--- a/netserver/Miscutils.hs Mon Oct 13 14:52:29 2008 +0000
+++ b/netserver/Miscutils.hs Mon Oct 13 18:37:59 2008 +0000
@@ -46,8 +46,10 @@
roomProto :: Word16,
teams :: [TeamInfo],
gamemap :: String,
+ gameinprogress :: Bool,
params :: Map.Map String [String]
}
+createRoom = (RoomInfo "" "" 0 [] "+rnd+" False Map.empty)
type ClientsTransform = [ClientInfo] -> [ClientInfo]
type RoomsTransform = [RoomInfo] -> [RoomInfo]
--- a/netserver/newhwserv.hs Mon Oct 13 14:52:29 2008 +0000
+++ b/netserver/newhwserv.hs Mon Oct 13 18:37:59 2008 +0000
@@ -67,7 +67,7 @@
r <- atomically $ (Left `fmap` readTChan acceptChan) `orElse` (Right `fmap` tselect clients)
case r of
Left ci -> do
- mainLoop servSock acceptChan (ci:clients) rooms
+ mainLoop servSock acceptChan (clients ++ [ci]) rooms
Right (cmd, client) -> do
putStrLn ("> " ++ show cmd)