servers now log (almost) everything to file

- regex'd in mysqlexception logging
- servers can now specify server_port, log_path, log_file
- added scripts to import/export all tables (exporting will export a handful of garbage table names, open and check for structure before deleting)
- fixed packet logging (thanks deviltti)
This commit is contained in:
Tahir Akhlaq 2016-06-08 22:29:04 +01:00
parent 92339ba0c4
commit 8b93abe86e
238 changed files with 684 additions and 1532 deletions

View file

@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Lobby_Server.common
namespace FFXIVClassic_Map_Server.common
{
[global::System.AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
sealed class BitfieldLengthAttribute : Attribute

View file

@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Lobby_Server.common
namespace FFXIVClassic_Map_Server.common
{
public class Blowfish
{

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.common
{

View file

@ -1,58 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace FFXIVClassic_Lobby_Server.common
namespace FFXIVClassic_Map_Server.common
{
class Log
{
public enum LogType
{
Error = ConsoleColor.Red,
Debug = ConsoleColor.Yellow,
Info = ConsoleColor.Cyan,
Sql = ConsoleColor.Magenta,
Conn = ConsoleColor.Green,
Default = ConsoleColor.Gray
}
public static void error(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[ERROR] ");
Console.ForegroundColor = ConsoleColor.Gray ;
Console.WriteLine(message);
log(message, LogType.Error);
}
public static void debug(String message)
{
#if DEBUG
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("[DEBUG] ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
#endif
{
#if DEBUG
log(message, LogType.Debug);
#endif
}
public static void info(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("[INFO] ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
log(message, LogType.Info);
}
public static void database(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Magenta;
Console.Write("[SQL] ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
log(message, LogType.Sql);
}
public static void conn(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[CONN] ");
log(message, LogType.Conn);
}
private static void log(String message, LogType type)
{
var timestamp = String.Format("[{0}] ", DateTime.Now.ToString("dd/MMM HH:mm:ss"));
var typestr = String.Format("[{0}] ", type.ToString().ToUpper());
Console.Write(timestamp);
Console.ForegroundColor = (ConsoleColor)type;
Console.Write(typestr);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
message = message.Insert(0, typestr);
message = message.Insert(0, timestamp);
Directory.CreateDirectory(ConfigConstants.OPTIONS_LOGPATH);
try
{
File.AppendAllText(ConfigConstants.OPTIONS_LOGPATH + ConfigConstants.OPTIONS_LOGFILE, message + Environment.NewLine);
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}
}

View file

@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Lobby_Server.common
namespace FFXIVClassic_Map_Server.common
{
static class Utils
{
@ -24,26 +21,64 @@ namespace FFXIVClassic_Lobby_Server.common
public static string ByteArrayToHex(byte[] bytes)
{
var lookup32 = _lookup32;
var result = new char[(bytes.Length * 3) + ((bytes.Length/16) < 1 ? 1 : (bytes.Length/16)*3) + bytes.Length+60];
int numNewLines = 0;
for (int i = 0; i < bytes.Length; i++)
{
var val = lookup32[bytes[i]];
result[(3 * i) + (17 * numNewLines) + 0] = (char)val;
result[(3 * i) + (17 * numNewLines) + 1] = (char)(val >> 16);
result[(3 * i) + (17 * numNewLines) + 2] = ' ';
result[(numNewLines * (3*16+17)) + (3 * 16) + (i % 16)] = (char)bytes[i] >= 32 && (char)bytes[i] <= 126 ? (char)bytes[i] : '.';
if (i != bytes.Length - 1 && bytes.Length > 16 && i != 0 && (i+1) % 16 == 0)
{
result[(numNewLines * (3*16+17)) + (3 * 16) + (16)] = '\n';
numNewLines++;
}
}
return new string(result);
if (bytes == null) return "<null>";
int bytesLength = bytes.Length;
var bytesPerLine = 16;
char[] HexChars = "0123456789ABCDEF".ToCharArray();
int firstHexColumn =
8 // 8 characters for the address
+ 3; // 3 spaces
int firstCharColumn = firstHexColumn
+ bytesPerLine * 3 // - 2 digit for the hexadecimal value and 1 space
+ (bytesPerLine - 1) / 8 // - 1 extra space every 8 characters from the 9th
+ 2; // 2 spaces
int lineLength = firstCharColumn
+ bytesPerLine // - characters to show the ascii value
+ Environment.NewLine.Length; // Carriage return and line feed (should normally be 2)
char[] line = (new String(' ', lineLength - Environment.NewLine.Length) + Environment.NewLine).ToCharArray();
int expectedLines = (bytesLength + bytesPerLine - 1) / bytesPerLine;
StringBuilder result = new StringBuilder(expectedLines * lineLength);
for (int i = 0; i < bytesLength; i += bytesPerLine)
{
line[0] = HexChars[(i >> 28) & 0xF];
line[1] = HexChars[(i >> 24) & 0xF];
line[2] = HexChars[(i >> 20) & 0xF];
line[3] = HexChars[(i >> 16) & 0xF];
line[4] = HexChars[(i >> 12) & 0xF];
line[5] = HexChars[(i >> 8) & 0xF];
line[6] = HexChars[(i >> 4) & 0xF];
line[7] = HexChars[(i >> 0) & 0xF];
int hexColumn = firstHexColumn;
int charColumn = firstCharColumn;
for (int j = 0; j < bytesPerLine; j++)
{
if (j > 0 && (j & 7) == 0) hexColumn++;
if (i + j >= bytesLength)
{
line[hexColumn] = ' ';
line[hexColumn + 1] = ' ';
line[charColumn] = ' ';
}
else
{
byte b = bytes[i + j];
line[hexColumn] = HexChars[(b >> 4) & 0xF];
line[hexColumn + 1] = HexChars[b & 0xF];
line[charColumn] = (b < 32 ? '.' : (char)b);
}
hexColumn += 3;
charColumn++;
}
result.Append(line);
}
return Environment.NewLine + result.ToString();
}
public static UInt32 UnixTimeStampUTC()
@ -223,7 +258,7 @@ namespace FFXIVClassic_Lobby_Server.common
offset += 4 + count2;
Console.WriteLine(result);
Log.debug(result);
}
}