LootLocker Unreal Server SDK 6.5.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"
14#include "LootLockerServerConfig.generated.h"
15
16UCLASS(Config = Game, DefaultConfig, meta = (DisplayName = "LootLocker Server SDK Settings"))
17class LOOTLOCKERSERVERSDK_API ULootLockerServerConfig : public UObject
18{
19 GENERATED_BODY()
20public:
22
23 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer")
24 FString LootLockerServerKey = "";
25 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer")
26 FString LootLockerDomainKey = "";
27 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "LootLockerServer", Meta = (EditCondition = "IsLegacyKey", EditConditionHides), Meta = (MultiLine = true), Meta = (DisplayName = "WARNING:"), Transient)
28 FString LegacyKeyWarning = "You are using a legacy API Key, please generate a new one here: https://console.lootlocker.com/settings/api-keys";
29 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "LootLockerServer", Meta = (EditCondition = "!IsValidGameVersion", EditConditionHides), Meta = (MultiLine = true), Meta = (DisplayName = "WARNING:"), Transient)
30 FString InvalidGameVersionWarning = "";
31 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer")
32 FString GameVersion = "";
33 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Meta = (EditCondition = "false", EditConditionHides), Category = "LootLockerServer")
34 FString LootLockerVersion = "2021-06-01";
36 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging")
37 ELootLockerServerLogLevel LimitLogLevelTo = ELootLockerServerLogLevel::Display;
38 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging")
39 bool LogOutsideOfEditor = false;
40 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging")
41 bool bEnableFileLogging = false;
42 UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "LootLockerServer|Logging")
43 FString LogFileName = TEXT("LootLockerServerLog");
44 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "LootLockerServer|Logging", Meta = (EditCondition = "bEnableFileLogging", EditConditionHides), Meta = (MultiLine = true), Meta = (DisplayName = "Actual Log File (on current device)"), Transient)
45 FString LongLogFilePath = "";
46private:
47 FString LogFilePath = "";
48public:
49 // Logging API
50 static ELootLockerServerLogLevel GetConfiguredLogLevel()
51 {
52 return GetDefault<ULootLockerServerConfig>()->LimitLogLevelTo;
53 }
54
59 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
60 static void SetRuntimeLogLevel(ELootLockerServerLogLevel NewLevel);
61
65 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
66 static ELootLockerServerLogLevel GetRuntimeLogLevel();
67
72 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
73 static void EnableFileLogging(const FString& FileName);
74
78 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
79 static void DisableFileLogging();
80
84 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
85 static bool IsFileLoggingEnabled();
86
90 UFUNCTION(BlueprintCallable, Category = "LootLocker|Logging")
91 static FString GetLogFilePath();
92
93private:
94
95 UFUNCTION()
96 bool IsLegacyAPIKey() const
97 {
98 return LootLockerServerKey.Find("dev_", ESearchCase::CaseSensitive) == -1 && LootLockerServerKey.Find("prod_", ESearchCase::CaseSensitive) == -1;
99 }
100
101 UFUNCTION()
102 static bool ShouldLog()
103 {
104#if WITH_EDITOR
105 return true;
106#else
107 return GetDefault<ULootLockerServerConfig>()->LogOutsideOfEditor;
108#endif
109 }
110
111 UFUNCTION()
112 static bool IsSemverString(const FString& str)
113 {
114#if ENGINE_MAJOR_VERSION >= 5
115 return std::regex_match(TCHAR_TO_UTF8(*str), SemverPattern);
116#else
117 return true;
118#endif
119 }
120#if WITH_EDITOR
121 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override
122 {
123 if (PropertyChangedEvent.GetPropertyName() == "LootLockerServerKey")
124 {
125 IsLegacyKey = IsLegacyAPIKey();
126 }
127 if (PropertyChangedEvent.GetPropertyName() == "GameVersion")
128 {
129 IsValidGameVersion = IsSemverString(GameVersion);
130 }
131 if (PropertyChangedEvent.GetPropertyName() == "bEnableFileLogging" || PropertyChangedEvent.GetPropertyName() == "LogFileName")
132 {
133 if (bEnableFileLogging)
134 {
135 EnableFileLogging(LogFileName.IsEmpty() ? "LootLockerServerLog" : LogFileName);
136 }
137 else
138 {
139 DisableFileLogging();
140 }
141 }
142 UObject::PostEditChangeProperty(PropertyChangedEvent);
143 }
144#endif //WITH_EDITOR
145 virtual void PostInitProperties() override
146 {
147 IsLegacyKey = IsLegacyAPIKey();
148 IsValidGameVersion = IsSemverString(GameVersion);
149 if(bEnableFileLogging)
150 {
151 EnableFileLogging(LogFileName.IsEmpty() ? "LootLockerServerLog" : LogFileName);
152 }
153 else
154 {
155 DisableFileLogging();
156 }
157 UObject::PostInitProperties();
158 }
159private:
160 UPROPERTY(Config, VisibleInstanceOnly, Meta = (EditCondition = "false", EditConditionHides), Transient, Category = "LootLockerServer")
161 bool IsLegacyKey = false;
162 UPROPERTY(Config, VisibleInstanceOnly, Meta = (EditCondition = "false", EditConditionHides), Transient, Category = "LootLockerServer")
163 bool IsValidGameVersion = true;
164#if ENGINE_MAJOR_VERSION >= 5
165 inline static const std::regex SemverPattern = std::regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?$");
166#endif
167};
Definition LootLockerServerConfig.h:18