LEAP Documentation 40220
Documentation for the LEAP project
NakamaManager.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2021. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "UObject/NoExportTypes.h"
7#include "nakama-cpp/Nakama.h"
8#include "NakamaManager.generated.h"
9
10class UGameInstance;
11
12DECLARE_DYNAMIC_MULTICAST_DELEGATE(FNakamaConnectedSignature);
13DECLARE_DYNAMIC_MULTICAST_DELEGATE(FNakamaFailedConnectionSignature);
14
15DECLARE_DELEGATE_OneParam(FUserIdFetchDelegate,const std::vector<NAKAMA_NAMESPACE::NUser>&);
16
17#define SYSTEM_USER std::string("00000000-0000-0000-0000-000000000000")
18#define STATS_COLLECTION std::string("stats");
19#define AUTHORITATIVE_STATS_COLLECTION std::string("stats_authoritative");
20#define LOAD_STAT_FUNCTION std::string("listLeaderboardStatEntries")
21#define SAVE_STAT_FUNCTION std::string("authenticatedUpdateStats")
22#define UPDATE_LEADERBOARD_FUNCTION std::string("authenticatedUpdateLeaderboard")
23#define SAVE_EXPERIENCE_FUNCTION std::string("updateExperienceRPC")
24#define LOAD_STORE_FUNCTION std::string("loadActiveStore")
25#define PLAYER_INVENTORY std::string("Inventory")
26#define SERVER_HISTORY std::string("ServerHistory")
27#define INITIALIZE_INVENTORY_FUNCTION std::string("initializePlayerInventory")
28#define PLAYER_EQUIPS_SAVE_FUNCTION std::string("savePlayerEquips")
29#define FETCH_ID_FROM_STEAM_ID std::string("getAccountBySteamId")
30#define FETCH_IDS_FROM_STEAM_IDS std::string("getAccountsBySteamIds")
31#define PURCHASE_STORE_ITEM std::string("purchaseStoreItem")
32#define EQUIP_REQUEST std::string("getPlayerEquips")
33#define LOAD_CHALLENGE_FUNCTION std::string("loadChallenges")
34#define LOAD_LEADERBOARD_FUNCTION std::string("loadLeaderboardEntriesForStat")
35#define REROLL_CHALLENGE_FUNCTION std::string("rerollChallenge")
36#define FREEREROLL_CHALLENGE_FUNCTION std::string("freeReroll")
37#define CLAIM_CHALLENGE_FUNCTION std::string("claimChallenge")
38#define UPDATE_CHALLENGE_FUNCTION std::string("updateChallengeProgress")
39#define SERVER_ITEM_UNLOCK_FUNCTION std::string("authenticatedWriteStorageObjects")
40#define GET_TWITCH_REWARDS std::string("awardTwitchDrops")
41#define VERIFY_TWITCH_INTEGRATION std::string("checkTwitchAccountLinked")
42#define REDEEM_REFERAFRIEND std::string("redeemReferral")
43#define CONSUME_MATCH_BONUS std::string("consumeMatchBonus")
44#define CONSUME_LOGIN_BONUS std::string("consumeLogInBonus")
45#define CHECK_LOGIN_BONUS std::string("checkLoginBonus")
46#define UNLINK_TWITCH_INTEGRATION std::string("unlinkTwitchAccount")
47#define UNLOCK_FOUNDERSPACK_FUNCTION std::string("unlockFoundersPackItemsSteam")
48#define CONSUME_ITEM_FUNCTION std::string("consumeItem")
49#define SESSION_LOCK_ITEM_FUNCTION std::string("saveSessionLockedCosmetics")
50#define REWARD_COLLECTION std::string("rewards")
51#define DAILY_COLLECTION std::string("dailyTimer")
52
53UCLASS(config = "Game")
54class PROJECTX_API UNakamaManager : public UObject
55{
56 GENERATED_BODY()
57
58public:
59 UFUNCTION(BlueprintCallable, Category = NakamaHelper)
60 static UNakamaManager* Get(UObject* const WorldContextObject);
61 UFUNCTION(BlueprintCallable,BlueprintPure)
62 static bool IsAvailable(UObject* const WorldContextObject);
63 UFUNCTION(BlueprintCallable)
64 static void Reconnect(UObject* const WorldContextObject);
65 static NAKAMA_NAMESPACE::NClientPtr GetClient(UObject* const WorldContextObject);
66 static NAKAMA_NAMESPACE::NSessionPtr GetSession(UObject* const WorldContextObject);
67
68 void Init(bool bDedicatedServer, UGameInstance* const WorldContextObject);
69 void Shutdown();
70 bool Tick(float DeltaSeconds);
71 bool GetAuthToken(FString& EncodedAuthToken);
72 void Authenticate(FString AuthToken,bool bReAuthenticationAttempt = false);
73
74 void AuthenticationResponse(NAKAMA_NAMESPACE::NSessionPtr session, bool bReAuthentication);
75 static void AsyncFetchUserAccount(const TArray<FString>& NakamaIDs, UObject* const WorldContextObject, FUserIdFetchDelegate Callback);
76
77 UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject"))
78 static FString GetNakamaUserId(UObject* const WorldContextObject);
79 UPROPERTY(BlueprintAssignable, Category = NakamaHelper)
80 FNakamaConnectedSignature OnNakamaConnected;
81 UPROPERTY(BlueprintAssignable, Category = NakamaHelper)
82 FNakamaFailedConnectionSignature OnNakamaFailedConnection;
83 UPROPERTY(config)
84 FString SecretKey = "12345678";
85
86private:
87 static TMap<UGameInstance*, UNakamaManager*> Singleton;
88 NAKAMA_NAMESPACE::NClientPtr NakamaClient = nullptr;
89 NAKAMA_NAMESPACE::NSessionPtr NakamaSession = nullptr;
90
91 std::string NakamaAuthToken;
92 bool bLocalPlayerInitialized = false;
93 bool bIsDedicatedServer = false;
94 bool bFailedReAuthentication = false;
95 bool bFirstRun = true;
96 FString UserID = "";
97};
DECLARE_DELEGATE_OneParam(FUserIdFetchDelegate, const std::vector< NAKAMA_NAMESPACE::NUser > &)
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FNakamaConnectedSignature)
Definition: NakamaManager.h:55