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 @@ -104,6 +104,7 @@ Each target has its own options and access token.
| Fleets | Live fleet state: each state change with cargo, mining and timers, and the server's view of deployed fleets. Every change is sent, not just the latest; up to 300 per session. Off unless a target sets `fleets`. |
| Store | Faction store offers: favor level prices, requirements and remaining purchases. Off unless a target sets `store_offers`. |
| 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`. |

Failed uploads retry with the latest observed values.
Target changes apply on reload and trigger a fresh snapshot.
Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_da.toml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Vil du synkronisere opgavedata?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Vil du synkronisere missionsdata?
missions = true

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Auftragsdaten synchronisieren?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Missionsdaten synchronisieren?
missions = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Do you want to sync jobs data?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Do you want to sync mission data?
missions = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Do you want to sync jobs data?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Do you want to sync mission data?
missions = true

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 @@ -964,6 +964,9 @@ inventory = true
# Do you want to sync jobs data?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Do you want to sync mission data?
missions = true

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_es.toml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# ¿Quieres sincronizar los datos de trabajos?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# ¿Quieres sincronizar los datos de misiones?
missions = true

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Voulez-vous synchroniser les données de tâches ?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Voulez-vous synchroniser les données des missions ?
missions = true

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_nl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Wil je data van je banen syncen?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Wil je data van missies syncen?
missions = true

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_ru.toml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Синхронизировать данные задач?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Синхронизировать данные заданий?
missions = true

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration/example_community_patch_settings_tlh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,9 @@ inventory = true
# Do you want Daq sync jobs De'?
jobs = true

# Sync mission acceptance requirement data. Requires mod 1.1.11 or newer.
mission_requirements = false

# Do you want Daq sync mission De'?
missions = true

Expand Down
40 changes: 21 additions & 19 deletions src/mod/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ struct SyncConfig {
};

std::string proxy;
bool verify_ssl = true;
bool away_assignments = false;
bool battlelogs = false;
bool buffs = false;
bool buildings = false;
bool fleets = false;
bool haven = false;
bool inventory = false;
bool jobs = false;
bool missions = false;
bool officers = false;
bool profile = false;
bool research = false;
bool resources = false;
bool ships = false;
bool slots = false;
bool store_offers = false;
bool tech = false;
bool traits = false;
bool verify_ssl = true;
bool away_assignments = false;
bool battlelogs = false;
bool buffs = false;
bool buildings = false;
bool fleets = false;
bool haven = false;
bool inventory = false;
bool jobs = false;
bool mission_requirements = false;
bool missions = false;
bool officers = false;
bool profile = false;
bool research = false;
bool resources = false;
bool ships = false;
bool slots = false;
bool store_offers = false;
bool tech = false;
bool traits = false;

bool operator==(const SyncConfig&) const = default;
};
Expand All @@ -60,6 +61,7 @@ constexpr auto SyncOptions = std::to_array<SyncConfig::Option>({
{"haven", &SyncConfig::haven},
{"inventory", &SyncConfig::inventory},
{"jobs", &SyncConfig::jobs},
{"mission_requirements", &SyncConfig::mission_requirements},
{"missions", &SyncConfig::missions},
{"officers", &SyncConfig::officers, "officer"},
{"profile", &SyncConfig::profile},
Expand Down
109 changes: 94 additions & 15 deletions src/mod/sync/records.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ namespace
json Seconds(bool has, int64_t seconds)
{ return has ? json(seconds) : json(nullptr); }

// 1234 not 1234.0, and 14.364 not 14.36400032043457.
json ShortNumber(float value)
{
if (std::trunc(value) == value && std::abs(value) < 9.0e15f)
return static_cast<int64_t>(value);
char buffer[32];
double widened = value;
if (const auto [end, ec] = std::to_chars(std::begin(buffer), std::end(buffer), value); ec == std::errc{}) {
// Float from_chars needs macOS 26 in Apple's libc++; the JSON parser reads the shortest form back instead.
if (auto parsed = json::parse(std::begin(buffer), end, nullptr, false); parsed.is_number())
return parsed;
}
return widened;
}

json AwayAssignment(const pb::AwayAssignmentInstance& instance)
{
// Protobuf maps are unordered; both lists go out in key order.
Expand Down Expand Up @@ -286,6 +301,83 @@ namespace
records[id] = {{"mid", id}};
});
}
// Requirement types: 3 {v: mission id}; 2 {m: module type, v: level}; 7 {min, max}; 8 {f: faction id, v: amount};
// 0 and 1 {s: core stat, v}; 4 {h: hull type, v}; 5 {g: grade, v}; 6 {c: component, v}. An unset oneof is {t} only.
json Requirement(const pb::MissionRequirement& requirement)
{
json out{{"t", static_cast<int>(requirement.type())}};
switch (requirement.Params_case()) {
case pb::MissionRequirement::kAllOfficersCoreStatTotalParams: {
const auto& p = requirement.allofficerscorestattotalparams();
out.update({{"s", static_cast<int>(p.type())}, {"v", p.value()}});
break;
}
case pb::MissionRequirement::kAtLeastOneOfficerWithCoreStatParams: {
const auto& p = requirement.atleastoneofficerwithcorestatparams();
out.update({{"s", static_cast<int>(p.type())}, {"v", p.value()}});
break;
}
case pb::MissionRequirement::kStarbaseModuleLevelParams: {
const auto& p = requirement.starbasemodulelevelparams();
out.update({{"m", p.type()}, {"v", p.value()}});
break;
}
case pb::MissionRequirement::kPreviouslyCompletedMissionParams:
out["v"] = requirement.previouslycompletedmissionparams().value();
break;
case pb::MissionRequirement::kHullTypeParams: {
const auto& p = requirement.hulltypeparams();
out.update({{"h", static_cast<int>(p.type())}, {"v", p.value()}});
break;
}
case pb::MissionRequirement::kHullGradeParams: {
const auto& p = requirement.hullgradeparams();
out.update({{"g", p.grade()}, {"v", p.value()}});
break;
}
case pb::MissionRequirement::kComponentValueParams: {
const auto& p = requirement.componentvalueparams();
out.update({{"c", p.type()}, {"v", ShortNumber(p.value())}});
break;
}
case pb::MissionRequirement::kPlayerLevelRangeParams: {
const auto& p = requirement.playerlevelrangeparams();
out.update({{"min", p.minvalue()}, {"max", p.maxvalue()}});
break;
}
case pb::MissionRequirement::kFactionStandingParams: {
const auto& p = requirement.factionstandingparams();
out.update({{"f", p.id()}, {"v", p.amount()}});
break;
}
case pb::MissionRequirement::PARAMS_NOT_SET:
break;
}
return out;
}
// One record per spec, empty lists too, so a target can tell "needs nothing" from "unseen". Specs are static game
// data: the store sends a spec once, and again only when its list changes.
void AddRequirements(const google::protobuf::RepeatedPtrField<pb::Mission>& specs, RecordSet& records)
{
for (const auto& spec : specs) {
auto req = json::array();
for (const auto& requirement : spec.acceptancerequirements())
req.push_back(Requirement(requirement));
records[spec.id()] = {{"mid", spec.id()}, {"req", std::move(req)}};
}
}
void ProcessMissionSpecs(const Input& input)
{
Read<pb::MissionSpecsResponse>(input, Stream::kMissionRequirements, [](const auto& response, auto& records) {
AddRequirements(response.missionspecs(), records);
});
}
void ProcessNodeMissions(const Input& input)
{
Read<pb::NodeMissionsResponse>(input, Stream::kMissionRequirements, [](const auto& response, auto& records) {
AddRequirements(response.missionspecs(), records);
});
}
void ProcessOfficers(const Input& input)
{
Read<pb::OfficersResponse>(input, Stream::kOfficers, [](const auto& response, auto& records) {
Expand Down Expand Up @@ -531,21 +623,6 @@ namespace
}
}

// 1234 not 1234.0, and 14.364 not 14.36400032043457.
json ShortNumber(float value)
{
if (std::trunc(value) == value && std::abs(value) < 9.0e15f)
return static_cast<int64_t>(value);
char buffer[32];
double widened = value;
if (const auto [end, ec] = std::to_chars(std::begin(buffer), std::end(buffer), value); ec == std::errc{}) {
// Float from_chars needs macOS 26 in Apple's libc++; the JSON parser reads the shortest form back instead.
if (auto parsed = json::parse(std::begin(buffer), end, nullptr, false); parsed.is_number())
return parsed;
}
return widened;
}

using StatMap = google::protobuf::Map<int32_t, float>;

std::optional<float> Stat(const StatMap& stats, pb::ClientModifierType key)
Expand Down Expand Up @@ -665,6 +742,8 @@ namespace
{EntityGroup::Kind::Jobs, ProcessJobs},
{EntityGroup::Kind::ActiveMissions, ProcessActiveMissions},
{EntityGroup::Kind::CompletedMissions, ProcessCompletedMissions},
{EntityGroup::Kind::MissionSpecs, ProcessMissionSpecs},
{EntityGroup::Kind::NodeMissions, ProcessNodeMissions},
{EntityGroup::Kind::Officers, ProcessOfficers},
{EntityGroup::Kind::ResearchTreesState, ProcessResearch},
{EntityGroup::Kind::Resources, ProcessResources},
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 @@ -46,6 +46,7 @@ namespace
Spec{Stream::kJobs, &SyncConfig::jobs, "job", FullSync::kInitial, "completed_job", "uuid"},
Spec{Stream::kActiveMissions, &SyncConfig::missions, "active_mission"},
Spec{Stream::kCompletedMissions, &SyncConfig::missions, "mission"},
Spec{Stream::kMissionRequirements, &SyncConfig::mission_requirements, "mission_requirement"},
Spec{Stream::kOfficers, &SyncConfig::officers, "officer"},
Spec{Stream::kProfile, &SyncConfig::profile, "profile", FullSync::kInitial},
Spec{Stream::kResearch, &SyncConfig::research, "research"},
Expand Down
2 changes: 2 additions & 0 deletions src/mod/sync/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ enum class Stream {
kJobs,
kActiveMissions,
kCompletedMissions,
// Static acceptance requirements of the mission specs the client receives, one record per spec.
kMissionRequirements,
kOfficers,
kProfile,
kResearch,
Expand Down
46 changes: 46 additions & 0 deletions tests/sync_logic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,51 @@ void AwayAndEmerald()
Process(EntityGroup::Kind::AllianceGetGameProperties, unclaimed);
Check(Send(target) == json::parse(R"([{"type":"emerald_chain","level":-1}])"), "no claimed tier is level -1");
}
void MissionRequirements()
{
auto target = Target();
game::MissionSpecsResponse specs;
auto* gated = specs.add_missionspecs();
gated->set_id(20);
auto* requirement = gated->add_acceptancerequirements();
requirement->set_type(game::MISSIONREQUIREMENTTYPE_SPREVIOUSLYCOMPLETEDMISSION);
requirement->mutable_previouslycompletedmissionparams()->set_value(10);
auto* ungated = specs.add_missionspecs();
ungated->set_id(21);
Process(EntityGroup::Kind::MissionSpecs, specs);
Delivery missions_only;
auto options = Options();
options.mission_requirements = false;
missions_only.Configure(options);
Check(!missions_only.Next(store, now), "mission requirements are opt-in, not part of missions");
Check(
Send(target)
== json::parse(
R"([{"type":"mission_requirement","mid":20,"req":[{"t":3,"v":10}]},{"type":"mission_requirement","mid":21,"req":[]}])"),
"mission requirement wire fixture, empty list kept");
Process(EntityGroup::Kind::MissionSpecs, specs);
Check(!target.Next(store, now), "unchanged mission specs are not uploaded again");
auto* range = ungated->add_acceptancerequirements();
range->set_type(game::MISSIONREQUIREMENTTYPE_SPLAYERLEVELRANGE);
range->mutable_playerlevelrangeparams()->set_minvalue(5);
range->mutable_playerlevelrangeparams()->set_maxvalue(60);
Process(EntityGroup::Kind::MissionSpecs, specs);
Check(Send(target) == json::parse(R"([{"type":"mission_requirement","mid":21,"req":[{"t":7,"min":5,"max":60}]}])"),
"a changed requirement list is sent again, alone");
game::NodeMissionsResponse node;
auto* entered = node.add_missionspecs();
entered->set_id(22);
auto* component = entered->add_acceptancerequirements();
component->set_type(game::MISSIONREQUIREMENTTYPE_SCOMPONENTVALUE);
component->mutable_componentvalueparams()->set_type("warp");
component->mutable_componentvalueparams()->set_value(14.364f);
Process(EntityGroup::Kind::NodeMissions, node);
Check(Send(target)
== json::parse(R"([{"type":"mission_requirement","mid":22,"req":[{"t":6,"c":"warp","v":14.364}]}])"),
"a system's mission specs are sent, floats in shortest form");
Check(store.Contains(Stream::kMissionRequirements, 20) && store.Contains(Stream::kMissionRequirements, 21),
"and merge with the login specs instead of replacing them");
}
void Snapshots()
{
auto target = Target();
Expand Down Expand Up @@ -797,6 +842,7 @@ int main()
run("presets", Presets);
run("slot transports", SlotTransports);
run("away and emerald", AwayAndEmerald);
run("mission requirements", MissionRequirements);
run("snapshots", Snapshots);
run("removals", EmptyAndRemoved);
run("jobs", Jobs);
Expand Down
2 changes: 2 additions & 0 deletions zig/deps/protobuf_roots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Digit.PrimeServer.Models.GlobalActiveBuffsResponse
Digit.PrimeServer.Models.InventoryResponse
Digit.PrimeServer.Models.Job
Digit.PrimeServer.Models.JobResponse
Digit.PrimeServer.Models.MissionSpecsResponse
# Declared by the mod in stfc.sync.proto; the game has no message for the MyDeployedFleets payload.
Digit.PrimeServer.Models.MyDeployedFleetsResponse
Digit.PrimeServer.Models.NodeMissionsResponse
Digit.PrimeServer.Models.OfficerTraitsResponse
Digit.PrimeServer.Models.OfficersResponse
Digit.PrimeServer.Models.PlanetaryBase
Expand Down
Loading