It seems, I finally got the solution
authorunc0rr
Mon, 03 Nov 2008 11:28:41 +0000
changeset 1466 c68b0a0969d3
parent 1465 08e98772235c
child 1467 b288aea6b3d2
It seems, I finally got the solution
netserver/Miscutils.hs
netserver/hedgewars-server.hs
--- a/netserver/Miscutils.hs	Mon Nov 03 09:55:30 2008 +0000
+++ b/netserver/Miscutils.hs	Mon Nov 03 11:28:41 2008 +0000
@@ -81,6 +81,9 @@
 deleteFirstsBy2t :: (a -> b -> Bool) -> [a] -> [b] -> [a]
 deleteFirstsBy2t eq =  foldl (flip (deleteBy2t eq))
 
+clientByHandle :: Handle -> [ClientInfo] -> Maybe ClientInfo
+clientByHandle chandle clients = find (\c -> handle c == chandle) clients
+
 sameRoom :: HandlesSelector
 sameRoom client clients rooms = map handle $ filter (\ci -> room ci == room client) clients
 
--- a/netserver/hedgewars-server.hs	Mon Nov 03 09:55:30 2008 +0000
+++ b/netserver/hedgewars-server.hs	Mon Nov 03 11:28:41 2008 +0000
@@ -61,12 +61,12 @@
 	unless (null recipients) $ putStrLn ("< " ++ (show answer))
 
 	clHandles' <- forM recipients $
-		\ch -> Control.Exception.handle (\e -> putStrLn ("handle exception: " ++ show e) >> if head answer == "BYE" then return [ch] else return []) $ -- cannot just remove
+		\ch -> Control.Exception.handle (\e -> putStrLn ("handle exception: " ++ show e) >> if head answer == "BYE" then return [ch] else atomically $ writeTChan (chan $ fromJust $ clientByHandle ch clients)  ["QUIT"] >> return []) $ -- cannot just remove
 			do
 			forM_ answer (\str -> hPutStrLn ch str)
 			hPutStrLn ch ""
 			hFlush ch
-			if head answer == "BYE" then hClose ch >> return [ch] else return []
+			if head answer == "BYE" then return [ch] else return []
 
 	let mclients = remove clients $ concat clHandles'