コード例 #1
0
 public OutPacket(InPacket inPacket)
 {
     m_stream = new MemoryStream(DefaultBufferSize);
     m_disposed = false;
     WriteUShort(inPacket.OperationCode);
     WriteBytes(inPacket.ReadLeftoverBytes());
 }
コード例 #2
0
 public override void Dispatch(InPacket inPacket)
 {
     using (OutPacket outPacket = new OutPacket(inPacket))
     {
         if (ServerSession.Instance != null)
         {
             ServerSession.Instance.Send(outPacket.ToArray());
         }
     }
 }
コード例 #3
0
ファイル: Session.cs プロジェクト: ppgutkus/ms-MapleLauncher
 public abstract void Dispatch(InPacket inPacket);
コード例 #4
0
ファイル: Session.cs プロジェクト: ppgutkus/ms-MapleLauncher
        /// <summary>
        /// Used as IAsyncResult parser for ContinueReading().
        /// </summary>
        /// <param name="pIAR">The result AsyncCallback makes</param>
        private void EndReading(IAsyncResult pIAR)
        {
            int amountReceived = 0;

            try
            {
                amountReceived = _socket.EndReceive(pIAR);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(TypeName + " : " + ex.ToString());
                amountReceived = 0;
            }
            if (amountReceived == 0)
            {
                // We got a disWvsBeta.Common.Sessions here!
                OnDisconnectINTERNAL();
                return;
            }

            // Add amount of bytes received to _bufferpos so we know if we got everything.
            _bufferpos += amountReceived;



            // Check if we got all data. There is _no_ way we would have received more bytes than needed. Period.
            if (_bufferpos == _bufferlen)
            {
                // It seems we have all data we need
                // Now check if we got a header
                if (_header)
                {
                    if (!_encryption && _receivingFromServer)
                    {
                        // Unencrypted Packet have a short header with plain length.
                        ushort length = (ushort)(_buffer[0] | _buffer[1] << 8);
                        StartReading(length);
                    }
                    else
                    {
                        int length = GetHeaderLength(_buffer);
                        StartReading(length);
                    }
                }
                else
                {
                    InPacket packet;
                    if (_encryption)
                    {
                        _buffer = Decrypt(_buffer);
                        packet  = new InPacket(_buffer);

                        Dispatch(packet);
                    }
                    else
                    {
                        _encryption = true; // First packet received or sent is unencrypted. All others are.
                        packet      = new InPacket(_buffer, false);

                        this.ServerInfo = new ServerInfo();

                        this.ServerInfo.Version    = packet.ReadUShort();
                        this.ServerInfo.Subversion = packet.ReadString();
                        _encryptIV = packet.ReadBytes(4);
                        _decryptIV = packet.ReadBytes(4);
                        this.ServerInfo.Localisation = (Localisation)packet.ReadByte();

                        Session.AssignUserKey(this.ServerInfo);

                        this.OnHandshake(this.ServerInfo);
                    }

                    StartReading(4, true);
                }
            }
            else
            {
                ContinueReading();
            }
        }
コード例 #5
0
ファイル: Session.cs プロジェクト: Yaminike/ms-MapleLauncher
        /// <summary>
        /// Used as IAsyncResult parser for ContinueReading().
        /// </summary>
        /// <param name="pIAR">The result AsyncCallback makes</param>
        private void EndReading(IAsyncResult pIAR)
        {
            int amountReceived = 0;
            try
            {
                amountReceived = _socket.EndReceive(pIAR);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(TypeName + " : " + ex.ToString());
                amountReceived = 0;
            }
            if (amountReceived == 0)
            {
                // We got a disWvsBeta.Common.Sessions here!
                OnDisconnectINTERNAL();
                return;
            }

            // Add amount of bytes received to _bufferpos so we know if we got everything.
            _bufferpos += amountReceived;

            // Check if we got all data. There is _no_ way we would have received more bytes than needed. Period.
            if (_bufferpos == _bufferlen)
            {
                // It seems we have all data we need
                // Now check if we got a header
                if (_header)
                {
                    if (!_encryption && _receivingFromServer)
                    {
                        // Unencrypted Packet have a short header with plain length.
                        ushort length = (ushort)(_buffer[0] | _buffer[1] << 8);
                        StartReading(length);
                    }
                    else
                    {
                        int length = GetHeaderLength(_buffer);
                        StartReading(length);
                    }
                }
                else
                {
                    InPacket packet;
                    if (_encryption)
                    {
                        _buffer = Decrypt(_buffer);
                        packet = new InPacket(_buffer);

                        Dispatch(packet);
                    }
                    else
                    {
                        _encryption = true; // First packet received or sent is unencrypted. All others are.
                        packet = new InPacket(_buffer, false);

                        this.ServerInfo = new ServerInfo();

                        this.ServerInfo.Version = packet.ReadUShort();
                        this.ServerInfo.Subversion = packet.ReadString();
                        _encryptIV = packet.ReadBytes(4);
                        _decryptIV = packet.ReadBytes(4);
                        this.ServerInfo.Localisation = (Localisation)packet.ReadByte();

                        Session.AssignUserKey(this.ServerInfo);

                        this.OnHandshake(this.ServerInfo);
                    }

                    StartReading(4, true);
                }
            }
            else
            {
                ContinueReading();
            }
        }
コード例 #6
0
ファイル: Session.cs プロジェクト: Yaminike/ms-MapleLauncher
 public abstract void Dispatch(InPacket inPacket);