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
Inject IPlayerService.
Constructors
PlayerService(ILoggerFactory, ILifetimeScope)
public PlayerService(ILoggerFactory loggerFactory, ILifetimeScope lifetimeScope)
Parameters
loggerFactoryILoggerFactorylifetimeScopeILifetimeScope
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
Exceptions
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
steam64CSteamIDtokenCancellationToken
Returns
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
steam64ulong
Returns
Exceptions
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
steam64ulong
Returns
Exceptions
GetOnlinePlayerOrNullThreadSafe(ulong)
Get a player if they're online, otherwise null.
public WarfarePlayer? GetOnlinePlayerOrNullThreadSafe(ulong steam64)
Parameters
steam64ulong
Returns
GetOnlinePlayerThreadSafe(ulong)
Get a player who's known to be online.
public WarfarePlayer GetOnlinePlayerThreadSafe(ulong steam64)
Parameters
steam64ulong
Returns
Exceptions
GetThreadsafePlayerList()
Gets a copy of the player list for working on non-game threads.
public IReadOnlyList<WarfarePlayer> GetThreadsafePlayerList()
Returns
IsPlayerOnline(ulong)
Quickly check if a player is online.
public bool IsPlayerOnline(ulong steam64)
Parameters
steam64ulong
Returns
Exceptions
IsPlayerOnlineThreadSafe(ulong)
Quickly check if a player is online.
public bool IsPlayerOnlineThreadSafe(ulong steam64)
Parameters
steam64ulong
Returns
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
subscribeAction<WarfarePlayer, TDelegate>valueTDelegate
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
tokenCancellationToken
Returns
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
unsubscribeAction<WarfarePlayer, TDelegate>valueTDelegate
Type Parameters
TDelegate