Skip to main content

ServerSettingsSync

A class in Root.Township, ATT.Character.QuickAccessMenu.

Syncs server settings between the server and the in-game settings menu. Singleton Instance on a networked entity; clients read and send settings, the server applies them.

Constructors​

MemberWhat it is
ServerSettingsSync()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
static ServerSettingsSync InstanceThe current settings sync, set in Initialize and cleared on destroy.
6 private and internal fields
MemberWhat it is
private static readonly Logger loggerNLog logger for this class.
private MethodSync requestSettingsSync for a client's settings request.
private ServerSettings serverSettingsClient: cached copy of the server's settings.
private TaskCompletionSource<ServerSettings> settingsSyncTaskClient: the pending settings request, completed when the server's settings arrive.
private MethodSync syncAvailabilitySync for IsMenuAvailable.
private MethodSyncClass<ServerSettings> syncSettingsSync that carries full server settings either way.

Properties​

MemberWhat it is
bool IsMenuAvailable { get; private set; }Whether the server has in-game settings turned on. Synced to each player on connect and on change.

Methods​

MemberWhat it is
void Close()Client: forgets the cached settings so the next request fetches them again.
override void Initialize()Sets Instance, creates the syncs and, on the server, reads and watches whether in-game settings are on.
override void OnConnected(Player player)Server: sends the menu availability to the new player.
async Task<ServerSettings> RequestSettings()Returns the settings: the live config on the server, else the cache or a fresh request. The sync handler overload is empty in this build.
void SetSettings(ServerSettings settings)Applies new settings on the server, or sends them to the server from a client.
13 private and internal methods
MemberWhat it is
private void ClientReadSettingsFromServer(IPlayer player, Stream stream)Client: reads settings from the stream and completes the pending request.
private static ServerSettings DeserializeServerSettingsFromStream(Stream stream)Reads a SerializableServerSettings from the stream and converts it to ServerSettings.
private async Task<bool> IsServerSyncPermitted(IPlayer player)Server: whether a player may change settings. Always true in this build.
private void OnDestroy()Clears Instance if it's this one.
private void ReadServerSettings(IPlayer player, Stream stream)Passes received settings to the server or client reader.
private async Task<ServerSettings> RequestServerSettingsFromServer()Client: sends a request and waits for the server's settings, sharing one pending request.
private async void RequestSettings(IPlayer player, Stream stream)Returns the settings: the live config on the server, else the cache or a fresh request. The sync handler overload is empty in this build.
private async void SaveServerSettingsFromClient(IPlayer player, ServerSettings settings)Server: if permitted, logs the change and applies the client's settings to the server config.
private void ServerReadSettingsFromClient(IPlayer player, Stream stream)Server: reads settings sent by a client and saves them.
private void SyncAvailability(IPlayer player, Stream stream)Reads or writes IsMenuAvailable.
private void SyncSettings(IPlayer player, Stream stream, ServerSettings settings)Writes settings when sending, or reads them on either side.
private void UpdateMenuSettingsValue(ServerSettings serverSettings)Server: when the in-game settings flag changes, updates IsMenuAvailable and tells clients.
private void WriteServerSettings(Stream stream, ServerSettings settings)Writes settings to the stream; on error cancels the pending request.