public void Execute() { lock (m_RecvPackets) { if (m_RecvPackets.Count > 0) { for (int i = 0; i < m_RecvPackets.Count; i++) { MessageRecvData recv = m_RecvPackets[i]; DispatchPacket(recv); } m_RecvPackets.Clear(); } } lock (m_SendPackets) { if (m_SendPackets.Count > 0) { for (int i = 0; i < m_SendPackets.Count; i++) { Send(m_SendPackets[i]); } m_SendPackets.Clear(); } } }
static void DispatchPacket(MessageRecvData recv) { Debug.Log("Receive MessageID:" + recv.MsgID); MessageCallbackData d = null; if (m_MessageDispatchs.TryGetValue(recv.MsgID, out d)) { d.Handler(recv); } }
public static void RecvS2C(NetworkClient client, byte[] bytes) { byte[] data = new byte[bytes.Length - 28]; for (int i = 0; i < data.Length; i++) { data[i] = bytes[i + 28]; } MessageRecvData evet = new MessageRecvData(); evet.Data = data; evet.Client = client; evet.MsgID = (MessageID)System.BitConverter.ToInt32(bytes, 4); evet.UserData = System.BitConverter.ToUInt32(bytes, 24); evet.TargetID = System.BitConverter.ToUInt64(bytes, 16); lock (m_RecvPackets) { m_RecvPackets.Add(evet); } }