-
Notifications
You must be signed in to change notification settings - Fork 2
Description
The SDK for Willow games ships with a built-in module, networking, that provides a high-level interface for messaging between copies of mods in an online game session: https://github.com/bl-sdk/willow2-mod-manager/tree/master/src/networking
This module could be adapted for Oak games by replacing each instance of its Willow-specific code with Oak-specific code, as proposed here.
Players
The Oak equivalent of Willow's PlayerReplicationInfo is PlayerState; a PlayerState instance exists for each player, and provides their PlayerID, as well as an Owner property referring to their player controller (host only).
The array of PlayerState instances (and therefore list of players) is referenced at ENGINE.GameViewport.World.GameState.PlayerArray.
The local player's PlayerState is referenced at get_pc().PlayerState
The host's PlayerState is referenced at ENGINE.GameViewport.World.GameState.HostPlayerState.
Whether the local player is currently serving as a client or not can be determined by comparing their PlayerState to that of the host's.
Transmission
Client and server transmission, respectively, can be performed with the following functions:
# /Script/Engine.PlayerController:ClientMessage
remote_pc.ClientMessage(msg, message_type, float(player_id)) # Loss of precision if player_id somehow exceeds platform float mantissa# /Script/Engine.PlayerController:ServerChangeName
local_pc.ServerChangeName(param_encoded_message) # message type and player_id must be serialized into the payloadAn additional message type for transmitting references to replicated Actors, actor_message, could be made possible with another pair of functions:
# /Script/OakGame.OakPlayerController:ClientCreatePlayerAlert
remote_pc.ClientCreatePlayerAlert(
make_struct("UniqueNetIdRepl"), # Must be empty, or else causes disconnect.
some_actor,
make_struct("Vector", X=MAGIC_IDENTIFIER) # A hard-coded value used to distinguish messages belonging to the networking module
)# /Script/OakGame.OakPlayerController:ServerCreatePlayerAlert
local_pc.ServerCreatePlayerAlert(
make_struct("UniqueNetIdRepl"), # Must be empty, or else causes disconnect.
some_actor,
make_struct("Vector", X=MAGIC_IDENTIFIER, Y=float(player_id)), # Loss of precision if player_id somehow exceeds platform float mantissa
)