Example #1
0
        /// <summary>
        /// Sends a command to the connected server.
        /// The return value of this function does not signify command success, only if the command was sent.
        /// </summary>
        /// <param name="command">The command type to send.</param>
        /// <param name="args">The arguments to send.</param>
        /// <returns>True if the command was sent; otherwise, false.</returns>
        protected bool SendCommand(byte command, params object[] args)
        {
            try
            {
                using (TcpPacket packet = new TcpPacket())
                {
                    packet.Write(command);

                    foreach (object arg in args)
                    {
                        if (arg is byte[])
                        {
                            packet.Write(( byte[] )arg);
                        }
                        else if (arg is string)
                        {
                            packet.Write(( string )arg, Encoding.ASCII);
                        }
                        else
                        {
                            packet.Write(arg.GetType(), arg);
                        }
                    }

                    Socket.Send(packet);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Requests the cell ID of the currently connected content server.
        /// </summary>
        /// <returns>The cell ID of the server.</returns>
        public uint GetCellID()
        {
            if (!this.HandshakeServer(( ESteam2ServerType )3))
            {
                throw new Steam2Exception("Package handshake with content server failed");
            }

            TcpPacket packet = new TcpPacket();

            packet.Write(( uint )2);


            try
            {
                this.Socket.Send(packet);

                uint cellId = NetHelpers.EndianSwap(this.Socket.Reader.ReadUInt32());

                return(cellId);
            }
            catch (Exception ex)
            {
                throw new Steam2Exception("Unable to request cell id", ex);
            }
        }
Example #3
0
            /// <summary>
            /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
            /// </summary>
            public void Dispose()
            {
                TcpPacket packet = new TcpPacket();

                packet.Write(( uint )3);

                // exit package mode
                this.Socket.Send(packet);
            }
Example #4
0
            /// <summary>
            /// Downloads the specified package file.
            /// </summary>
            /// <param name="fileName">Name of the file.</param>
            /// <returns>A byte array representing the file.</returns>
            public byte[] DownloadPackage(string fileName)
            {
                TcpPacket packet = new TcpPacket();

                packet.Write(( uint )0);   // unknown, always 0?
                packet.Write(( uint )0);   // unknown, always 0?
                packet.Write(( uint )fileName.Length);
                packet.Write(fileName);
                packet.Write(this.CellID);

                this.Socket.Send(packet);

                // length is sent twice, as two uints
                uint len1 = NetHelpers.EndianSwap(this.Socket.Reader.ReadUInt32());
                uint len2 = NetHelpers.EndianSwap(this.Socket.Reader.ReadUInt32());

                byte[] packageData = this.Socket.Reader.ReadBytes(( int )len1);

                return(packageData);
            }
Example #5
0
            /// <summary>
            /// Downloads the specified package file.
            /// </summary>
            /// <param name="fileName">Name of the file.</param>
            /// <returns>A byte array representing the file.</returns>
            public byte[] DownloadPackage( string fileName )
            {
                TcpPacket packet = new TcpPacket();
                packet.Write( ( uint )0 ); // unknown, always 0?
                packet.Write( ( uint )0 ); // unknown, always 0?
                packet.Write( ( uint )fileName.Length );
                packet.Write( fileName );
                packet.Write( this.CellID );

                this.Socket.Send( packet );

                // length is sent twice, as two uints
                uint len1 = NetHelpers.EndianSwap( this.Socket.Reader.ReadUInt32() );
                uint len2 = NetHelpers.EndianSwap( this.Socket.Reader.ReadUInt32() );

                byte[] packageData = this.Socket.Reader.ReadBytes( ( int )len1 );

                return packageData;
            }
Example #6
0
            /// <summary>
            /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
            /// </summary>
            public void Dispose()
            {
                TcpPacket packet = new TcpPacket();
                packet.Write( ( uint )3 );

                // exit package mode
                this.Socket.Send( packet );
            }
Example #7
0
        /// <summary>
        /// Requests the cell ID of the currently connected content server.
        /// </summary>
        /// <returns>The cell ID of the server.</returns>
        public uint GetCellID()
        {
            if ( !this.HandshakeServer( ( ESteam2ServerType )3 ) )
                throw new Steam2Exception( "Package handshake with content server failed" );

            TcpPacket packet = new TcpPacket();
            packet.Write( ( uint )2 );


            try
            {
                this.Socket.Send( packet );

                uint cellId = NetHelpers.EndianSwap( this.Socket.Reader.ReadUInt32() );

                return cellId;
            }
            catch ( Exception ex )
            {
                throw new Steam2Exception( "Unable to request cell id", ex );
            }
        }