It's explicitly not using the timestamp as the timestamp might be removed in 
future to save bandwidth.
---
 lib/wormux/include/WORMUX_action.h |    1 +
 src/game/game.cpp                  |   22 +++++++++++++++-------
 src/include/action_handler.cpp     |    9 +++++++++
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/lib/wormux/include/WORMUX_action.h 
b/lib/wormux/include/WORMUX_action.h
index b443741..ff525d1 100644
--- a/lib/wormux/include/WORMUX_action.h
+++ b/lib/wormux/include/WORMUX_action.h
@@ -119,6 +119,7 @@ public:
     // ########################################################
     ACTION_NETWORK_PING,
     ACTION_NETWORK_VERIFY_RANDOM_SYNC,
+    ACTION_TIME_VERIFY_SYNC,
     // ########################################################
   } Action_t;
 
diff --git a/src/game/game.cpp b/src/game/game.cpp
index a52214f..d71d866 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -524,15 +524,23 @@ void Game::MainLoop()
       FOR_ALL_CHARACTERS(team,character)
         character->GetBody()->Build();
 
-      // The action which verifys the random seed must be the first action 
sheduled!
-      // Otherwise the following could happen:
-      // 1. Action C gets sheduled which draws values from the random source.
-      // 2. Action V gets sheduled which verifies that random seed is X.
-      // 3. Action C gets executed: As a result the random seed has changed to 
another value Y.
-      // 4. Action V gets executed: It fails as the random seed is no longer X 
but Y.
-      if (Network::GetInstance()->IsTurnMaster())
+
+      if (Network::GetInstance()->IsTurnMaster()) {
+        // The action which verifys the random seed must be the first action 
sheduled!
+        // Otherwise the following could happen:
+        // 1. Action C gets sheduled which draws values from the random source.
+        // 2. Action V gets sheduled which verifies that random seed is X.
+        // 3. Action C gets executed: As a result the random seed has changed 
to another value Y.
+        // 4. Action V gets executed: It fails as the random seed is no longer 
X but Y.
         RandomSync().Verify();
 
+#ifdef DEBUG
+        Action* action = new Action(Action::ACTION_TIME_VERIFY_SYNC);
+        action->Push((int)Time::GetInstance()->Read());
+        ActionHandler::GetInstance()->NewAction(action);
+#endif
+      }
+
       if (Time::GetInstance()->Read() % 1000 == 20 && 
Network::GetInstance()->IsGameMaster())
         PingClient();
     }
diff --git a/src/include/action_handler.cpp b/src/include/action_handler.cpp
index 9ed80fe..439b3d5 100644
--- a/src/include/action_handler.cpp
+++ b/src/include/action_handler.cpp
@@ -714,6 +714,14 @@ static void Action_Network_VerifyRandomSync(Action *a)
     RandomSync().SetSeed(remote_seed);
 }
 
+static void Action_Time_VerifySync(Action *a)
+{
+  uint local_time = Time::GetInstance()->Read();
+  uint remote_time = (uint)(a->PopInt());
+  MSG_DEBUG("time.verify","Verify time: %d (local) == %d (remote)", 
local_time, remote_time);
+  ASSERT(local_time == remote_time);
+}
+
 // Nothing to do here. Just for time synchronisation
 static void Action_Network_Ping(Action */*a*/)
 {
@@ -961,6 +969,7 @@ void Action_Handler_Init()
   ActionHandler::GetInstance()->Register (Action::ACTION_NETWORK_PING, 
"NETWORK_ping", &Action_Network_Ping);
   ActionHandler::GetInstance()->Register (Action::ACTION_NETWORK_RANDOM_INIT, 
"NETWORK_random_init", &Action_Network_RandomInit);
   ActionHandler::GetInstance()->Register 
(Action::ACTION_NETWORK_VERIFY_RANDOM_SYNC, "NETWORK_verify_random_sync", 
&Action_Network_VerifyRandomSync);
+  ActionHandler::GetInstance()->Register (Action::ACTION_TIME_VERIFY_SYNC, 
"TIME_verify_sync", &Action_Time_VerifySync);
   ActionHandler::GetInstance()->Register 
(Action::ACTION_INFO_CLIENT_DISCONNECT, "INFO_client_disconnect", 
&Action_Info_ClientDisconnect);
   ActionHandler::GetInstance()->Register (Action::ACTION_INFO_CLIENT_CONNECT, 
"INFO_client_connect", &Action_Info_ClientConnect);
 
-- 
1.6.0.4


_______________________________________________
Wormux-dev mailing list
Wormux-dev@gna.org
https://mail.gna.org/listinfo/wormux-dev

Répondre à