gameServer/ClientIO.hs
changeset 2001 d909152bdc21
parent 1804 4e78ad846fb6
child 2126 cb249fa8e3da
--- 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