-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.h
More file actions
243 lines (210 loc) · 8.15 KB
/
Config.h
File metadata and controls
243 lines (210 loc) · 8.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#ifndef CONFIG_H
#define CONFIG_H
#include <filesystem>
#include <format>
#include <map>
#include <stdexcept>
#include <string>
#include <variant>
#include <vector>
namespace rustLaunchSite
{
class Logger;
/// @brief rustLaunchSite application configuration facility
/// @details Abstracts use of config file parser to load config file data into
/// an instance of this class, which can then be queried for settings. Only
/// the constructor should throw exceptions.
class Config
{
public:
enum class ModFrameworkType { NONE, CARBON, OXIDE };
static std::string ToString(const ModFrameworkType type)
{
using enum ModFrameworkType;
switch (type)
{
case NONE: return "None";
case CARBON: return "Carbon";
case OXIDE: return "Oxide";
}
return "Unknown";
}
enum class SeedStrategy { FIXED, LIST, RANDOM };
struct Parameter
{
const std::variant<bool, double, int, std::string> data_ = {};
Parameter() = delete;
explicit Parameter(const bool b) : data_(b) {}
explicit Parameter(const double d) : data_(d) {}
explicit Parameter(const int i) : data_(i) {}
explicit Parameter(const std::string& s) : data_(s) {}
explicit Parameter(std::string&& s) : data_(std::move(s)) {}
Parameter(const Parameter&) = default;
Parameter(Parameter&&) noexcept = default;
~Parameter() = default;
Parameter& operator= (const Parameter&) = delete;
Parameter& operator= (Parameter&&) = delete;
constexpr bool IsBool() const
{
return std::holds_alternative<bool>(data_);
}
constexpr bool IsDouble() const
{
return std::holds_alternative<double>(data_);
}
constexpr bool IsInt() const
{
return std::holds_alternative<int>(data_);
}
constexpr bool IsString() const
{
return std::holds_alternative<std::string>(data_);
}
constexpr bool GetBool() const
{
if (!IsBool())
{
throw std::runtime_error("Called Parameter::GetBool() on a non-bool");
}
return std::get<bool>(data_);
}
constexpr double GetDouble() const
{
if (!IsDouble())
{
throw std::runtime_error("Called Parameter::GetDouble() on a non-double");
}
return std::get<double>(data_);
}
constexpr int GetInt() const
{
if (!IsInt())
{
throw std::runtime_error("Called Parameter::GetInt() on a non-int");
}
return std::get<int>(data_);
}
constexpr std::string GetString() const
{
if (!IsString())
{
throw std::runtime_error("Called Parameter::GetString() on a non-string");
}
return std::get<std::string>(data_);
}
constexpr std::string ToString() const
{
return std::visit(
[](const auto& arg) { return std::format("{}", arg); }, data_);
}
};
using ParameterMapType = std::map<std::string, Parameter, std::less<>>;
/// @brief Primary constructor
/// @details Creates an instance that is populated with data from the
/// specified config file.
/// @param configFile Configuration file to load
/// @throw @c std::invalid_argument on parse or validation failure
explicit Config(Logger& logger, std::filesystem::path configFile);
// accessor methods for loaded settings
std::filesystem::path GetInstallPath() const
{ return installPath_; }
std::string GetInstallIdentity() const
{ return installIdentity_; }
bool GetProcessAutoRestart() const
{ return processAutoRestart_; }
std::filesystem::path GetProcessReasonPath() const
{ return processReasonPath_; }
int GetProcessShutdownDelaySeconds() const
{ return processShutdownDelaySeconds_; }
std::string GetRconPassword() const
{ return rconPassword_; }
std::string GetRconIP() const
{ return rconIP_; }
int GetRconPort() const
{ return rconPort_; }
bool GetRconPassthroughIP() const
{ return rconPassthroughIP_; }
bool GetRconPassthroughPort() const
{ return rconPassthroughPort_; }
bool GetRconLog() const
{ return rconLog_; }
SeedStrategy GetSeedStrategy() const
{ return seedStrategy_; }
int GetSeedFixed() const
{ return seedFixed_; }
std::vector<int> GetSeedList() const
{ return seedList_; }
std::filesystem::path GetSteamcmdPath() const
{ return steamcmdPath_; }
bool GetUpdateServerOnInterval() const
{ return updateServerOnInterval_; }
bool GetUpdateServerOnRelaunch() const
{ return updateServerOnRelaunch_; }
bool GetUpdateServerOnStartup() const
{ return updateServerOnStartup_; }
int GetUpdateServerRetryDelaySeconds() const
{ return updateServerRetryDelaySeconds_; }
bool GetUpdateModFrameworkOnInterval() const
{ return updateModFrameworkOnInterval_; }
bool GetUpdateModFrameworkOnRelaunch() const
{ return updateModFrameworkOnRelaunch_; }
bool GetUpdateModFrameworkOnServerUpdate() const
{ return updateModFrameworkOnServerUpdate_; }
bool GetUpdateModFrameworkOnStartup() const
{ return updateModFrameworkOnStartup_; }
int GetUpdateModFrameworkRetryDelaySeconds() const
{ return updateModFrameworkRetryDelaySeconds_; }
ModFrameworkType GetUpdateModFrameworkType() const
{ return updateModFrameworkType_; }
int GetUpdateIntervalMinutes() const
{ return updateIntervalMinutes_; }
bool GetWipeOnProtocolChange() const
{ return wipeOnProtocolChange_; }
bool GetWipeBlueprints() const
{ return wipeBlueprints_; }
ParameterMapType GetMinusParams() const
{ return minusParams_; }
ParameterMapType GetPlusParams() const
{ return plusParams_; }
private:
// rustLaunchSite settings
std::filesystem::path installPath_ = {};
std::string installIdentity_ = {};
bool processAutoRestart_ = {};
std::filesystem::path processReasonPath_ = {};
int processShutdownDelaySeconds_ = {};
std::string rconPassword_ = {};
std::string rconIP_ = {};
int rconPort_ = {};
bool rconPassthroughIP_ = {};
bool rconPassthroughPort_ = {};
bool rconLog_ = {};
SeedStrategy seedStrategy_ = SeedStrategy::RANDOM;
int seedFixed_ = {};
std::vector<int> seedList_ = {};
std::filesystem::path steamcmdPath_ = {};
bool updateServerOnInterval_ = {};
bool updateServerOnRelaunch_ = {};
bool updateServerOnStartup_ = {};
int updateServerRetryDelaySeconds_ = {};
bool updateModFrameworkOnInterval_ = {};
bool updateModFrameworkOnRelaunch_ = {};
bool updateModFrameworkOnServerUpdate_ = {};
bool updateModFrameworkOnStartup_ = {};
int updateModFrameworkRetryDelaySeconds_ = {};
ModFrameworkType updateModFrameworkType_ = ModFrameworkType::NONE;
int updateIntervalMinutes_ = {};
bool wipeOnProtocolChange_ = {};
bool wipeBlueprints_ = {};
// dedicatedServer settings
ParameterMapType minusParams_ = {};
ParameterMapType plusParams_ = {};
// logger
Logger& logger_;
// disabled constructors/operators
Config() = delete;
Config(const Config&) = delete;
Config& operator= (const Config&) = delete;
};
}
#endif // CONFIG_H