PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/SteamKit3/SteamKit3/Networking/Connection.cs

https://bitbucket.org/VoiDeD/steamre/
C# | 162 lines | 91 code | 22 blank | 49 comment | 6 complexity | a6365be4b1eeb46f56dca9096aecbb7a 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. using System.Collections.Generic;
  7. using System.Text;
  8. using System.Net.Sockets;
  9. using System.Net;
  10. using System.Diagnostics;
  11. using System.IO;
  12. using log4net;
  13. namespace SteamKit3
  14. {
  15. /// <summary>
  16. /// Represents data that has been received over the network.
  17. /// </summary>
  18. public class NetMsgEventArgs : EventArgs
  19. {
  20. /// <summary>
  21. /// Gets the data for this network message.
  22. /// </summary>
  23. public byte[] Data { get; private set; }
  24. /// <summary>
  25. /// Gets the remote endpoint of this message.
  26. /// </summary>
  27. public IPEndPoint EndPoint { get; private set; }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="NetMsgEventArgs"/> class.
  30. /// </summary>
  31. /// <param name="data">The data.</param>
  32. /// <param name="endPoint">The remote endpoint.</param>
  33. public NetMsgEventArgs( byte[] data, IPEndPoint endPoint )
  34. {
  35. this.Data = data;
  36. this.EndPoint = endPoint;
  37. }
  38. }
  39. class NetFilterEncryption
  40. {
  41. byte[] sessionKey;
  42. public NetFilterEncryption( byte[] sessionKey )
  43. {
  44. this.sessionKey = sessionKey;
  45. }
  46. public byte[] ProcessIncoming( byte[] data )
  47. {
  48. return CryptoHelper.SymmetricDecrypt( data, sessionKey );
  49. }
  50. public byte[] ProcessOutgoing( byte[] ms )
  51. {
  52. return CryptoHelper.SymmetricEncrypt( ms, sessionKey );
  53. }
  54. }
  55. abstract class Connection
  56. {
  57. public static readonly IPEndPoint[] CMServers =
  58. {
  59. new IPEndPoint( IPAddress.Parse( "68.142.64.164" ), 27017 ),
  60. new IPEndPoint( IPAddress.Parse( "68.142.64.165" ), 27017 ),
  61. new IPEndPoint( IPAddress.Parse( "68.142.91.34" ), 27017 ),
  62. new IPEndPoint( IPAddress.Parse( "68.142.91.35" ), 27017 ),
  63. new IPEndPoint( IPAddress.Parse( "68.142.91.36" ), 27017 ),
  64. new IPEndPoint( IPAddress.Parse( "68.142.116.178" ), 27017 ),
  65. new IPEndPoint( IPAddress.Parse( "68.142.116.179" ), 27017 ),
  66. new IPEndPoint( IPAddress.Parse( "69.28.145.170" ), 27017 ),
  67. new IPEndPoint( IPAddress.Parse( "69.28.145.171" ), 27017 ),
  68. new IPEndPoint( IPAddress.Parse( "69.28.145.172" ), 27017 ),
  69. new IPEndPoint( IPAddress.Parse( "69.28.156.250" ), 27017 ),
  70. new IPEndPoint( IPAddress.Parse( "72.165.61.185" ), 27017 ),
  71. new IPEndPoint( IPAddress.Parse( "72.165.61.186" ), 27017 ),
  72. new IPEndPoint( IPAddress.Parse( "72.165.61.187" ), 27017 ),
  73. new IPEndPoint( IPAddress.Parse( "72.165.61.188" ), 27017 ),
  74. new IPEndPoint( IPAddress.Parse( "208.111.133.84" ), 27017 ),
  75. new IPEndPoint( IPAddress.Parse( "208.111.133.85" ), 27017 ),
  76. new IPEndPoint( IPAddress.Parse( "208.111.158.52" ), 27017 ),
  77. new IPEndPoint( IPAddress.Parse( "208.111.158.53" ), 27017 ),
  78. new IPEndPoint( IPAddress.Parse( "208.111.171.82" ), 27017 ),
  79. new IPEndPoint( IPAddress.Parse( "208.111.171.83" ), 27017 ),
  80. };
  81. /// <summary>
  82. /// Gets or sets the net filter for this connection.
  83. /// </summary>
  84. /// <value>The net filter.</value>
  85. public NetFilterEncryption NetFilter { get; set; }
  86. /// <summary>
  87. /// Gets the log4net log context for this connection.
  88. /// </summary>
  89. protected ILog Log { get; private set; }
  90. /// <summary>
  91. /// Initializes a new instance of the <see cref="Connection"/> class.
  92. /// </summary>
  93. public Connection()
  94. {
  95. Log = LogManager.GetLogger( this.GetType() );
  96. }
  97. /// <summary>
  98. /// Occurs when a net message is recieved over the network.
  99. /// </summary>
  100. public event EventHandler<NetMsgEventArgs> NetMsgReceived;
  101. /// <summary>
  102. /// Raises the <see cref="E:NetMsgReceived"/> event.
  103. /// </summary>
  104. /// <param name="e">The <see cref="NetMsgEventArgs"/> instance containing the event data.</param>
  105. protected void OnNetMsgReceived( NetMsgEventArgs e )
  106. {
  107. if ( NetMsgReceived != null )
  108. NetMsgReceived( this, e );
  109. }
  110. /// <summary>
  111. /// Occurs when the physical connection is broken.
  112. /// </summary>
  113. public event EventHandler Disconnected;
  114. protected void OnDisconnected( EventArgs e )
  115. {
  116. if ( Disconnected != null )
  117. Disconnected( this, e );
  118. }
  119. public event EventHandler Connected;
  120. protected void OnConnected( EventArgs e )
  121. {
  122. if ( Connected != null )
  123. Connected( this, e );
  124. }
  125. /// <summary>
  126. /// Connects to the specified end point.
  127. /// </summary>
  128. /// <param name="endPoint">The end point.</param>
  129. public abstract void Connect( IPEndPoint endPoint );
  130. /// <summary>
  131. /// Disconnects this instance.
  132. /// </summary>
  133. public abstract void Disconnect();
  134. /// <summary>
  135. /// Sends the specified client net message.
  136. /// </summary>
  137. /// <param name="clientMsg">The client net message.</param>
  138. public abstract void Send( IClientMsg clientMsg );
  139. }
  140. }