Represents a data packet sent over tcp. Contains a length and payload.
Inheritance: BinaryWriterEx
        /// <summary>
        /// Gets a list of all currently active content servers.
        /// </summary>
        /// <returns>A list of servers on success; otherwise, <c>null</c>.</returns>
        public IPEndPoint[] GetContentServerList()
        {
            TcpPacket packet = base.GetRawServerList(3);   // command 3

            if (packet == null)
            {
                return(null);
            }

            DataStream ds = new DataStream(packet.GetPayload(), true);

            ushort numAddrs = ds.ReadUInt16();

            IPEndPoint[] serverList = new IPEndPoint[numAddrs];
            for (int x = 0; x < numAddrs; ++x)
            {
                IPAddrPort ipAddr = IPAddrPort.Deserialize(ds.ReadBytes(6));
                serverList[x] = ipAddr;
            }

            return(serverList);
        }
Exemple #2
0
        /// <summary>
        /// Gets the server list for a specific server type.
        /// </summary>
        /// <param name="type">The server type.</param>
        /// <returns>A list of servers on success; otherwise, <c>null</c>.</returns>
        public IPEndPoint[] GetServerList(ESteam2ServerType type)
        {
            TcpPacket packet = this.GetRawServerList(( byte )type);

            if (packet == null)
            {
                return(null);
            }

            DataStream ds = new DataStream(packet.GetPayload(), true);

            ushort numAddrs = ds.ReadUInt16();

            IPEndPoint[] serverList = new IPEndPoint[numAddrs];
            for (int x = 0; x < numAddrs; ++x)
            {
                IPAddrPort ipAddr = IPAddrPort.Deserialize(ds.ReadBytes(6));

                serverList[x] = ipAddr;
            }

            return(serverList);
        }
            /// <summary>
            /// Downloads a list of updated FileIDs since the given version.
            /// </summary>
            /// <param name="oldVersion">The old version to compare to.</param>
            /// <returns>A list of FileIDs that have been updated.</returns>
            public uint[] DownloadUpdates(uint oldVersion)
            {
                bool bRet = this.SendCommand(
                    5, // download updates
                    this.StorageID,
                    this.MessageID,
                    oldVersion
                    );

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

                byte updateState = this.Socket.Reader.ReadByte();

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

                if (numUpdates == 0)
                {
                    return(null);
                }

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

                TcpPacket  packet = this.Socket.ReceivePacket();
                DataStream ds     = new DataStream(packet.GetPayload());

                uint[] fileIdList = new uint[numUpdates];
                for (int x = 0; x < numUpdates; ++x)
                {
                    fileIdList[x] = ds.ReadUInt32();
                }

                this.MessageID++;

                return(fileIdList);
            }
        static ContentServer[] GetServersFromPacket(TcpPacket packet)
        {
            DataStream ds = new DataStream(packet.GetPayload(), true);

            ushort numAddrs = ds.ReadUInt16();

            ContentServer[] serverList = new ContentServer[numAddrs];
            for (int x = 0; x < numAddrs; ++x)
            {
                uint weighedLoad = ds.ReadUInt32();

                IPAddrPort ipAddr  = IPAddrPort.Deserialize(ds.ReadBytes(6));
                IPAddrPort ipAddr2 = IPAddrPort.Deserialize(ds.ReadBytes(6));

                serverList[x] = new ContentServer()
                {
                    Load          = weighedLoad,
                    PackageServer = ipAddr,
                    StorageServer = ipAddr2,
                };
            }

            return(serverList);
        }
Exemple #5
0
 /// <summary>
 /// Sends the specified packet on the socket.
 /// </summary>
 /// <param name="packet">The packet.</param>
 public void Send(TcpPacket packet)
 {
     this.Send(packet.GetData());
 }
        static ContentServer[] GetServersFromPacket( TcpPacket packet )
        {
            DataStream ds = new DataStream( packet.GetPayload(), true );

            ushort numAddrs = ds.ReadUInt16();

            ContentServer[] serverList = new ContentServer[ numAddrs ];
            for ( int x = 0 ; x < numAddrs ; ++x )
            {
                uint weighedLoad = ds.ReadUInt32();

                IPAddrPort ipAddr = IPAddrPort.Deserialize( ds.ReadBytes( 6 ) );
                IPAddrPort ipAddr2 = IPAddrPort.Deserialize( ds.ReadBytes( 6 ) );

                serverList[ x ] = new ContentServer()
                {
                    Load = weighedLoad,
                    PackageServer = ipAddr,
                    StorageServer = ipAddr2,
                };

            }

            return serverList;
        }
            /// <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;
            }
            /// <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 );
            }
        /// <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 );
            }
        }