Fix a bug with 'ghosts' on server
authorunc0rr
Mon, 06 Oct 2008 18:40:47 +0000
changeset 1309 1a38a967bd48
parent 1308 d5dcd6cfa5e2
child 1310 4616e15d566f
Fix a bug with 'ghosts' on server
netserver/HWProto.hs
netserver/newhwserv.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
--- 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 ""