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 CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ It uses text matching. Runtime type checks and in-game validation remain necessa
| `sync/state.cc` | Comparisons, removals, and per-target acknowledgements |
| `sync/upload.cc` | Sessions, the record store, target workers, and HTTP delivery |
| `sync/battlelogs.cc` | Battle-journal fetching |
| `sync/journal.cc` | Protobuf battle journals rebuilt in the JSON journal shape |
| `sync/fleets.cc` | Client fleet records: slot polling, state changes, snapshots, and late re-reads, on the game thread |

Payload construction and HTTP run outside the store lock.
Expand Down
102 changes: 102 additions & 0 deletions src/mod/game/proto/Digit.PrimeServer.Models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5615,3 +5615,105 @@ message JournalHeaderProto {
message BattleResultHeadersResponse {
repeated JournalHeaderProto headers = 1;
}

// ===== Battle report (journal) messages for POST /journals/get. Recovered from the game client metadata and
// checked against live responses (2026-11-20). Wrapper: ServiceResponse.entityGroups[type == TYPE_BATTLEREPORT].group.
// Only new messages; existing messages are untouched. =====
// EntityGroup type 221 (TYPE_BATTLEREPORT) payload; response to POST /journals/get.
message JournalResponse {
int64 id = 1; // id
int64 battleDuration = 2; // battle_duration
google.protobuf.Timestamp battleTime = 3; // battle_time (seconds only on the wire)
int32 battleType = 4; // battle_type
bool initiatorWins = 5; // initiator_wins
bool initiatorFiredFirst = 6; // initiator_fired_first
string initiatorId = 7; // initiator_id
string targetId = 8; // target_id
int64 systemId = 9; // system_id
PlanetSlotsConfig.Slot coords = 10; // coords {float x=1, float y=2}
repeated string battleLog = 11; // battle_log: one python-repr number per element ("-96", "1.2000000000000002", "5.0")
JournalFleetData initiatorFleetData = 12; // initiator_fleet_data
JournalFleetData targetFleetData = 13; // target_fleet_data
map<int64, int64> resourcesDropped = 14; // resources_dropped
map<int64, int64> resourcesTransferred = 15; // resources_transferred
JournalChestDrop chestDrop = 16; // chest_drop
JournalContextData battleContextData = 17; // battle_context_data
}

message JournalFleetData {
int32 battleDataType = 1; // battle_data_type
int32 cargoMax = 2; // cargo_max
int64 defenseRating = 3; // defense_rating
int64 healthRating = 4; // health_rating
int64 attackRating = 5; // attack_rating (old JSON key: offense_rating)
int64 officerRating = 6; // officer_rating
int32 numDrydocks = 7; // num_drydocks
repeated int64 hullIds = 8; // hull_ids (packed)
repeated int64 shipIds = 9; // ship_ids (packed)
repeated int64 initialShipHps = 10; // initial_ship_hps (packed)
repeated int64 finalShipHps = 11; // final_ship_hps (packed)
repeated int64 maxShipHps = 12; // max_ship_hps (packed)
repeated int64 initialShipShps = 13; // initial_ship_shps (packed)
repeated int64 finalShipShps = 14; // final_ship_shps (packed)
repeated int64 maxShipShps = 15; // max_ship_shps (packed)
repeated float initialShipLevelPercentages = 16;// initial_ship_level_percentages (packed fixed32)
repeated float finalShipLevelPercentages = 17; // final_ship_level_percentages (packed fixed32)
repeated int32 initialShipLevels = 18; // initial_ship_levels (packed)
repeated int32 finalShipLevels = 19; // final_ship_levels (packed)
CargoProto initialCargo = 20; // initial_cargo
CargoProto finalCargo = 21; // final_cargo
repeated JournalFleetOfficerEntry fleetsOfficers = 22; // fleets_officers (old JSON: {fleetId: [officer|null ...]})
map<int64, DeployedFleet> deployedFleets = 23; // deployed_fleets
DeployedFleet deployedFleet = 24; // deployed_fleet
repeated CargoProto initialCargoList = 25; // initial_cargo_list
repeated CargoProto finalCargoList = 26; // final_cargo_list
repeated int32 cargoMaxList = 27; // cargo_max_list (packed; -1 = 10-byte varint)
string armadaOwnerId = 28; // armada_owner_id
IdRefs refIds = 29; // ref_ids (NPC side only)
}

message JournalFleetOfficerEntry {
int64 fleetId = 1; // fleet_id
repeated BridgeCrewOfficer officers = 2; // officers
int32 crewSize = 3; // crew_size (10 in all samples)
}

message BridgeCrewOfficer {
int64 id = 1; // id
int32 level = 2; // level
int32 rank = 3; // rank
int64 slotIndex = 4; // slot_index (absent = slot 0)
}

message CargoProto {
map<int64, int64> resources = 1; // resources
}

message JournalChestDrop {
repeated InventoryItem chestsGained = 1; // chests_gained (wire: type, count, commonParams.refId only)
repeated InventoryItem chestsDiscarded = 2; // chests_discarded (not in old JSON)
int32 capacity = 3; // capacity (not in old JSON)
int32 currentCount = 4; // current_count (not in old JSON)
repeated IdRefs chestIdRefs = 5; // chest_id_refs
repeated string userIdRefs = 6; // user_id_refs
}

message JournalContextData {
JournalContextDataInner contextDataMapping = 1; // context_data_mapping (old JSON key: context_data)
}

message JournalContextDataInner {
JournalMultitargetArmadaInfo multitargetArmadaInformation = 1; // multitarget_armada_information (old: multi_target_armadas_info)
int32 flags = 2; // flags
JournalGalacticAnomalyData galacticAnomalyData = 3; // galactic_anomaly_data (never seen in old JSON)
}

message JournalMultitargetArmadaInfo {
int64 mtaId = 1; // mta_id (old: multi_armada_attack_id)
int32 mtaSize = 2; // mta_size (old: mta_group_size)
}

message JournalGalacticAnomalyData {
int64 tournamentId = 1; // tournament_id
map<int64, int64> systemBuffs = 2; // system_buffs
}
37 changes: 28 additions & 9 deletions src/mod/sync/battlelogs.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Battle logs: the game only sends battle headers, so each new battle's journal is fetched from the game server
// with the participants' player and alliance names resolved, then uploaded.

#include "sync/journal.h"
#include "sync/sync.h"
#include "version.h"

Expand Down Expand Up @@ -181,8 +182,9 @@ namespace
return response.text;
}

// The players in a battle. Fleet battles list them in deployed_fleets (fleet data with ref_ids is an NPC's);
// cracked stations have no fleet, so a base raid's defender only shows up in the journal's own ids.
// The players in a battle. Fleet battles list them in deployed_fleets, an object keyed by fleet id (fleet data
// with ref_ids is an NPC's); cracked stations have no fleet, so a base raid's defender only shows up in the
// journal's own ids.
std::unordered_set<std::string> Participants(const json& journal)
{
std::unordered_set<std::string> ids;
Expand All @@ -193,11 +195,15 @@ namespace
if (fleet == journal.end() || !fleet->is_object() || !fleet->value("ref_ids", json()).is_null())
continue;
const auto deployed_fleets = fleet->find("deployed_fleets");
if (deployed_fleets == fleet->end() || !deployed_fleets->is_array())
if (deployed_fleets == fleet->end() || !deployed_fleets->is_structured())
continue;
for (const auto& deployed : *deployed_fleets)
for (const auto& deployed : *deployed_fleets) {
if (!deployed.is_object())
continue;
if (const auto uid = deployed.find("uid"); uid != deployed.end() && uid->is_string())
ids.insert(uid->get<std::string>());
if (const auto& text = uid->get_ref<const std::string&>(); !text.empty())
ids.insert(text);
}
}
// NPC ids contain '_' (mar_61, npc_<id>_1); there is nothing to resolve for them.
for (const char* key : {"initiator_id", "target_id"})
Expand Down Expand Up @@ -303,10 +309,23 @@ namespace
const auto text = RequestGameData(session, "/journals/get", json{{"journal_id", battle.id}}.dump());
if (text.empty())
return false;
auto reply = json::parse(text, nullptr, false);
if (!reply.is_object() || !reply.contains("journal")) {
logging::Error("process", "battle log", "the journal of battle {} does not parse", battle.id);
return false;
json reply;
if (IsJsonBody(text)) {
reply = json::parse(text, nullptr, false);
if (!reply.is_object() || !reply.contains("journal")) {
logging::Error("process", "battle log", "the journal of battle {} does not parse", battle.id);
return false;
}
} else {
// Since 2026-11-19 the game server answers with protobuf; the journal is rebuilt in the JSON shape.
std::string error;
auto converted = JournalFromProtobuf(text, &error);
if (!converted) {
logging::Error("process", "battle log", "the protobuf journal of battle {} ({} bytes) does not convert: {}",
battle.id, text.size(), error);
return false;
}
reply = {{"journal", std::move(*converted)}};
}
auto& journal = reply["journal"];
auto names = ResolveNames(session, journal);
Expand Down
Loading
Loading