/SteamKit3/SteamKit3/Networking/Connection.cs
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
- /*
- * This file is subject to the terms and conditions defined in
- * file 'license.txt', which is part of this source code package.
- */
-
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Net.Sockets;
- using System.Net;
- using System.Diagnostics;
- using System.IO;
- using log4net;
-
- namespace SteamKit3
- {
- /// <summary>
- /// Represents data that has been received over the network.
- /// </summary>
- public class NetMsgEventArgs : EventArgs
- {
- /// <summary>
- /// Gets the data for this network message.
- /// </summary>
- public byte[] Data { get; private set; }
- /// <summary>
- /// Gets the remote endpoint of this message.
- /// </summary>
- public IPEndPoint EndPoint { get; private set; }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="NetMsgEventArgs"/> class.
- /// </summary>
- /// <param name="data">The data.</param>
- /// <param name="endPoint">The remote endpoint.</param>
- public NetMsgEventArgs( byte[] data, IPEndPoint endPoint )
- {
- this.Data = data;
- this.EndPoint = endPoint;
- }
- }
-
- class NetFilterEncryption
- {
- byte[] sessionKey;
-
- public NetFilterEncryption( byte[] sessionKey )
- {
- this.sessionKey = sessionKey;
- }
-
- public byte[] ProcessIncoming( byte[] data )
- {
- return CryptoHelper.SymmetricDecrypt( data, sessionKey );
- }
-
- public byte[] ProcessOutgoing( byte[] ms )
- {
- return CryptoHelper.SymmetricEncrypt( ms, sessionKey );
- }
- }
-
- abstract class Connection
- {
- public static readonly IPEndPoint[] CMServers =
- {
- new IPEndPoint( IPAddress.Parse( "68.142.64.164" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "68.142.64.165" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "68.142.91.34" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "68.142.91.35" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "68.142.91.36" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "68.142.116.178" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "68.142.116.179" ), 27017 ),
-
- new IPEndPoint( IPAddress.Parse( "69.28.145.170" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "69.28.145.171" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "69.28.145.172" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "69.28.156.250" ), 27017 ),
-
- new IPEndPoint( IPAddress.Parse( "72.165.61.185" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "72.165.61.186" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "72.165.61.187" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "72.165.61.188" ), 27017 ),
-
- new IPEndPoint( IPAddress.Parse( "208.111.133.84" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "208.111.133.85" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "208.111.158.52" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "208.111.158.53" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "208.111.171.82" ), 27017 ),
- new IPEndPoint( IPAddress.Parse( "208.111.171.83" ), 27017 ),
- };
-
- /// <summary>
- /// Gets or sets the net filter for this connection.
- /// </summary>
- /// <value>The net filter.</value>
- public NetFilterEncryption NetFilter { get; set; }
-
- /// <summary>
- /// Gets the log4net log context for this connection.
- /// </summary>
- protected ILog Log { get; private set; }
-
-
- /// <summary>
- /// Initializes a new instance of the <see cref="Connection"/> class.
- /// </summary>
- public Connection()
- {
- Log = LogManager.GetLogger( this.GetType() );
- }
-
-
- /// <summary>
- /// Occurs when a net message is recieved over the network.
- /// </summary>
- public event EventHandler<NetMsgEventArgs> NetMsgReceived;
- /// <summary>
- /// Raises the <see cref="E:NetMsgReceived"/> event.
- /// </summary>
- /// <param name="e">The <see cref="NetMsgEventArgs"/> instance containing the event data.</param>
- protected void OnNetMsgReceived( NetMsgEventArgs e )
- {
- if ( NetMsgReceived != null )
- NetMsgReceived( this, e );
- }
-
- /// <summary>
- /// Occurs when the physical connection is broken.
- /// </summary>
- public event EventHandler Disconnected;
- protected void OnDisconnected( EventArgs e )
- {
- if ( Disconnected != null )
- Disconnected( this, e );
- }
-
- public event EventHandler Connected;
- protected void OnConnected( EventArgs e )
- {
- if ( Connected != null )
- Connected( this, e );
- }
-
- /// <summary>
- /// Connects to the specified end point.
- /// </summary>
- /// <param name="endPoint">The end point.</param>
- public abstract void Connect( IPEndPoint endPoint );
- /// <summary>
- /// Disconnects this instance.
- /// </summary>
- public abstract void Disconnect();
-
- /// <summary>
- /// Sends the specified client net message.
- /// </summary>
- /// <param name="clientMsg">The client net message.</param>
- public abstract void Send( IClientMsg clientMsg );
- }
-
- }