# HG changeset patch # User unc0rr # Date 1209657303 0 # Node ID 344ba7dba23db1615fd078ec1a62555568d08b1d # Parent 35d91fa3753b2350f5606a5694d48cfc97061740 Handle QUIT of the master: disconnect all roommates diff -r 35d91fa3753b -r 344ba7dba23d netserver/HWProto.hs --- a/netserver/HWProto.hs Thu May 01 15:26:09 2008 +0000 +++ b/netserver/HWProto.hs Thu May 01 15:55:03 2008 +0000 @@ -71,12 +71,14 @@ handleCmd_inRoom client _ rooms _ = (client, rooms, [client], ["ERROR", "Bad command or incorrect parameter"]) --- state-independent comman handlers +-- state-independent command handlers handleCmd :: ClientInfo -> [ClientInfo] -> [RoomInfo] -> [String] -> (ClientInfo, [RoomInfo], [ClientInfo], [String]) handleCmd client clients rooms ("QUIT":xs) = if null (room client) then (client, rooms, [client], ["QUIT"]) + else if isMaster client then + (client, filter (\rm -> room client /= name rm) rooms, fromRoom (room client) clients, ["ROOMABANDONED"]) else (client, rooms, fromRoom (room client) clients, ["QUIT", nick client]) diff -r 35d91fa3753b -r 344ba7dba23d netserver/newhwserv.hs --- a/netserver/newhwserv.hs Thu May 01 15:26:09 2008 +0000 +++ b/netserver/newhwserv.hs Thu May 01 15:55:03 2008 +0000 @@ -44,7 +44,7 @@ \ci -> do forM_ strs (\str -> hPutStrLn (handle ci) str) hFlush (handle ci) - return [] + if (not $ null strs) && (head strs == "ROOMABANDONED") then hClose (handle ci) >> return [ci] else return [] `catch` const (hClose (handle ci) >> return [ci]) client' <- if (not $ null strs) && (head strs == "QUIT") then hClose (handle client) >> return [client] else return []