Table of Contents

Class PlayerService

Namespace
Uncreated.Warfare.Players.Management
Assembly
Uncreated.Warfare.dll

Handles keeping track of online WarfarePlayer's.

public class PlayerService : IPlayerService
Inheritance
PlayerService
Implements
Inherited Members
Extension Methods

Remarks

Constructors

PlayerService(ILoggerFactory, ILifetimeScope)

public PlayerService(ILoggerFactory loggerFactory, ILifetimeScope lifetimeScope)

Parameters

loggerFactory ILoggerFactory
lifetimeScope ILifetimeScope

Fields

PlayerComponents

All types will be added to a player on join and removed on leave. They dont necessarily have to be UnityEngine.MonoBehaviour's but must implement IPlayerComponent.

public readonly Type[] PlayerComponents

Field Value

Type[]

Remarks

Components can implement IDisposable if desired to run code before the player leaves. UnityEngine.MonoBehaviour's will be automatically destroyed.

Components can receive events, but any IPlayerEvent args will only be received if they're about the player that owns the component.

PlayerTasks

All types here will be created when a player starts to join (PlayerPending). They must implement IPlayerPendingTask and can not be UnityEngine.MonoBehaviour components.

public readonly Type[] PlayerTasks

Field Value

Type[]

Properties

OnlinePlayers

List of all online players. Not to be accessed from any thread other than the game thread.

public ReadOnlyTrackingList<WarfarePlayer> OnlinePlayers { get; }

Property Value

ReadOnlyTrackingList<WarfarePlayer>

Exceptions

GameThreadException

Methods

CreateOfflinePlayerAsync(CSteamID, CancellationToken)

Create an IPlayer instance from a possibly offline player and fetch their usernames for display.

public ValueTask<IPlayer> CreateOfflinePlayerAsync(CSteamID steam64, CancellationToken token = default)

Parameters

steam64 CSteamID
token CancellationToken

Returns

ValueTask<IPlayer>

GetOnlinePlayer(ulong)

Get a player who's known to be online. Not to be invoked from any thread other than the game thread.

public WarfarePlayer GetOnlinePlayer(ulong steam64)

Parameters

steam64 ulong

Returns

WarfarePlayer

Exceptions

GameThreadException
PlayerOfflineException

GetOnlinePlayerOrNull(ulong)

Get a player if they're online, otherwise null. Not to be invoked from any thread other than the game thread.

public WarfarePlayer? GetOnlinePlayerOrNull(ulong steam64)

Parameters

steam64 ulong

Returns

WarfarePlayer

Exceptions

GameThreadException

GetOnlinePlayerOrNullThreadSafe(ulong)

Get a player if they're online, otherwise null.

public WarfarePlayer? GetOnlinePlayerOrNullThreadSafe(ulong steam64)

Parameters

steam64 ulong

Returns

WarfarePlayer

GetOnlinePlayerThreadSafe(ulong)

Get a player who's known to be online.

public WarfarePlayer GetOnlinePlayerThreadSafe(ulong steam64)

Parameters

steam64 ulong

Returns

WarfarePlayer

Exceptions

PlayerOfflineException

GetThreadsafePlayerList()

Gets a copy of the player list for working on non-game threads.

public IReadOnlyList<WarfarePlayer> GetThreadsafePlayerList()

Returns

IReadOnlyList<WarfarePlayer>

IsPlayerOnline(ulong)

Quickly check if a player is online.

public bool IsPlayerOnline(ulong steam64)

Parameters

steam64 ulong

Returns

bool

Exceptions

GameThreadException

IsPlayerOnlineThreadSafe(ulong)

Quickly check if a player is online.

public bool IsPlayerOnlineThreadSafe(ulong steam64)

Parameters

steam64 ulong

Returns

bool

ReleasePlayerConnectionLock()

Re-allow players to join after calling TakePlayerConnectionLock(CancellationToken).

public void ReleasePlayerConnectionLock()

SubscribeToPlayerEvent<TDelegate>(Action<WarfarePlayer, TDelegate>, TDelegate)

Subscribes to an instance event on a player.

public void SubscribeToPlayerEvent<TDelegate>(Action<WarfarePlayer, TDelegate> subscribe, TDelegate value) where TDelegate : MulticastDelegate

Parameters

subscribe Action<WarfarePlayer, TDelegate>
value TDelegate

Type Parameters

TDelegate

TakePlayerConnectionLock(CancellationToken)

Temporarily stop players from joining. Note that the lock will already be taken on startup and only has to be released whenever players are first allowed to join.

public Task TakePlayerConnectionLock(CancellationToken token)

Parameters

token CancellationToken

Returns

Task

Remarks

Call ReleasePlayerConnectionLock() to allow players to join again.

UnsubscribeFromPlayerEvent<TDelegate>(Action<WarfarePlayer, TDelegate>, TDelegate)

Unsubscribes from an instance event on a player.

public void UnsubscribeFromPlayerEvent<TDelegate>(Action<WarfarePlayer, TDelegate> unsubscribe, TDelegate value) where TDelegate : MulticastDelegate

Parameters

unsubscribe Action<WarfarePlayer, TDelegate>
value TDelegate

Type Parameters

TDelegate