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