Open 3D Engine Multiplayer Gem API Reference  24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Multiplayer::MultiplayerSystemComponent Class Referencefinal

Multiplayer system component wraps the bridging logic between the game and transport layer. More...

#include <MultiplayerSystemComponent.h>

Inherits AZ::Component, AZ::TickBus::Handler, SessionNotificationBus::Handler, Multiplayer::ISessionHandlingClientRequests, AzNetworking::IConnectionListener, Multiplayer::IMultiplayer, AzFramework::RootSpawnableNotificationBus::Handler, and AzFramework::LevelLoadBlockerBus::Handler.

Public Member Functions

 AZ_COMPONENT (MultiplayerSystemComponent, "{7C99C4C1-1103-43F9-AD62-8B91CF7C1981}")
 
bool IsHandshakeComplete (AzNetworking::IConnection *connection) const
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::Connect &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::Accept &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::ReadyForEntityUpdates &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::SyncConsole &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::ConsoleCommand &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::EntityUpdates &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::EntityRpcs &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::RequestReplicatorReset &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::ClientMigration &packet)
 
bool HandleRequest (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, MultiplayerPackets::VersionMismatch &packet)
 
void Activate () override
 
void Deactivate () override
 
bool OnSessionHealthCheck () override
 
bool OnCreateSessionBegin (const SessionConfig &sessionConfig) override
 
void OnCreateSessionEnd () override
 
bool OnDestroySessionBegin () override
 
void OnDestroySessionEnd () override
 
void OnUpdateSessionBegin (const SessionConfig &sessionConfig, const AZStd::string &updateReason) override
 
void OnUpdateSessionEnd () override
 
void OnTick (float deltaTime, AZ::ScriptTimePoint time) override
 
int GetTickOrder () override
 
AzNetworking::ConnectResult ValidateConnect (const AzNetworking::IpAddress &remoteAddress, const AzNetworking::IPacketHeader &packetHeader, AzNetworking::ISerializer &serializer) override
 
void OnConnect (AzNetworking::IConnection *connection) override
 
AzNetworking::PacketDispatchResult OnPacketReceived (AzNetworking::IConnection *connection, const AzNetworking::IPacketHeader &packetHeader, AzNetworking::ISerializer &serializer) override
 
void OnPacketLost (AzNetworking::IConnection *connection, AzNetworking::PacketId packetId) override
 
void OnDisconnect (AzNetworking::IConnection *connection, AzNetworking::DisconnectReason reason, AzNetworking::TerminationEndpoint endpoint) override
 
bool RequestPlayerJoinSession (const SessionConnectionConfig &sessionConnectionConfig) override
 
void RequestPlayerLeaveSession () override
 Request the connected player leave session.
 
MultiplayerAgentType GetAgentType () const override
 
void InitializeMultiplayer (MultiplayerAgentType state) override
 
bool StartHosting (uint16_t port=UseDefaultHostPort, bool isDedicated=true) override
 
bool Connect (const AZStd::string &remoteAddress, uint16_t port) override
 
void Terminate (AzNetworking::DisconnectReason reason) override
 
void AddClientMigrationStartEventHandler (ClientMigrationStartEvent::Handler &handler) override
 
void AddClientMigrationEndEventHandler (ClientMigrationEndEvent::Handler &handler) override
 
void AddEndpointDisconnectedHandler (EndpointDisconnectedEvent::Handler &handler) override
 
void AddNotifyClientMigrationHandler (NotifyClientMigrationEvent::Handler &handler) override
 
void AddNotifyEntityMigrationEventHandler (NotifyEntityMigrationEvent::Handler &handler) override
 
void AddConnectionAcquiredHandler (ConnectionAcquiredEvent::Handler &handler) override
 
void AddNetworkInitHandler (NetworkInitEvent::Handler &handler) override
 
void AddSessionInitHandler (SessionInitEvent::Handler &) override
 
void AddSessionShutdownHandler (SessionShutdownEvent::Handler &) override
 
void AddLevelLoadBlockedHandler (LevelLoadBlockedEvent::Handler &handler) override
 
void AddNoServerLevelLoadedHandler (NoServerLevelLoadedEvent::Handler &handler) override
 
void AddVersionMismatchHandler (VersionMismatchEvent::Handler &handler) override
 
void AddServerAcceptanceReceivedHandler (ServerAcceptanceReceivedEvent::Handler &handler) override
 
void SendNotifyClientMigrationEvent (AzNetworking::ConnectionId connectionId, const HostId &hostId, uint64_t userIdentifier, ClientInputId lastClientInputId, NetEntityId controlledEntityId) override
 
void SendNotifyEntityMigrationEvent (const ConstNetworkEntityHandle &entityHandle, const HostId &remoteHostId) override
 
void SendReadyForEntityUpdates (bool readyForEntityUpdates) override
 
AZ::TimeMs GetCurrentHostTimeMs () const override
 
float GetCurrentBlendFactor () const override
 
INetworkTimeGetNetworkTime () override
 
INetworkEntityManagerGetNetworkEntityManager () override
 
void RegisterPlayerIdentifierForRejoin (uint64_t temporaryUserIdentifier, NetEntityId controlledEntityId) override
 
void CompleteClientMigration (uint64_t temporaryUserIdentifier, AzNetworking::ConnectionId connectionId, const HostId &publicHostId, ClientInputId migratedClientInputId) override
 
void SetShouldSpawnNetworkEntities (bool value) override
 
bool GetShouldSpawnNetworkEntities () const override
 
void DumpStats (const AZ::ConsoleCommandContainer &arguments)
 
void OnRootSpawnableReady (AZ::Data::Asset< AzFramework::Spawnable > rootSpawnable, uint32_t generation) override
 
bool ShouldBlockLevelLoading (const char *levelName) override
 
- Public Member Functions inherited from Multiplayer::ISessionHandlingClientRequests
 AZ_RTTI (ISessionHandlingClientRequests, "{41DE6BD3-72BC-4443-BFF9-5B1B9396657A}")
 
- Public Member Functions inherited from Multiplayer::IMultiplayer
 AZ_RTTI (IMultiplayer, "{90A001DD-AD31-46C7-9FBE-1059AFB7F5E9}")
 
MultiplayerStatsGetStats ()
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 
static void GetRequiredServices (AZ::ComponentDescriptor::DependencyArrayType &required)
 
static void GetProvidedServices (AZ::ComponentDescriptor::DependencyArrayType &provided)
 
static void GetIncompatibleServices (AZ::ComponentDescriptor::DependencyArrayType &incompatible)
 

Additional Inherited Members

- Static Public Attributes inherited from Multiplayer::IMultiplayer
static const uint16_t UseDefaultHostPort = 0
 

Detailed Description

Multiplayer system component wraps the bridging logic between the game and transport layer.

Member Function Documentation

◆ Activate()

void Multiplayer::MultiplayerSystemComponent::Activate ( )
override

AZ::Component overrides.

◆ AddClientMigrationEndEventHandler()

void Multiplayer::MultiplayerSystemComponent::AddClientMigrationEndEventHandler ( ClientMigrationEndEvent::Handler &  handler)
overridevirtual

Adds a ClientMigrationEndEvent Handler which is invoked when a client completes migration.

Parameters
handlerThe ClientMigrationEndEvent Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddClientMigrationStartEventHandler()

void Multiplayer::MultiplayerSystemComponent::AddClientMigrationStartEventHandler ( ClientMigrationStartEvent::Handler &  handler)
overridevirtual

Adds a ClientMigrationStartEvent Handler which is invoked at the start of a client migration.

Parameters
handlerThe ClientMigrationStartEvent Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddConnectionAcquiredHandler()

void Multiplayer::MultiplayerSystemComponent::AddConnectionAcquiredHandler ( ConnectionAcquiredEvent::Handler &  handler)
overridevirtual

Adds a ConnectionAcquiredEvent Handler which is invoked when a new endpoint connects to the session.

Parameters
handlerThe ConnectionAcquiredEvent Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddEndpointDisconnectedHandler()

void Multiplayer::MultiplayerSystemComponent::AddEndpointDisconnectedHandler ( EndpointDisconnectedEvent::Handler &  handler)
overridevirtual

Adds a EndpointDisconnectedEvent Handler which is invoked on the client when a disconnection occurs.

Parameters
handlerThe EndpointDisconnectedEvent Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddLevelLoadBlockedHandler()

void Multiplayer::MultiplayerSystemComponent::AddLevelLoadBlockedHandler ( LevelLoadBlockedEvent::Handler &  handler)
overridevirtual

Adds a LevelLoadBlockedEvent Handler which is invoked whenever the multiplayer system blocks a level load.

Parameters
handlerThe LevelLoadBlockedEvent handler to add

Implements Multiplayer::IMultiplayer.

◆ AddNetworkInitHandler()

void Multiplayer::MultiplayerSystemComponent::AddNetworkInitHandler ( NetworkInitEvent::Handler &  handler)
overridevirtual

Adds a NetworkInitEvent Handler which is invoked when the network is initialized on the dedicated server or client-server.

Parameters
handlerThe NetworkInitEvent Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddNoServerLevelLoadedHandler()

void Multiplayer::MultiplayerSystemComponent::AddNoServerLevelLoadedHandler ( NoServerLevelLoadedEvent::Handler &  handler)
overridevirtual

Adds a NoServerLevelLoadedEvent Handler which is invoked whenever a client connects to a server that doesn't have any level loaded.

Parameters
handlerThe NoServerLevelLoadedEvent handler to add

Implements Multiplayer::IMultiplayer.

◆ AddNotifyClientMigrationHandler()

void Multiplayer::MultiplayerSystemComponent::AddNotifyClientMigrationHandler ( NotifyClientMigrationEvent::Handler &  handler)
overridevirtual

Adds a NotifyClientMigrationEvent Handler which is invoked when a client migrates from one host to another.

Parameters
handlerThe NotifyClientMigrationEvent Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddNotifyEntityMigrationEventHandler()

void Multiplayer::MultiplayerSystemComponent::AddNotifyEntityMigrationEventHandler ( NotifyEntityMigrationEvent::Handler &  handler)
overridevirtual

Adds a NotifyEntityMigrationEvent Handler which is invoked when an entity migrates from one host to another.

Parameters
handlerThe NotifyEntityMigrationEvent Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddServerAcceptanceReceivedHandler()

void Multiplayer::MultiplayerSystemComponent::AddServerAcceptanceReceivedHandler ( ServerAcceptanceReceivedEvent::Handler &  handler)
overridevirtual

Adds a ServerAcceptanceReceived Handler which is invoked when the client receives the accept packet from the server.

Parameters
handlerThe ServerAcceptanceReceived Handler to add

Implements Multiplayer::IMultiplayer.

◆ AddSessionInitHandler()

void Multiplayer::MultiplayerSystemComponent::AddSessionInitHandler ( SessionInitEvent::Handler &  )
inlineoverridevirtual
Deprecated:
If looking for an event when a multiplayer session is created, use SessionNotificationBus::OnCreateSessionBegin or SessionNotificationBus::OnCreateSessionEnd.

Implements Multiplayer::IMultiplayer.

◆ AddSessionShutdownHandler()

void Multiplayer::MultiplayerSystemComponent::AddSessionShutdownHandler ( SessionShutdownEvent::Handler &  )
inlineoverridevirtual
Deprecated:
If looking for an event when the multiplayer session ends, use SessionNotificationBus::OnDestroySessionBegin or SessionNotificationBus::OnDestroySessionEnd.

Implements Multiplayer::IMultiplayer.

◆ AddVersionMismatchHandler()

void Multiplayer::MultiplayerSystemComponent::AddVersionMismatchHandler ( VersionMismatchEvent::Handler &  handler)
overridevirtual

Adds a VersionMismatchEvent Handler which is invoked whenever two multiplayer endpoints have a version mismatch. For example, the provided handler will be triggered if a client tries connecting to a server that's using a different multiplayer version.

Parameters
handlerThe VersionMismatchEvent handler to add

Implements Multiplayer::IMultiplayer.

◆ CompleteClientMigration()

void Multiplayer::MultiplayerSystemComponent::CompleteClientMigration ( uint64_t  temporaryUserIdentifier,
AzNetworking::ConnectionId  connectionId,
const HostId &  publicHostId,
ClientInputId  migratedClientInputId 
)
overridevirtual

Completes a client migration event by informing the appropriate client to migrate between hosts.

Parameters
temporaryUserIdentifierthe temporary user identifier used to identify a player across hosts
connectionIdthe connection id of the player being migrated
publicHostIdthe public address of the new host the client should connect to
migratedClientInputIdthe last clientInputId processed prior to migration

Implements Multiplayer::IMultiplayer.

◆ Connect()

bool Multiplayer::MultiplayerSystemComponent::Connect ( const AZStd::string &  remoteAddress,
uint16_t  port 
)
overridevirtual

Connects to the specified IP as a Client.

Parameters
remoteAddressThe domain or IP to connect to
portThe port to connect to
Returns
if a connection was successfully created

Implements Multiplayer::IMultiplayer.

◆ DumpStats()

void Multiplayer::MultiplayerSystemComponent::DumpStats ( const AZ::ConsoleCommandContainer &  arguments)

Console commands.

◆ GetAgentType()

MultiplayerAgentType Multiplayer::MultiplayerSystemComponent::GetAgentType ( ) const
overridevirtual

IMultiplayer interface

Implements Multiplayer::IMultiplayer.

◆ GetCurrentBlendFactor()

float Multiplayer::MultiplayerSystemComponent::GetCurrentBlendFactor ( ) const
overridevirtual

Returns the current blend factor for client side interpolation. This value is only relevant on the client and is used to smooth between host frames

Returns
the current blend factor

Implements Multiplayer::IMultiplayer.

◆ GetCurrentHostTimeMs()

AZ::TimeMs Multiplayer::MultiplayerSystemComponent::GetCurrentHostTimeMs ( ) const
overridevirtual

Returns the current server time in milliseconds. This can be one of three possible values:

  1. On the host outside of rewind scope, this will return the latest application elapsed time in ms.
  2. On the host within rewind scope, this will return the rewound time in ms.
  3. On the client, this will return the most recently replicated server time in ms.
    Returns
    the current server time in milliseconds

Implements Multiplayer::IMultiplayer.

◆ GetNetworkEntityManager()

INetworkEntityManager* Multiplayer::MultiplayerSystemComponent::GetNetworkEntityManager ( )
overridevirtual

Returns the network entity manager instance bound to this multiplayer instance.

Returns
pointer to the network entity manager instance bound to this multiplayer instance

Implements Multiplayer::IMultiplayer.

◆ GetNetworkTime()

INetworkTime* Multiplayer::MultiplayerSystemComponent::GetNetworkTime ( )
overridevirtual

Returns the network time instance bound to this multiplayer instance.

Returns
pointer to the network time instance bound to this multiplayer instance

Implements Multiplayer::IMultiplayer.

◆ GetShouldSpawnNetworkEntities()

bool Multiplayer::MultiplayerSystemComponent::GetShouldSpawnNetworkEntities ( ) const
overridevirtual

Retrieves the current network entity instantiation behaviour.

Returns
boolean true if netbound entities should be auto instantiated, false if not

Implements Multiplayer::IMultiplayer.

◆ InitializeMultiplayer()

void Multiplayer::MultiplayerSystemComponent::InitializeMultiplayer ( MultiplayerAgentType  state)
overridevirtual

Sets the type of this Multiplayer connection and calls any related callback.

Parameters
stateThe state of this connection

Implements Multiplayer::IMultiplayer.

◆ OnRootSpawnableReady()

void Multiplayer::MultiplayerSystemComponent::OnRootSpawnableReady ( AZ::Data::Asset< AzFramework::Spawnable >  rootSpawnable,
uint32_t  generation 
)
override

AzFramework::RootSpawnableNotificationBus::Handler

◆ OnSessionHealthCheck()

bool Multiplayer::MultiplayerSystemComponent::OnSessionHealthCheck ( )
override

SessionNotificationBus::Handler overrides.

◆ OnTick()

void Multiplayer::MultiplayerSystemComponent::OnTick ( float  deltaTime,
AZ::ScriptTimePoint  time 
)
override

AZ::TickBus::Handler overrides.

◆ RegisterPlayerIdentifierForRejoin()

void Multiplayer::MultiplayerSystemComponent::RegisterPlayerIdentifierForRejoin ( uint64_t  temporaryUserIdentifier,
NetEntityId  controlledEntityId 
)
overridevirtual

Registers a temp userId to allow a host to look up a players controlled entity in the event of a rejoin or migration event.

Parameters
temporaryUserIdentifierthe temporary user identifier used to identify a player across hosts
controlledEntityIdthe controlled entityId of the players autonomous entity

Implements Multiplayer::IMultiplayer.

◆ RequestPlayerJoinSession()

bool Multiplayer::MultiplayerSystemComponent::RequestPlayerJoinSession ( const SessionConnectionConfig sessionConnectionConfig)
overridevirtual

◆ SendNotifyClientMigrationEvent()

void Multiplayer::MultiplayerSystemComponent::SendNotifyClientMigrationEvent ( AzNetworking::ConnectionId  connectionId,
const HostId &  hostId,
uint64_t  userIdentifier,
ClientInputId  lastClientInputId,
NetEntityId  controlledEntityId 
)
overridevirtual

Signals a NotifyClientMigrationEvent with the provided parameters.

Parameters
connectionIdthe connection id of the client that is migrating
hostIdthe host id of the host the client is migrating to
userIdentifierthe user identifier the client will provide the new host to validate identity
lastClientInputIdthe last processed clientInputId by the current host
controlledEntityIdthe entityId of the clients autonomous entity

Implements Multiplayer::IMultiplayer.

◆ SendNotifyEntityMigrationEvent()

void Multiplayer::MultiplayerSystemComponent::SendNotifyEntityMigrationEvent ( const ConstNetworkEntityHandle entityHandle,
const HostId &  remoteHostId 
)
overridevirtual

Signals a NotifyEntityMigrationEvent with the provided parameters.

Parameters
entityHandlethe network entity handle of the entity being migrated
remoteHostIdthe host id of the host the entity is migrating to

Implements Multiplayer::IMultiplayer.

◆ SendReadyForEntityUpdates()

void Multiplayer::MultiplayerSystemComponent::SendReadyForEntityUpdates ( bool  readyForEntityUpdates)
overridevirtual

Sends a packet telling if entity update messages can be sent.

Parameters
readyForEntityUpdatesReady for entity updates or not

Implements Multiplayer::IMultiplayer.

◆ SetShouldSpawnNetworkEntities()

void Multiplayer::MultiplayerSystemComponent::SetShouldSpawnNetworkEntities ( bool  value)
overridevirtual

Enables or disables automatic instantiation of netbound entities. This setting is controlled by the networking layer and should not be touched If enabled, netbound entities will instantiate as spawnables are loaded into the game world, generally true for the server If disabled, netbound entities will only stream from a host, always true for a client

Parameters
valueboolean value controlling netbound entity instantiation behaviour

Implements Multiplayer::IMultiplayer.

◆ ShouldBlockLevelLoading()

bool Multiplayer::MultiplayerSystemComponent::ShouldBlockLevelLoading ( const char *  levelName)
override

AzFramework::LevelLoadBlockerBus::Handler overrides.

◆ Terminate()

void Multiplayer::MultiplayerSystemComponent::Terminate ( AzNetworking::DisconnectReason  reason)
overridevirtual
Parameters
reasonThe reason for terminating connections

Implements Multiplayer::IMultiplayer.

◆ ValidateConnect()

AzNetworking::ConnectResult Multiplayer::MultiplayerSystemComponent::ValidateConnect ( const AzNetworking::IpAddress &  remoteAddress,
const AzNetworking::IPacketHeader &  packetHeader,
AzNetworking::ISerializer &  serializer 
)
override

IConnectionListener interface


The documentation for this class was generated from the following file: