- More verbose output
authorunc0rr
Fri, 17 Apr 2009 19:58:21 +0000
changeset 2001 d909152bdc21
parent 2000 f9f47e681aad
child 2002 37c71f5983c9
- More verbose output - Fix one way of crashing server
gameServer/Actions.hs
gameServer/ClientIO.hs
--- a/gameServer/Actions.hs	Fri Apr 17 17:02:24 2009 +0000
+++ b/gameServer/Actions.hs	Fri Apr 17 19:58:21 2009 +0000
@@ -117,6 +117,7 @@
 
 
 processAction (clID, serverInfo, clients, rooms) (ByeClient msg) = do
+	infoM "Clients" ((show $ clientUID client) ++ " quits: " ++ msg)
 	(_, _, newClients, newRooms) <-
 			if roomID client /= 0 then
 				processAction  (clID, serverInfo, clients, rooms)
--- a/gameServer/ClientIO.hs	Fri Apr 17 17:02:24 2009 +0000
+++ b/gameServer/ClientIO.hs	Fri Apr 17 19:58:21 2009 +0000
@@ -8,18 +8,21 @@
 ----------------
 import CoreTypes
 
-listenLoop :: Handle -> [String] -> Chan CoreMessage -> Int -> IO ()
-listenLoop handle buf chan clientID = do
+listenLoop :: Handle -> Int -> [String] -> Chan CoreMessage -> Int -> IO ()
+listenLoop handle linesNumber buf chan clientID = do
 	str <- hGetLine handle
-	if str == "" then do
-		writeChan chan $ ClientMessage (clientID, buf)
-		listenLoop handle [] chan clientID
+	if (linesNumber > 50) || (length str > 450) then
+		writeChan chan $ ClientMessage (clientID, ["QUIT", "Protocol violation"])
 		else
-		listenLoop handle (buf ++ [str]) chan clientID
+		if str == "" then do
+			writeChan chan $ ClientMessage (clientID, buf)
+			listenLoop handle 0 [] chan clientID
+			else
+			listenLoop handle (linesNumber + 1) (buf ++ [str]) chan clientID
 
 clientRecvLoop :: Handle -> Chan CoreMessage -> Int -> IO ()
 clientRecvLoop handle chan clientID =
-	listenLoop handle [] chan clientID
+	listenLoop handle 0 [] chan clientID
 		`catch` (\e -> (clientOff $ show e) >> return ())
 	where clientOff msg = writeChan chan $ ClientMessage (clientID, ["QUIT", msg]) -- if the client disconnects, we perform as if it sent QUIT message