diff --git a/AscNet.GameServer/Handlers/AccountModule.cs b/AscNet.GameServer/Handlers/AccountModule.cs index 62fc4af..5dc66c5 100644 --- a/AscNet.GameServer/Handlers/AccountModule.cs +++ b/AscNet.GameServer/Handlers/AccountModule.cs @@ -490,7 +490,7 @@ namespace AscNet.GameServer.Handlers }; session.SendPush(notifyTrialData); - + NotifyPivotCombatData notifyPivotCombatData = new() { diff --git a/AscNet.GameServer/Session.cs b/AscNet.GameServer/Session.cs index f0c1a69..ffdfb07 100644 --- a/AscNet.GameServer/Session.cs +++ b/AscNet.GameServer/Session.cs @@ -118,20 +118,28 @@ namespace AscNet.GameServer public void SendPush(T push) { - Packet.Push packet = new() + try { - Name = typeof(T).Name, - Content = MessagePackSerializer.Serialize(push) - }; + Packet.Push packet = new() + { + Name = typeof(T).Name, + Content = MessagePackSerializer.Serialize(push) + }; - Send(new Packet() + Packet pushPacket = new Packet() + { + No = packetNo, + Type = Packet.ContentType.Push, + Content = MessagePackSerializer.Serialize(packet) + }; + + Send(pushPacket); + packetNo++; + } + catch (Exception ex) { - No = packetNo, - Type = Packet.ContentType.Push, - Content = MessagePackSerializer.Serialize(packet) - }); - c.Log(packet.Name); - packetNo++; + c.Error(ex.Message); + } } public void SendResponse(T response) diff --git a/AscNet.Test/AscNet.Test.csproj b/AscNet.Test/AscNet.Test.csproj new file mode 100644 index 0000000..95db04c --- /dev/null +++ b/AscNet.Test/AscNet.Test.csproj @@ -0,0 +1,15 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + + diff --git a/AscNet.Test/Program.cs b/AscNet.Test/Program.cs new file mode 100644 index 0000000..9e69a52 --- /dev/null +++ b/AscNet.Test/Program.cs @@ -0,0 +1,82 @@ +using AscNet.Common.MsgPack; +using System.Text.Json; +using Newtonsoft.Json; +using System.Reflection; +using AscNet.GameServer; +using MessagePack; +using static AscNet.GameServer.Packet; + +namespace AscNet.Test +{ + internal class Program + { + static void Main(string[] args) + { + string lines = File.ReadAllText("Data/NotifyLogin.json"); + NotifyLogin notifyLogin = System.Text.Json.JsonSerializer.Deserialize(lines)!; + NotifyLogin notifyLoginNew = JsonConvert.DeserializeObject(lines)!; + + foreach (PropertyCompareResult resultItem in Compare(notifyLogin, notifyLoginNew)) + { + Console.WriteLine(" Property name: {0} -- old: {1}, new: {2}", + resultItem.Name, resultItem.OldValue ?? "", resultItem.NewValue ?? ""); + } + } + + class PropertyCompareResult + { + public string Name { get; private set; } + public object OldValue { get; private set; } + public object NewValue { get; private set; } + + public PropertyCompareResult(string name, object oldValue, object newValue) + { + Name = name; + OldValue = oldValue; + NewValue = newValue; + } + } + + class IgnorePropertyCompareAttribute : Attribute { } + + private static List Compare(T oldObject, T newObject, Type typecast = null) + { + PropertyInfo[] properties = null; + if (typecast != null) + { + properties = typecast.GetProperties(); + } + else + { + properties = typeof(T).GetProperties(); + } + List result = new List(); + + foreach (PropertyInfo pi in properties) + { + if (pi.CustomAttributes.Any(ca => ca.AttributeType == typeof(IgnorePropertyCompareAttribute))) + { + continue; + } + + object oldValue = pi.GetValue(oldObject), newValue = pi.GetValue(newObject); + + if (!object.Equals(oldValue, newValue)) + { + PropertyInfo[] propertyInfos = oldValue.GetType().GetProperties(); + if (propertyInfos.Length > 1 && oldValue.GetType().IsClass && !oldValue.GetType().IsArray && !oldValue.GetType().IsGenericType) + { + result.AddRange(Compare(oldValue, newValue, oldValue.GetType())); + } + else + { + result.Add(new PropertyCompareResult(pi.Name, oldValue, newValue)); + } + } + } + + return result; + } + + } +} \ No newline at end of file diff --git a/AscNet.sln b/AscNet.sln index f9c7676..a9705db 100644 --- a/AscNet.sln +++ b/AscNet.sln @@ -3,13 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AscNet", "AscNet\AscNet.csproj", "{817773C2-B4F3-48D5-9CDE-977BB0A0920E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AscNet", "AscNet\AscNet.csproj", "{817773C2-B4F3-48D5-9CDE-977BB0A0920E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AscNet.Common", "AscNet.Common\AscNet.Common.csproj", "{BE6BB857-5DA2-4A7D-B8AB-6901460DC2B9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AscNet.SDKServer", "AscNet.SDKServer\AscNet.SDKServer.csproj", "{B5040F93-BA7F-4E76-AF54-E3FAA857A5DA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AscNet.GameServer", "AscNet.GameServer\AscNet.GameServer.csproj", "{EB20C0CB-7CA1-459F-8410-7A27CC99F98C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AscNet.GameServer", "AscNet.GameServer\AscNet.GameServer.csproj", "{EB20C0CB-7CA1-459F-8410-7A27CC99F98C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AscNet.Test", "AscNet.Test\AscNet.Test.csproj", "{DD4C8BB1-2422-4AA4-A12C-9B3A25873887}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {EB20C0CB-7CA1-459F-8410-7A27CC99F98C}.Debug|Any CPU.Build.0 = Debug|Any CPU {EB20C0CB-7CA1-459F-8410-7A27CC99F98C}.Release|Any CPU.ActiveCfg = Release|Any CPU {EB20C0CB-7CA1-459F-8410-7A27CC99F98C}.Release|Any CPU.Build.0 = Release|Any CPU + {DD4C8BB1-2422-4AA4-A12C-9B3A25873887}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD4C8BB1-2422-4AA4-A12C-9B3A25873887}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD4C8BB1-2422-4AA4-A12C-9B3A25873887}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD4C8BB1-2422-4AA4-A12C-9B3A25873887}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE