Server: Packet logging

This commit is contained in:
Nick Renieris 2022-06-22 20:29:07 +03:00
parent d3918dd5c6
commit 23f952a577
2 changed files with 29 additions and 0 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using Shared;
using Shared.Packet;
@ -50,6 +51,18 @@ public class Client : IDisposable {
Logger.Error(e);
}
#if DEBUG
Type packetType = packet.GetType();
FieldInfo[] fields = packetType.GetFields();
Logger.Debug($"[SEND] {packetType.Name} {{");
foreach (FieldInfo field in fields)
{
Logger.Debug($"\t{field.Name} = {field.GetValue(packet)}");
}
Logger.Debug($"}}");
#endif
await Socket!.SendAsync(memory.Memory[..(Constants.HeaderSize + packet.Size)], SocketFlags.None);
memory.Dispose();
}

View File

@ -1,6 +1,8 @@
using System.Buffers;
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using Shared;
using Shared.Packet;
@ -270,6 +272,20 @@ public class Server {
try {
IPacket packet = (IPacket) Activator.CreateInstance(Constants.PacketIdMap[header.Type])!;
packet.Deserialize(memory.Memory.Span[Constants.HeaderSize..(Constants.HeaderSize + packet.Size)]);
// TODO: expose toggle to config
#if DEBUG
Type packetType = packet.GetType();
FieldInfo[] fields = packetType.GetFields();
client.Logger.Debug($"[RECV] {packetType.Name} {{");
foreach (FieldInfo field in fields)
{
client.Logger.Debug($"\t{field.Name} = {field.GetValue(packet)}");
}
client.Logger.Debug($"}}");
#endif
if (PacketHandler?.Invoke(client, packet) is false) {
memory.Dispose();
continue;