# HG changeset patch
# User unc0rr
# Date 1337632172 -14400
# Node ID 1c1afb5a15652d4890c6e6bf9a4de6d0842c6123
# Parent  96f655d06e9ec21155f0cd75b697827160b172f8
Feel free to add real checksum function

diff -r 96f655d06e9e -r 1c1afb5a1565 hedgewars/uCommandHandlers.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;
 
diff -r 96f655d06e9e -r 1c1afb5a1565 hedgewars/uIO.pas
--- 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
diff -r 96f655d06e9e -r 1c1afb5a1565 hedgewars/uVariables.pas
--- 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