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.

ConversationSystem *GetConversationSystem() const

Gets a pointer to the conversation system.

Returns

A pointer to the conversation system.

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 recieve 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.

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.