This commit is contained in:
azw 2024-05-22 09:05:09 +08:00
parent d936cd3ef4
commit caca938059
2 changed files with 12 additions and 9 deletions

View File

@ -31,14 +31,14 @@ namespace F6
this.smMsgType = smMsgType; this.smMsgType = smMsgType;
} }
public int GetCMMsgId(string msgName) public int GetCMMsgId(Type type)
{ {
return this.GetPbMsgId(this.cmMsgType, "_" + msgName); return this.GetPbMsgId(this.cmMsgType, "_" + type.Name);
} }
public int GetSMMsgId(string msgName) public int GetSMMsgId(Type type)
{ {
return this.GetPbMsgId(this.smMsgType, "_" + msgName); return this.GetPbMsgId(this.smMsgType, "_" + type.Name);
} }
public int GetPbMsgId(Type enumType, string msgName) public int GetPbMsgId(Type enumType, string msgName)
@ -61,7 +61,7 @@ namespace F6
protected void RegisterHandler<T>(HandlerDelegate<T> handler) where T : IMessage<T> ,new() protected void RegisterHandler<T>(HandlerDelegate<T> handler) where T : IMessage<T> ,new()
{ {
int msgId = this.GetSMMsgId(typeof(T).Name); int msgId = this.GetSMMsgId(typeof(T));
HandlerRec handler1; HandlerRec handler1;
if (!this.handlerHash.TryGetValue(msgId, out handler1)) if (!this.handlerHash.TryGetValue(msgId, out handler1))
{ {

View File

@ -6,7 +6,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Google.Protobuf; using Google.Protobuf;
using pbr = global::Google.Protobuf.Reflection;
namespace Net namespace Net
{ {
@ -52,7 +51,7 @@ namespace Net
{ {
try try
{ {
int msgId = this.msgHandler.GetCMMsgId(typeof(T).Name); int msgId = this.msgHandler.GetCMMsgId(typeof(T));
int packLen = msg.CalculateSize(); int packLen = msg.CalculateSize();
const int magicCode = 21323; const int magicCode = 21323;
byte[] data = new byte[12 + packLen]; byte[] data = new byte[12 + packLen];
@ -84,7 +83,6 @@ namespace Net
private void OnWsBinaryReceived(WebSocket ws, byte[] data) private void OnWsBinaryReceived(WebSocket ws, byte[] data)
{ {
Debug.Log("ClientNet.OnBinaryReceived");
this.AddEvent(EventType.Read, new object[]{data.Clone()}); this.AddEvent(EventType.Read, new object[]{data.Clone()});
} }
@ -119,6 +117,11 @@ namespace Net
} }
} }
private void ParsePkt(byte[] data)
{
}
private void DispatchEvent(KeyValuePair<EventType, object[]> e) private void DispatchEvent(KeyValuePair<EventType, object[]> e)
{ {
switch (e.Key) switch (e.Key)
@ -149,7 +152,7 @@ namespace Net
break; break;
case EventType.Read: case EventType.Read:
{ {
this.ParsePkt((byte[])e.Value[0]);
} }
break; break;
} }