Beispiel #1
0
        public void DispatchPacket(IPacket packet)
        {
            Action <IPacket> handler;

            if (!m_PacketHandlerMap.TryGetValue(packet.GetPacketID(), out handler))
            {
#if _DEBUG
                Debug.Log("<color=red>Packet ID: " + packet.GetPacketID() + " Doesn't have a handler</color>");
#endif
                return;
            }

            handler.Invoke(packet);
        }
Beispiel #2
0
 public void SendPacket(IPacket packet, int hostId, int connId, int channel)
 {
     m_Buffer.Reset();
     m_Buffer.WriteHead(packet.GetPacketID());
     packet.Write(m_Buffer);
     NetworkTransport.Send(hostId, connId, channel, m_Buffer.BufferArray, m_Buffer.DataSize, out m_Err);
 }
Beispiel #3
0
        /// <summary>
        /// Disassembly packet into byte array
        /// </summary>
        /// <param name="packet">packet need to dessembly</param>
        /// <param name="buffer">target buffer</param>
        /// <returns>
        ///     0: disassembly success,
        ///    -1: disassembly failed
        /// </returns>
        public static int DisaessemblyPacket(IPacket packet, ref ByteArray buffer)
        {
            PACKET_DISAESSEMBLER func;

            if (!m_PacketDisassemblerMap.TryGetValue(packet.GetPacketID(), out func))
            {
#if UNITY_EDITOR
                Debug.LogError(string.Format("Packet {0} don't have any dessembly function!", packet.GetPacketID().ToString()));
#endif
                return(-1);
            }

            func.Invoke(packet, ref buffer);
            return(0);
        }