Feel free to add real checksum function
authorunc0rr
Tue, 22 May 2012 00:29:32 +0400
changeset 7103 1c1afb5a1565
parent 7102 96f655d06e9e
child 7104 2468316c1d9d
Feel free to add real checksum function
hedgewars/uCommandHandlers.pas
hedgewars/uIO.pas
hedgewars/uVariables.pas
--- a/hedgewars/uCommandHandlers.pas	Mon May 21 06:34:17 2012 +0200
+++ b/hedgewars/uCommandHandlers.pas	Tue May 22 00:29:32 2012 +0400
@@ -412,12 +412,23 @@
 end;
 
 procedure chNextTurn(var s: shortstring);
+var checksum: Longword;
 begin
     s:= s; // avoid compiler hint
+
     TryDo(AllInactive, '/nextturn called when not all gears are inactive', true);
 
+    checksum:= GameTicks;
+
     if not CurrentTeam^.ExtDriven then
-        SendIPC(_S'N');
+        begin
+        s[0]:= #5;
+        s[1]:= 'N';
+        SDLNet_Write32(checksum, @s[2]);
+        SendIPC(s)
+        end
+    else
+        TryDo(checksum = lastTurnChecksum, 'Desync detected', true);
     AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));
 end;
 
--- a/hedgewars/uIO.pas	Mon May 21 06:34:17 2012 +0200
+++ b/hedgewars/uIO.pas	Tue May 22 00:29:32 2012 +0400
@@ -318,6 +318,7 @@
         'F': ParseCommand('teamgone ' + copy(headcmd^.str, 2, Pred(headcmd^.len)), true);
         'N': begin
             tmpflag:= false;
+            lastTurnChecksum:= SDLNet_Read32(@headcmd^.str[2]);
             AddFileLog('got cmd "N": time '+IntToStr(hiTicks shl 16 + headcmd^.loTime))
              end;
         'p': begin
--- a/hedgewars/uVariables.pas	Mon May 21 06:34:17 2012 +0200
+++ b/hedgewars/uVariables.pas	Tue May 22 00:29:32 2012 +0400
@@ -2461,6 +2461,8 @@
 
     DefaultBinds : TBinds;
 
+    lastTurnChecksum : Longword;
+
 var trammo:  array[TAmmoStrId] of ansistring;   // name of the weapon
     trammoc: array[TAmmoStrId] of ansistring;   // caption of the weapon
     trammod: array[TAmmoStrId] of ansistring;   // description of the weapon