PutUShort() public method

Put the given ushort at the current offset.
public PutUShort ( ushort s ) : void
s ushort
return 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
ファイル: 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();
            }
        }