- Send previous moves info to newly connected client when it joins a room with already started game
authorunc0rr
Fri, 02 Jan 2009 13:00:46 +0000
changeset 1558 3370b7ffeb5c
parent 1557 0d1fa1d6d8d5
child 1559 71e1f67dcfe7
- Send previous moves info to newly connected client when it joins a room with already started game - Shows a bug in frontend which needs to be fixed
QTfrontend/newnetclient.cpp
netserver/HWProto.hs
netserver/Miscutils.hs
netserver/hedgewars-server.hs
--- a/QTfrontend/newnetclient.cpp	Fri Jan 02 09:55:17 2009 +0000
+++ b/QTfrontend/newnetclient.cpp	Fri Jan 02 13:00:46 2009 +0000
@@ -189,7 +189,7 @@
 
 void HWNewNet::ParseCmd(const QStringList & lst)
 {
-	//qDebug() << "Server: " << lst;
+	qDebug() << "Server: " << lst;
 
 	if(!lst.size())
 	{
@@ -448,8 +448,11 @@
 			qWarning("Net: Bad GAMEMSG message");
 			return;
 		}
-		QByteArray em = QByteArray::fromBase64(lst[1].toAscii());
-		emit FromNet(em);
+		for(int i = 1; i < lst.size(); ++i)
+		{
+			QByteArray em = QByteArray::fromBase64(lst[1].toAscii());
+			emit FromNet(em);
+		}
 		return;
 	}
 
--- a/netserver/HWProto.hs	Fri Jan 02 09:55:17 2009 +0000
+++ b/netserver/HWProto.hs	Fri Jan 02 13:00:46 2009 +0000
@@ -191,13 +191,17 @@
 	else if isRestrictedJoins clRoom then
 		(noChangeClients, noChangeRooms, answerRestricted)
 	else
-		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ answerReady ++ (answerJoined $ nick client) ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom)
+		(modifyClient client{room = roomName}, modifyRoom clRoom{playersIn = 1 + playersIn clRoom}, answerNicks ++ answerReady ++ (answerJoined $ nick client) ++ (answerNotReady $ nick client) ++ answerFullConfig clRoom ++ answerAllTeams clRoom ++ watchRound)
 	where
 		noSuchRoom = isNothing $ find (\room -> roomName == name room && roomProto room == protocol client) rooms
 		answerNicks = answerClientOnly $ ["JOINED"] ++ (map nick $ sameRoomClients)
 		answerReady = concatMap (\c -> answerClientOnly [if isReady c then "READY" else "NOT_READY", nick c]) sameRoomClients
 		sameRoomClients = filter (\ci -> room ci == roomName) clients
 		clRoom = roomByName roomName rooms
+		watchRound = if (roomProto clRoom < 20) || (not $ gameinprogress clRoom) then
+					[]
+				else
+					answerRunGame ++ answerClientOnly ("GAMEMSG" : roundMsgs clRoom)
 
 handleCmd_noRoom client clients rooms ["JOIN", roomName] =
 	handleCmd_noRoom client clients rooms ["JOIN", roomName, ""]
@@ -343,8 +347,14 @@
 		sameRoomClients = filter (\ci -> room ci == name clRoom) clients
 		answerAllNotReady = concatMap (\cl -> answerSameRoom ["NOT_READY", nick cl]) sameRoomClients
 
-handleCmd_inRoom client _ _ ["GAMEMSG", msg] =
-	(noChangeClients, noChangeRooms, answerOthersRoom ["GAMEMSG", msg])
+handleCmd_inRoom client _ rooms ["GAMEMSG", msg] =
+	(noChangeClients, addMsg, answerOthersRoom ["GAMEMSG", msg])
+	where
+		addMsg = if roomProto clRoom < 20 then
+					noChangeRooms
+				else
+					modifyRoom clRoom{roundMsgs = roundMsgs clRoom ++ [msg]}
+		clRoom = roomByName (room client) rooms
 
 handleCmd_inRoom client clients rooms ["KICK", kickNick] =
 	if isMaster client then
--- a/netserver/Miscutils.hs	Fri Jan 02 09:55:17 2009 +0000
+++ b/netserver/Miscutils.hs	Fri Jan 02 13:00:46 2009 +0000
@@ -58,6 +58,7 @@
 		readyPlayers :: Int,
 		isRestrictedJoins :: Bool,
 		isRestrictedTeams :: Bool,
+		roundMsgs :: [String],
 		params :: Map.Map String [String]
 	}
 createRoom = (
@@ -72,6 +73,7 @@
 		0
 		False
 		False
+		[]
 		Map.empty
 	)
 
--- a/netserver/hedgewars-server.hs	Fri Jan 02 09:55:17 2009 +0000
+++ b/netserver/hedgewars-server.hs	Fri Jan 02 13:00:46 2009 +0000
@@ -1,4 +1,4 @@
-{-# LANGUAGE CPP, ScopedTypeVariables #-}
+{-# LANGUAGE CPP, ScopedTypeVariables, PatternSignatures #-}
 
 module Main where
 
@@ -20,7 +20,6 @@
 import System.Posix
 #endif
 
--- #define IOException Exception
 
 data Messages =
 	Accept ClientInfo
@@ -40,7 +39,7 @@
 
 acceptLoop :: Socket -> TChan ClientInfo -> IO ()
 acceptLoop servSock acceptChan =
-	Control.Exception.handle (\(_ :: IOException) -> putStrLn "exception on connect" >> acceptLoop servSock acceptChan) $
+	Control.Exception.handle (\(_ :: Exception) -> putStrLn "exception on connect" >> acceptLoop servSock acceptChan) $
 	do
 	(cHandle, host, _) <- accept servSock
 	
@@ -77,14 +76,14 @@
 clientSendLoop handle clChan chan = do
 	answer <- atomically $ readTChan chan
 	doClose <- Control.Exception.handle
-		(\(e :: IOException) -> if isQuit answer then return True else sendQuit e >> return False) $ do
+		(\(e :: Exception) -> if isQuit answer then return True else sendQuit e >> return False) $ do
 		forM_ answer (\str -> hPutStrLn handle str)
 		hPutStrLn handle ""
 		hFlush handle
 		return $ isQuit answer
 
 	if doClose then
-		Control.Exception.handle (\(_ :: IOException) -> putStrLn "error on hClose") $ hClose handle
+		Control.Exception.handle (\(_ :: Exception) -> putStrLn "error on hClose") $ hClose handle
 		else
 		clientSendLoop handle clChan chan