public override void OnMessage(USocket us, ByteBuf bb) { bb.ReaderIndex(us.getProtocal().HeaderLen()); short cmd = bb.ReadShort(); byte[] bs = bb.GetRaw(); Statics.SetXor(bs, bb.ReaderIndex()); MemoryStream stream = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes()); object obj = ProtoBuf.Serializer.NonGeneric.Deserialize(MessageQueueHandler.GetProtocolType(cmd), stream); FieldInfo success = obj.GetType().GetField("success"); if (success != null) { if ((bool)success.GetValue(obj) == true) { MessageQueueHandler.PushQueue(cmd, obj); } else { FieldInfo info = obj.GetType().GetField("info"); if (info != null) { Debug.LogWarning("下行出错, cmd=" + cmd + ", type=" + MessageQueueHandler.GetProtocolType(cmd).ToString()); MessageQueueHandler.PushError(info.GetValue(obj).ToString()); } } } }
public override void OnMessage(USocket us, ByteBuf bb) { bb.ReaderIndex(us.getProtocol().HeaderLen()); short cmd = bb.ReadShort(); byte[] bs = bb.GetRaw(); using (var stream = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes())) { object obj = protocol.DecodeMessage(MessageQueueHandler.GetProtocolType(cmd), stream); MessageQueueHandler.PushQueue(cmd, obj); } }
public override void OnMessage(USocket us, ByteBuf bb) { bb.ReaderIndex(us.getProtocol().HeaderLen()); int cmd = bb.ReadInt(); Debug.Log("Socket Recive Message ID: " + cmd); byte[] bs = bb.GetRaw(); using (var stream = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes())) { if (MessageQueueHandler.GetProtocolType(cmd) != null) { object obj = protocol.DecodeMessage(MessageQueueHandler.GetProtocolType(cmd), stream); MessageQueueHandler.PushQueue((short)cmd, obj); } } }