Flag script parsecommands to avoid echoing to net
authornemo
Tue, 23 Oct 2012 16:52:13 -0400
changeset 7805 2a249a4faf5b
parent 7804 9122461ae32b
child 7806 c27713b5e052
Flag script parsecommands to avoid echoing to net
hedgewars/uCommandHandlers.pas
hedgewars/uCommands.pas
hedgewars/uGears.pas
hedgewars/uScript.pas
--- a/hedgewars/uCommandHandlers.pas	Wed Oct 24 00:35:27 2012 +0400
+++ b/hedgewars/uCommandHandlers.pas	Tue Oct 23 16:52:13 2012 -0400
@@ -37,7 +37,7 @@
     'R': if ReadyTimeLeft > 1 then 
         begin
         ReadyTimeLeft:= 1;
-        if not CurrentTeam^.ExtDriven then
+        if not isExternalSource then
             SendIPC('c'+s);
         end
     end
@@ -218,7 +218,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'L');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -231,7 +231,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'l');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmLeft and InputMask));
@@ -243,7 +243,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'R');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -256,7 +256,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'r');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmRight and InputMask));
@@ -268,7 +268,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'U');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -281,7 +281,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'u');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmUp and InputMask));
@@ -293,7 +293,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'D');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -306,7 +306,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'd');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmDown and InputMask));
@@ -318,7 +318,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'Z');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -331,7 +331,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'z');
 with CurrentHedgehog^.Gear^ do
     Message:= Message and (not (gmPrecise and InputMask));
@@ -343,7 +343,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'j');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -356,7 +356,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'J');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -376,7 +376,7 @@
     if ((State and gstHHDriven) <> 0) then
         begin
         FollowGear:= CurrentHedgehog^.Gear;
-        if not CurrentTeam^.ExtDriven then
+        if not isExternalSource then
             SendIPC(_S'A');
         Message:= Message or (gmAttack and InputMask);
         ScriptCall('onAttack');
@@ -391,7 +391,7 @@
     exit;
 with CurrentHedgehog^.Gear^ do
     begin
-    if not CurrentTeam^.ExtDriven and
+    if not isExternalSource and
         ((Message and gmAttack) <> 0) then
             SendIPC(_S'a');
     Message:= Message and (not (gmAttack and InputMask));
@@ -404,7 +404,7 @@
 s:= s; // avoid compiler hint
 if CheckNoTeamOrHH or isPaused then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S'S');
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -428,7 +428,7 @@
         gi := gi^.NextGear
         end;
 
-    if not CurrentTeam^.ExtDriven then
+    if not isExternalSource then
         begin
         s[0]:= #5;
         s[1]:= 'N';
@@ -447,7 +447,7 @@
 
 TryDo((s[0] = #1) and (s[1] >= '1') and (s[1] <= '5'), 'Malformed /timer', true);
 
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(s);
 bShowFinger:= false;
 with CurrentHedgehog^.Gear^ do
@@ -467,7 +467,7 @@
 slot:= byte(s[1]) - 49;
 if slot > cMaxSlotIndex then
     exit;
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     begin
     ss[0]:= #1;
     ss[1]:= char(byte(s[1]) + 79);
@@ -489,7 +489,7 @@
 
     TryDo((s[0] = #1) and (s[1] <= char(High(TAmmoType))), 'Malformed /setweap', true);
 
-    if not CurrentTeam^.ExtDriven then
+    if not isExternalSource then
         SendIPC('w' + s);
 
     with CurrentHedgehog^.Gear^ do
@@ -508,7 +508,7 @@
 if TWave(s[1]) > High(TWave) then
     exit;
 
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC('t' + s);
 
 with CurrentHedgehog^.Gear^ do
--- a/hedgewars/uCommands.pas	Wed Oct 24 00:35:27 2012 +0400
+++ b/hedgewars/uCommands.pas	Tue Oct 23 16:52:13 2012 -0400
@@ -23,13 +23,15 @@
 interface
 
 var isDeveloperMode: boolean;
+var isExternalSource: boolean;
 type TCommandHandler = procedure (var params: shortstring);
 
 procedure initModule;
 procedure freeModule;
 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean; Rand: boolean);
 procedure RegisterVariable(Name: shortstring; p: TCommandHandler; Trusted: boolean);
-procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
+procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); inline;
+procedure ParseCommand(CmdStr: shortstring; TrustedSource, ExternalSource: boolean);
 procedure ParseTeamCommand(s: shortstring);
 procedure StopMessages(Message: Longword);
 
@@ -73,11 +75,17 @@
 end;
 
 
-procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean);
+procedure ParseCommand(CmdStr: shortstring; TrustedSource: boolean); inline;
+begin
+    ParseCommand(CmdStr, TrustedSource, false)
+end;
+
+procedure ParseCommand(CmdStr: shortstring; TrustedSource, ExternalSource: boolean);
 var s: shortstring;
     t: PVariable;
     c: char;
 begin
+isExternalSource:= ExternalSource or CurrentTeam^.ExtDriven;
 //WriteLnToConsole(CmdStr);
 if CmdStr[0]=#0 then
     exit;
--- a/hedgewars/uGears.pas	Wed Oct 24 00:35:27 2012 +0400
+++ b/hedgewars/uGears.pas	Tue Oct 23 16:52:13 2012 -0400
@@ -1223,7 +1223,7 @@
 procedure chSkip(var s: shortstring);
 begin
 s:= s; // avoid compiler hint
-if not CurrentTeam^.ExtDriven then
+if not isExternalSource then
     SendIPC(_S',');
 uStats.Skipped;
 skipFlag:= true
--- a/hedgewars/uScript.pas	Wed Oct 24 00:35:27 2012 +0400
+++ b/hedgewars/uScript.pas	Tue Oct 23 16:52:13 2012 -0400
@@ -46,7 +46,7 @@
 function ScriptExists(fname : shortstring) : boolean;
 
 
-function ParseCommandOverride(key, value : shortstring) : shortstring;
+//function ParseCommandOverride(key, value : shortstring) : shortstring;  This did not work out well
 
 procedure initModule;
 procedure freeModule;
@@ -196,7 +196,7 @@
         for i:= 1 to c do s[i]:= t[i-1];
         s[0]:= char(c);
 
-        ParseCommand(s, true);
+        ParseCommand(s, true, true);
 
         end
     else
@@ -1306,11 +1306,11 @@
         end
     else
         begin
-        ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true);
-        ParseCommand('grave ' + lua_tostring(L, 3), true);
-        ParseCommand('fort ' + lua_tostring(L, 4), true);
-        ParseCommand('voicepack ' + lua_tostring(L, 5), true);
-        if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true);
+        ParseCommand('addteam x ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 1), true, true);
+        ParseCommand('grave ' + lua_tostring(L, 3), true, true);
+        ParseCommand('fort ' + lua_tostring(L, 4), true, true);
+        ParseCommand('voicepack ' + lua_tostring(L, 5), true, true);
+        if (np = 6) then ParseCommand('flag ' + lua_tostring(L, 6), true, true);
         CurrentTeam^.Binds:= DefaultBinds
         // fails on x64
         //lua_pushinteger(L, LongInt(CurrentTeam));
@@ -1329,8 +1329,8 @@
     else
         begin
         temp:= lua_tostring(L, 4);
-        ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true);
-        ParseCommand('hat ' + temp, true);
+        ParseCommand('addhh ' + lua_tostring(L, 2) + ' ' + lua_tostring(L, 3) + ' ' + lua_tostring(L, 1), true, true);
+        ParseCommand('hat ' + temp, true, true);
         lua_pushinteger(L, CurrentHedgehog^.Gear^.uid);
         end;
     lc_addhog:= 1;
@@ -1871,7 +1871,7 @@
 ScriptCall('onGameInit');
 
 // pop game variables
-ParseCommand('seed ' + ScriptGetString('Seed'), true);
+ParseCommand('seed ' + ScriptGetString('Seed'), true, true);
 cTemplateFilter  := ScriptGetInteger('TemplateFilter');
 LuaTemplateNumber:= ScriptGetInteger('TemplateNumber');
 cMapGen          := ScriptGetInteger('MapGen');
@@ -1893,9 +1893,9 @@
 cHealthDecrease  := ScriptGetInteger('HealthDecrease');
 
 if cMapName <> ScriptGetString('Map') then
-    ParseCommand('map ' + ScriptGetString('Map'), true);
+    ParseCommand('map ' + ScriptGetString('Map'), true, true);
 if ScriptGetString('Theme') <> '' then
-    ParseCommand('theme ' + ScriptGetString('Theme'), true);
+    ParseCommand('theme ' + ScriptGetString('Theme'), true, true);
 LuaGoals:= ScriptGetString('Goals');
 
 // Support lua changing the ammo layout - assume all hogs have same ammo, note this might leave a few ammo stores lying around.
@@ -2017,6 +2017,7 @@
 GetGlobals;
 end;
 
+(*
 function ParseCommandOverride(key, value : shortstring) : shortstring;
 begin
 ParseCommandOverride:= value;
@@ -2036,6 +2037,7 @@
     lua_pop(luaState, 1)
     end;
 end;
+*)
 
 function ScriptCall(fname : shortstring; par1: LongInt) : LongInt;
 begin
@@ -2450,7 +2452,7 @@
     fname:= fname; // avoid hint
     ScriptExists:= false
 end;
-
+(*
 function ParseCommandOverride(key, value : shortstring) : shortstring;
 begin
     // avoid hints
@@ -2458,6 +2460,7 @@
     value:= value;
     ParseCommandOverride:= ''
 end;
+*)
 
 procedure ScriptOnScreenResize;
 begin