Class NetworkEventBus
Defined in File NetworkEventBus.h
Class Documentation
-
class NetworkEventBus
Handles registration of interest, and dispatch of callbacks to interested parties, of events sent over the network to connected clients.
This object may be used to send arbitrary messages between clients, broadcasting messages to either all clients, or particular clients specified by a clientID. Particular messages are generic and may be defined as any arbitrary string, and may carry payloads of csp::common::ReplicatedValue.
Public Types
Public Functions
-
void SendNetworkEvent(const csp::common::String &EventName, const csp::common::Array<csp::common::ReplicatedValue> &Args, ErrorCodeCallbackHandler Callback)
Sends a network event by EventName to all currently connected clients.
- Parameters
EventName – csp::common::String : The identifying name for the event.
Args – csp::common::Array<csp::common::ReplicatedValue> : An array of arguments (csp::common::ReplicatedValue) to be passed as part of the event payload.
Callback – ErrorCodeCallbackHandler : a callback with failure state.
-
async::task<std::optional<csp::multiplayer::ErrorCode>> SendNetworkEvent(const csp::common::String &EventName, const csp::common::Array<csp::common::ReplicatedValue> &Args)
-
void SendNetworkEventToClient(const csp::common::String &EventName, const csp::common::Array<csp::common::ReplicatedValue> &Args, uint64_t TargetClientId, ErrorCodeCallbackHandler Callback)
Sends a network event by EventName, to TargetClientId.
- Parameters
EventName – csp::common::String : The identifying name for the event.
Args – csp::common::Array<csp::common::ReplicatedValue> : An array of arguments (csp::common::ReplicatedValue) to be passed as part of the event payload.
TargetClientId – uint64_t : The client ID to send the event to.
Callback – ErrorCodeCallbackHandler : a callback with failure state.
-
void ListenNetworkEvent(NetworkEventRegistration Registration, NetworkEventCallback Callback)
Register interest in a network event, such that the NetworkEventBus will call the provided callback when it arrives.
- Parameters
Registration – NetworkEventRegistration : Registration information, containing a ReceiverID and an EventName. Will fail to register if identical callback registration already registered.
Callback – NetworkEventCallback : Callback to invoke when specified event is received. Will fail to register if null.
-
void StopListenNetworkEvent(NetworkEventRegistration Registration)
Deregister interest in a network event.
- Parameters
Registration – NetworkEventRegistration : Registration information of already registered event, containing a ReceiverID and an EventName.
-
void StopListenAllNetworkEvents(const csp::common::String &EventReceiverId)
Deregister interest in all network events registered to a particular EventReceiverId.
- Parameters
EventReceiverId – const csp::common::String& : EventReceiverId to deregister.
-
csp::common::Array<NetworkEventRegistration> AllRegistrations() const
Get an array of all interests currently registered to the NetworkEventBus.
- Returns
csp::common::Array<csp::multiplayer::NetworkEventRegistration> A container of all currently registered registrations.
-
bool StartEventMessageListening()
Instructs the event bus to start listening to messages.
- Returns
True is successfully started listening, false if the connection is unavailable for some reason.
-
NetworkEventBus(MultiplayerConnection *InMultiplayerConnection, csp::common::LogSystem &LogSystem)
NetworkEventBus constructor.
- Parameters
InMultiplayerConnection – MultiplayerConnection* : the multiplayer connection to construct the event bus with
-
~NetworkEventBus()
NetworkEventBus destructor.
Public Static Functions
-
static NetworkEvent NetworkEventFromString(const csp::common::String &EventString)
-
static csp::common::String StringFromNetworkEvent(NetworkEvent Event)
-
void SendNetworkEvent(const csp::common::String &EventName, const csp::common::Array<csp::common::ReplicatedValue> &Args, ErrorCodeCallbackHandler Callback)