Add TeamSync configuration scaffold

This commit is contained in:
2026-06-11 21:53:48 -04:00
parent fe412ebd84
commit c4fb18b3b4
4 changed files with 128 additions and 0 deletions
+1
View File
@@ -51,6 +51,7 @@ set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/Revision.cc
src/Account.cc
src/AccountSync.cc
src/TeamSync.cc
src/AddressTranslator.cc
src/AFSArchive.cc
src/AsyncHTTPServer.cc
+2
View File
@@ -19,6 +19,7 @@
#include "Text.hh"
#include "TextIndex.hh"
#include "AccountSync.hh"
#include "TeamSync.hh"
#ifdef PHOSG_WINDOWS
static constexpr bool IS_WINDOWS = true;
@@ -886,6 +887,7 @@ void ServerState::load_config_early() {
this->patch_client_idle_timeout_usecs = this->config_json->get_int("PatchClientIdleTimeout", 300000000);
AccountSync::configure_from_json(this->config_json->get("AccountSync", phosg::JSON::dict()));
AccountSync::start_login_lock_heartbeat_task(*this->io_context);
TeamSync::configure_from_json(this->config_json->get("TeamSync", phosg::JSON::dict()));
this->psopeeps_dcv2_exp_multiplier = this->config_json->get_int("PsoPeepsDCV2EXPMultiplier", 5);
if ((this->psopeeps_dcv2_exp_multiplier != 5) && (this->psopeeps_dcv2_exp_multiplier != 10)) {
throw std::runtime_error("PsoPeepsDCV2EXPMultiplier must be 5 or 10");
+93
View File
@@ -0,0 +1,93 @@
#include "TeamSync.hh"
#include <cstddef>
#include <cstdio>
#include <mutex>
namespace TeamSync {
static std::mutex config_mutex;
static Config current_config;
static std::string source_label(const Config& cfg) {
if (!cfg.source.empty()) {
return cfg.source;
}
if (!cfg.source_region.empty() && !cfg.source_ship.empty()) {
return cfg.source_region + "-" + cfg.source_ship;
}
if (!cfg.source_ship.empty()) {
return cfg.source_ship;
}
return cfg.source_region;
}
static Config get_config() {
std::lock_guard<std::mutex> g(config_mutex);
return current_config;
}
void configure(const Config& cfg) {
{
std::lock_guard<std::mutex> g(config_mutex);
current_config = cfg;
}
if (cfg.enabled) {
std::fprintf(stderr,
"[TeamSync] config enabled source=%s source_region=%s source_ship=%s coordinator_url=%s relay_team_chat=%s relay_team_points=%s relay_team_actions=%s\n",
source_label(cfg).c_str(),
cfg.source_region.c_str(),
cfg.source_ship.c_str(),
cfg.coordinator_url.c_str(),
cfg.relay_team_chat ? "true" : "false",
cfg.relay_team_points ? "true" : "false",
cfg.relay_team_actions ? "true" : "false");
} else {
std::fprintf(stderr, "[TeamSync] config disabled\n");
}
}
void configure_from_json(const phosg::JSON& json) {
Config cfg;
cfg.enabled = json.get_bool("Enabled", false);
const std::string legacy_region = json.get_string("Region", "");
cfg.source = json.get_string("Source", legacy_region);
cfg.source_region = json.get_string("SourceRegion", "");
cfg.source_ship = json.get_string("SourceShip", "");
if (cfg.source_region.empty() && cfg.source_ship.empty() && !legacy_region.empty()) {
size_t dash_offset = legacy_region.find('-');
if (dash_offset != std::string::npos) {
cfg.source_region = legacy_region.substr(0, dash_offset);
cfg.source_ship = legacy_region.substr(dash_offset + 1);
} else {
cfg.source_region = legacy_region;
}
}
cfg.coordinator_url = json.get_string("CoordinatorURL", "");
cfg.shared_secret = json.get_string("SharedSecret", "");
cfg.request_timeout_usecs = json.get_int("RequestTimeoutUsecs", 3000000);
if (cfg.request_timeout_usecs < 100000) {
cfg.request_timeout_usecs = 100000;
}
cfg.relay_team_chat = json.get_bool("RelayTeamChat", false);
cfg.relay_team_points = json.get_bool("RelayTeamPoints", false);
cfg.relay_team_actions = json.get_bool("RelayTeamActions", false);
configure(cfg);
}
bool enabled() {
return get_config().enabled;
}
bool relay_team_chat_enabled() {
auto cfg = get_config();
return cfg.enabled && cfg.relay_team_chat;
}
} // namespace TeamSync
+32
View File
@@ -0,0 +1,32 @@
#pragma once
#include <cstdint>
#include <string>
#include <phosg/JSON.hh>
namespace TeamSync {
struct Config {
bool enabled = false;
std::string source;
std::string source_region;
std::string source_ship;
std::string coordinator_url;
std::string shared_secret;
uint64_t request_timeout_usecs = 3000000;
bool relay_team_chat = false;
bool relay_team_points = false;
bool relay_team_actions = false;
};
void configure(const Config& cfg);
void configure_from_json(const phosg::JSON& json);
bool enabled();
bool relay_team_chat_enabled();
} // namespace TeamSync