Show / Hide Table of Contents

Class NetworkController

A Network Controller with extra functionality for the client.

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.Client.Controllers
Assembly: DuneNet.Client.dll
Syntax
public sealed class NetworkController

Methods

Connect(String, Int32)

Connects to a serverside Network Controller.

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

The IP of the serverside Network Controller to connect to.

System.Int32 port

The port of the serverside Network Controller to connect to.

Returns
Type Description
System.Boolean

True if the Network Controller was able to start the connection process, False otherwise (for example, if the client was already trying to establish a connection or was already connected).

Remarks

This is an asynchronous operation whose results can be hooked into by using a DuneModule or by listening for the following events:

Disconnect()

Disconnects the Network Controller.

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

True if the Network Controller was able to disconnect, False otherwise (for example, if the client was not connected).

Remarks

If no connetion was established when called but the Network Controller was trying to do so, it will stop attempting the connection (this case will not invoke the OnClientDisconnect event).

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.

GetLocalConnection()

Returns the local connection of the Network Controller.

Declaration
public DuneConnection GetLocalConnection()
Returns
Type Description
DuneConnection

A DuneConnection instance representing the connection used by the Network Controller to communicate with a server.

GetRemoteDelayTimeMs(Int32, out Byte)

Calculates the delay of the provided timestamp for the current connection.

Declaration
public int GetRemoteDelayTimeMs(int remoteTime, out byte error)
Parameters
Type Name Description
System.Int32 remoteTime

Timestamp received from the server.

System.Byte error

A byte representing any error during the delay calculation (can be casted to NetworkError for more information). Null if no errors occurred.

Returns
Type Description
System.Int32

The delay between the client and the server.

Remarks

This is useful for time sensitive operations between the client and the server such as movement synchronization and some types of authentication.

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. 1 connection is usually enough for most cases.

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.

IsAuthenticated()

Returns whether the Network Controller has successfully authenticated with a serverside Network Controller.

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

True if the Network Controller is authenticated, False otherwise.

Remarks

It is preferable to use a DuneModule or the events OnClientAuthenticationSuccess and OnClientAuthenticationError to handle authentication rather than using this method.

IsConnected()

Returns whether the Network Controller is currently connected to a serverside Network Controller.

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

True if the Network Controller is connected, False otherwise.

IsConnecting()

Returns whether the Network Controller is currently attempting to establish a connection.

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

True if the Network Controller is attempting a connection, False otherwise.

IsReady()

Returns whether the Network Controller is ready.

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

True if the Network Controller is ready, False otherwise.

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.

SendByChannelToServer(Int16, MessageBase, Int16)

Sends a message to the server using the provided channel.

Declaration
public void SendByChannelToServer(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.

SetNotReady()

Sets the Network Controller not ready.

Declaration
public void SetNotReady()
Remarks

This instructs the receiving serverside Network Controller that this Network Controller is not ready to receive scene information (useful for changing scenes). This method has no effect until the Network Controller has been authenticated with the serverside Network Controller or if the Network Controller is not connected.

SetReady()

Sets the Network Controller ready.

Declaration
public void SetReady()
Remarks

This instructs the receiving serverside Network Controller that this Network Controller is ready to receive scene information. This method has no effect until the Network Controller has been authenticated with the serverside Network Controller or if the Network Controller is not connected.

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.