Exemple #1
0
        private void ProcessReceiveDatas()
        {
            if (this._cache.length == 0)
            {
                return;
            }

            byte[] data;
            lock (this._cache)
            {
                int len = LengthEncoder.Decode(this._cache.GetBuffer(), 0, this._cache.position, out data);
                if (data == null)
                {
                    return;
                }

                this._cache.Strip(len, ( int )this._cache.length - len);
            }

            Packet packet = NetworkHelper.DecodePacket(data, 0, data.Length);

            packet.OnReceive();

            if (packet.module == NetworkConfig.INTERNAL_MODULE && packet.command == 1)
            {
                this.id     = (( PacketAccept )packet).tokenId;
                this._state = State.Connected;
                this._pingScheduler.Start(NetworkConfig.PING_INTERVAL, this.SendPing);
                this.OnSocketEvent?.Invoke(new SocketEvent(SocketEvent.Type.Connect, string.Empty, SocketError.Success, null));
            }
            else
            {
                this.OnSocketEvent?.Invoke(new SocketEvent(SocketEvent.Type.Receive, packet, null));
            }

            if (this._cache.length > 0)
            {
                this.ProcessReceiveDatas();
            }
        }
Exemple #2
0
 public void Send(Packet packet)
 {
     packet.OnSend();
     this.Send(NetworkHelper.EncodePacket(packet));
 }
Exemple #3
0
 public PacketAttribute(byte module, ushort command)
 {
     this.id = NetworkHelper.EncodePacketID(module, command);
 }
Exemple #4
0
 internal static Type GetPacketType(byte module, ushort command)
 {
     return(!PACKET_MAP.TryGetValue(NetworkHelper.EncodePacketID(module, command), out Type type) ? null : type);
 }