ForgeDocs
Documentation for the forge framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
Forge.Networking.Core.NetworkContext Class Reference

Holds important information about the current network connection and additionally about INetworkMessage listeners. More...

Public Member Functions

IEnumerable< IPAddress > GetServerIPs ()
 Tries to fetch all possible IPs that might be possible for clients to connect to the server with. This operation throws an exception if the context is not a server. More...
 
bool IsPlayerServer (Player player)
 Returns true if the given Player is the server. More...
 
void Kick (Player player)
 Kicks the given player. This function is only operable if the context is a server (otherwise an exception is thrown). More...
 
void AddMessageHandler (INetworkMessageHandler handler)
 Adds the given message handler to the network context. More...
 
void RemoveMessageHandler (INetworkMessageHandler handler)
 Removes the given message handler from the context. If the dispatcher was not previously contained in the context, then an exception is thrown. More...
 
void AddConnectionMonitor (INetworkConnectionMonitor monitor)
 Add a new connection monitor listener. This allows for client code to be notified when another player connects or disconnects from the network. More...
 
void RemoveConnectionMonitor (INetworkConnectionMonitor monitor)
 Remove a previously added connection monitor. If the monitor was not found when removing it, an exception is thrown. More...
 
void Update ()
 Update the network context; ie, invoke handlers for received network messages if we're a client or broadcast out received messages if we're a server. More...
 
void SendMessage (NetworkMessageRecipient recipient, INetworkMessage message)
 Send the given message to the given recipients. More...
 
void SendMessage (Player recipient, INetworkMessage message)
 Send the given message to only the specified recipient. More...
 

Static Public Member Functions

static NetworkContext CreateServer (Player player, string password)
 Creates a new server. More...
 
static Maybe< NetworkContextCreateClient (string ip, Player player, string password)
 Creates a new client connection connected to the given IP end point. This method blocks until we know if the client has either connected or disconnected. More...
 

Properties

bool IsServer [get]
 Returns true if this NetworkConext is acting as a server. More...
 
bool IsClient [get]
 Returns true if this NetworkContext is acting as a client. More...
 
Player LocalPlayer [get, set]
 The local player. More...
 

Detailed Description

Holds important information about the current network connection and additionally about INetworkMessage listeners.

Member Function Documentation

void Forge.Networking.Core.NetworkContext.AddConnectionMonitor ( INetworkConnectionMonitor  monitor)

Add a new connection monitor listener. This allows for client code to be notified when another player connects or disconnects from the network.

Parameters
monitorThe connection monitor to add.
void Forge.Networking.Core.NetworkContext.AddMessageHandler ( INetworkMessageHandler  handler)

Adds the given message handler to the network context.

Parameters
handlerThe network message handler to add.
static Maybe<NetworkContext> Forge.Networking.Core.NetworkContext.CreateClient ( string  ip,
Player  player,
string  password 
)
static

Creates a new client connection connected to the given IP end point. This method blocks until we know if the client has either connected or disconnected.

Parameters
ipThe IP to connect to.
playerThis computer's player.
passwordThe password that the server is expecting.
Returns
static NetworkContext Forge.Networking.Core.NetworkContext.CreateServer ( Player  player,
string  password 
)
static

Creates a new server.

Parameters
playerThe player that is running this server.
passwordThe password that clients have to have to connect.
Returns
A network context for the created server.
IEnumerable<IPAddress> Forge.Networking.Core.NetworkContext.GetServerIPs ( )

Tries to fetch all possible IPs that might be possible for clients to connect to the server with. This operation throws an exception if the context is not a server.

bool Forge.Networking.Core.NetworkContext.IsPlayerServer ( Player  player)

Returns true if the given Player is the server.

Parameters
playerThe player to check.
Returns
True if the player is the server, otherwise false.
void Forge.Networking.Core.NetworkContext.Kick ( Player  player)

Kicks the given player. This function is only operable if the context is a server (otherwise an exception is thrown).

Parameters
playerThe player to kick.
void Forge.Networking.Core.NetworkContext.RemoveConnectionMonitor ( INetworkConnectionMonitor  monitor)

Remove a previously added connection monitor. If the monitor was not found when removing it, an exception is thrown.

Parameters
monitorThe connection monitor to remove.
void Forge.Networking.Core.NetworkContext.RemoveMessageHandler ( INetworkMessageHandler  handler)

Removes the given message handler from the context. If the dispatcher was not previously contained in the context, then an exception is thrown.

Parameters
handlerThe network message handler to remove.
void Forge.Networking.Core.NetworkContext.SendMessage ( NetworkMessageRecipient  recipient,
INetworkMessage  message 
)

Send the given message to the given recipients.

Parameters
recipientThe computers that should receive the message.
messageThe message to send.
void Forge.Networking.Core.NetworkContext.SendMessage ( Player  recipient,
INetworkMessage  message 
)

Send the given message to only the specified recipient.

Parameters
recipientThe player that should receive the message.
messageWho to send the message to.
void Forge.Networking.Core.NetworkContext.Update ( )

Update the network context; ie, invoke handlers for received network messages if we're a client or broadcast out received messages if we're a server.

Property Documentation

bool Forge.Networking.Core.NetworkContext.IsClient
get

Returns true if this NetworkContext is acting as a client.

bool Forge.Networking.Core.NetworkContext.IsServer
get

Returns true if this NetworkConext is acting as a server.

Player Forge.Networking.Core.NetworkContext.LocalPlayer
getset

The local player.


The documentation for this class was generated from the following file: