This commit is contained in:
azw 2024-05-22 08:56:45 +08:00
parent e05bd5bded
commit d936cd3ef4
2 changed files with 2 additions and 51 deletions

View File

@ -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<battle.cs.SMKcpHandshake> SMKcpHandshakeHandler;
public BattleHandler(): base(typeof(battle.cs.CMMessageId_e), typeof(battle.cs.SMMessageId_e))
{
this.RegisterHandler(this.SMKcpHandshakeHandler);
}
}
}

View File

@ -33,6 +33,7 @@ namespace Net
public OnNetClosed OnClosed;
private readonly object lockObj = new object();
private Queue<KeyValuePair<EventType, object[]>> events = new Queue<KeyValuePair<EventType, object[]>>();
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>(T msg) where T : IMessage<T>
{
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)