SetLength() 공개 메소드

Write the data length to the first 2 bytes of the packet.
public SetLength ( ) : void
리턴 void
예제 #1
0
파일: NetIO.cs 프로젝트: zNext666/SagaECO
        /// <summary>
        /// Sends a packet, which is not yet encrypted, to the client.
        /// </summary>
        /// <param name="p">The packet containing all info.</param>
        public void SendPacket(Packet p, bool nolength, bool noWarper)
        {
            if (!noWarper)
            {
                byte[] buf = new byte[p.data.Length + firstLevelLenth];
                Array.Copy(p.data, 0, buf, firstLevelLenth, p.data.Length);
                p.data = buf;
                if (firstLevelLenth == 4)
                {
                    p.SetLength();
                }
                else
                {
                    p.PutUShort((ushort)(p.data.Length - 2), 0);
                }
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
                p.SetLength();
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
            }
            if (!nolength)
            {
                int mod = 16 - ((p.data.Length - 8) % 16);
                if (mod != 0)
                {
                    byte[] buf = new byte[p.data.Length + mod];
                    Array.Copy(p.data, 0, buf, 0, p.data.Length);
                    p.data = buf;
                }
                p.PutUInt((uint)(p.data.Length - 8), 0);
            }

            try
            {
                byte[] data;
                data = Crypt.Encrypt(p.data, 8);
                sock.BeginSend(data, 0, data.Length, SocketFlags.None, null, null);
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex);
                this.Disconnect();
            }
        }
예제 #2
0
        /// <summary>
        /// Sends a packet, which is not yet encrypted, to the client.
        /// </summary>
        /// <param name="p">The packet containing all info.</param>
        private void SendPacket(Packet p, uint SessionID, bool nosession)
        {
            p.SetLength();

            try
            {
                if (this.isGateway)
                {
                    byte[] data;
                    if (p.doNotEncryptBuffer)
                    {
                        data = Encryption.Encrypt((byte[])p.data.Clone(), 2, this.serverKey);
                    }
                    else
                    {
                        data = Encryption.Encrypt(p.data, 2, this.serverKey);
                    }
                    sock.BeginSend(data, 0, data.Length, SocketFlags.None, null, null);
                }
                else
                {
                    if (!nosession)
                    {
                        byte[] data;
                        data = new byte[p.data.Length + 4];
                        Array.Copy(p.data, 2, data, 6, p.data.Length - 2);
                        p.data      = data;
                        p.SessionID = SessionID;
                        p.SetLength();
                    }
                    sock.BeginSend(p.data, 0, p.data.Length, SocketFlags.None, null, null);
                    //sock.Send(p.data);
                }
            }
            catch (Exception)
            {
                this.Disconnect();
            }
        }
예제 #3
0
파일: NetIO.cs 프로젝트: Willyham/SagaRO2
        /// <summary>
        /// Sends a packet, which is not yet encrypted, to the client.
        /// </summary>
        /// <param name="p">The packet containing all info.</param>
        private void SendPacket(Packet p, uint SessionID, bool nosession)
        {
            p.SetLength();

                try
                {
                    if (this.isGateway)
                    {
                        byte[] data;
                        if (p.doNotEncryptBuffer) data = Encryption.Encrypt((byte[])p.data.Clone(), 2, this.serverKey);
                        else data = Encryption.Encrypt(p.data, 2, this.serverKey);
                        sock.BeginSend(data, 0, data.Length, SocketFlags.None, null, null);
                    }
                    else
                    {
                        if (!nosession)
                        {
                            byte[] data;
                            data = new byte[p.data.Length + 4];
                            Array.Copy(p.data, 2, data, 6, p.data.Length - 2);
                            p.data = data;
                            p.SessionID = SessionID;
                            p.SetLength();
                        }
                        sock.BeginSend(p.data, 0, p.data.Length, SocketFlags.None, null, null);
                        //sock.Send(p.data);
                    }

                }
                catch (Exception)
                {
                    this.Disconnect();
                }
        }
예제 #4
0
파일: NetIO.cs 프로젝트: yasuhiro91/SagaECO
        /// <summary>
        /// Sends a packet, which is not yet encrypted, to the client.
        /// </summary>
        /// <param name="p">The packet containing all info.</param>
        public void SendPacket(Packet p, bool nolength, bool noWarper)
        {
            if (!noWarper)
            {
                byte[] buf = new byte[p.data.Length + firstLevelLenth];
                Array.Copy(p.data, 0, buf, firstLevelLenth, p.data.Length);
                p.data = buf;
                if (firstLevelLenth == 4)
                    p.SetLength();
                else
                    p.PutUShort((ushort)(p.data.Length - 2), 0);
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
                p.SetLength();
                buf = new byte[p.data.Length + 4];
                Array.Copy(p.data, 0, buf, 4, p.data.Length);
                p.data = buf;
            }
            if (!nolength)
            {
                int mod = 16-((p.data.Length - 8) % 16);
                if (mod != 0)
                {
                    byte[] buf = new byte[p.data.Length + mod];
                    Array.Copy(p.data, 0, buf, 0, p.data.Length);
                    p.data = buf;
                }
                p.PutUInt((uint)(p.data.Length - 8), 0);
            }

            try
            {
                byte[] data;
                data = Crypt.Encrypt(p.data, 8);
                sock.BeginSend(data, 0, data.Length, SocketFlags.None, null, null);
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex);
                this.Disconnect();
            }
        }