diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index 519b7050b..091dded8f 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -13,7 +13,7 @@ namespace Common { struct WebResult { - enum Code : u32 { + enum class Code : u32 { Success, InvalidURL, CredentialsMissing, @@ -39,7 +39,7 @@ struct Room { u64 game_id; }; std::string name; - std::string GUID; + std::string UID; std::string owner; std::string ip; u16 port; @@ -60,8 +60,8 @@ using RoomList = std::vector; class Backend : NonCopyable { public: virtual ~Backend() = default; - virtual void SetRoomInformation(const std::string& guid, const std::string& name, - const u16 port, const u32 max_player, const u32 net_version, + virtual void SetRoomInformation(const std::string& uid, const std::string& name, const u16 port, + const u32 max_player, const u32 net_version, const bool has_password, const std::string& preferred_game, const u64 preferred_game_id) = 0; virtual void AddPlayer(const std::string& nickname, const MacAddress& mac_address, @@ -79,7 +79,7 @@ public: class NullBackend : public Backend { public: ~NullBackend() = default; - void SetRoomInformation(const std::string& /*guid*/, const std::string& /*name*/, + void SetRoomInformation(const std::string& /*uid*/, const std::string& /*name*/, const u16 /*port*/, const u32 /*max_player*/, const u32 /*net_version*/, const bool /*has_password*/, const std::string& /*preferred_game*/, const u64 /*preferred_game_id*/) override {} diff --git a/src/core/announce_multiplayer_session.cpp b/src/core/announce_multiplayer_session.cpp index 5cc2781a9..a3ba78d78 100644 --- a/src/core/announce_multiplayer_session.cpp +++ b/src/core/announce_multiplayer_session.cpp @@ -77,29 +77,30 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { finished = false; std::future future; while (announce) { - if (std::shared_ptr room = Network::GetRoom().lock()) { - if (room->GetState() == Network::Room::State::Open) { - Network::RoomInformation room_information = room->GetRoomInformation(); - std::vector memberlist = room->GetRoomMemberList(); - backend->SetRoomInformation( - room_information.guid, room_information.name, room_information.port, - room_information.member_slots, Network::network_version, room->HasPassword(), - room_information.preferred_game, room_information.preferred_game_id); - backend->ClearPlayers(); - for (const auto& member : memberlist) { - backend->AddPlayer(member.nickname, member.mac_address, member.game_info.id, - member.game_info.name); - } - future = backend->Announce(); - } else { - announce = false; - } - } else { + std::shared_ptr room = Network::GetRoom().lock(); + if (!room) { announce = false; + continue; } + if (room->GetState() != Network::Room::State::Open) { + announce = false; + continue; + } + Network::RoomInformation room_information = room->GetRoomInformation(); + std::vector memberlist = room->GetRoomMemberList(); + backend->SetRoomInformation( + room_information.uid, room_information.name, room_information.port, + room_information.member_slots, Network::network_version, room->HasPassword(), + room_information.preferred_game, room_information.preferred_game_id); + backend->ClearPlayers(); + for (const auto& member : memberlist) { + backend->AddPlayer(member.nickname, member.mac_address, member.game_info.id, + member.game_info.name); + } + future = backend->Announce(); if (future.valid()) { Common::WebResult result = future.get(); - if (result.result_code != Common::WebResult::Success) { + if (result.result_code != Common::WebResult::Code::Success) { std::lock_guard lock(callback_mutex); for (auto callback : error_callbacks) { (*callback)(result); diff --git a/src/web_service/announce_room_json.cpp b/src/web_service/announce_room_json.cpp index b8af09720..d2b79cbae 100644 --- a/src/web_service/announce_room_json.cpp +++ b/src/web_service/announce_room_json.cpp @@ -23,7 +23,7 @@ void from_json(const nlohmann::json& json, Room::Member& member) { } void to_json(nlohmann::json& json, const Room& room) { - json["id"] = room.GUID; + json["id"] = room.UID; json["port"] = room.port; json["name"] = room.name; json["preferredGameName"] = room.preferred_game; @@ -58,12 +58,12 @@ void from_json(const nlohmann::json& json, Room& room) { namespace WebService { -void RoomJson::SetRoomInformation(const std::string& guid, const std::string& name, const u16 port, +void RoomJson::SetRoomInformation(const std::string& uid, const std::string& name, const u16 port, const u32 max_player, const u32 net_version, const bool has_password, const std::string& preferred_game, const u64 preferred_game_id) { room.name = name; - room.GUID = guid; + room.UID = uid; room.port = port; room.max_player = max_player; room.net_version = net_version; @@ -105,7 +105,7 @@ std::future RoomJson::GetRoomList(std::functi void RoomJson::Delete() { nlohmann::json json; - json["id"] = room.GUID; + json["id"] = room.UID; DeleteJson(endpoint_url, json.dump(), username, token); } diff --git a/src/web_service/announce_room_json.h b/src/web_service/announce_room_json.h index 907a76b3a..85550e838 100644 --- a/src/web_service/announce_room_json.h +++ b/src/web_service/announce_room_json.h @@ -20,7 +20,7 @@ public: RoomJson(const std::string& endpoint_url, const std::string& username, const std::string& token) : endpoint_url(endpoint_url), username(username), token(token) {} ~RoomJson() = default; - void SetRoomInformation(const std::string& guid, const std::string& name, const u16 port, + void SetRoomInformation(const std::string& uid, const std::string& name, const u16 port, const u32 max_player, const u32 net_version, const bool has_password, const std::string& preferred_game, const u64 preferred_game_id) override; diff --git a/src/web_service/telemetry_json.cpp b/src/web_service/telemetry_json.cpp index 642c2617a..28ae0d34e 100644 --- a/src/web_service/telemetry_json.cpp +++ b/src/web_service/telemetry_json.cpp @@ -81,9 +81,8 @@ void TelemetryJson::Complete() { SerializeSection(Telemetry::FieldType::UserConfig, "UserConfig"); SerializeSection(Telemetry::FieldType::UserSystem, "UserSystem"); - // Send the telemetry async but don't handle the errors since the were written to the log - static std::future future = - PostJson(endpoint_url, TopSection().dump(), true, username, token); + // Send the telemetry async but don't handle the errors since they were written to the log + future = PostJson(endpoint_url, TopSection().dump(), true, username, token); } } // namespace WebService diff --git a/src/web_service/telemetry_json.h b/src/web_service/telemetry_json.h index 9e78c6803..ae4a6f3c7 100644 --- a/src/web_service/telemetry_json.h +++ b/src/web_service/telemetry_json.h @@ -5,8 +5,10 @@ #pragma once #include +#include #include #include +#include "common/announce_multiplayer_room.h" #include "common/telemetry.h" namespace WebService { @@ -54,6 +56,7 @@ private: std::string endpoint_url; std::string username; std::string token; + std::future future; }; } // namespace WebService