Improve Logging

This commit is contained in:
Hexafluorine 2025-05-16 16:40:53 -07:00
parent 27c8a06a4f
commit 4432406caa
7 changed files with 38 additions and 17 deletions

View File

@ -31,8 +31,10 @@
}
public class LogSettings
{
public bool packets;
public bool debugPrint=false;
public bool packets = true;
public bool packetWarnings = true;
public bool packetBodies = false;
public bool debugPrint = false;
public LogSettings()
{

View File

@ -1,3 +1,5 @@
using Campofinale;
using Pastel;
using System.Diagnostics;
public static class Logger
@ -44,6 +46,9 @@ public static class Logger
/// <param name="text"></param>
public static void PrintWarn(string text)
{
if (!Server.config.logOptions.packetWarnings)
return;
string className = GetCallingClassName();
Logger.Log(text);
string prefix = "<" + "WARN".Pastel("ff9100") + $":{className.Pastel("999")}>";

View File

@ -134,7 +134,7 @@ namespace Campofinale.Network
PutByteArray(data, head.ToByteArray(), 3);
PutByteArray(data, body.ToByteArray(), 3+head.ToByteArray().Length);
if(Server.config.logOptions.packets && !Server.scMessageToHide.Contains((ScMsgId)msgId))
Logger.Print($"Sending packet: {((ScMsgId)msgId).ToString().Pastel(Color.LightBlue)} id: {msgId} with {data.Length} bytes");
Logger.Print($"Sending Packet: {((ScMsgId)msgId).ToString().Pastel(Color.LightBlue)} Id: {msgId} with {data.Length} Bytes");
return data;
}
@ -166,7 +166,7 @@ namespace Campofinale.Network
PutByteArray(data, head.ToByteArray(), 3);
PutByteArray(data, body, 3 + head.ToByteArray().Length);
if (Server.config.logOptions.packets && !Server.scMessageToHide.Contains((ScMsgId)msgId))
Logger.Print($"Sending packet: {((ScMsgId)msgId).ToString().Pastel(Color.LightBlue)} id: {msgId} with {data.Length} bytes");
Logger.Print($"Sending Packet: {((ScMsgId)msgId).ToString().Pastel(Color.LightBlue)} Id: {msgId} with {data.Length} Bytes");
return data;
}
@ -186,10 +186,10 @@ namespace Campofinale.Network
Array.Copy(byteArray, 3, csHeadBytes, 0, headLength);
Array.Copy(byteArray, 3+ headLength, BodyBytes, 0, bodyLength);
CSHead csHead_ = CSHead.Parser.ParseFrom(csHeadBytes);
if (Server.config.logOptions.packets && !Server.csMessageToHide.Contains((CsMsgId)csHead_.Msgid))
/*if (Server.config.logOptions.packets && !Server.csMessageToHide.Contains((CsMsgId)csHead_.Msgid))
{
Logger.Print(csHead_.ToString());
}
}*/
seqNext = csHead_.UpSeqid;
return new Packet() { csHead = csHead_, finishedBody = BodyBytes,cmdId=csHead_.Msgid };
}

View File

@ -1,6 +1,10 @@
using Campofinale.Network;
using System.Drawing;
using Campofinale.Network;
using Campofinale.Protocol;
using Pastel;
namespace Campofinale.Packets.Cs
{
public class HandleCsMergeMsg
@ -30,8 +34,9 @@ namespace Campofinale.Packets.Cs
};
if (Server.config.logOptions.packets)
{
Logger.Print("CmdId: " + (CsMsgId)packet.csHead.Msgid);
Logger.Print(BitConverter.ToString(packet.finishedBody).Replace("-", string.Empty).ToLower());
Logger.Print("Recieved Packet: " + ((CsMsgId)packet.csHead.Msgid).ToString().Pastel(Color.LightCyan) + $" Id: {packet.csHead.Msgid} with {packet.finishedBody.Length} Bytes");
if (Server.config.logOptions.packetBodies)
Logger.Print(BitConverter.ToString(packet.finishedBody).Replace("-", string.Empty).ToLower());
}
try

View File

@ -14,6 +14,8 @@ using Campofinale.Game.Spaceship;
using Campofinale.Game.Dungeons;
using Campofinale.Game.Factory;
using Campofinale.Game.Mission;
using Pastel;
using System.Drawing;
namespace Campofinale
@ -504,8 +506,9 @@ namespace Campofinale
if (Server.config.logOptions.packets && !Server.csMessageToHide.Contains((CsMsgId)packet.csHead.Msgid))
{
Logger.Print("CmdId: " + (CsMsgId)packet.csHead.Msgid);
Logger.Print(BitConverter.ToString(packet.finishedBody).Replace("-", string.Empty).ToLower());
Logger.Print("Recieved Packet: " + ((CsMsgId)packet.csHead.Msgid).ToString().Pastel(Color.LightCyan) + $" Id: {packet.csHead.Msgid} with {packet.finishedBody.Length} Bytes");
if (Server.config.logOptions.packetBodies)
Logger.Print(BitConverter.ToString(packet.finishedBody).Replace("-", string.Empty).ToLower());
}
try

View File

@ -12,7 +12,7 @@ class Program
{
Console.Title = "Initializing...";
bool disableLogs = args.Length > 0 && args[0].ToLower() == "nologs";
//bool disableLogs = args.Length > 0 && args[0].ToLower() == "nologs";
ConfigFile config = new ConfigFile();
if (File.Exists("server_config.json"))
@ -23,7 +23,7 @@ class Program
new Thread(() =>
{
new Server().Start(disableLogs, config);
new Server().Start(config);
}).Start();
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{

View File

@ -51,6 +51,8 @@ namespace Campofinale
public static string ServerVersion = "1.1.2-dev";
public static bool Initialized = false;
public static bool showLogs = true;
public static bool showWarningLogs = true;
public static bool showBodyLogs = false;
public static Dispatch dispatch;
public static ResourceManager resourceManager;
public static ConfigFile config;
@ -60,7 +62,7 @@ namespace Campofinale
{
return resourceManager;
}
public void Start(bool hideLogs = false, ConfigFile config = null)
public void Start(ConfigFile config)
{
{
Assembly assembly = Assembly.GetExecutingAssembly();
@ -77,10 +79,14 @@ namespace Campofinale
}
Logger.Initialize();
Logger.Print($"Starting server version {ServerVersion} with supported client version {GameConstants.GAME_VERSION}");
showLogs = !hideLogs;
Logger.Print($"Logs are {(showLogs ? "enabled" : "disabled")}");
Server.config = config;
showLogs = config.logOptions.packets;
showWarningLogs = config.logOptions.packetWarnings;
showBodyLogs = config.logOptions.packetBodies;
Logger.Print($"Starting server version {ServerVersion} with supported client version {GameConstants.GAME_VERSION}");
Logger.Print($"Logs are {(showLogs ? "enabled" : "disabled")}");
Logger.Print($"Warning logs are {(showWarningLogs ? "enabled" : "disabled")}");
Logger.Print($"Packet body logs are {(showBodyLogs ? "enabled" : "disabled")}");
StartDBService();
DatabaseManager.Init();
ResourceManager.Init();