From 83c8771490ce9f2a9b3e87876633d6b9437de5fd Mon Sep 17 00:00:00 2001 From: blevouschurverantunt <35274597+blevouschurverantunt@users.noreply.github.com> Date: Wed, 25 Nov 2026 19:49:46 -0600 Subject: [PATCH] Add opt-in alliance sync stream New sync option `alliance` (default false) and event type `alliance_league`: {"type":"alliance_league","league":,"level":}, the league and level of the player's own alliance and nothing else (no alliance id, name, tag, slogan, announcement or member count). Source: the game server's AllianceDetails group (225), which decodes as an AllianceProfile and arrives about every 30 seconds. It is one record with a fixed key, so the framework sends it only when league or level changes. The group may describe an alliance other than the player's own, so it is used only when its alliance id equals the alliance id listed in the player's own profile record, read from the UserProfiles response. Until that record has been read in the session nothing is sent. When the own profile lists no alliance, nothing is sent either; the mod has no verified signal for "no alliance" and does not guess. Co-Authored-By: Claude Fable 5.2 --- docs/FEATURES.md | 1 + .../example_community_patch_settings_en.toml | 3 + src/mod/config.h | 2 + src/mod/sync/records.cc | 24 ++++++++ src/mod/sync/state.cc | 1 + src/mod/sync/sync.h | 3 + tests/sync_logic.cc | 55 +++++++++++++++++++ 7 files changed, 89 insertions(+) diff --git a/docs/FEATURES.md b/docs/FEATURES.md index bec5d3e28..f6c669df6 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -105,6 +105,7 @@ Each target has its own options and access token. | Store | Faction store offers: favor level prices, requirements and remaining purchases. Off unless a target sets `store_offers`. | | Store bundles | Sync store bundles for the refining and alliance tournament store categories: costs, requirements, contents, remaining purchases and validity times. Off unless a target sets `store_bundles`. | | Store orders | Sync the results of refining store purchases (`refining_materials` and `refining_ship_parts`), one record per order, including each order of a bulk purchase: the bundle, what was paid and what each chest granted. Up to 300 recent orders per session; orders not yet delivered when a new session starts are dropped. A request that got no answer is retried, so a record can arrive more than once. It carries no order id: a repeat is identical, and `bid` and `at` together recognise it. An order is only recorded when the store's bundles were received in the same session. Off unless a target sets `store_orders`. | +| Alliance | Sync the player's own alliance league and level (two numbers; no alliance id, name or members). Off unless a target sets `alliance`. | | Profile | Your own level, XP, Power and Haven unlock. Other players' records are never sent. Off unless a target sets `profile`. | | Mission requirements | Acceptance requirements of the mission specs the client receives (login, active missions, and systems you enter). Off unless a target sets `mission_requirements`. | diff --git a/docs/configuration/example_community_patch_settings_en.toml b/docs/configuration/example_community_patch_settings_en.toml index 7b1fac42d..32ea027f9 100644 --- a/docs/configuration/example_community_patch_settings_en.toml +++ b/docs/configuration/example_community_patch_settings_en.toml @@ -958,6 +958,9 @@ show_station_cargo = true # Subgroup: Data # -------------- +# Sync the player's own alliance league and level (two numbers; no alliance id, name or members). +alliance = false + # Do you want to sync away team assignment data? away_assignments = true diff --git a/src/mod/config.h b/src/mod/config.h index ed5ddcf3b..e34b31f65 100644 --- a/src/mod/config.h +++ b/src/mod/config.h @@ -28,6 +28,7 @@ struct SyncConfig { std::string proxy; bool verify_ssl = true; + bool alliance = false; bool away_assignments = false; bool battlelogs = false; bool buffs = false; @@ -55,6 +56,7 @@ struct SyncConfig { // Every category, as [sync] and [sync.targets.] spell it. constexpr auto SyncOptions = std::to_array({ + {"alliance", &SyncConfig::alliance}, {"away_assignments", &SyncConfig::away_assignments}, {"battlelogs", &SyncConfig::battlelogs}, {"buffs", &SyncConfig::buffs}, diff --git a/src/mod/sync/records.cc b/src/mod/sync/records.cc index 5a7755018..9c3a609eb 100644 --- a/src/mod/sync/records.cc +++ b/src/mod/sync/records.cc @@ -730,6 +730,7 @@ namespace {EntityGroup::Kind::BattleResultHeaders, ProcessBattleHeaders, true}, {EntityGroup::Kind::UserProfiles, CachePlayerNames, true}, {EntityGroup::Kind::AllianceProfiles, CacheAllianceNames, true}, + {EntityGroup::Kind::AllianceDetails, ProcessAllianceLeague}, {EntityGroup::Kind::GlobalActiveBuffs, ProcessBuffs}, {EntityGroup::Kind::AllianceGetGameProperties, ProcessAllianceGameProperties}, {EntityGroup::Kind::StarbaseModules, ProcessStarbaseModules}, @@ -828,6 +829,12 @@ namespace {"valid_until", until}, {"cooldown", details.cooldownconfigured()}}; } + // The alliance the own profile record listed in this session, kept for ProcessAllianceLeague. Both processors run + // on the processing thread, in response order. + struct OwnAlliance { + uint64_t generation = 0; + int64_t id = 0; + } own_alliance; } // namespace // A realtime slot update: the same record as the protobuf EntitySlot, from the realtime channel's JSON. The cases @@ -1059,6 +1066,22 @@ void ProcessStoreOrders(const Input& input) Publish(Stream::kStoreOrders, std::move(records), input.generation); } +// AllianceDetails is an AllianceProfile. Only the league and level are kept: no id, name, tag, slogan or members. +// The group may describe an alliance the player is looking at, so it counts only when it is the alliance the own +// profile record lists; before that record has been read, nothing is sent. Nothing resets the record, so after +// leaving an alliance the last league and level stay for the session. +void ProcessAllianceLeague(const Input& input) +{ + const auto parsed = Parse(input, "alliance details"); + if (!parsed) + return; + if (own_alliance.generation != input.generation || own_alliance.id == 0 || parsed->id() != own_alliance.id) + return; + RecordSet records; + records["alliance_league"] = {{"league", parsed->league()}, {"level", parsed->level()}}; + Publish(Stream::kAlliance, std::move(records), input.generation); +} + // UserProfiles responses also list other players; only the local player's record is read. The level is the in-memory // Level captured with the response: it lags one own-record response after a level-up. (The record's own level is a // fixed32 field; it read 0 while it was declared as a varint.) @@ -1072,6 +1095,7 @@ void ProcessOwnProfile(const Input& input) profiles, [&input](const pb::UserProfile& profile) { return profile.userid() == input.user_id; }); if (own == profiles.end()) return; + own_alliance = {input.generation, own->allianceid()}; RecordSet records; records[input.user_id] = {{"uid", input.user_id}, {"level", input.level}, diff --git a/src/mod/sync/state.cc b/src/mod/sync/state.cc index 22f3ef3dd..02522c115 100644 --- a/src/mod/sync/state.cc +++ b/src/mod/sync/state.cc @@ -33,6 +33,7 @@ namespace size_t journal = 0; }; constexpr std::array kStreams{ + Spec{Stream::kAlliance, &SyncConfig::alliance, "alliance_league"}, Spec{Stream::kAway, &SyncConfig::away_assignments, "away_assignment", FullSync::kInitial, "collected_away_assignment", "aid"}, Spec{Stream::kBattles, &SyncConfig::battlelogs, "battlelog", FullSync::kNever, nullptr, nullptr, kRecentBattles}, diff --git a/src/mod/sync/sync.h b/src/mod/sync/sync.h index a9efc8e71..e0a23d539 100644 --- a/src/mod/sync/sync.h +++ b/src/mod/sync/sync.h @@ -197,6 +197,7 @@ template class NameCache // One stream per wire record type. Player and alliance resources, and active and completed missions, are separate // streams because the wire protocol keeps them apart. enum class Stream { + kAlliance, kAway, kBattles, kBuffs, @@ -450,6 +451,8 @@ void ProcessStoreOffers(const Input& input); void ProcessStoreBundles(const Input& input); void ProcessStoreOrder(const Input& input); void ProcessStoreOrders(const Input& input); +// The own alliance's league and level from an AllianceDetails response; needs the own profile to have been read. +void ProcessAllianceLeague(const Input& input); // The local player's own record from a UserProfiles response; needs user_id and level. void ProcessOwnProfile(const Input& input); diff --git a/tests/sync_logic.cc b/tests/sync_logic.cc index b62bb4e71..4f0e65e58 100644 --- a/tests/sync_logic.cc +++ b/tests/sync_logic.cc @@ -1548,6 +1548,60 @@ void StoreOrderLists() list({OrderBytes("list-n", {30})}); Check(!Drain(other).contains("store_order"), "a target without store_orders receives no orders"); } +std::string AllianceBytes(int64_t id, int32_t league, int32_t level) +{ + game::AllianceProfile profile; + profile.set_id(id); + profile.set_name("name"); + profile.set_tag("tag"); + profile.set_slogan("slogan"); + profile.set_league(league); + profile.set_level(level); + return profile.SerializeAsString(); +} +void AllianceLeague() +{ + auto target = Target(); + const auto league = [](const std::string& bytes) { ProcessAllianceLeague({store.Generation(), bytes}); }; + league(AllianceBytes(55, 4, 45)); + Check(!Drain(target).contains("alliance_league"), "nothing is sent before the own alliance is known"); + + game::UserProfilesResponse profiles; + auto* own = profiles.add_userprofiles(); + own->set_userid("me"); + own->set_allianceid(55); + ProcessOwnProfile({store.Generation(), profiles.SerializeAsString(), "me", 10}); + Drain(target); + + league(AllianceBytes(66, 3, 9)); + Check(!Drain(target).contains("alliance_league"), "another alliance sends nothing"); + league(AllianceBytes(55, 4, 45)); + const auto first = Drain(target); + Check(first.contains("alliance_league") && first.at("alliance_league").size() == 1 + && first.at("alliance_league")[0] == json::parse(R"({"type":"alliance_league","league":4,"level":45})"), + "only the league and level are sent"); + league(AllianceBytes(55, 4, 45)); + Check(!Drain(target).contains("alliance_league"), "unchanged values are sent once"); + league(AllianceBytes(55, 5, 45)); + const auto second = Drain(target); + Check(second.contains("alliance_league") && second.at("alliance_league")[0].at("league") == 5, + "a changed league is sent again"); + league(AllianceBytes(66, 1, 1)); + Check(!Drain(target).contains("alliance_league"), "another alliance does not overwrite the own one"); + + // A new session forgets the alliance the previous one learned. + store.Reset(); + league(AllianceBytes(55, 4, 45)); + Check(!Drain(target).contains("alliance_league"), "the own alliance of an earlier session is ignored"); + + // An own profile that lists no alliance matches no alliance. + game::UserProfilesResponse alone; + alone.add_userprofiles()->set_userid("me"); + ProcessOwnProfile({store.Generation(), alone.SerializeAsString(), "me", 10}); + league(AllianceBytes(0, 4, 45)); + league(AllianceBytes(55, 4, 45)); + Check(!Drain(target).contains("alliance_league"), "an own profile without an alliance sends nothing"); +} void ProtobufJournals() { const auto body = BattleReportBody(SyntheticJournal()); @@ -1696,6 +1750,7 @@ int main() run("store bundles", StoreBundles); run("store orders", StoreOrders); run("store order lists", StoreOrderLists); + run("alliance league", AllianceLeague); if (!failures) std::cout << "Sync wire and delivery tests passed\n"; return failures ? 1 : 0;