add some logging, and change the form of packet logging, add todos

This commit is contained in:
Master 2023-10-11 23:15:35 +02:00
parent c09b6daadc
commit a707deaa9f
3 changed files with 40 additions and 31 deletions

View File

@ -2,6 +2,7 @@
namespace AscNet.Common.Util
{
// TODO: Extend, add file logging, correct some behavior, ensure proper formatting
public class Logger
{
public static readonly Logger c = new(nameof(AscNet), ConsoleColor.DarkRed);

View File

@ -9,6 +9,11 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("HandshakeRequest")]
public static void HandshakeRequestHandler(Session session, byte[] packet)
{
// TODO: make this somehow universal, look into better architecture to handle packets
// and automatically log their deserialized form
HandshakeRequest request = MessagePackSerializer.Deserialize<HandshakeRequest>(packet);
session.c.Log("HandshakeRequest" + " " + JsonConvert.SerializeObject(request));
HandshakeResponse response = new()
{
Code = 0,
@ -23,6 +28,8 @@ namespace AscNet.GameServer.Handlers
public static void LoginRequestHandler(Session session, byte[] packet)
{
LoginRequest request = MessagePackSerializer.Deserialize<LoginRequest>(packet);
session.c.Log("LoginRequest" + " " + JsonConvert.SerializeObject(request));
session.SendResponse(new LoginResponse
{
Code = 0,
@ -38,6 +45,9 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("EnterWorldChatRequest")]
public static void EnterWorldChatRequestHandler(Session session, byte[] packet)
{
//EnterWorldChatRequest request = MessagePackSerializer.Deserialize<EnterWorldChatRequest>(packet);
//session.c.Log("EnterWorldChatRequest" + " " + JsonConvert.SerializeObject(request));
EnterWorldChatResponse enterWorldChatResponse = new()
{
Code = 0,
@ -49,6 +59,9 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("GetWorldChannelInfoRequest")]
public static void GetWorldChannelInfoRequestHandler(Session session, byte[] packet)
{
//GetWorldChannelInfoRequest request = MessagePackSerializer.Deserialize<GetWorldChannelInfoRequest>(packet);
//session.c.Log("GetWorldChannelInfoRequest" + " " + JsonConvert.SerializeObject(request));
GetWorldChannelInfoResponse getWorldChannelInfoResponse = new()
{
Code = 0,
@ -65,6 +78,9 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("OfflineMessageRequest")]
public static void OfflineMessageRequestHandler(Session session, byte[] packet)
{
OfflineMessageRequest request = MessagePackSerializer.Deserialize<OfflineMessageRequest>(packet);
session.c.Log("OfflineMessageRequest" + " " + JsonConvert.SerializeObject(request));
OfflineMessageResponse offlineMessageResponse = new()
{
Code = 0,
@ -76,6 +92,9 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("HeartbeatRequest")]
public static void HeartbeatRequestHandler(Session session, byte[] packet)
{
//HeartbeatRequest request = MessagePackSerializer.Deserialize<HeartbeatRequest>(packet);
//session.c.Log("HeartbeatRequest" + " " + JsonConvert.SerializeObject(request));
HeartbeatResponse heartbeatResponse = new()
{
UtcServerTime = (uint)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
@ -86,7 +105,8 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("DoClientTaskEventRequest")]
public static void DoClientTaskEventRequestHandler(Session session, byte[] packet)
{
DoClientTaskEventRequest doClientTaskEventRequest = MessagePackSerializer.Deserialize<DoClientTaskEventRequest>(packet);
DoClientTaskEventRequest request = MessagePackSerializer.Deserialize<DoClientTaskEventRequest>(packet);
session.c.Log("DoClientTaskEventRequest" + " " + JsonConvert.SerializeObject(request));
DoClientTaskEventResponse doClientTaskEventResponse = new()
{
@ -98,7 +118,8 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("SignInRequest")]
public static void SignInRequestHandler(Session session, byte[] packet)
{
SignInRequest signInRequest = MessagePackSerializer.Deserialize<SignInRequest>(packet);
SignInRequest request = MessagePackSerializer.Deserialize<SignInRequest>(packet);
session.c.Log("SignInRequest" + " " + JsonConvert.SerializeObject(request));
SignInResponse signInResponse = new()
{
@ -111,7 +132,8 @@ namespace AscNet.GameServer.Handlers
[PacketHandler("GetPurchaseListRequest")]
public static void GetPurchaseListRequestHandler(Session session, byte[] packet)
{
GetPurchaseListRequest getPurchaseListRequest = MessagePackSerializer.Deserialize<GetPurchaseListRequest>(packet);
GetPurchaseListRequest request = MessagePackSerializer.Deserialize<GetPurchaseListRequest>(packet);
session.c.Log("GetPurchaseListRequest" + " " + JsonConvert.SerializeObject(request));
GetPurchaseListResponse getPurchaseListResponse = new()
{
@ -121,6 +143,7 @@ namespace AscNet.GameServer.Handlers
session.SendResponse(getPurchaseListResponse);
}
// TODO: Move somewhere else, also split.
static void DoLogin(Session session)
{
NotifyLogin notifyLogin = JsonConvert.DeserializeObject<NotifyLogin>(File.ReadAllText("Data/NotifyLogin.json"))!;
@ -490,8 +513,6 @@ namespace AscNet.GameServer.Handlers
};
session.SendPush(notifyTrialData);
NotifyPivotCombatData notifyPivotCombatData = new()
{
PivotCombatData = { }

View File

@ -1,9 +1,8 @@
using System.Buffers.Binary;
using System.Net.Mail;
using System.Net.Sockets;
using System.Text.Json;
using AscNet.Common.Util;
using MessagePack;
using Newtonsoft.Json;
namespace AscNet.GameServer
{
@ -76,13 +75,11 @@ namespace AscNet.GameServer
{
case Packet.ContentType.Request:
Packet.Request request = MessagePackSerializer.Deserialize<Packet.Request>(packet.Content);
c.Log(request.Name);
debugContent = request.Content;
PacketFactory.GetPacketHandler(request.Name)?.Invoke(this, request.Content);
break;
case Packet.ContentType.Push:
Packet.Push push = MessagePackSerializer.Deserialize<Packet.Push>(packet.Content);
c.Log(push.Name);
debugContent = push.Content;
PacketFactory.GetPacketHandler(push.Name)?.Invoke(this, push.Content);
break;
@ -117,30 +114,21 @@ namespace AscNet.GameServer
}
public void SendPush<T>(T push)
{
try
{
Packet.Push packet = new()
{
Name = typeof(T).Name,
Content = MessagePackSerializer.Serialize(push)
};
Packet pushPacket = new Packet()
Send(new Packet()
{
No = packetNo,
Type = Packet.ContentType.Push,
Content = MessagePackSerializer.Serialize(packet)
};
Send(pushPacket);
});
c.Log(packet.Name + " " + JsonConvert.SerializeObject(push));
packetNo++;
}
catch (Exception ex)
{
c.Error(ex.Message);
}
}
public void SendResponse<T>(T response)
{
@ -150,14 +138,13 @@ namespace AscNet.GameServer
Name = typeof(T).Name,
Content = MessagePackSerializer.Serialize(response)
};
Send(new Packet()
{
No = packetNo,
Type = Packet.ContentType.Response,
Content = MessagePackSerializer.Serialize(packet)
});
c.Log(packet.Name);
c.Log(packet.Name + " " + JsonConvert.SerializeObject(response));
packetNo++;
}