1
This commit is contained in:
parent
e05bd5bded
commit
d936cd3ef4
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user