C# Class WDServer.Server

Datei anzeigen Open project: Good4m/WindowsDefender Class Usage Examples

Public Properties

Property Type Description
CLIENT_TIMEOUT int
DEBUG bool
RUNNING bool
_matches Match>.ConcurrentDictionary
_users User>.ConcurrentDictionary

Public Methods

Method Description
OnJoin ( IPEndPoint remoteEndPoint, string ipAddress, Instruction instruction ) : void

When the JOIN command is received by a user.

Server ( ) : System

Entry point. It creates a new thread that will be checking for timeouts. Listens on the main thread, for any instructions from the client.

Private Methods

Method Description
AddToMatch ( User user ) : void

Adds a user to his/her Match. If it doesn't exist yet then it will be created.

Init ( ) : void

Initializes the server socket and tells the user if everything worked.

Listen ( ) : void

Listens for packets and responds accordingly by passing the incoming data to other functions.

OnCommand ( string ipAddress, Instruction instruction, byte data ) : void

When a command instruction is received it is simply echoed to everyone in the same match as the user.

OnDisconnect ( string ipAddress ) : void

Disconnects a user based on their IP address.

ResetUserTimeout ( string ipAddress ) : void

Resets a user's timeout (heartbeat counter).

SendToMatch ( User user, byte data ) : void

Sends data to all users in a match. The data is from one client and it needs to find the match that that one client belongs to, but will broadcast to all client in the match.

TimeoutCheckerThread ( ) : void

If we haven't received messages from users for awhile, we consider them disconnected and they can be removed from any match they were a part of.

Method Details

OnJoin() public method

When the JOIN command is received by a user.
public OnJoin ( IPEndPoint remoteEndPoint, string ipAddress, Instruction instruction ) : void
remoteEndPoint System.Net.IPEndPoint The information such as IP, port and etc. of the client that just sent the 'Join' Instruction.
ipAddress string The ip address of the client that requested to join.
instruction Instruction The Instruction that the client sent.
return void

Server() public method

Entry point. It creates a new thread that will be checking for timeouts. Listens on the main thread, for any instructions from the client.
public Server ( ) : System
return System

Property Details

CLIENT_TIMEOUT public_oe static_oe property

The amount of seconds that the server waits before kicking the client out.
public static int CLIENT_TIMEOUT
return int

DEBUG public_oe static_oe property

Set this to false for Release builds so we aren't wasting cycles by printing to the console.
public static bool DEBUG
return bool

RUNNING public_oe static_oe property

If this is set to false, the server will stop listening and exit.
public static bool RUNNING
return bool

_matches public_oe property

A list of the matches that are currently in session.
public ConcurrentDictionary _matches
return Match>.ConcurrentDictionary

_users public_oe property

A list of the users that are currently connected to the server with IP addresses of the users being the key.
public ConcurrentDictionary _users
return User>.ConcurrentDictionary