Class MultiplayerConnection

Class Documentation

class MultiplayerConnection

Handling of all multiplayer connection functionality, such as connect, disconnect, entity replication and network events.

Public Types

typedef std::function<void(ErrorCode)> ErrorCodeCallbackHandler
typedef std::function<void(const csp::common::String&)> DisconnectionCallbackHandler
typedef std::function<void(const csp::common::String&)> ConnectionCallbackHandler
typedef std::function<void(const csp::common::String&)> NetworkInterruptionCallbackHandler

Public Functions

void SetDisconnectionCallback(DisconnectionCallbackHandler Callback)

Sets a callback for a disconnection event.

Parameters

CallbackDisconnectionCallbackHandler : The callback for disconnection, contains a string with a reason for disconnection.

void SetConnectionCallback(ConnectionCallbackHandler Callback)

Sets a callback for a connection event.

Parameters

CallbackConnectionCallbackHandler : The callback for connection, contains a string with a status of connection (Success, Failure etc).

void SetNetworkInterruptionCallback(NetworkInterruptionCallbackHandler Callback)

Sets a callback for a network interruption event.

Connection isn’t recoverable after this point and Disconnect should be called.

Parameters

CallbackNetworkInterruptionCallbackHandler : The callback for network interruption, contains a string showing failure.

uint64_t GetClientId() const

Requests the ClientID.

Returns

uint64_t the ClientID for this connection.

ConnectionState GetConnectionState() const

Gets the current connection state.

Returns

A ConnectionState enum value.

void SetAllowSelfMessagingFlag(const bool AllowSelfMessaging, ErrorCodeCallbackHandler Callback)

Sets the Self Messaging flag for this client.

This allows a client to declare that it wishes to receive every patch and object message it sends.

Warning

Don’t use this function if you aren’t sure of the consequences, it’s very unlikely that a client would want to use this!

Parameters
  • AllowSelfMessaging – bool : True to allow and false to disallow.

  • CallbackErrorCodeCallbackHandler : a callback with failure state.

bool GetAllowSelfMessagingFlag() const

Gets the bool representing if we’re using self-messaging or not.

Returns

True if self messaging is allowed, false otherwise.

void Connect(ErrorCodeCallbackHandler Callback, ISignalRConnection *SignalRConnection)

Start the connection and register to start receiving updates from the server.

Connect should be called after LogIn and before EnterSpace.

Parameters
  • CallbackErrorCodeCallbackHandler : a callback with failure state.

  • ISignalRConnection* – SignalRConnection : The SignalR connection to use when talking to the server. The MultiplayerConnection takes ownership of this pointer.

inline bool IsConnected() const

Indicates whether the multiplayer connection is established.

Returns

bool : true if connected, false otherwise

inline csp::multiplayer::ISignalRConnection *GetSignalRConnection()

Getter for the signalR connection.

Returns

ISignalRConnection* : pointer to the signalR connection

inline csp::multiplayer::NetworkEventManagerImpl *GetNetworkEventManager()

Getter for the NetworkEventManager.

Returns

NetworkEventManagerImpl* : pointer to the NetworkEventManager

inline EventBus *GetEventBusPtr()

Getter for the EventBus.

Returns

EventBus* : pointer to the EventBus

void DisconnectWithReason(const csp::common::String &Reason, ErrorCodeCallbackHandler Callback)

Disconnect the multiplayer and provide a reason.

Parameters
std::function<async::task<void>()> StartListening()
void SetScopes(csp::common::String InSpaceId, ErrorCodeCallbackHandler Callback)

Subscribes the connected user to the specified space’s scope.

Parameters

CallbackErrorCodeCallbackHandler : a callback with failure state.

void StopListening(ErrorCodeCallbackHandler Callback)

Stop listening to the multiplayer.

Parameters

CallbackErrorCodeCallbackHandler : a callback with failure state.

void ResetScopes(ErrorCodeCallbackHandler Callback)

Clears the connected user’s subscription to their current set of scopes.

Parameters

CallbackErrorCodeCallbackHandler : a callback with failure state.

MultiplayerConnection()

MultiplayerConnection constructor.

~MultiplayerConnection()

MultiplayerConnection destructor.

void Disconnect(ErrorCodeCallbackHandler Callback)

End the multiplayer connection.

Parameters

CallbackErrorCodeCallbackHandler : a callback with failure state.

Public Static Functions

static std::pair<ErrorCode, std::string> ParseMultiplayerErrorFromExceptionPtr(std::exception_ptr Exception)

Parse a SignalR multiplayer error.

Unpacks the exception and forwards to ParseMultiplayerError

Parameters

std::exception_ptr – Exception : Pointer to the exception to parse.

Returns

std::pair<ErrorCode, std::string> First element being the deduced error code, second being the exception message.

static std::pair<ErrorCode, std::string> ParseMultiplayerError(const std::exception &Exception)

Parse a SignalR multiplayer error.

Parameters

const – std::exception& Exception : The exception to parse

Returns

std::pair<ErrorCode, std::string> First element being the deduced error code, second being the exception message.

static ISignalRConnection *MakeSignalRConnection()

Create a default SignalRConnection configured to the configured MultiplayerServiceURI.

Returns

ISignalRConnection* Pointer to SignalR connection. The caller should take ownership of the pointer.