Types fix
This commit is contained in:
parent
5d772848e8
commit
7a984ca417
File diff suppressed because it is too large
Load Diff
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MessagePack" Version="2.5.129" />
|
<PackageReference Include="MessagePack" Version="2.5.129" />
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
using AscNet.Common.MsgPack;
|
using AscNet.Common.MsgPack;
|
||||||
using MessagePack;
|
using MessagePack;
|
||||||
using MongoDB.Bson.IO;
|
using Newtonsoft.Json;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using static AscNet.GameServer.Packet;
|
|
||||||
|
|
||||||
namespace AscNet.GameServer.Handlers
|
namespace AscNet.GameServer.Handlers
|
||||||
{
|
{
|
||||||
|
@ -12,7 +9,6 @@ namespace AscNet.GameServer.Handlers
|
||||||
[PacketHandler("HandshakeRequest")]
|
[PacketHandler("HandshakeRequest")]
|
||||||
public static void HandshakeRequestHandler(Session session, byte[] packet)
|
public static void HandshakeRequestHandler(Session session, byte[] packet)
|
||||||
{
|
{
|
||||||
HandshakeRequest request = MessagePackSerializer.Deserialize<HandshakeRequest>(packet);
|
|
||||||
HandshakeResponse response = new()
|
HandshakeResponse response = new()
|
||||||
{
|
{
|
||||||
Code = 0,
|
Code = 0,
|
||||||
|
@ -26,6 +22,7 @@ namespace AscNet.GameServer.Handlers
|
||||||
[PacketHandler("LoginRequest")]
|
[PacketHandler("LoginRequest")]
|
||||||
public static void LoginRequestHandler(Session session, byte[] packet)
|
public static void LoginRequestHandler(Session session, byte[] packet)
|
||||||
{
|
{
|
||||||
|
LoginRequest request = MessagePackSerializer.Deserialize<LoginRequest>(packet);
|
||||||
session.SendResponse(new LoginResponse
|
session.SendResponse(new LoginResponse
|
||||||
{
|
{
|
||||||
Code = 0,
|
Code = 0,
|
||||||
|
@ -34,7 +31,8 @@ namespace AscNet.GameServer.Handlers
|
||||||
UtcServerTime = (uint)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
UtcServerTime = (uint)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
|
||||||
});
|
});
|
||||||
|
|
||||||
session.SendPush(JsonSerializer.Deserialize<NotifyLogin>(File.ReadAllText("Data\\NotifyLogin.json")));
|
NotifyLogin notifyLogin = JsonConvert.DeserializeObject<NotifyLogin>(File.ReadAllText("Data/NotifyLogin.json"))!;
|
||||||
|
session.SendPush(notifyLogin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,25 +68,35 @@ namespace AscNet.GameServer
|
||||||
|
|
||||||
foreach (var packet in packets)
|
foreach (var packet in packets)
|
||||||
{
|
{
|
||||||
switch (packet.Type)
|
byte[] debugContent = packet.Content;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
case Packet.ContentType.Request:
|
switch (packet.Type)
|
||||||
Packet.Request request = MessagePackSerializer.Deserialize<Packet.Request>(packet.Content);
|
{
|
||||||
c.Log(request.Name);
|
case Packet.ContentType.Request:
|
||||||
PacketFactory.GetPacketHandler(request.Name)?.Invoke(this, request.Content);
|
Packet.Request request = MessagePackSerializer.Deserialize<Packet.Request>(packet.Content);
|
||||||
break;
|
c.Log(request.Name);
|
||||||
case Packet.ContentType.Push:
|
debugContent = request.Content;
|
||||||
Packet.Push push = MessagePackSerializer.Deserialize<Packet.Push>(packet.Content);
|
PacketFactory.GetPacketHandler(request.Name)?.Invoke(this, request.Content);
|
||||||
c.Log(push.Name);
|
break;
|
||||||
PacketFactory.GetPacketHandler(push.Name)?.Invoke(this, push.Content);
|
case Packet.ContentType.Push:
|
||||||
break;
|
Packet.Push push = MessagePackSerializer.Deserialize<Packet.Push>(packet.Content);
|
||||||
case Packet.ContentType.Exception:
|
c.Log(push.Name);
|
||||||
Packet.Exception exception = MessagePackSerializer.Deserialize<Packet.Exception>(packet.Content);
|
debugContent = push.Content;
|
||||||
c.Error($"Exception packet received: {exception.Code}, {exception.Message}");
|
PacketFactory.GetPacketHandler(push.Name)?.Invoke(this, push.Content);
|
||||||
break;
|
break;
|
||||||
default:
|
case Packet.ContentType.Exception:
|
||||||
c.Error($"Unknown packet received: {packet}");
|
Packet.Exception exception = MessagePackSerializer.Deserialize<Packet.Exception>(packet.Content);
|
||||||
break;
|
c.Error($"Exception packet received: {exception.Code}, {exception.Message}");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
c.Error($"Unknown packet received: {packet}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
c.Error("Failed to invoke handler: " + ex.Message + $", Raw {packet.Type} packet: " + BitConverter.ToString(debugContent).Replace("-", ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue