LootLocker Unreal SDK 10.4.0
Game backend SDK for Unreal Engine
Loading...
Searching...
No Matches
LootLockerPresenceManager.h
Go to the documentation of this file.
1// Copyright (c) 2021 LootLocker
2
3#pragma once
4
7
8#include "CoreMinimal.h"
9#include "UObject/NoExportTypes.h"
10#include "Engine/Engine.h"
11#include "LootLockerPresenceClient.h"
13#include "LootLockerPresenceManager.generated.h"
14
15// ========================================================================
16// FORWARD DECLARATIONS & DELEGATES
17// ========================================================================
18
22DECLARE_DELEGATE_FourParams(FLootLockerPresenceConnectionDelegate, const FString&, ELootLockerPresenceConnectionState, ELootLockerPresenceConnectionState, const FString&); // (PlayerUlid, PreviousState, CurrentState, ErrorMessage)
23
27DECLARE_DELEGATE_TwoParams(FLootLockerPresenceCallbackDelegate, bool, const FString&); // (Success, ErrorMessage)
28
29// ========================================================================
30// CONFIGURATION TYPES
31// ========================================================================
32
36USTRUCT(BlueprintType)
37struct LOOTLOCKERSDK_API FLootLockerPresenceManagerConfig
38{
39 GENERATED_BODY()
40
41
42 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "LootLocker")
43 bool bIsEnabled = true;
44
46 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "LootLocker")
47 bool bAutoConnectEnabled = true;
48
50 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "LootLocker")
51 bool bAutoDisconnectOnFocusChange = true;
52
54 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "LootLocker")
55 bool bEnabledInEditor = true;
56};
57
58// ========================================================================
59// CACHED STATUS UPDATE STRUCTURE
60// ========================================================================
61USTRUCT()
63{
64 GENERATED_BODY()
65
66
67 FString Status;
68
70 TMap<FString, FString> Metadata;
71};
72
73
74// ========================================================================
75// MAIN CLASS
76// ========================================================================
77
83UCLASS(BlueprintType)
84class LOOTLOCKERSDK_API ULootLockerPresenceManager : public UObject
85{
86 GENERATED_BODY()
87
88public:
90
91 // ====================================================================
92 // PUBLIC API - MANUAL PRESENCE CONTROL
93 // ====================================================================
94
100 void ConnectPresence(const FString& PlayerUlid, const FLootLockerPresenceCallbackDelegate& OnComplete);
101
107 void DisconnectPresence(const FString& PlayerUlid, const FLootLockerPresenceCallbackDelegate& OnComplete);
108
116 void UpdateStatus(const FString& PlayerUlid, const FString& Status, const TMap<FString, FString>& Metadata, const FLootLockerPresenceCallbackDelegate& OnComplete);
117
123 void UpdateSessionToken(const FString& PlayerUlid, const FString& NewToken);
124
125 // ====================================================================
126 // PUBLIC API - BULK OPERATIONS
127 // ====================================================================
128
134
140
146
151 void PauseConnection(const FString& PlayerUlid);
152
158
163 void ResumeConnection(const FString& PlayerUlid);
164
170
171 // ====================================================================
172 // PUBLIC API - QUERY & STATUS
173 // ====================================================================
174
180 bool IsPresenceActiveForPlayer(const FString& PlayerUlid) const;
181
187 ELootLockerPresenceConnectionState GetPresenceStateForPlayer(const FString& PlayerUlid) const;
188
194 FLootLockerPresenceConnectionStats GetConnectionStatsForPlayer(const FString& PlayerUlid) const;
195
200 TArray<FString> GetConnectedPlayerUlids() const;
201
207
208 // ====================================================================
209 // PUBLIC API - CONFIGURATION
210 // ====================================================================
211
216 static bool IsEnabled();
217
222 static void SetEnabled(bool bEnabled);
223
228 static bool IsAutoConnectEnabled();
229
234 static void SetAutoConnectEnabled(bool bEnabled);
235
241
246 static void SetPauseOnBackgroundEnabled(bool bEnabled);
247
252 static bool IsEnabledInEditor();
253
258 static void SetEnabledInEditor(bool bEnabled);
259
260protected:
261 virtual void BeginDestroy() override;
262
263private:
264 // ====================================================================
265 // PRIVATE MEMBERS - CLIENT MANAGEMENT
266 // ====================================================================
267
269 UPROPERTY()
270 TMap<FString, ULootLockerPresenceClient*> PresenceClients;
271
273 TSet<FString> ConnectingClients;
274
276 TSet<FString> PausedClients;
277
279 mutable FCriticalSection ClientMapLock;
280
281 // ====================================================================
282 // PRIVATE MEMBERS - CONFIGURATION & STATE
283 // ====================================================================
284
287
288 TMap<FString , FLootLockerCachedPresenceStatusUpdate> CachedStatusUpdate;
289
290 // ====================================================================
291 // PRIVATE METHODS - CLIENT LIFECYCLE
292 // ====================================================================
293
299 ULootLockerPresenceClient* CreatePresenceClient(const FString& PlayerUlid, const FString& SessionToken);
300
308 void HandleClientConnectionStateChange(const FString& PlayerUlid, ELootLockerPresenceConnectionState OldState, ELootLockerPresenceConnectionState NewState, const FString& ErrorMessage);
309
310 // ====================================================================
311 // LIFECYCLE EVENT HANDLERS
312 // ====================================================================
313
315 UFUNCTION(Category="LootLocker")
316 void HandleStartup();
317
319 UFUNCTION(Category="LootLocker")
320 void HandleShutdown();
321
323 UFUNCTION(Category="LootLocker")
324 void HandleApplicationBackground();
325
327 UFUNCTION(Category="LootLocker")
328 void HandleApplicationForeground();
329
330 // ====================================================================
331 // OTHER EVENT HANDLERS
332 // ====================================================================
333
335 UFUNCTION(Category="LootLocker")
336 void HandleConfigurationUpdated(const FString& SettingName);
337
338 // ====================================================================
339 // SINGLETON MANAGEMENT
340 // ====================================================================
341public:
345 static ULootLockerPresenceManager* GetInstance();
346
350 static void Initialize();
354 static void Shutdown();
355
356 // ====================================================================
357 // PUBLIC API - EVENTS
358 // ====================================================================
359
365 static void NotifyPlayerActivated(const FString& PlayerUlid);
366
372 static void NotifyPlayerDeactivated(const FString& PlayerUlid);
373private:
375 static ULootLockerPresenceManager* Instance;
376
378 static FCriticalSection InstanceLock;
379};
Manager for LootLocker presence functionality Coordinates presence connections for multiple players/s...
Definition LootLockerPresenceManager.h:85
static bool IsAutoConnectEnabled()
Check if auto-connect is enabled.
void ConnectPresence(const FString &PlayerUlid, const FLootLockerPresenceCallbackDelegate &OnComplete)
Manually connect presence for a specific player.
bool IsPresenceActiveForPlayer(const FString &PlayerUlid) const
Check if presence is active for a specific player.
static void SetEnabledInEditor(bool bEnabled)
Enable or disable presence in editor.
static void SetPauseOnBackgroundEnabled(bool bEnabled)
Enable or disable pause-on-background behavior.
void UpdateSessionToken(const FString &PlayerUlid, const FString &NewToken)
Update session token for an existing presence connection.
void PauseConnection(const FString &PlayerUlid)
Pause presence connection for a specific player.
virtual void BeginDestroy() override
void PauseAllConnections()
Pause all active presence connections (keeps connections alive but stops activity) Called when app go...
void ResumeConnection(const FString &PlayerUlid)
Resume presence connection for a specific player.
FLootLockerPresenceConnectionStats GetConnectionStatsForPlayer(const FString &PlayerUlid) const
Get connection statistics for a specific player.
ELootLockerPresenceConnectionState GetPresenceStateForPlayer(const FString &PlayerUlid) const
Get connection state for a specific player.
static bool IsPauseOnBackgroundEnabled()
Check if pause-on-background is enabled.
int32 GetActiveConnectionCount() const
Get count of currently active presence connections.
static bool IsEnabledInEditor()
Check if presence is enabled in editor.
static void SetEnabled(bool bEnabled)
Enable or disable presence manager globally.
static void SetAutoConnectEnabled(bool bEnabled)
Enable or disable auto-connect behavior.
void UpdateStatus(const FString &PlayerUlid, const FString &Status, const TMap< FString, FString > &Metadata, const FLootLockerPresenceCallbackDelegate &OnComplete)
Update status for a player's presence connection.
TArray< FString > GetConnectedPlayerUlids() const
Get list of all currently connected player ULIDs.
static bool IsEnabled()
Check if presence manager is globally enabled.
void GracefullyShutdown()
Gracefully shutdown all presence connections Called during application termination.
void DisconnectAll(const FLootLockerPresenceCallbackDelegate &OnComplete)
Disconnect all active presence connections.
void ResumeAllConnections()
Resume all paused presence connections Called when app returns to foreground, network is restored,...
void ConnectPresenceForAllActiveSessions(const FLootLockerPresenceCallbackDelegate &OnComplete)
Connect presence for all currently authenticated players/sessions.
void DisconnectPresence(const FString &PlayerUlid, const FLootLockerPresenceCallbackDelegate &OnComplete)
Manually disconnect presence for a specific player.
void(* FLootLockerPresenceConnectionDelegate)(const FString &, ELootLockerPresenceConnectionState, ELootLockerPresenceConnectionState, const FString &)
Delegate for presence connection state changes.
Definition LootLockerPresenceManager.h:22
void(* FLootLockerPresenceCallbackDelegate)(bool, const FString &)
Delegate for handling presence connection process callbacks.
Definition LootLockerPresenceManager.h:27
Definition LootLockerPresenceManager.h:63
Configuration structure for presence manager behavior.
Definition LootLockerPresenceManager.h:38