Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`. |

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/mod/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +56,7 @@ struct SyncConfig {

// Every category, as [sync] and [sync.targets.<name>] spell it.
constexpr auto SyncOptions = std::to_array<SyncConfig::Option>({
{"alliance", &SyncConfig::alliance},
{"away_assignments", &SyncConfig::away_assignments},
{"battlelogs", &SyncConfig::battlelogs},
{"buffs", &SyncConfig::buffs},
Expand Down
24 changes: 24 additions & 0 deletions src/mod/sync/records.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<pb::AllianceProfile>(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.)
Expand All @@ -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},
Expand Down
1 change: 1 addition & 0 deletions src/mod/sync/state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
3 changes: 3 additions & 0 deletions src/mod/sync/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ template <typename Key, typename Value> 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,
Expand Down Expand Up @@ -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);

Expand Down
55 changes: 55 additions & 0 deletions tests/sync_logic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
Loading