I thirst for randomness.
authornemo
Fri, 20 Jul 2012 15:12:47 -0400
changeset 7407 c1ade666c124
parent 7406 1fe2c821f9bf
child 7408 38d369c59d51
I thirst for randomness.
hedgewars/uCommandHandlers.pas
hedgewars/uCommands.pas
hedgewars/uGears.pas
--- a/hedgewars/uCommandHandlers.pas	Fri Jul 20 14:16:05 2012 -0400
+++ b/hedgewars/uCommandHandlers.pas	Fri Jul 20 15:12:47 2012 -0400
@@ -786,23 +786,23 @@
 procedure initModule;
 begin
 //////// Begin top sorted by freq analysis not including chatmsg
-    RegisterVariable('+right'  , @chRight_p      , false);
-    RegisterVariable('-right'  , @chRight_m      , false);
-    RegisterVariable('+up'     , @chUp_p         , false);
-    RegisterVariable('-up'     , @chUp_m         , false);
-    RegisterVariable('+left'   , @chLeft_p       , false);
-    RegisterVariable('-left'   , @chLeft_m       , false);
-    RegisterVariable('+attack' , @chAttack_p     , false);
-    RegisterVariable('+down'   , @chDown_p       , false);
-    RegisterVariable('-down'   , @chDown_m       , false);
-    RegisterVariable('hjump'   , @chHJump        , false);
-    RegisterVariable('ljump'   , @chLJump        , false);
-    RegisterVariable('nextturn', @chNextTurn     , false);
-    RegisterVariable('-attack' , @chAttack_m     , false);
-    RegisterVariable('slot'    , @chSlot         , false);
-    RegisterVariable('setweap' , @chSetWeapon    , false);
+    RegisterVariable('+right'  , @chRight_p      , false, true);
+    RegisterVariable('-right'  , @chRight_m      , false, true);
+    RegisterVariable('+up'     , @chUp_p         , false, true);
+    RegisterVariable('-up'     , @chUp_m         , false, true);
+    RegisterVariable('+left'   , @chLeft_p       , false, true);
+    RegisterVariable('-left'   , @chLeft_m       , false, true);
+    RegisterVariable('+attack' , @chAttack_p     , false, true);
+    RegisterVariable('+down'   , @chDown_p       , false, true);
+    RegisterVariable('-down'   , @chDown_m       , false, true);
+    RegisterVariable('hjump'   , @chHJump        , false, true);
+    RegisterVariable('ljump'   , @chLJump        , false, true);
+    RegisterVariable('nextturn', @chNextTurn     , false, true);
+    RegisterVariable('-attack' , @chAttack_m     , false, true);
+    RegisterVariable('slot'    , @chSlot         , false, true);
+    RegisterVariable('setweap' , @chSetWeapon    , false, true);
 //////// End top by freq analysis
-    RegisterVariable('gencmd'  , @chGenCmd       , false);
+    RegisterVariable('gencmd'  , @chGenCmd       , false, true);
     RegisterVariable('flag'    , @chFlag         , false);
     RegisterVariable('script'  , @chScript       , false);
     RegisterVariable('proto'   , @chCheckProto   , true );
--- a/hedgewars/uCommands.pas	Fri Jul 20 14:16:05 2012 -0400
+++ b/hedgewars/uCommands.pas	Fri Jul 20 15:12:47 2012 -0400
@@ -27,26 +27,31 @@
 
 procedure initModule;
 procedure freeModule;
+procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Synced: boolean);
 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean);
 procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
 procedure ParseTeamCommand(s: shortstring);
 procedure StopMessages(Message: Longword);
 
 implementation
-uses uConsts, uVariables, uConsole, uUtils, uDebug;
+uses uConsts, uVariables, uConsole, uUtils, uDebug, SDLh;
 
 type  PVariable = ^TVariable;
     TVariable = record
         Next: PVariable;
         Name: string[15];
         Handler: TCommandHandler;
-        Trusted: boolean;
+        Trusted, Synced: boolean;
         end;
 
 var
     Variables: PVariable;
 
 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean);
+begin
+RegisterVariable(Name, p, Trusted, false);
+end;
+procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Synced: boolean);
 var
     value: PVariable;
 begin
@@ -56,6 +61,7 @@
 value^.Name:= Name;
 value^.Handler:= p;
 value^.Trusted:= Trusted;
+value^.Synced:= Synced;
 
 if Variables = nil then
     Variables:= value
@@ -81,11 +87,13 @@
 s:= '';
 SplitBySpace(CmdStr, s);
 AddFileLog('[Cmd] ' + CmdStr + ' (' + inttostr(length(s)) + ')');
+
 t:= Variables;
 while t <> nil do
     begin
     if t^.Name = CmdStr then
         begin
+        if t^.Synced then CheckSum:= CheckSum xor LongWord(SDLNet_Read32(@CmdStr)) xor LongWord(s[0]) xor GameTicks;
         if TrustedSource or t^.Trusted then
             t^.Handler(s);
         exit
--- a/hedgewars/uGears.pas	Fri Jul 20 14:16:05 2012 -0400
+++ b/hedgewars/uGears.pas	Fri Jul 20 15:12:47 2012 -0400
@@ -461,6 +461,7 @@
     if (not CurrentTeam^.ExtDriven) or CurrentTeam^.hasGone then
         inc(hiTicks) // we do not recieve a message for this
     end;
+AddRandomness(CheckSum);
 ScriptCall('onGameTick');
 if GameTicks mod 20 = 0 then ScriptCall('onGameTick20');
 inc(GameTicks)