in NearbyConnectionsCpp/app/src/main/cpp/NearbyConnection.cpp [589:628]
void Engine::UpdatePlayerScore(std::string const & endpoint_id,
int score, bool final) {
auto player = players_score_.find(endpoint_id);
if (player == players_score_.end()) {
LOGE("Error: player(%s) is not in my cache", endpoint_id.c_str());
DebugDumpConnections();
return;
}
if (player->second.score_ > score) {
LOGI("Score (%d) is lower than saved one(%d), no action", score,
player->second.score_);
return;
}
player->second.score_ = score;
player->second.finished_ = final;
if (!player->second.is_host_) {
// I am not a host for this link, done
return;
}
//broadcast the score to all others connected to me
std::vector<uint8_t> payload;
if (BuildScorePayload(payload, score, endpoint_id, final) == false) {
LOGE("failed to build payload for player %s:", endpoint_id.c_str());
return;
}
auto *this_player = &player->second;
for (player = players_score_.begin(); player != players_score_.end();
++player) {
if (player->first == this_player->endpoint_id_ ||
!player->second.is_direct_connection_ || !player->second.is_host_) {
continue; // do not send back for his own score
}
LOGV("Sending(%s) for %s score = %d", player->first.c_str(),
endpoint_id.c_str(), this_player->score_);
nearby_connection_->SendUnreliableMessage(player->first, payload);
}
}