Show / Hide Table of Contents

Class NetworkController

A Network Controller with extra functionality for the server.

Inheritance
System.Object
NetworkController
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: DuneNet.Server.Controllers
Assembly: DuneNet.Server.dll
Syntax
public sealed class NetworkController

Methods

AllowLocalReadiness(DuneConnection)

Allows the provided connection to control its own readiness.

Declaration
public void AllowLocalReadiness(DuneConnection conn)
Parameters
Type Name Description
DuneConnection conn

The connection to allow local readiness control on.

Remarks

This is useful to allow clients to set theirselves ready and unready, for example, to indicate the loading state of a scene change.

Disconnect()

Stops listening.

Declaration
public bool Disconnect()
Returns
Type Description
System.Boolean

True if the Network Controller was able to stop listening, False otherwise (for example, if the server was not listening).

Dispose()

Disposes the Network Controller and frees any resources internally used by it.

Declaration
public void Dispose()
Remarks

There should be no need to manually call this in most cases as it is already automatically called on application quit.

ForceServerReadiness(DuneConnection)

Prevents the provided connection from controlling its own readiness.

Declaration
public void ForceServerReadiness(DuneConnection conn)
Parameters
Type Name Description
DuneConnection conn

The connection to force readiness on.

Remarks

This is useful for preventing clients from setting theirselves ready and unready when they are not supposed to.

ForEachConnection(Action<DuneConnection>)

Performs the provided action for each valid connection.

Declaration
public void ForEachConnection(Action<DuneConnection> action)
Parameters
Type Name Description
System.Action<DuneConnection> action

The action to perform for each connection.

Remarks

This method skips the default server connection, which is always equal to null.

GetConnectionAmount()

Declaration
public int GetConnectionAmount()
Returns
Type Description
System.Int32

GetConnectionFromId(Int32)

Returns a connection identified by the provided ID.

Declaration
public DuneConnection GetConnectionFromId(int connectionId)
Parameters
Type Name Description
System.Int32 connectionId

The ID of the connection to retrieve

Returns
Type Description
DuneConnection

A DuneConnection instance representing the requested connection.

GetListenPort()

Returns the port the Network Controller is currently listening on.

Declaration
public int GetListenPort()
Returns
Type Description
System.Int32

The port the server is listening on if the server is listening, -1 otherwise

Init(GlobalConfig, ConnectionConfig, Int32, Single)

Initializes the Network Controller.

Declaration
public void Init(GlobalConfig globalConfig, ConnectionConfig connectionConfig, int maxConnections = 1, float maxDelay = 0.1F)
Parameters
Type Name Description
GlobalConfig globalConfig

The global configuration to use for the Network Controller.

ConnectionConfig connectionConfig

The connection configuration to use for the Network Controller.

System.Int32 maxConnections

The maximum amount of connections the Network Controller will handle at the same time. One connection is required per client so this normally equals the maximum amount of clients the Network Controller will be able to handle at the same time. This value should be higher than the amount of expected clients and the maximum amount of clients manually restricted with a DuneModule or by listening for the OnServerConnect event.

System.Single maxDelay

The maximum delay before sending packets on connections. Setting this to zero will send messages as soon as they are ready instead of aggregating them.

Remarks

Must be called before using any of the Network Controller's functionality.

IsListening()

Returns whether the Network Controller is currently listening.

Declaration
public bool IsListening()
Returns
Type Description
System.Boolean

True if the Network Controller is listening, False otherwise.

IsReady(DuneConnection)

Returns whether the provided connection is ready.

Declaration
public bool IsReady(DuneConnection conn)
Parameters
Type Name Description
DuneConnection conn
Returns
Type Description
System.Boolean

True if the provided connection is ready, False otherwise.

KickConnection(NetworkConnection)

Kicks a connection.

Declaration
public void KickConnection(NetworkConnection conn)
Parameters
Type Name Description
NetworkConnection conn

The connection to kick.

Remarks

This forcefuly disconnects the provided connection after one second. This delay allows for graceful disconnection messages to be sent before the connetion is closed.

Listen(String, Int32)

Listens for connections on the supplied endpoint.

Declaration
public bool Listen(string ip, int port)
Parameters
Type Name Description
System.String ip

The IP Network Controller should listen on.

System.Int32 port

The port the Network Controller should listen on.

Returns
Type Description
System.Boolean

True if the Network Controller was able to start listening at the provided endpoint, False otherwise (for example, if the IP is not valid or the endpoint is already in use by another process).

Remarks

After listening, the network interactions can be hooked into by using a DuneModule or by listening for the following events:

RegisterHandler(Int16, NetworkMessageDelegate)

Registers a network message handler.

Declaration
public void RegisterHandler(short msgType, NetworkMessageDelegate handler)
Parameters
Type Name Description
System.Int16 msgType

The type of the message to register. This must be unique for each message type.

NetworkMessageDelegate handler

The handler that the Network Controller will invoke when a message of this type is received.

SendByChannelToReady(Int16, MessageBase, Int16)

Sends a message to all ready clients using the provided channel.

Declaration
public void SendByChannelToReady(short msgType, MessageBase msg, short channel)
Parameters
Type Name Description
System.Int16 msgType

The type of the message to send.

MessageBase msg

The message to send.

System.Int16 channel

The channel to send the message through.

Remarks

The channel must have been previously been manually registered or be one of the default channels from MessageChannels.

SendByChannelToReadyWithAuthority(Int16, NetworkConnection, SharedAuthorityMessage, Int16)

Sends a message to all ready clients using the provided channel. Additionally, it sets the authority of the message to the provided connection before sending it.

Declaration
public void SendByChannelToReadyWithAuthority(short msgType, NetworkConnection authoritativeConnection, SharedAuthorityMessage msg, short channel)
Parameters
Type Name Description
System.Int16 msgType

The type of the message to send.

NetworkConnection authoritativeConnection

The connection that will have authority over the message.

SharedAuthorityMessage msg

The message to send.

System.Int16 channel

The channel to send the message through.

Remarks

The channel must have been previously been manually registered or be one of the default channels from MessageChannels. This method is specially useful for custom messages that deal with authority entities.

SetNotReady(DuneConnection)

Sets the provided connection not ready.

Declaration
public void SetNotReady(DuneConnection conn)
Parameters
Type Name Description
DuneConnection conn

The connection to set not ready.

Remarks

This instructs the receiving clientside Network Controller that it should not be able to receive scene information (useful for changing scenes). This method has no effect until the client has been authenticated.

SetReady(DuneConnection)

Sets the provided connection ready.

Declaration
public void SetReady(DuneConnection conn)
Parameters
Type Name Description
DuneConnection conn

The connection to set ready.

Remarks

This instructs the receiving clientside Network Controller that it should be able to receive scene information. This method has no effect until the client has been authenticated.

Shutdown()

Shuts down the Network Controller. Init must be called again to perform further operations with the Network Controller after calling this.

Declaration
public void Shutdown()
Remarks

There should be no need to manually call this in most cases as it is already automatically called on application quit.

Back to top Copyright © 2018 Dune Interactive.