-
Notifications
You must be signed in to change notification settings - Fork 16
/
configuration.cc
81 lines (71 loc) · 4.31 KB
/
configuration.cc
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
#include "configuration.h"
#include "logger.h"
#include <algorithm>
#include <glibmm/convert.h>
#include <glibmm/datetime.h>
#include <glibmm/keyfile.h>
#include <glibmm/ustring.h>
Configuration::Configuration(const std::string &filename) {
Glib::KeyFile kf;
kf.load_from_file(filename);
normal_half_seconds = kf.get_integer(u8"normal", u8"HALF");
normal_half_time_seconds = kf.get_integer(u8"normal", u8"HALF_TIME");
normal_timeout_seconds = static_cast<unsigned int>(kf.get_integer(u8"normal", u8"TIMEOUT_TIME"));
normal_timeouts = static_cast<unsigned int>(kf.get_integer(u8"normal", u8"TIMEOUTS"));
overtime_break_seconds = kf.get_integer(u8"overtime", u8"BREAK");
overtime_half_seconds = kf.get_integer(u8"overtime", u8"HALF");
overtime_half_time_seconds = kf.get_integer(u8"overtime", u8"HALF_TIME");
overtime_timeout_seconds = static_cast<unsigned int>(kf.get_integer(u8"overtime", u8"TIMEOUT_TIME"));
overtime_timeouts = static_cast<unsigned int>(kf.get_integer(u8"overtime", u8"TIMEOUTS"));
shootout_break_seconds = kf.get_integer(u8"shootout", u8"BREAK");
yellow_card_seconds = static_cast<unsigned int>(kf.get_integer(u8"global", u8"YELLOW_CARD_TIME"));
team_names_required = kf.get_boolean(u8"global", u8"TEAM_NAMES_REQUIRED");
rcon_enabled_by_default = kf.get_boolean(u8"global", u8"RCON_ENABLED_BY_DEFAULT");
if (kf.has_key(u8"files", u8"SAVE")) {
save_filename = Glib::filename_from_utf8(Glib::ustring::compose(kf.get_string(u8"files", u8"SAVE"), Glib::DateTime::create_now_local().format(u8"%Y%m%dT%H%M%S")));
}
log_filename = kf.has_key(u8"files", u8"LOG") ? Glib::filename_from_utf8(kf.get_string(u8"files", u8"LOG")) : "";
address = kf.get_string(u8"ip", u8"ADDRESS");
legacy_port = kf.has_key(u8"ip", u8"LEGACY_PORT") ? kf.get_string(u8"ip", u8"LEGACY_PORT") : "";
protobuf_port = kf.has_key(u8"ip", u8"PROTOBUF_PORT") ? kf.get_string(u8"ip", u8"PROTOBUF_PORT") : "";
interface = kf.has_key(u8"ip", u8"INTERFACE") ? kf.get_string(u8"ip", u8"INTERFACE") : "";
if (kf.has_key(u8"ip", u8"RCON_PORT")) {
rcon_port = static_cast<uint16_t>(kf.get_integer(u8"ip", u8"RCON_PORT"));
} else {
rcon_port = 0;
}
for (const Glib::ustring &key : kf.get_keys(u8"teams")) {
teams.push_back(kf.get_string(u8"teams", key));
}
std::sort(teams.begin(), teams.end());
}
void Configuration::dump(Logger &logger) {
logger.write(Glib::ustring::compose(u8"Configuration: Normal halves: %1 seconds.", normal_half_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Normal half time: %1 seconds.", normal_half_time_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Normal timeouts: %1, totalling up to %2 seconds.", normal_timeouts, normal_timeout_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Pre-overtime break: %1 seconds.", overtime_break_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Overtime halves: %1 seconds.", overtime_half_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Overtime half time: %1 seconds.", overtime_half_time_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Overtime timeouts: %1, totalling up to %2 seconds.", overtime_timeouts, overtime_timeout_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Pre-shootout break: %1 seconds.", shootout_break_seconds));
logger.write(Glib::ustring::compose(u8"Configuration: Yellow card: %1 seconds.", yellow_card_seconds));
if (!save_filename.empty()) {
logger.write(Glib::ustring::compose(u8"Configuration: State save filename: \"%1\".", Glib::filename_to_utf8(save_filename)));
}
if (!log_filename.empty()) {
logger.write(Glib::ustring::compose(u8"Configuration: Log filename: \"%1\".", Glib::filename_to_utf8(log_filename)));
}
logger.write(Glib::ustring::compose(u8"Configuration: Packet destination address: \"%1\".", Glib::locale_to_utf8(address)));
if (!legacy_port.empty()) {
logger.write(Glib::ustring::compose(u8"Configuration: Legacy port: \"%1\".", legacy_port));
}
if (!protobuf_port.empty()) {
logger.write(Glib::ustring::compose(u8"Configuration: Protobuf port: \"%1\".", protobuf_port));
}
if (rcon_port) {
logger.write(Glib::ustring::compose(u8"Configuration: Remote control port: %1.", rcon_port));
}
if (!interface.empty()) {
logger.write(Glib::ustring::compose(u8"Configuration: Network interface: \"%1\".", Glib::locale_to_utf8(interface)));
}
}