Просмотр исходного кода

Read the score the record actually carries

The extraction never read record row +92, so every claim scored zero however many points its
record was worth. The claim log made it look like the records were worthless rather than unread.

Read the score into the domain the way the completion flag already is.

This was lost rather than never written. The read went in, was confirmed working in play, and was
then discarded by a git checkout that reverted an unrelated probe sharing the file while the read
was still uncommitted. Every commit since carried the offset constant and no use of it.

Both caches have to be cleared for this: build_data.bin holds records extracted without the score,
and record_claims.bin holds claims that scored zero.
Millie 2 недель назад
Родитель
Сommit
f96d4d9f18

+ 4 - 0
Sunrise/src/client/content/items/packages/package_record_build.cpp

@@ -104,9 +104,13 @@ bool build_records(const reader::Source& source,
         std::memcpy(&slot,
                     blob.data() + at + tables::kRecordCompletionFlagOffset,
                     sizeof slot);
+        std::uint32_t score = 0;
+        std::memcpy(&score, blob.data() + at + tables::kRecordScoreOffset, sizeof score);
         domain::Definition& definition = output[static_cast<std::size_t>(row)];
         definition = {};
         definition.definitionIndex = static_cast<std::uint16_t>(row);
+        // The shipped table tops out at 500, so anything wider is not a score and is dropped.
+        definition.scoreValue = score <= 0xFFFFU ? static_cast<std::uint16_t>(score) : 0U;
         if (addressable_slot(slot) && static_cast<std::size_t>(slot) < kSlotSpace) {
             definition.completionFlagIndex = indexBySlot[static_cast<std::size_t>(slot)];
         }

+ 28 - 13
Sunrise/src/server/web_service/web_service_actions.cpp

@@ -673,13 +673,14 @@ void report_record_claim(const middleware::web_service::Message& message,
                          std::string_view result,
                          std::string_view reason,
                          std::uint32_t recordIndex,
-                         std::uint32_t completionFlagIndex) noexcept {
+                         std::uint32_t completionFlagIndex,
+                         std::uint32_t scoreValue) noexcept {
     std::array<char, core::log::kLineCapacity> line{};
     const int count = std::snprintf(
         line.data(),
         line.size(),
         "ev=ws1801 stage=claim result=%.*s reason=%.*s transaction=%u payload_bytes=%zu "
-        "record_index=%u completion_flag_index=%u",
+        "record_index=%u completion_flag_index=%u score=%u total_score=%u claims=%zu",
         static_cast<int>(result.size()),
         result.data(),
         static_cast<int>(reason.size()),
@@ -687,7 +688,10 @@ void report_record_claim(const middleware::web_service::Message& message,
         static_cast<unsigned>(message.transactionId),
         message.payload.size(),
         recordIndex,
-        completionFlagIndex);
+        completionFlagIndex,
+        scoreValue,
+        state::record_claims::total_score(),
+        state::record_claims::count());
     if (count > 0) {
         core::log::write(core::log::Channel::server,
                          result == "ok" ? core::log::Level::debug : core::log::Level::warn,
@@ -852,21 +856,27 @@ void claim_record(const middleware::web_service::Message& message, Outcome& outc
     namespace records = state::build_data::records;
     middleware::web_service::messages::opcode1801::Request request{};
     if (!middleware::web_service::messages::opcode1801::parse_request(message, request)) {
-        report_record_claim(message, "fail", "payload_bits", 0, records::kUnavailableFlagIndex);
+        report_record_claim(message, "fail", "payload_bits", 0, records::kUnavailableFlagIndex, 0);
         return;
     }
     records::Definition definition{};
     if (!state::build_data::find_record_definition(request.recordIndex, definition)) {
-        report_record_claim(
-            message, "fail", "record_definition", request.recordIndex,
-            records::kUnavailableFlagIndex);
+        report_record_claim(message,
+                            "fail",
+                            "record_definition",
+                            request.recordIndex,
+                            records::kUnavailableFlagIndex,
+                            0);
         return;
     }
     if (definition.completionFlagIndex == records::kUnavailableFlagIndex) {
         // The record carries no completion flag, or its slot has no row in the account bank.
-        report_record_claim(
-            message, "fail", "no_completion_flag", request.recordIndex,
-            records::kUnavailableFlagIndex);
+        report_record_claim(message,
+                            "fail",
+                            "no_completion_flag",
+                            request.recordIndex,
+                            records::kUnavailableFlagIndex,
+                            definition.scoreValue);
         return;
     }
     if (!state::record_claims::claim(definition.completionFlagIndex, definition.scoreValue)) {
@@ -874,13 +884,18 @@ void claim_record(const middleware::web_service::Message& message, Outcome& outc
                             "fail",
                             "flag_index_range",
                             request.recordIndex,
-                            definition.completionFlagIndex);
+                            definition.completionFlagIndex,
+                            definition.scoreValue);
         return;
     }
     // The claim is already in the store, so the account image only has to be sent again.
     outcome.hasRecordClaim = true;
-    report_record_claim(
-        message, "ok", "claimed", request.recordIndex, definition.completionFlagIndex);
+    report_record_claim(message,
+                        "ok",
+                        "claimed",
+                        request.recordIndex,
+                        definition.completionFlagIndex,
+                        definition.scoreValue);
 }
 
 } // namespace sunrise::server::web_service