From d936cd3ef4aacd2dab36de0b2816a8a9658636c1 Mon Sep 17 00:00:00 2001 From: azw Date: Wed, 22 May 2024 08:56:45 +0800 Subject: [PATCH] 1 --- Net/BattleHandler.cs | 20 -------------------- Net/ClientNet.cs | 33 ++------------------------------- 2 files changed, 2 insertions(+), 51 deletions(-) delete mode 100644 Net/BattleHandler.cs diff --git a/Net/BattleHandler.cs b/Net/BattleHandler.cs deleted file mode 100644 index a669539..0000000 --- a/Net/BattleHandler.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Net -{ - class BattleHandler : F6.MsgHandler - { - public HandlerDelegate SMKcpHandshakeHandler; - - public BattleHandler(): base(typeof(battle.cs.CMMessageId_e), typeof(battle.cs.SMMessageId_e)) - { - - this.RegisterHandler(this.SMKcpHandshakeHandler); - } - } - -} diff --git a/Net/ClientNet.cs b/Net/ClientNet.cs index f9bb014..7cbd9af 100644 --- a/Net/ClientNet.cs +++ b/Net/ClientNet.cs @@ -33,6 +33,7 @@ namespace Net public OnNetClosed OnClosed; private readonly object lockObj = new object(); private Queue> events = new Queue>(); + private F6.MsgHandler msgHandler = new F6.MsgHandler(typeof(battle.cs.CMMessageId_e), typeof(battle.cs.SMMessageId_e)); public void Init(string uri) { @@ -47,40 +48,11 @@ namespace Net { this.ws.Open(); } - - public int GetCMMsgId(string msgName) - { - return this.GetPbMsgId(typeof(battle.cs.CMMessageId_e), "_" + msgName); - } - - public int GetSMMsgId(string msgName) - { - return this.GetPbMsgId(typeof(battle.cs.SMMessageId_e), "_" + msgName); - } - - private int GetPbMsgId(Type enumType,string msgName) - { - foreach (var f in enumType.GetFields()) - { - var tAttrs = f.GetCustomAttributes(typeof(pbr::OriginalNameAttribute), false); - if (tAttrs.Length > 0) - { - var tAttr = (pbr::OriginalNameAttribute)tAttrs[0]; - if (tAttr.Name.Equals(msgName)) - { - var val = Enum.Parse(enumType, f.Name); - return Convert.ToInt32(val); - } - } - } - return 0; - } - public void SendMsg(T msg) where T : IMessage { try { - int msgId = this.GetCMMsgId(typeof(T).Name); + int msgId = this.msgHandler.GetCMMsgId(typeof(T).Name); int packLen = msg.CalculateSize(); const int magicCode = 21323; byte[] data = new byte[12 + packLen]; @@ -96,7 +68,6 @@ namespace Net data[9] = (byte)((magicCode & 0xFFFF) >> 8); data[10] = 0; data[11] = 0; - msg.ToByteArray().CopyTo(data, 12); this.ws.Send(data); }catch(Exception e)