DEADSOFTWARE

svrlist: fix local server ip decoding on big endian machines
[d2df-sdl.git] / src / engine / e_log.pas
index 22db6527781c00ec9d8301d13e2b705a5365c7e4..dbe7b5dc2773f5881427c776d1d66f57e2835e7d 100644 (file)
@@ -2,8 +2,7 @@
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -40,21 +39,18 @@ function DecodeIPV4 (ip: LongWord): string;
 // start Write/WriteLn driver. it will write everything to cbuf.
 procedure e_InitWritelnDriver ();
 
-procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
+procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
 
-
 procedure e_WriteStackTrace (const msg: AnsiString);
 
-
-var
-  e_WriteToStdOut: Boolean = False;
-
-
 implementation
 
 uses
-  SDL2, conbuf, utils;
+  {$IFDEF ANDROID}
+    SDL2,
+  {$ENDIF}
+  conbuf, utils;
 
 var
   FirstRecord: Boolean;
@@ -64,19 +60,32 @@ var
 
 function DecodeIPV4 (ip: LongWord): string;
 begin
+{$IFDEF FPC_LITTLE_ENDIAN}
   Result := Format('%d.%d.%d.%d', [ip and $FF, (ip shr 8) and $FF, (ip shr 16) and $FF, (ip shr 24)]);
+{$ELSE}
+  Result := Format('%d.%d.%d.%d', [(ip shr 24), (ip shr 16) and $FF, (ip shr 8) and $FF, ip and $FF]);
+{$ENDIF}
+end;
+
+
+function consoleAllow (const s: String): Boolean;
+begin
+  Result := False;
+  if Pos('[Chat] ', s) = 1 then
+    Exit;
+  Result := True;
 end;
 
 
 procedure e_WriteLog (TextLine: String; RecordCategory: TMsgType; WriteTime: Boolean=True);
 begin
-  e_LogWritefln('%s', [TextLine], RecordCategory, WriteTime);
+  e_LogWritefln('%s', [TextLine], RecordCategory, WriteTime, consoleAllow(TextLine));
 end;
 
 
 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
 begin
-  e_LogWritefln('%s', [s], category, writeTime);
+  e_LogWritefln('%s', [s], category, writeTime, consoleAllow(s));
 end;
 
 
@@ -180,7 +189,7 @@ begin
 end;
 
 
-procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
+procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
 
   procedure xwrite (const s: AnsiString);
   begin
@@ -189,7 +198,7 @@ procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category:
   end;
 
 begin
-  if driverInited and (length(fmt) > 0) then
+  if driverInited and (length(fmt) > 0) and writeConsole then
   begin
     case category of
       TMsgType.Fatal: write('FATAL: ');