LootLocker Unreal Server SDK 6.6.0
Server-side backend SDK for Unreal Engine
Loading...
Searching...
No Matches
LootLockerServerConfig.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 "Runtime/Launch/Resources/Version.h"
10#if ENGINE_MAJOR_VERSION >= 5
11#include <regex>
12#endif
13#include "LootLockerServerLogger.h"
15#include "LootLockerServerConfig.generated.h"
16
17UCLASS(Config = Game, DefaultConfig, meta = (DisplayName = "LootLocker Server SDK Settings"))
18class LOOTLOCKERSERVERSDK_API ULootLockerServerConfig : public UObject
19{
20 GENERATED_BODY()
21public:
26 static bool IsFileConfigActive();
27
33 static TOptional<FLootLockerServerFileConfig> ParseFileConfigContent(const FString& Content);
34
39#if ENGINE_MAJOR_VERSION >= 5
40 inline static const FString PreConfigFileName = TEXT("LootLockerServerPreConfig.bytes");
41#else
42 static const FString PreConfigFileName;
43#endif
44 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "LootLockerServer", Meta = (EditCondition = "bIsFileConfigLocked", EditConditionHides), Meta = (MultiLine = true), Meta = (DisplayName = "INFO:"), Transient)
45 FString FileConfigActiveNotice = "Settings are governed by the pre-configured file config shipped with the plugin and cannot be changed from the editor.";
46 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer", Meta = (EditCondition = "!bIsFileConfigLocked"))
47 FString LootLockerServerKey = "";
48 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer", Meta = (EditCondition = "!bIsFileConfigLocked"))
49 FString LootLockerDomainKey = "";
50 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "LootLockerServer", Meta = (EditCondition = "IsLegacyKey", EditConditionHides), Meta = (MultiLine = true), Meta = (DisplayName = "WARNING:"), Transient)
51 FString LegacyKeyWarning = "You are using a legacy API Key, please generate a new one here: https://console.lootlocker.com/settings/api-keys";
52 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "LootLockerServer", Meta = (EditCondition = "!IsValidGameVersion", EditConditionHides), Meta = (MultiLine = true), Meta = (DisplayName = "WARNING:"), Transient)
53 FString InvalidGameVersionWarning = "";
54 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer", Meta = (EditCondition = "!bIsFileConfigLocked"))
55 FString GameVersion = "";
56 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Meta = (EditCondition = "false", EditConditionHides), Category = "LootLockerServer")
57 FString LootLockerVersion = "2021-06-01";
59 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging", Meta = (EditCondition = "!bIsFileConfigLocked"))
60 ELootLockerServerLogLevel LimitLogLevelTo = ELootLockerServerLogLevel::Warning;
61 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging", Meta = (EditCondition = "!bIsFileConfigLocked"))
62 bool LogOutsideOfEditor = false;
63 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging", Meta = (EditCondition = "!bIsFileConfigLocked"))
64 bool bEnableFileLogging = false;
65 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging", Meta = (EditCondition = "bEnableFileLogging && !bIsFileConfigLocked", EditConditionHides))
66 FString LogFileName = TEXT("LootLockerServerLog");
67 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "LootLockerServer|Logging", Meta = (EditCondition = "bEnableFileLogging", EditConditionHides), Meta = (MultiLine = true), Meta = (DisplayName = "Actual Log File (on current device)"), Transient)
68 FString LongLogFilePath = "";
69private:
70 FString LogFilePath = "";
71public:
72 // Logging API
73 static ELootLockerServerLogLevel GetConfiguredLogLevel()
74 {
75 return GetDefault<ULootLockerServerConfig>()->LimitLogLevelTo;
76 }
77
82 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
83 static void SetRuntimeLogLevel(ELootLockerServerLogLevel NewLevel);
84
88 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
89 static ELootLockerServerLogLevel GetRuntimeLogLevel();
90
95 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
96 static void EnableFileLogging(const FString& FileName);
97
101 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
102 static void DisableFileLogging();
103
107 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
108 static bool IsFileLoggingEnabled();
109
113 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
114 static FString GetLogFilePath();
115
116private:
117
118 UFUNCTION()
119 bool IsLegacyAPIKey() const
120 {
121 return LootLockerServerKey.Find("dev_", ESearchCase::CaseSensitive) == -1 && LootLockerServerKey.Find("prod_", ESearchCase::CaseSensitive) == -1;
122 }
123
124 UFUNCTION()
125 static bool ShouldLog()
126 {
127#if WITH_EDITOR
128 return true;
129#else
130 return GetDefault<ULootLockerServerConfig>()->LogOutsideOfEditor;
131#endif
132 }
133
134 UFUNCTION()
135 static bool IsSemverString(const FString& str)
136 {
137#if ENGINE_MAJOR_VERSION >= 5
138 return std::regex_match(TCHAR_TO_UTF8(*str), SemverPattern);
139#else
140 return true;
141#endif
142 }
143#if WITH_EDITOR
144 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override
145 {
146 if (PropertyChangedEvent.GetPropertyName() == "LootLockerServerKey")
147 {
148 IsLegacyKey = IsLegacyAPIKey();
149 }
150 if (PropertyChangedEvent.GetPropertyName() == "GameVersion")
151 {
152 IsValidGameVersion = IsSemverString(GameVersion);
153 }
154 if (PropertyChangedEvent.GetPropertyName() == "bEnableFileLogging" || PropertyChangedEvent.GetPropertyName() == "LogFileName")
155 {
156 if (bEnableFileLogging)
157 {
158 EnableFileLogging(LogFileName.IsEmpty() ? "LootLockerServerLog" : LogFileName);
159 }
160 else
161 {
162 DisableFileLogging();
163 }
164 }
165 UObject::PostEditChangeProperty(PropertyChangedEvent);
166 }
167#endif //WITH_EDITOR
168 virtual void PostInitProperties() override
169 {
170 IsLegacyKey = IsLegacyAPIKey();
171 IsValidGameVersion = IsSemverString(GameVersion);
172 LoadFileConfig();
173 ApplyFileConfigIfPresent();
174 // File logging is already handled by ApplyFileConfigIfPresent
175 // when a file config is active. Only apply the default behavior
176 // when no file config is governing the setting.
177 if (!bIsFileConfigLocked)
178 {
179 if(bEnableFileLogging)
180 {
181 EnableFileLogging(LogFileName.IsEmpty() ? "LootLockerServerLog" : LogFileName);
182 }
183 else
184 {
185 DisableFileLogging();
186 }
187 }
188 UObject::PostInitProperties();
189 }
190private:
191 UPROPERTY(Config, VisibleInstanceOnly, Meta = (EditCondition = "false", EditConditionHides), Transient, Category = "LootLockerServer")
192 bool IsLegacyKey = false;
193 UPROPERTY(Config, VisibleInstanceOnly, Meta = (EditCondition = "false", EditConditionHides), Transient, Category = "LootLockerServer")
194 bool IsValidGameVersion = true;
195 UPROPERTY(Config, VisibleInstanceOnly, Meta = (EditCondition = "false", EditConditionHides), Transient, Category = "LootLockerServer")
196 bool bIsFileConfigLocked = false;
197#if ENGINE_MAJOR_VERSION >= 5
198 inline static bool bFileConfigChecked = false;
199 inline static TOptional<FLootLockerServerFileConfig> FileConfig;
200#else
201 static bool bFileConfigChecked;
202 static TOptional<FLootLockerServerFileConfig> FileConfig;
203#endif
204 static void LoadFileConfig();
205 void ApplyFileConfigIfPresent();
206#if ENGINE_MAJOR_VERSION >= 5
207 inline static const std::regex SemverPattern = std::regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?$");
208#endif
209};
Definition LootLockerServerConfig.h:19
static TOptional< FLootLockerServerFileConfig > ParseFileConfigContent(const FString &Content)
Parses a pre-config file's raw content (plain JSON or encrypted) into an FLootLockerServerFileConfig.
static bool IsFileConfigActive()
Returns true when a pre-configured file config is active and governing settings.
static const FString PreConfigFileName
Filename of the pre-config file that the SDK looks for in the plugin's Config directory.
Definition LootLockerServerConfig.h:42