public void Send(byte flag, IMessage message) { ushort opcode = Game.Scene.GetComponent <OpcodeTypeComponent>().GetOpcode(message.GetType()); byte[] bytes = ProtobufHelper.ToBytes(message); session.Send(flag, opcode, bytes); }
public void Run(Session s, Packet p) { ushort opcode = p.Opcode(); byte flag = p.Flag(); OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>(); Type responseType = opcodeTypeComponent.GetType(opcode); object message = ProtobufHelper.FromBytes(responseType, p.Bytes, Packet.Index, p.Length - Packet.Index); if ((flag & 0x01) > 0) { IResponse response = message as IResponse; if (response == null) { throw new Exception($"flag is response, but hotfix message is not! {opcode}"); } Action <IResponse> action; if (!this.requestCallback.TryGetValue(response.RpcId, out action)) { return; } this.requestCallback.Remove(response.RpcId); action(response); return; } Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(opcode, message)); }
public static void Run(Session session, PacketInfo packetInfo) { ushort opcode = packetInfo.Opcode; Type t = Game.Scene.GetComponent <OpcodeTypeComponent>().GetType(opcode); object message = ProtobufHelper.FromBytes(t, packetInfo.Bytes, packetInfo.Index, packetInfo.Length); Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(packetInfo.RpcId, packetInfo.Opcode, message)); }
//记录操作信息 private static void RecordInfo(this FiveStarRoom fiveStarRoom, int opcode, Google.Protobuf.IMessage iMessage) { //只有房卡才记录 if (fiveStarRoom.RoomType != RoomType.RoomCard) { return; } MiltaryRecordData miltaryRecordData = ComponentFactory.Create <MiltaryRecordData>(); miltaryRecordData.Opcode = opcode; miltaryRecordData.Data = new ByteString(ProtobufHelper.ToBytes(iMessage));; fiveStarRoom.CurrParticularMiltaryRecordData.MiltaryRecordDatas.Add(miltaryRecordData); }
public static async Task <IResponse> Call(this Session session, IRequest request) { OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent <OpcodeTypeComponent>(); byte[] bytes = ProtobufHelper.ToBytes(request); ushort opcode = opcodeTypeComponent.GetOpcode(request.GetType()); PacketInfo packetInfo = await session.Call(opcode, bytes); ushort responseOpcode = packetInfo.Opcode; Type t = opcodeTypeComponent.GetType(responseOpcode); object aa = ProtobufHelper.FromBytes(t, packetInfo.Bytes, packetInfo.Index, packetInfo.Length); IResponse response = (IResponse)aa; return(response); }