FNetSession
The session surface a co-op game actually calls. Owns the host/join/leave state machine on top of NetworkManager + ReplicationManager, one player record per connection (pawn spawned on join, destroyed on leave), and a gameplay-event channel that rides the existing RPC packet with a default-deny client->server policy.
- Module
- Networking
- Header
#include "Networking/Session/FNetSession.h"- Namespace
Mowo
Ticked from ReplicationManager::Update, which Scene drives in the runtime and simulation system sets. Headless drivers call Tick directly.
Type aliases
| Alias | Description |
|---|---|
using FPawnHostFactoryFn = INetPawnHost* (*)(MWorld* world) | Factory invoked whenever a session gains an actor world (host/join/ world-swap with an MWorld); release is called with the same pointer on leave/swap so allocation and free stay in the installing image. |
using FPawnHostReleaseFn = void (*)(INetPawnHost* host) | |
using FContentIdentityFn = void (*)(std::string& outBuildId, uint64_t& outContentHash) | Build id + mounted-content hash for the join compatibility handshake (DLC lives above this module). Unset provider = empty id + 0, which still round-trips the handshake symmetrically. |
using FWorldAdapterFn = World* (*)(MWorld* world) | MWorld is opaque down here; the same installer provides the one thing the convenience overloads need from it — its ECS world. |
using EventHandler = std::function<void(uint32_t senderPlayerId, FNetEventReader& reader)> | |
using PlayerDelegate = std::function<void(const FNetPlayer&)> | |
using StateDelegate = std::function<void(ENetSessionState, ENetSessionFailure)> | |
using LidarShotDelegate = std::function<void(const FNetLidarShot&)> | |
using RpcFallback = std::function<void(NetworkId, uint16_t, uint16_t, const uint8_t*, size_t, uint32_t)> | |
using TravelDelegate = std::function<void(const std::string& scenePath, uint32_t travelId)> | |
using FActorRpcInvokeFn = void (*)(uint64_t entityId, AActor* actorOrNull, const uint8_t* data, size_t len, bool fromServer, uint32_t senderPeerId) | Game-installed receive dispatch. Plain fn ptr — it crosses a DLL boundary; the session treats AActor* as opaque and hands over both the resolved entity and the attach-registry actor (null when the entity was never registered — the installer may resolve it through its own world). |
using PhaseDelegate = std::function<void(ENetSessionPhase)> | |
using ReturnToMenuDelegate = std::function<void(ENetSessionFailure failure, const std::string& reason)> | Fired once on a client whose session ended for good: the host left (HostEndedSession), the host was lost after the automatic rejoin attempts (HostLost), the player was kicked or banned, or the build differs. The runtime wires it to a travel to the project's start scene; like the travel delegate it is host wiring and survives ClearGameCallbacks. |
Constructors
| Signature | Name | Description |
|---|---|---|
FNetSession(const FNetSession&) = delete | FNetSession |
Public functions
| Returns | Name | Description |
|---|---|---|
FNetSession& | Get | |
void | SetPawnHostFactory | |
void | SetContentIdentityProvider | |
void | SetWorldAdapter | |
bool | HostSession | Listen server. |
bool | HostSession | |
bool | JoinSession | |
bool | JoinSession | |
bool | JoinSteamHost | Steam lobby / invite handoff — the SteamID64 form makes the composite transport pick the Steam P2P backend. |
bool | JoinSteamHost | |
void | EnableInviteHandling | Claim the platform's invite / "Join Game" delegate so accepting one joins THIS session layer instead of opening a bare transport connection. |
void | EnableInviteHandling | |
void | DisableInviteHandling | |
bool | IsInviteHandlingEnabled | |
void | RebindInviteWorld | Point invite joins at the world that is live now. |
void | RebindInviteWorld | |
uint64_t | GetPendingInviteHost | Host id of an invite that arrived with no world to join into. |
uint64_t | ConsumePendingInviteHost | |
uint32_t | GetInviteCount | Invites accepted since the delegate was claimed, for tests and UI. |
void | LeaveSession | |
bool | IsRejoinPending | Reconnect / rejoin A client whose link failed while the host still holds its slot keeps enough to come back as the SAME player: the id the host issued, the address it was talking to, and the token that proves the claim. |
uint64_t | GetRejoinToken | |
bool | RejoinSession | |
bool | RejoinSession | |
float | GetRejoinGraceSeconds | Seconds the HOST holds a dropped player's slot. |
void | SetRejoinGraceSeconds | |
uint32_t | GetPendingRejoinCount | Players whose link is down but whose slot is still held. |
uint32_t | ServerBeginTravel | |
void | PrepareForWorldSwap | |
bool | CompleteWorldSwap | |
bool | CompleteWorldSwap | |
void | ServerCompleteTravel | |
bool | ClientSendTravelAck | |
void | SetOnTravelRequested | |
bool | IsTravelInProgress | |
uint32_t | GetTravelId | |
uint32_t | GetClientPendingTravelId | |
const std::string& | GetClientPendingTravelScene | |
bool | IsSafeTravelScenePath | The scene a host names for travel is peer data, and the client loads it. |
void | Tick | |
ENetSessionState | GetState | |
ENetSessionFailure | GetFailure | |
bool | IsHost | |
bool | IsClient | |
bool | IsInSession | |
const FNetSessionSettings& | GetSettings | |
std::string | GetJoinKey | What a player on another machine needs to join this hosted session directly: "<address>:<port>#<key>". |
ENetSessionRoute | GetRoute | |
const std::vector<FNetPlayer>& | GetPlayers | |
uint32_t | GetPlayerCount | |
const FNetPlayer* | FindPlayerById | |
const FNetPlayer* | FindPlayerByPeer | |
const FNetPlayer* | GetLocalPlayer | |
uint32_t | GetLocalPlayerId | |
bool | IsSessionFull | |
void | SetPlayerPawnClass | Pawn class spawned per connected player. |
MClass* | GetPlayerPawnClass | |
void | SetOnPlayerJoined | |
void | SetOnPlayerLeft | |
void | SetOnStateChanged | |
void | SetOnLidarShot | |
void | SetOnPlayerIntegrity | Fires on the host when a joining or rejoining client reported a non-zero engine integrity status (a modified build). |
void | ClearGameCallbacks | Drops every game-installed per-session slot: event handlers, client event policies, the player/state/lidar delegates, the RPC fallback and the pawn class. |
void | RegisterEventHandler | Gameplay events. |
void | UnregisterEventHandler | |
bool | HasEventHandler | |
void | AllowClientEvent | Client->server events are refused unless allow-listed. |
void | DenyClientEvent | |
bool | SendEventToServer | |
bool | SendEventToAllClients | |
bool | SendEventToPlayer | |
bool | BroadcastEvent | Role-agnostic: on the host runs the handler locally and fans out to every client; on a client asks the server to do that. |
bool | ReportLidarShot | The driving co-op case. |
const FLidarShotAuthority& | GetLidarShotAuthority | |
void | FlushPendingShots | Ship whatever is queued right now instead of waiting out the coalescing window — for a driver with no clock, and for the last shot before a deliberate leave. |
uint32_t | GetPendingShotCount | |
bool | WasShotLocallyEchoed | True when this machine already applied that shot locally, so the server's relay of it must be skipped. |
void | SetLocalPlayerState | Packed animation / gameplay word for the local pawn, replicated on the reliable discrete-state stream. |
bool | GetPlayerState | |
void | SetRpcFallback | Component RPCs (a networkId that is not the session sentinel) land here after the default reflection dispatch has run. |
void | SetActorRpcInvoker | |
ENetActorRpcRoute | RouteActorRpc | Ship one named actor RPC toward where its flags say it runs. |
void | SetScriptActorRpcInvoker | The same shape for script-defined actors: the blob is the script layer's envelope and the installed invoker is the only reader of it. |
ENetActorRpcRoute | RouteScriptActorRpc | |
ReplicationManager* | GetReplication | |
World* | GetECSWorld | |
MWorld* | GetGameWorld | |
uint64_t | GetBytesSentToPlayer | |
uint32_t | ResolvePeerByteBudget | The per-client outgoing budget the session actually applies: the settings' per-peer figure, lowered so maxPlayers - 1 clients together fit hostUplinkBytesPerSecond. |
bool | CheckContentCompatibility | |
ENetSessionFailure | ClassifyClientFailure | What a connecting client's drop or timeout really was: ProtocolMismatch when the replication layer refused the host's packets at the header (version or schema), else fallback. |
const std::string& | GetLastJoinRefusalReason | Also the reason a kick or ban carried, on the ejected client. |
ENetSessionPhase | GetPhase | Host only. |
bool | ServerStartRun | |
bool | ServerReturnToLobby | |
bool | SetLocalReady | |
bool | IsPlayerReady | |
bool | AreAllPlayersReady | |
void | SetOnPhaseChanged | |
void | SetOnReturnToMenu | |
const std::string& | GetLastExitReason | |
uint32_t | GetReturnToMenuCount | |
uint32_t | GetAutoRejoinAttemptsLeft | |
bool | KickPlayer | |
bool | BanPlayer | |
void | BanPlatformId | |
bool | UnbanPlatformId | |
bool | IsPlatformIdBanned | |
const std::vector<uint64_t>& | GetBannedPlatformIds | |
FNetSession& | operator= |
Function details
FNetSession
FNetSession(const FNetSession&) = deleteGet
static FNetSession& Get()SetPawnHostFactory
static void SetPawnHostFactory(FPawnHostFactoryFn factory, FPawnHostReleaseFn release)SetContentIdentityProvider
static void SetContentIdentityProvider(FContentIdentityFn fn)SetWorldAdapter
static void SetWorldAdapter(FWorldAdapterFn fn)HostSession
bool HostSession(MWorld* world, const FNetSessionSettings& settings)Listen server. The hosting player gets playerId 1 / peerId 0 and a pawn of its own, so host and clients run the same code path.
HostSession
bool HostSession(World* ecsWorld, const FNetSessionSettings& settings)JoinSession
bool JoinSession(MWorld* world, const std::string& address, uint16_t port, const FNetSessionSettings& settings)JoinSession
bool JoinSession(World* ecsWorld, const std::string& address, uint16_t port, const FNetSessionSettings& settings)JoinSteamHost
bool JoinSteamHost(MWorld* world, uint64_t hostSteamId, const FNetSessionSettings& settings)Steam lobby / invite handoff — the SteamID64 form makes the composite transport pick the Steam P2P backend.
JoinSteamHost
bool JoinSteamHost(World* ecsWorld, uint64_t hostSteamId, const FNetSessionSettings& settings)EnableInviteHandling
void EnableInviteHandling(MWorld* world, const FNetSessionSettings& settings)Claim the platform's invite / "Join Game" delegate so accepting one joins THIS session layer instead of opening a bare transport connection. The world and settings are the ones the join will use; a null world parks the invite (GetPendingInviteHost) for a menu that has not built its world yet.
EnableInviteHandling
void EnableInviteHandling(World* ecsWorld, const FNetSessionSettings& settings)DisableInviteHandling
void DisableInviteHandling()IsInviteHandlingEnabled
bool IsInviteHandlingEnabled() constRebindInviteWorld
void RebindInviteWorld(MWorld* world)Point invite joins at the world that is live now. The stored world is raw, so map travel — which destroys the world invite handling was claimed with — has to hand over the replacement or a later invite joins into freed memory. No-op while invite handling is not claimed.
RebindInviteWorld
void RebindInviteWorld(World* ecsWorld)GetPendingInviteHost
uint64_t GetPendingInviteHost() constHost id of an invite that arrived with no world to join into. Consuming it clears the slot, so a menu can drive the join on its own terms.
ConsumePendingInviteHost
uint64_t ConsumePendingInviteHost()GetInviteCount
uint32_t GetInviteCount() constInvites accepted since the delegate was claimed, for tests and UI.
LeaveSession
void LeaveSession()IsRejoinPending
bool IsRejoinPending() constReconnect / rejoin A client whose link failed while the host still holds its slot keeps enough to come back as the SAME player: the id the host issued, the address it was talking to, and the token that proves the claim. RejoinSession reconnects to that address and presents the token; the host re-binds the held pawn, its NetworkIds and its ownership, then resyncs the whole world state to it.
GetRejoinToken
uint64_t GetRejoinToken() constRejoinSession
bool RejoinSession(MWorld* world)RejoinSession
bool RejoinSession(World* ecsWorld)GetRejoinGraceSeconds
float GetRejoinGraceSeconds() constSeconds the HOST holds a dropped player's slot. Negative in the settings means "follow net.rejoin_grace_seconds"; the resolved value is here.
SetRejoinGraceSeconds
void SetRejoinGraceSeconds(float seconds)GetPendingRejoinCount
uint32_t GetPendingRejoinCount() constPlayers whose link is down but whose slot is still held.
ServerBeginTravel
uint32_t ServerBeginTravel(const std::string& scenePath)PrepareForWorldSwap
void PrepareForWorldSwap()CompleteWorldSwap
bool CompleteWorldSwap(MWorld* world)CompleteWorldSwap
bool CompleteWorldSwap(World* ecsWorld)ServerCompleteTravel
void ServerCompleteTravel()ClientSendTravelAck
bool ClientSendTravelAck(uint32_t travelId)SetOnTravelRequested
void SetOnTravelRequested(TravelDelegate d)IsTravelInProgress
bool IsTravelInProgress() constGetTravelId
uint32_t GetTravelId() constGetClientPendingTravelId
uint32_t GetClientPendingTravelId() constGetClientPendingTravelScene
const std::string& GetClientPendingTravelScene() constIsSafeTravelScenePath
static bool IsSafeTravelScenePath(const std::string& scenePath)The scene a host names for travel is peer data, and the client loads it. Only a relative content path passes: an absolute or drive-qualified path skips the VFS mounts, a UNC path makes the client authenticate to that share, and a ".." segment climbs out of the content tree.
Tick
void Tick(float deltaSeconds)GetState
ENetSessionState GetState() constGetFailure
ENetSessionFailure GetFailure() constIsHost
bool IsHost() constIsClient
bool IsClient() constIsInSession
bool IsInSession() constGetSettings
const FNetSessionSettings& GetSettings() constGetJoinKey
std::string GetJoinKey() constWhat a player on another machine needs to join this hosted session directly: "<address>:<port>#<key>". Empty when not hosting, or when the link authenticates otherwise (a configured net.psk, Steam).
GetRoute
ENetSessionRoute GetRoute() constGetPlayers
const std::vector<FNetPlayer>& GetPlayers() constGetPlayerCount
uint32_t GetPlayerCount() constFindPlayerById
const FNetPlayer* FindPlayerById(uint32_t playerId) constFindPlayerByPeer
const FNetPlayer* FindPlayerByPeer(uint32_t peerId) constGetLocalPlayer
const FNetPlayer* GetLocalPlayer() constGetLocalPlayerId
uint32_t GetLocalPlayerId() constIsSessionFull
bool IsSessionFull() constSetPlayerPawnClass
void SetPlayerPawnClass(MClass* pawnClass)Pawn class spawned per connected player. Null falls back to a bare Transform + NetworkObject entity, which is what a headless driver and the self-test use.
GetPlayerPawnClass
MClass* GetPlayerPawnClass() constSetOnPlayerJoined
void SetOnPlayerJoined(PlayerDelegate d)SetOnPlayerLeft
void SetOnPlayerLeft(PlayerDelegate d)SetOnStateChanged
void SetOnStateChanged(StateDelegate d)SetOnLidarShot
void SetOnLidarShot(LidarShotDelegate d)SetOnPlayerIntegrity
void SetOnPlayerIntegrity(PlayerDelegate d)Fires on the host when a joining or rejoining client reported a non-zero engine integrity status (a modified build). The server's own code decides what to do — kick, flag for review, tell a match service. The default without a handler is log-only; it never changes gameplay. The FNetPlayer carries the bits in integrityBits, and is also delivered to OnPlayerJoined with them set, so an existing join handler can read them.
ClearGameCallbacks
void ClearGameCallbacks()Drops every game-installed per-session slot: event handlers, client event policies, the player/state/lidar delegates, the RPC fallback and the pawn class. LeaveSession calls it — the installers live in game code (often the hot-reloadable game module), and a std::function carries no address the session could attribute to an image, so the slots cannot be allowed to outlive the session they were set up for. Install your handlers when starting a session, not once per process. The travel delegate stays: it is engine-host wiring with its own lifetime (the runtime clears it in StopGame).
RegisterEventHandler
void RegisterEventHandler(uint16_t eventId, EventHandler handler)Gameplay events. Ids must sit at or above kGameEventFirst; the reserved block above kReservedFirst belongs to the join protocol.
UnregisterEventHandler
void UnregisterEventHandler(uint16_t eventId)HasEventHandler
bool HasEventHandler(uint16_t eventId) constAllowClientEvent
void AllowClientEvent(uint16_t eventId, bool ownerOnly = true, ENetEventRate rate = ENetEventRate::Default)Client->server events are refused unless allow-listed. OwnerOnly (the default) additionally requires the sender to own the pawn the event is stamped with — the correct setting for anything a pawn does.
DenyClientEvent
void DenyClientEvent(uint16_t eventId)SendEventToServer
bool SendEventToServer(uint16_t eventId, const FNetEventWriter& payload)SendEventToAllClients
bool SendEventToAllClients(uint16_t eventId, const FNetEventWriter& payload)SendEventToPlayer
bool SendEventToPlayer(uint32_t playerId, uint16_t eventId, const FNetEventWriter& payload)BroadcastEvent
bool BroadcastEvent(uint16_t eventId, const FNetEventWriter& payload)Role-agnostic: on the host runs the handler locally and fans out to every client; on a client asks the server to do that. The call site a game writes for "this happened".
ReportLidarShot
bool ReportLidarShot(const FNetLidarShot& shot)The driving co-op case. Scans replicate as one shot record, never as point clouds — the receiving side regenerates the points. The shooter's own scan is applied LOCALLY the instant this is called, so the beam is not one round trip late on the machine that fired it, and the server's relay of that same scan is recognised by its shot id and skipped rather than painted twice. Shots are coalesced for settings.shotCoalesceSeconds and shipped as one batch on the high-rate channel; Tick does the flush, so a session that stops ticking does not strand them.
GetLidarShotAuthority
const FLidarShotAuthority& GetLidarShotAuthority() constFlushPendingShots
void FlushPendingShots()Ship whatever is queued right now instead of waiting out the coalescing window — for a driver with no clock, and for the last shot before a deliberate leave.
GetPendingShotCount
uint32_t GetPendingShotCount() constWasShotLocallyEchoed
bool WasShotLocallyEchoed(uint32_t shotId, uint32_t shooterPlayerId) constTrue when this machine already applied that shot locally, so the server's relay of it must be skipped. Keyed on the shooter as well as the id: two players' shot counters run independently and would collide.
SetLocalPlayerState
void SetLocalPlayerState(const FNetPlayerState& state)Packed animation / gameplay word for the local pawn, replicated on the reliable discrete-state stream.
GetPlayerState
bool GetPlayerState(uint32_t playerId, FNetPlayerState& outState) constSetRpcFallback
void SetRpcFallback(RpcFallback fallback)Component RPCs (a networkId that is not the session sentinel) land here after the default reflection dispatch has run.
SetActorRpcInvoker
static void SetActorRpcInvoker(FActorRpcInvokeFn fn)RouteActorRpc
ENetActorRpcRoute RouteActorRpc(NetworkId nid, uint16_t rpcFlags, const uint8_t* data, size_t len)Ship one named actor RPC toward where its flags say it runs. nid is the target actor's replication id, rpcFlags the function's reflected flags (Server/Client/Multicast decide the direction). Returns RunLocal when the destination resolves to this machine (Client RPC on a host-owned actor) — the caller invokes locally then.
SetScriptActorRpcInvoker
static void SetScriptActorRpcInvoker(FActorRpcInvokeFn fn)The same shape for script-defined actors: the blob is the script layer's envelope and the installed invoker is the only reader of it. unreliable picks the high-rate class and the unreliable channel. Direction comes from the flags exactly as RouteActorRpc reads them.
RouteScriptActorRpc
ENetActorRpcRoute RouteScriptActorRpc(NetworkId nid, uint16_t rpcFlags, bool unreliable, const uint8_t* data, size_t len)GetReplication
ReplicationManager* GetReplication() constGetECSWorld
World* GetECSWorld() constGetGameWorld
MWorld* GetGameWorld() constGetBytesSentToPlayer
uint64_t GetBytesSentToPlayer(uint32_t playerId) constResolvePeerByteBudget
static uint32_t ResolvePeerByteBudget(const FNetSessionSettings& settings)The per-client outgoing budget the session actually applies: the settings' per-peer figure, lowered so maxPlayers - 1 clients together fit hostUplinkBytesPerSecond.
CheckContentCompatibility
static bool CheckContentCompatibility(const std::string& localBuildId, uint64_t localDlcHash, const std::string& remoteBuildId, uint64_t remoteDlcHash, std::string& outReason)ClassifyClientFailure
static ENetSessionFailure ClassifyClientFailure(uint32_t versionMismatches, uint32_t schemaMismatches, ENetSessionFailure fallback, std::string& outReason)What a connecting client's drop or timeout really was: ProtocolMismatch when the replication layer refused the host's packets at the header (version or schema), else fallback. Fills the reason for the UI.
GetLastJoinRefusalReason
const std::string& GetLastJoinRefusalReason() constAlso the reason a kick or ban carried, on the ejected client.
GetPhase
ENetSessionPhase GetPhase() constHost only. A kicked player is told why (kKicked), released at once — never held for rejoin, the hold is for a link that dropped, not one the host cut — and disconnected; the other clients get the usual kPlayerLeft. A ban is a kick whose platform id is refused at the next join request for the life of this hosted session (LeaveSession clears the list; persisting bans across sessions is the game's job). A player with no platform id (LAN, no online service) can only be kicked. The host and the local player refuse both. The phase is the host's; clients follow kSessionPhase. ServerStartRun refuses while anyone connected is not ready unless forced, and ServerReturnToLobby clears every ready flag for the next run. With lateJoinPolicy = LobbyOnly a new player is refused InRun (RunInProgress) while a held slot can still be rejoined.
ServerStartRun
bool ServerStartRun(bool force = false)ServerReturnToLobby
bool ServerReturnToLobby()SetLocalReady
bool SetLocalReady(bool ready)IsPlayerReady
bool IsPlayerReady(uint32_t playerId) constAreAllPlayersReady
bool AreAllPlayersReady() constSetOnPhaseChanged
void SetOnPhaseChanged(PhaseDelegate d)SetOnReturnToMenu
void SetOnReturnToMenu(ReturnToMenuDelegate d)GetLastExitReason
const std::string& GetLastExitReason() constGetReturnToMenuCount
uint32_t GetReturnToMenuCount() constGetAutoRejoinAttemptsLeft
uint32_t GetAutoRejoinAttemptsLeft() constKickPlayer
bool KickPlayer(uint32_t playerId, const std::string& reason)BanPlayer
bool BanPlayer(uint32_t playerId, const std::string& reason)BanPlatformId
void BanPlatformId(uint64_t platformId)UnbanPlatformId
bool UnbanPlatformId(uint64_t platformId)IsPlatformIdBanned
bool IsPlatformIdBanned(uint64_t platformId) constGetBannedPlatformIds
const std::vector<uint64_t>& GetBannedPlatformIds() constoperator=
FNetSession& operator=(const FNetSession&) = delete