forked from PGR/ascnet
1
0
Fork 0

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 namespace AscNet.Common.Util
{ {
// TODO: Extend, add file logging, correct some behavior, ensure proper formatting
public class Logger public class Logger
{ {
public static readonly Logger c = new(nameof(AscNet), ConsoleColor.DarkRed); public static readonly Logger c = new(nameof(AscNet), ConsoleColor.DarkRed);

View File

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

View File

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