PageRenderTime 23ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/SteamKit2/SteamKit2/Steam2/ConfigServerClient.cs

https://bitbucket.org/VoiDeD/steamre/
C# | 119 lines | 68 code | 26 blank | 25 comment | 12 complexity | 30fe13e556e7794ebec2d73ce51902ca MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /*
  2. * This file is subject to the terms and conditions defined in
  3. * file 'license.txt', which is part of this source code package.
  4. */
  5. using System;
  6. namespace SteamKit2
  7. {
  8. /// <summary>
  9. /// This client is capable of connecting to a config server.
  10. /// </summary>
  11. public sealed class ConfigServerClient : ServerClient
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="ConfigServerClient"/> class.
  15. /// </summary>
  16. public ConfigServerClient()
  17. {
  18. }
  19. /// <summary>
  20. /// Requests the network key from the config server.
  21. /// </summary>
  22. /// <returns>The network key.</returns>
  23. public byte[] GetNetworkKey()
  24. {
  25. if ( !this.HandshakeServer( ESteam2ServerType.ConfigServer ) )
  26. return null;
  27. uint externalIp = this.Socket.Reader.ReadUInt32();
  28. if ( !this.SendCommand( 4 ) ) // command: get network key
  29. return null;
  30. ushort keyLen = NetHelpers.EndianSwap( this.Socket.Reader.ReadUInt16() );
  31. byte[] key = this.Socket.Reader.ReadBytes( keyLen );
  32. ushort sigLen = NetHelpers.EndianSwap( this.Socket.Reader.ReadUInt16() );
  33. byte[] signature = this.Socket.Reader.ReadBytes( sigLen );
  34. return key;
  35. }
  36. /// <summary>
  37. /// Gets the current content description record (CDR) provided by the config server.
  38. /// Optionally accepts an old CDR hash in order to determine if a new CDR should be downloaded or not.
  39. /// The old CDR hash is a SHA-1 hash of the entire CDR payload.
  40. /// </summary>
  41. /// <param name="oldCDRHash">An optional CDR hash.</param>
  42. /// <returns>A byte blob representing the CDR on success; otherwise, <c>null</c>.</returns>
  43. public byte[] GetContentDescriptionRecord( byte[] oldCDRHash = null )
  44. {
  45. try
  46. {
  47. if ( !this.HandshakeServer( ESteam2ServerType.ConfigServer ) )
  48. return null;
  49. uint externalIp = Socket.Reader.ReadUInt32();
  50. if ( oldCDRHash == null )
  51. oldCDRHash = new byte[ 20 ];
  52. if ( !SendCommand( 9, oldCDRHash ) )
  53. {
  54. return null;
  55. }
  56. byte[] unk = Socket.Reader.ReadBytes( 11 );
  57. TcpPacket pack = Socket.ReceivePacket();
  58. Socket.Disconnect();
  59. if ( pack == null )
  60. return null;
  61. return pack.GetPayload();
  62. }
  63. catch ( Exception ex )
  64. {
  65. DebugLog.WriteLine( "ConfigServerClient", "GetContentDescriptionRecord threw an exception.\n{0}", ex.ToString() );
  66. Socket.Disconnect();
  67. return null;
  68. }
  69. }
  70. /// <summary>
  71. /// Requests the client config record from the server.
  72. /// </summary>
  73. /// <returns>A binary blob that represents the config record on success; otherwise <c>null</c>.</returns>
  74. public byte[] GetClientConfigRecord()
  75. {
  76. if ( !this.HandshakeServer( ESteam2ServerType.ConfigServer ) )
  77. {
  78. this.Disconnect();
  79. return null;
  80. }
  81. uint externalIp = Socket.Reader.ReadUInt32();
  82. if ( !this.SendCommand( 1 ) ) // command: Get CCR
  83. {
  84. return null;
  85. }
  86. TcpPacket pack = Socket.ReceivePacket();
  87. this.Disconnect();
  88. if ( pack == null )
  89. return null;
  90. return pack.GetPayload();
  91. }
  92. }
  93. }