- Send additional info on rooms
authorunc0rr
Wed, 22 Oct 2008 15:31:35 +0000
changeset 1396 abb28dcb6d0d
parent 1395 46fd70de89e2
child 1397 471c42a1c358
- Send additional info on rooms - Handle SIGPIPE
netserver/HWProto.hs
netserver/Miscutils.hs
netserver/hedgewars-server.hs
--- a/netserver/HWProto.hs	Wed Oct 22 14:01:43 2008 +0000
+++ b/netserver/HWProto.hs	Wed Oct 22 15:31:35 2008 +0000
@@ -62,7 +62,7 @@
 	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, playersIn = (playersIn clRoom) - 1}, answerQuit ++ (answerQuitInform $ nick client) ++ answerRemoveClientTeams)
 	where
 		clRoom = roomByName (room client) rooms
 		answerRemoveClientTeams = map (\tn -> (othersInRoom, ["REMOVE_TEAM", teamname tn])) clientTeams
@@ -107,7 +107,9 @@
 -- 'noRoom' clients state command handlers
 handleCmd_noRoom :: CmdHandler
 handleCmd_noRoom client _ rooms ["LIST"] =
-		(noChangeClients, noChangeRooms, answerServerMessage ++ (answerRoomsList $ map name rooms))
+		(noChangeClients, noChangeRooms, answerServerMessage ++ (answerRoomsList $ concat $ map roomInfo rooms))
+		where
+			roomInfo room = [name room, show $ playersIn room, show $ gameinprogress room]
 
 handleCmd_noRoom client _ rooms ["CREATE", newRoom, roomPassword] =
 	if (not $ isDedicated globalOptions) && (not $ null rooms) then
@@ -129,7 +131,7 @@
 	else if roomPassword /= password clRoom then
 		(noChangeClients, noChangeRooms, answerWrongPassword)
 	else
-		(modifyClient client{room = roomName}, noChangeRooms, answerNicks ++ (answerJoined $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
+		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ (answerJoined $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
 	where
 		noSuchRoom = isNothing $ find (\room -> roomName == name room) rooms
 		answerNicks = [(clientOnly, ["JOINED"] ++ (map nick $ filter (\ci -> room ci == roomName) clients))]
--- a/netserver/Miscutils.hs	Wed Oct 22 14:01:43 2008 +0000
+++ b/netserver/Miscutils.hs	Wed Oct 22 15:31:35 2008 +0000
@@ -48,9 +48,10 @@
 		teams :: [TeamInfo],
 		gamemap :: String,
 		gameinprogress :: Bool,
+		playersIn :: Int,
 		params :: Map.Map String [String]
 	}
-createRoom = (RoomInfo "" "" 0 [] "+rnd+" False Map.empty)
+createRoom = (RoomInfo "" "" 0 [] "+rnd+" False 1 Map.empty)
 
 type ClientsTransform = [ClientInfo] -> [ClientInfo]
 type RoomsTransform = [RoomInfo] -> [RoomInfo]
--- a/netserver/hedgewars-server.hs	Wed Oct 22 14:01:43 2008 +0000
+++ b/netserver/hedgewars-server.hs	Wed Oct 22 15:31:35 2008 +0000
@@ -12,6 +12,7 @@
 import Miscutils
 import HWProto
 import Opts
+import System.Posix
 
 acceptLoop :: Socket -> TChan ClientInfo -> IO ()
 acceptLoop servSock acceptChan = do
@@ -96,6 +97,7 @@
 
 
 main = withSocketsDo $ do
+	installHandler sigPIPE Ignore Nothing;
 	putStrLn $ "Listening on port " ++ show (listenPort globalOptions)
 	serverSocket <- listenOn $ PortNumber (listenPort globalOptions)
 	startServer serverSocket `finally` sClose serverSocket