- Implement ping timeout
authorunc0rr
Fri, 27 Mar 2009 20:36:50 +0000
changeset 1928 9bf8f4f30d6b
parent 1927 e2031906a347
child 1929 7e6cc8da1c58
- Implement ping timeout - It triggers bug with kicking room creator
gameServer/Actions.hs
gameServer/HWProtoCore.hs
--- a/gameServer/Actions.hs	Fri Mar 27 20:29:38 2009 +0000
+++ b/gameServer/Actions.hs	Fri Mar 27 20:36:50 2009 +0000
@@ -343,8 +343,14 @@
 
 
 processAction (clID, serverInfo, clients, rooms) PingAll = do
+	(_, _, newClients, newRooms) <- foldM kickTimeouted (clID, serverInfo, clients, rooms) $ elems clients
 	processAction (clID,
 		serverInfo,
-		map (\cl -> cl{pingsQueue = pingsQueue cl + 1}) clients,
-		rooms) $ AnswerAll ["PING"]
-
+		Data.IntMap.map (\cl -> cl{pingsQueue = pingsQueue cl + 1}) newClients,
+		newRooms) $ AnswerAll ["PING"]
+	where
+		kickTimeouted (clID, serverInfo, clients, rooms) client =
+			if pingsQueue client > 0 then
+				processAction (clientUID client, serverInfo, clients, rooms) $ ByeClient "Ping timeout"
+				else
+				return (clID, serverInfo, clients, rooms)
--- a/gameServer/HWProtoCore.hs	Fri Mar 27 20:29:38 2009 +0000
+++ b/gameServer/HWProtoCore.hs	Fri Mar 27 20:36:50 2009 +0000
@@ -24,6 +24,15 @@
 		msg = if not $ null xs then head xs else ""
 
 
+handleCmd clID clients _ ["PONG"] =
+	if pingsQueue client == 0 then
+		[ProtocolError "Protocol violation"]
+	else
+		[ModifyClient (\cl -> cl{pingsQueue = pingsQueue cl - 1})]
+	where
+		client = clients IntMap.! clID
+
+
 handleCmd clID clients rooms cmd =
 	if not $ logonPassed client then
 		handleCmd_NotEntered clID clients rooms cmd