Esempio n. 1
0
        /// <summary>todo optimize perfomance by sortin eng rus clients</summary>
        /// <param name="addEndOfPacket"></param>
        /// <param name="isRus"></param>
        public void FinalizeAsda(bool addEndOfPacket, Locale locale)
        {
            if (locale == this.EncodedLocale)
            {
                return;
            }
            if (this.EncodedLocale == Locale.Any && addEndOfPacket)
            {
                this.WriteInt32(RealmPacketOut._cnter++);
                this.WriteInt16(0);
            }

            Asda2CryptHelper.XorData(this.BufferSegment.Buffer.Array, this.BufferSegment.Offset + 3, this.Position - 3L,
                                     this.EncodedLocale, locale);
            if (this.EncodedLocale == Locale.Any)
            {
                this.WriteByte(254);
            }
            short position = (short)this.Position;

            if (this.EncodedLocale == Locale.Any)
            {
                Array.Copy((Array)BitConverter.GetBytes(position), 0, (Array)this.BufferSegment.Buffer.Array,
                           this.BufferSegment.Offset + 1, 2);
            }
            this.EncodedLocale = locale;
            if (position >= (short)2048)
            {
                throw new InvalidOperationException(string.Format("Packet {0} Len >= 2048", (object)this));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// todo optimize perfomance by sortin eng rus clients
        /// </summary>
        /// <param name="addEndOfPacket"></param>
        /// <param name="isRus"></param>
        public void FinalizeAsda(bool addEndOfPacket, Locale locale)
        {
            if (locale == EncodedLocale)
            {
                return;
            }
            if (EncodedLocale == Locale.UnEncoded)
            {
                if (addEndOfPacket)
                {
                    WriteInt32(_cnter++);
                    WriteInt16(0);
                }
            }
            if (EncodedLocale == Locale.UnEncoded)
            {
                WriteByte(0xFE);
            }
            Asda2CryptHelper.XorData(BufferSegment.Buffer.Array, BufferSegment.Offset + 3, Position - 4, EncodedLocale, locale);

            var packetLen = (short)Position;

            //Write packetLen
            if (EncodedLocale == Locale.UnEncoded)
            {
                Array.Copy(BitConverter.GetBytes(packetLen), 0, BufferSegment.Buffer.Array,
                           BufferSegment.Offset + 1, 2);
            }
            EncodedLocale = locale;
            if (packetLen >= 700)
            {
                throw new InvalidOperationException(string.Format("Packet {0} Len >= 700", this));
            }
        }
Esempio n. 3
0
        /// <summary>todo optimize perfomance by sortin eng rus clients</summary>
        /// <param name="addEndOfPacket"></param>
        /// <param name="isRus"></param>
        public void FinalizeAsda(bool addEndOfPacket, Locale locale)
        {
            if (locale == EncodedLocale)
            {
                return;
            }
            if (EncodedLocale == Locale.Any && addEndOfPacket)
            {
                WriteInt32(_cnter++);
                WriteInt16(0);
            }

            Asda2CryptHelper.XorData(BufferSegment.Buffer.Array, BufferSegment.Offset + 3, Position - 3L,
                                     EncodedLocale, locale);
            if (EncodedLocale == Locale.Any)
            {
                WriteByte(254);
            }
            short position = (short)Position;

            if (EncodedLocale == Locale.Any)
            {
                Array.Copy(BitConverter.GetBytes(position), 0, BufferSegment.Buffer.Array,
                           BufferSegment.Offset + 1, 2);
            }
            EncodedLocale = locale;
            if (position >= 2048)
            {
                throw new InvalidOperationException(string.Format("Packet {0} Len >= 2048", this));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Pass recieved data into the packet buffer and try to parse.
        /// </summary>
        /// <param name="_remainingLength">number of bytes waiting to be read</param>
        /// <returns>false, if there is a part of a packet still remaining</returns>
        protected override bool OnReceive()
        {
            ushort uint16;

            while (true)
            {
                int offset = _bufferSegment.Offset;
                uint16 = BitConverter.ToUInt16(_bufferSegment.Buffer.Array, offset + 1);
                if (uint16 != 0)
                {
                    if (uint16 <= 4096)
                    {
                        if (_remainingLength >= uint16)
                        {
                            if (!KnownClientVersion)
                            {
                                byte[] buffer = new byte[2]
                                {
                                    _bufferSegment.Buffer.Array[offset + 3],
                                    _bufferSegment.Buffer.Array[offset + 4]
                                };
                                Asda2CryptHelper.XorData(buffer, 0, 2L, Locale.Start, Locale.Any);
                                if (buffer[1] == 0)
                                {
                                    Locale = Locale.Start;
                                }
                                else if (buffer[1] == 116)
                                {
                                    Locale = Locale.Ar;
                                }
                                else if (buffer[1] == 228)
                                {
                                    Locale = Locale.Ru;
                                }
                                else
                                {
                                    Asda2CryptHelper.XorData(buffer, 0, 2L, Locale.Start, Locale.Tahadi);

                                    if (buffer[1] == 0)
                                    {
                                        Locale = Locale.Tahadi;
                                    }
                                    else if (buffer[1] == 103)
                                    {
                                        Locale = Locale.LOS;
                                    }
                                }

                                KnownClientVersion = true;
                            }

                            Asda2CryptHelper.XorData(_bufferSegment.Buffer.Array, offset + 3,
                                                     uint16 - 4, Locale, Locale.Any);
                            RealmPacketIn packet = new RealmPacketIn(_bufferSegment, 7, uint16 - 8,
                                                                     IsGameServerConnection);
                            RealmPacketMgr.Instance.HandlePacket(this, packet);
                            _remainingLength -= uint16;
                            BufferSegment bufferSegment = _bufferSegment;
                            _bufferSegment = Buffers.CheckOut();
                            if (_remainingLength > 0)
                            {
                                Array.Copy(bufferSegment.Buffer.Array, bufferSegment.Offset + uint16,
                                           _bufferSegment.Buffer.Array, _bufferSegment.Offset,
                                           _remainingLength);
                            }
                            else
                            {
                                goto label_14;
                            }
                        }
                        else
                        {
                            goto label_5;
                        }
                    }
                    else
                    {
                        goto label_3;
                    }
                }
                else
                {
                    break;
                }
            }

            throw new ObjectDisposedException("none");
label_3:
            LogUtil.WarnException("{0} send packet with lenght {1}. HACKER! Remaining length {2}", (object)AccountName,
                                  (object)uint16, (object)_remainingLength);
            _remainingLength = 0;
            Disconnect(false);
            throw new InvalidOperationException("Wrong data from client.");
label_5:
            return(true);

label_14:
            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Pass recieved data into the packet buffer and try to parse.
        /// </summary>
        /// <param name="_remainingLength">number of bytes waiting to be read</param>
        /// <returns>false, if there is a part of a packet still remaining</returns>
        protected override bool OnReceive()
        {
            while (true)
            {
                var packetOfset = _bufferSegment.Offset;

                var packetLength = BitConverter.ToUInt16(_bufferSegment.Buffer.Array, packetOfset + 1);
                if (packetLength == 0)
                {
                    throw new ObjectDisposedException("none");
                }
                if (packetLength > 4096)
                {
                    LogUtil.WarnException("{0} send packet with lenght {1}. HACKER! Remaining length {2}", AccountName, packetLength, _remainingLength);
                    _remainingLength = 0;
                    Disconnect(false);
                    throw new InvalidOperationException("Wrong data from client.");
                }
                if (_remainingLength < packetLength)
                {
                    return(true);
                }
                if (!KnownClientVersion)
                {
                    var data = new byte[2];
                    data[0] = _bufferSegment.Buffer.Array[packetOfset + 3];
                    data[1] = _bufferSegment.Buffer.Array[packetOfset + 4];
                    Asda2CryptHelper.XorData(data, 0, 2, Locale.En, Locale.UnEncoded);
                    if (data[1] == 0)
                    {
                        Locale = Locale.En;
                        //eng client
                    }
                    else if (data[1] == 228)
                    {
                        Locale = Locale.Ru;
                    }
                    else if (data[1] == 116)
                    {
                        Locale = Locale.Ar;
                    }
                    else
                    {
                        //unknown client
                    }
                    KnownClientVersion = true;
                }
                Asda2CryptHelper.XorData(_bufferSegment.Buffer.Array, packetOfset + 3, packetLength - 4, Locale, Locale.UnEncoded);
                var bs     = _bufferSegment;
                var packet = new RealmPacketIn(bs, 7, packetLength - 8, IsGameServerConnection);
                //Console.WriteLine(@"S <- C: {0}", packet.PacketId);

                RealmPacketMgr.Instance.HandlePacket(this, packet);
                _remainingLength -= packetLength;

                var curBs = _bufferSegment;
                _bufferSegment = Buffers.CheckOut();
                if (_remainingLength > 0)
                {
                    //log.Info("remaining length = " + _remainingLength);
                    Array.Copy(curBs.Buffer.Array, curBs.Offset + packetLength, _bufferSegment.Buffer.Array,
                               _bufferSegment.Offset, _remainingLength);
                }
                else
                {
                    return(true);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Pass recieved data into the packet buffer and try to parse.
        /// </summary>
        /// <param name="_remainingLength">number of bytes waiting to be read</param>
        /// <returns>false, if there is a part of a packet still remaining</returns>
        protected override bool OnReceive()
        {
            ushort uint16;

            while (true)
            {
                int offset = this._bufferSegment.Offset;
                uint16 = BitConverter.ToUInt16(this._bufferSegment.Buffer.Array, offset + 1);
                if (uint16 != (ushort)0)
                {
                    if (uint16 <= (ushort)4096)
                    {
                        if (this._remainingLength >= (int)uint16)
                        {
                            if (!this.KnownClientVersion)
                            {
                                byte[] buffer = new byte[2]
                                {
                                    this._bufferSegment.Buffer.Array[offset + 3],
                                    this._bufferSegment.Buffer.Array[offset + 4]
                                };
                                Asda2CryptHelper.XorData(buffer, 0, 2L, Locale.Start, Locale.Any);
                                if (buffer[1] == (byte)0)
                                {
                                    this.Locale = Locale.Start;
                                }
                                else if (buffer[1] == (byte)228)
                                {
                                    this.Locale = Locale.Ru;
                                }
                                this.KnownClientVersion = true;
                            }

                            Asda2CryptHelper.XorData(this._bufferSegment.Buffer.Array, offset + 3,
                                                     (long)((int)uint16 - 4), this.Locale, Locale.Any);
                            RealmPacketIn packet = new RealmPacketIn(this._bufferSegment, 7, (int)uint16 - 8,
                                                                     this.IsGameServerConnection);
                            RealmPacketMgr.Instance.HandlePacket((IRealmClient)this, packet);
                            this._remainingLength -= (int)uint16;
                            BufferSegment bufferSegment = this._bufferSegment;
                            this._bufferSegment = ClientBase.Buffers.CheckOut();
                            if (this._remainingLength > 0)
                            {
                                Array.Copy((Array)bufferSegment.Buffer.Array, bufferSegment.Offset + (int)uint16,
                                           (Array)this._bufferSegment.Buffer.Array, this._bufferSegment.Offset,
                                           this._remainingLength);
                            }
                            else
                            {
                                goto label_14;
                            }
                        }
                        else
                        {
                            goto label_5;
                        }
                    }
                    else
                    {
                        goto label_3;
                    }
                }
                else
                {
                    break;
                }
            }

            throw new ObjectDisposedException("none");
label_3:
            LogUtil.WarnException("{0} send packet with lenght {1}. HACKER! Remaining length {2}", new object[3]
            {
                (object)this.AccountName,
                (object)uint16,
                (object)this._remainingLength
            });
            this._remainingLength = 0;
            this.Disconnect(false);
            throw new InvalidOperationException("Wrong data from client.");
label_5:
            return(true);

label_14:
            return(true);
        }