public void HandleData(p_AllMsg p_allmsg) { if (p_allmsg.NetworkMsg.type == (int)CmdType.REPLYJOIN) { List <string> ids = p_allmsg.ReplyJoin.player_names; int connectID = p_allmsg.ReplyJoin.real_player_id; game.on_reply_join(connectID, ids); Debug.Log("replyJoin connectID=" + connectID); } else if (p_allmsg.NetworkMsg.type == (int)CmdType.REPLYSTART) { bool isGameStart = p_allmsg.ReplyStart.start; game.on_reply_start(isGameStart); } else if (p_allmsg.NetworkMsg.type == (int)CmdType.REPLYASKFRAME) { Dictionary <int, List <SyncFrame> > replyframes = extract_replyFrames(p_allmsg.ReplyAskFrame.replyFrames); game.on_reply_frames(replyframes); } else if (p_allmsg.NetworkMsg.type == (int)CmdType.REPLYID) { int your_connectID = p_allmsg.ReplyID.your_connectID; game.on_reply_ID(your_connectID); } }
public static p_AllMsg DeserializeData(byte[] data) { using (MemoryStream stream = new MemoryStream(data, 0, data.Length)) { // int len = ProtoReader.DirectReadVarintInt32(stream); stream.Write(data, 0, data.Length); stream.Position = 0; p_AllMsg = Serializer.Deserialize <p_AllMsg>(stream); } return(p_AllMsg); }
void DecodData() { byte[] bytes = NetCommon.Decode(ref ReceiveCache); if (bytes == null) { return; } p_AllMsg p_AllMsg = new p_AllMsg(); p_AllMsg = Serialization.DeserializeData(bytes); NetCommon.HandleData(connectionID, p_AllMsg); DecodData(); }
public p_AllMsg ReceiveData() { byte[] bytes = null; bytes = TCPSocket.ReceiveData(); cache.AddRange(bytes); byte[] data = Decode(ref cache); p_AllMsg p_allmsg = null; if (bytes != null) { p_allmsg = new p_AllMsg(); p_allmsg = Serialization.DeserializeData(data); } return(p_allmsg); }
public static p_AllMsg DeserializeData(byte[] data) { using (MemoryStream stream = new MemoryStream(data, 0, data.Length)) { stream.Write(data, 0, data.Length); stream.Position = 0; try { p_AllMsg = Serializer.Deserialize <p_AllMsg>(stream); } catch (Exception ex) { throw new Exception("DeserializeData error" + ex); } } return(p_AllMsg); }
void ReadData() { byte[] bytes = Decode(ref cache); if (bytes != null) { //Debug.Log("once decode at times : " + times + " bytes length is: " + bytes.Length); Server_msg = new p_AllMsg(); Server_msg = Serialization.DeserializeData(bytes); //Debug.Log("Receive Server_msg.NetworkMsg.type Finished!!" + ((CmdType)Server_msg.NetworkMsg.type).ToString()); HandleData(Server_msg); ReadData(); } else { isReceiving = false; } }
public static byte[] SerializeData(BaseProtocol baseProtocol, NetworkMsg networkMsg, ReplyGetRooms replyGetRooms = null, ReplyJoin replyJoin = null, ReplyAskFrame replyAskFrame = null, ReplyID replyID = null, ReplyStart replyStart = null) { p_AllMsg = new p_AllMsg(); if (baseProtocol != null) { Buffer_BaseProtocol(baseProtocol); } if (networkMsg != null) { Buffer_NetworkMsg(networkMsg); } if (networkMsg.type == (int)CmdType.REPLYGETROOMS) { replyGetRooms = networkMsg as ReplyGetRooms; Buffer_ReplyGetRooms(replyGetRooms); } else if (networkMsg.type == (int)CmdType.REPLYJOIN) { replyJoin = networkMsg as ReplyJoin; Buffer_ReplyJoin(replyJoin); } else if (networkMsg.type == (int)CmdType.REPLYASKFRAME) { replyAskFrame = networkMsg as ReplyAskFrame; Buffer_ReplyAskFrame(replyAskFrame); } else if (networkMsg.type == (int)CmdType.REPLYSTART) { replyStart = networkMsg as ReplyStart; BufferReplyStart(replyStart); } else if (networkMsg.type == (int)CmdType.REPLYID) { replyID = networkMsg as ReplyID; Buffer_ReplyID(replyID); } return(Serialize <p_AllMsg>(p_AllMsg)); }
public static byte[] Serialize(BaseProtocol baseProtocol, NetworkMsg networkMsg, StartGame startGame = null, Frame frame = null, SyncFrame syncFrame = null, AskFrame askFrame = null )//在这可以继续添加要发送的Msg { p_AllMsg = new p_AllMsg(); if (baseProtocol != null) { Buffer_BaseProtocol(baseProtocol); } if (networkMsg != null) { Buffer_NetworkMsg(networkMsg); } if (networkMsg.type == (int)CmdType.START) { startGame = networkMsg as StartGame; Buffer_StartGame(startGame); } if (networkMsg.type == (int)CmdType.FRAME) { frame = networkMsg as Frame; Buffer_Frame(frame); } if (networkMsg.type == (int)CmdType.SYNC_FRAME) { Buffer_SyncFrame(syncFrame); } if (networkMsg.type == (int)CmdType.ASKFRAME) { askFrame = networkMsg as AskFrame; Buffer_AskFrame(askFrame); } return(Serialize <p_AllMsg>(p_AllMsg)); }
public static void HandleData(int clientID, p_AllMsg p_allmsg) { //p_AllMsg ReceiveMsg = new p_AllMsg(); int msg_type = p_allmsg.NetworkMsg.type; int seq = p_allmsg.BaseProtocol.seq; //gameServer.hanldeSeq(client_id, seq); //Console.WriteLine("get client: " + client_id + "seq pkg : " + seq); if (msg_type == (int)CmdType.START) { Debug.Log("get start info\n"); gameServer.OnGameStart(clientID); } else if (msg_type == (int)CmdType.FRAME) { Debug.Log("get frame info " + clientID.ToString() + "\n"); int frame_count = p_allmsg.Frame.syncFrame.frame_count; int player_id = p_allmsg.Frame.player_id; List <CustomSyncMsg> msg_list = extract_msg(p_allmsg.Frame.syncFrame.msg_list); SyncFrame syncFrame = new SyncFrame(frame_count, 0); syncFrame.msg_list = msg_list; Frame frame = new Frame(player_id, syncFrame); gameServer.OnGetFrame(frame, clientID); } else if (msg_type == (int)CmdType.ASKFRAME) { Debug.Log("get askframe info from" + clientID.ToString() + "\n"); List <int> frames = new List <int>(); foreach (int val in p_allmsg.AskFrame.frame) { frames.Add(val); } gameServer.OnAskFrame(frames, clientID); } else if (msg_type == (int)CmdType.JOIN) { Debug.Log("get join info, it is from :" + clientID); gameServer.OnPlayerJoin(clientID); } //else if (msg_type == (int)CmdType.ASKCHASEFRAME) //{ // //Console.WriteLine("get asked chase frame request"); // List<int> areas_id = p_allmsg.AskChaseFranme.areas_id; // Dictionary<int, List<int>> areas_to_frame = p_allmsg.AskChaseFranme.area_to_frame; // int player_Id = p_allmsg.AskChaseFranme.player_id; // if (player_Id == -1) // { // areas_id = null; // areas_to_frame = null; // } // //List<int> miss_frame = allMsg.AskFrame.frame_list; // //int area_id = allMsg.AskFrame.area_id; // gameServer.OnAskedChaseFrame(clientID, areas_id, areas_to_frame); //} //else if (msg_type == (int)CmdType.END) //{ // //Console.WriteLine("get End"); // gameServer.OnGetEnd(clientID); //} }