Bring back full log strings for commands, just a bit sanitized
authorunc0rr
Mon, 11 Feb 2013 10:20:07 +0400
changeset 8498 eecadca7db50
parent 8497 c5605c6f5bb3
child 8499 da5394a3eb0e
Bring back full log strings for commands, just a bit sanitized
hedgewars/uCommands.pas
hedgewars/uIO.pas
hedgewars/uUtils.pas
--- a/hedgewars/uCommands.pas	Mon Feb 11 00:19:15 2013 +0400
+++ b/hedgewars/uCommands.pas	Mon Feb 11 10:20:07 2013 +0400
@@ -88,12 +88,14 @@
 //WriteLnToConsole(CmdStr);
 if CmdStr[0]=#0 then
     exit;
+
+AddFileLog('[Cmd] ' + sanitizeForLog(CmdStr));
+
 c:= CmdStr[1];
 if (c = '/') or (c = '$') then
     Delete(CmdStr, 1, 1);
 s:= '';
 SplitBySpace(CmdStr, s);
-AddFileLog('[Cmd] ' + CmdStr + ' (' + inttostr(length(s)) + ')');
 
 t:= Variables;
 while t <> nil do
--- a/hedgewars/uIO.pas	Mon Feb 11 00:19:15 2013 +0400
+++ b/hedgewars/uIO.pas	Mon Feb 11 10:20:07 2013 +0400
@@ -144,7 +144,7 @@
      else
      loTicks:= SDLNet_Read16(@s[byte(s[0]) - 1]);
      AddCmd(loTicks, s);
-     AddFileLog('[IPC in] '+s[1]+' ticks '+IntToStr(lastcmd^.loTime));
+     AddFileLog('[IPC in] ' + sanitizeCharForLog(s[1]) + ' ticks ' + IntToStr(lastcmd^.loTime));
      end
 end;
 
@@ -239,7 +239,8 @@
         s[0]:= #251;
         
     SDLNet_Write16(GameTicks, @s[Succ(byte(s[0]))]);
-    AddFileLog('[IPC out] '+ s[1]);
+    
+    AddFileLog('[IPC out] '+ sanitizeCharForLog(s[1]));
     inc(s[0], 2);
     
     if isSyncedCommand(s[1]) then
--- a/hedgewars/uUtils.pas	Mon Feb 11 00:19:15 2013 +0400
+++ b/hedgewars/uUtils.pas	Mon Feb 11 10:20:07 2013 +0400
@@ -84,6 +84,9 @@
 procedure AudioServicesPlaySystemSound(num: LongInt); cdecl; external;
 {$ENDIF}
 
+function  sanitizeForLog(s: shortstring): shortstring;
+function  sanitizeCharForLog(c: char): shortstring;
+
 procedure initModule(isNotPreview: boolean);
 procedure freeModule;
 
@@ -441,6 +444,31 @@
 {$ENDIF}
 end;
 
+function  sanitizeForLog(s: shortstring): shortstring;
+var i: byte;
+    r: shortstring;
+begin
+    r[0]:= s[0];
+    for i:= 1 to length(s) do
+        if (s[i] < #32) or (s[i] > #127) then
+            r[i]:= '?'
+            else
+            r[i]:= s[i];
+            
+    sanitizeForLog:= r
+end;
+
+function  sanitizeCharForLog(c: char): shortstring;
+var r: shortstring;
+begin
+    if (c < #32) or (c > #127) then
+        r:= '#' + inttostr(byte(c))
+        else
+        r:= c;
+            
+    sanitizeCharForLog:= r
+end;
+
 procedure initModule(isNotPreview: boolean);
 {$IFDEF DEBUGFILE}
 var logfileBase: shortstring;