mirror of
https://git.muiegratis.online/suikoakari/Campofinale
synced 2025-12-19 21:14:38 +01:00
Improve Logging
This commit is contained in:
@@ -31,7 +31,9 @@
|
|||||||
}
|
}
|
||||||
public class LogSettings
|
public class LogSettings
|
||||||
{
|
{
|
||||||
public bool packets;
|
public bool packets = true;
|
||||||
|
public bool packetWarnings = true;
|
||||||
|
public bool packetBodies = false;
|
||||||
public bool debugPrint = false;
|
public bool debugPrint = false;
|
||||||
|
|
||||||
public LogSettings()
|
public LogSettings()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using Campofinale;
|
||||||
|
|
||||||
using Pastel;
|
using Pastel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
public static class Logger
|
public static class Logger
|
||||||
@@ -44,6 +46,9 @@ public static class Logger
|
|||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
public static void PrintWarn(string text)
|
public static void PrintWarn(string text)
|
||||||
{
|
{
|
||||||
|
if (!Server.config.logOptions.packetWarnings)
|
||||||
|
return;
|
||||||
|
|
||||||
string className = GetCallingClassName();
|
string className = GetCallingClassName();
|
||||||
Logger.Log(text);
|
Logger.Log(text);
|
||||||
string prefix = "<" + "WARN".Pastel("ff9100") + $":{className.Pastel("999")}>";
|
string prefix = "<" + "WARN".Pastel("ff9100") + $":{className.Pastel("999")}>";
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ namespace Campofinale.Network
|
|||||||
PutByteArray(data, head.ToByteArray(), 3);
|
PutByteArray(data, head.ToByteArray(), 3);
|
||||||
PutByteArray(data, body.ToByteArray(), 3+head.ToByteArray().Length);
|
PutByteArray(data, body.ToByteArray(), 3+head.ToByteArray().Length);
|
||||||
if(Server.config.logOptions.packets && !Server.scMessageToHide.Contains((ScMsgId)msgId))
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ namespace Campofinale.Network
|
|||||||
PutByteArray(data, head.ToByteArray(), 3);
|
PutByteArray(data, head.ToByteArray(), 3);
|
||||||
PutByteArray(data, body, 3 + head.ToByteArray().Length);
|
PutByteArray(data, body, 3 + head.ToByteArray().Length);
|
||||||
if (Server.config.logOptions.packets && !Server.scMessageToHide.Contains((ScMsgId)msgId))
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -186,10 +186,10 @@ namespace Campofinale.Network
|
|||||||
Array.Copy(byteArray, 3, csHeadBytes, 0, headLength);
|
Array.Copy(byteArray, 3, csHeadBytes, 0, headLength);
|
||||||
Array.Copy(byteArray, 3+ headLength, BodyBytes, 0, bodyLength);
|
Array.Copy(byteArray, 3+ headLength, BodyBytes, 0, bodyLength);
|
||||||
CSHead csHead_ = CSHead.Parser.ParseFrom(csHeadBytes);
|
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());
|
Logger.Print(csHead_.ToString());
|
||||||
}
|
}*/
|
||||||
seqNext = csHead_.UpSeqid;
|
seqNext = csHead_.UpSeqid;
|
||||||
return new Packet() { csHead = csHead_, finishedBody = BodyBytes,cmdId=csHead_.Msgid };
|
return new Packet() { csHead = csHead_, finishedBody = BodyBytes,cmdId=csHead_.Msgid };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
using Campofinale.Network;
|
using System.Drawing;
|
||||||
|
|
||||||
|
using Campofinale.Network;
|
||||||
using Campofinale.Protocol;
|
using Campofinale.Protocol;
|
||||||
|
|
||||||
|
using Pastel;
|
||||||
|
|
||||||
namespace Campofinale.Packets.Cs
|
namespace Campofinale.Packets.Cs
|
||||||
{
|
{
|
||||||
public class HandleCsMergeMsg
|
public class HandleCsMergeMsg
|
||||||
@@ -30,7 +34,8 @@ namespace Campofinale.Packets.Cs
|
|||||||
};
|
};
|
||||||
if (Server.config.logOptions.packets)
|
if (Server.config.logOptions.packets)
|
||||||
{
|
{
|
||||||
Logger.Print("CmdId: " + (CsMsgId)packet.csHead.Msgid);
|
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());
|
Logger.Print(BitConverter.ToString(packet.finishedBody).Replace("-", string.Empty).ToLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ using Campofinale.Game.Spaceship;
|
|||||||
using Campofinale.Game.Dungeons;
|
using Campofinale.Game.Dungeons;
|
||||||
using Campofinale.Game.Factory;
|
using Campofinale.Game.Factory;
|
||||||
using Campofinale.Game.Mission;
|
using Campofinale.Game.Mission;
|
||||||
|
using Pastel;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
|
||||||
namespace Campofinale
|
namespace Campofinale
|
||||||
@@ -504,7 +506,8 @@ namespace Campofinale
|
|||||||
|
|
||||||
if (Server.config.logOptions.packets && !Server.csMessageToHide.Contains((CsMsgId)packet.csHead.Msgid))
|
if (Server.config.logOptions.packets && !Server.csMessageToHide.Contains((CsMsgId)packet.csHead.Msgid))
|
||||||
{
|
{
|
||||||
Logger.Print("CmdId: " + (CsMsgId)packet.csHead.Msgid);
|
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());
|
Logger.Print(BitConverter.ToString(packet.finishedBody).Replace("-", string.Empty).ToLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Program
|
|||||||
{
|
{
|
||||||
Console.Title = "Initializing...";
|
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();
|
ConfigFile config = new ConfigFile();
|
||||||
if (File.Exists("server_config.json"))
|
if (File.Exists("server_config.json"))
|
||||||
@@ -23,7 +23,7 @@ class Program
|
|||||||
|
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
new Server().Start(disableLogs, config);
|
new Server().Start(config);
|
||||||
}).Start();
|
}).Start();
|
||||||
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
|
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ namespace Campofinale
|
|||||||
public static string ServerVersion = "1.1.2-dev";
|
public static string ServerVersion = "1.1.2-dev";
|
||||||
public static bool Initialized = false;
|
public static bool Initialized = false;
|
||||||
public static bool showLogs = true;
|
public static bool showLogs = true;
|
||||||
|
public static bool showWarningLogs = true;
|
||||||
|
public static bool showBodyLogs = false;
|
||||||
public static Dispatch dispatch;
|
public static Dispatch dispatch;
|
||||||
public static ResourceManager resourceManager;
|
public static ResourceManager resourceManager;
|
||||||
public static ConfigFile config;
|
public static ConfigFile config;
|
||||||
@@ -60,7 +62,7 @@ namespace Campofinale
|
|||||||
{
|
{
|
||||||
return resourceManager;
|
return resourceManager;
|
||||||
}
|
}
|
||||||
public void Start(bool hideLogs = false, ConfigFile config = null)
|
public void Start(ConfigFile config)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
@@ -77,10 +79,14 @@ namespace Campofinale
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.Initialize();
|
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;
|
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();
|
StartDBService();
|
||||||
DatabaseManager.Init();
|
DatabaseManager.Init();
|
||||||
ResourceManager.Init();
|
ResourceManager.Init();
|
||||||
|
|||||||
Reference in New Issue
Block a user