From c4fb18b3b42b512da05545bed0708ec84e534b08 Mon Sep 17 00:00:00 2001 From: James Osborne Date: Thu, 11 Jun 2026 21:53:48 -0400 Subject: [PATCH] Add TeamSync configuration scaffold --- CMakeLists.txt | 1 + src/ServerState.cc | 2 + src/TeamSync.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++++ src/TeamSync.hh | 32 ++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 src/TeamSync.cc create mode 100644 src/TeamSync.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 64c3ac59..4b4c71f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/ServerState.cc b/src/ServerState.cc index f21d2b73..4d78ca57 100644 --- a/src/ServerState.cc +++ b/src/ServerState.cc @@ -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"); diff --git a/src/TeamSync.cc b/src/TeamSync.cc new file mode 100644 index 00000000..2250592c --- /dev/null +++ b/src/TeamSync.cc @@ -0,0 +1,93 @@ +#include "TeamSync.hh" + +#include +#include +#include + +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 g(config_mutex); + return current_config; +} + +void configure(const Config& cfg) { + { + std::lock_guard 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 diff --git a/src/TeamSync.hh b/src/TeamSync.hh new file mode 100644 index 00000000..25eaf41b --- /dev/null +++ b/src/TeamSync.hh @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#include + +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