# HG changeset patch # User unc0rr # Date 1224689495 0 # Node ID abb28dcb6d0d2844f5607b37ff5821d3b833fd4e # Parent 46fd70de89e2774176a0134bbba78469e8400d49 - Send additional info on rooms - Handle SIGPIPE diff -r 46fd70de89e2 -r abb28dcb6d0d netserver/HWProto.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))] diff -r 46fd70de89e2 -r abb28dcb6d0d netserver/Miscutils.hs --- 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] diff -r 46fd70de89e2 -r abb28dcb6d0d netserver/hedgewars-server.hs --- 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