# HG changeset patch # User unc0rr # Date 1223318447 0 # Node ID 1a38a967bd48358370603e982157bf5ac5fd54c7 # Parent d5dcd6cfa5e27338e1a0df607633185e5522a47e Fix a bug with 'ghosts' on server diff -r d5dcd6cfa5e2 -r 1a38a967bd48 netserver/HWProto.hs --- a/netserver/HWProto.hs Mon Oct 06 18:37:47 2008 +0000 +++ b/netserver/HWProto.hs Mon Oct 06 18:40:47 2008 +0000 @@ -7,9 +7,9 @@ import Maybe (fromMaybe, fromJust) answerBadCmd = [(clientOnly, ["ERROR", "Bad command, state or incorrect parameter"])] -answerQuit = [(clientOnly, ["BYE"])] +answerQuit = [(clientOnly, ["off"])] answerAbandoned = [(sameRoom, ["BYE"])] -answerQuitInform nick = [(othersInRoom, ["QUIT", nick])] +answerQuitInform nick = [(othersInRoom, ["LEFT", nick])] answerNickChosen = [(clientOnly, ["ERROR", "The nick already chosen"])] answerNickChooseAnother = [(clientOnly, ["WARNING", "Choose another nick"])] answerNick nick = [(clientOnly, ["NICK", nick])] @@ -32,7 +32,7 @@ else if isMaster client then (noChangeClients, removeRoom (room client), answerAbandoned) -- core disconnects clients on ROOMABANDONED answer else - (noChangeClients, noChangeRooms, answerQuitInform $ nick client) + (noChangeClients, noChangeRooms, answerQuit ++ (answerQuitInform $ nick client)) -- check state and call state-dependent commmand handlers diff -r d5dcd6cfa5e2 -r 1a38a967bd48 netserver/newhwserv.hs --- a/netserver/newhwserv.hs Mon Oct 06 18:37:47 2008 +0000 +++ b/netserver/newhwserv.hs Mon Oct 06 18:40:47 2008 +0000 @@ -36,7 +36,7 @@ clientLoop handle chan = listenLoop handle [] chan `catch` (const $ clientOff >> return ()) - where clientOff = atomically $ writeTChan chan ["QUIT"] -- если клиент отключается, то делаем вид, что от него пришла команда QUIT + where clientOff = atomically $ writeTChan chan ["QUIT"] -- if the client disconnects, we perform as if it sent QUIT message sendAnswers [] _ clients _ = return clients @@ -46,6 +46,7 @@ clHandles' <- forM recipients $ \ch -> Control.Exception.handle (\e -> putStrLn (show e) >> hClose ch >> return [ch]) $ + if (not $ null answer) && (head answer == "off") then hClose ch >> return [ch] else -- probably client with exception, don't send him anything do forM_ answer (\str -> hPutStrLn ch str) hPutStrLn ch ""