diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index 8773ce4dbb..2ff38b6cfc 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -15,27 +15,40 @@ namespace AnnounceMultiplayerRoom { using MacAddress = std::array; +struct Member { + std::string username; + std::string nickname; + std::string display_name; + std::string avatar_url; + MacAddress mac_address; + std::string game_name; + u64 game_id; +}; + +struct RoomInformation { + std::string name; ///< Name of the server + std::string description; ///< Server description + u32 member_slots; ///< Maximum number of members in this room + u16 port; ///< The port of this room + std::string preferred_game; ///< Game to advertise that you want to play + u64 preferred_game_id; ///< Title ID for the advertised game + std::string host_username; ///< Forum username of the host + bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room +}; + +struct GameInfo { + std::string name{""}; + u64 id{0}; +}; + struct Room { - struct Member { - std::string username; - std::string nickname; - std::string avatar_url; - MacAddress mac_address; - std::string game_name; - u64 game_id; - }; + RoomInformation information; + std::string id; std::string verify_UID; ///< UID used for verification - std::string name; - std::string description; - std::string owner; std::string ip; - u16 port; - u32 max_player; u32 net_version; bool has_password; - std::string preferred_game; - u64 preferred_game_id; std::vector members; }; @@ -71,9 +84,7 @@ public: * @param game_id The title id of the game the player plays * @param game_name The name of the game the player plays */ - virtual void AddPlayer(const std::string& username, const std::string& nickname, - const std::string& avatar_url, const MacAddress& mac_address, - const u64 game_id, const std::string& game_name) = 0; + virtual void AddPlayer(const Member& member) = 0; /** * Updates the data in the announce service. Re-register the room when required. @@ -116,9 +127,7 @@ public: 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 {} - void AddPlayer(const std::string& /*username*/, const std::string& /*nickname*/, - const std::string& /*avatar_url*/, const MacAddress& /*mac_address*/, - const u64 /*game_id*/, const std::string& /*game_name*/) override {} + void AddPlayer(const Member& /*member*/) override {} WebService::WebResult Update() override { return WebService::WebResult{WebService::WebResult::Code::NoWebservice, "WebService is missing", ""}; diff --git a/src/core/announce_multiplayer_session.cpp b/src/core/announce_multiplayer_session.cpp index aeca87aaca..f8aa9bb0b2 100644 --- a/src/core/announce_multiplayer_session.cpp +++ b/src/core/announce_multiplayer_session.cpp @@ -88,15 +88,14 @@ AnnounceMultiplayerSession::~AnnounceMultiplayerSession() { void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr room) { Network::RoomInformation room_information = room->GetRoomInformation(); - std::vector memberlist = room->GetRoomMemberList(); + std::vector memberlist = room->GetRoomMemberList(); backend->SetRoomInformation( room_information.name, room_information.description, 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.username, member.nickname, member.avatar_url, member.mac_address, - member.game_info.id, member.game_info.name); + backend->AddPlayer(member); } } diff --git a/src/network/room.cpp b/src/network/room.cpp index b82a757491..fe55d194c4 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp @@ -1066,8 +1066,8 @@ Room::BanList Room::GetBanList() const { return {room_impl->username_ban_list, room_impl->ip_ban_list}; } -std::vector Room::GetRoomMemberList() const { - std::vector member_list; +std::vector Room::GetRoomMemberList() const { + std::vector member_list; std::lock_guard lock(room_impl->member_mutex); for (const auto& member_impl : room_impl->members) { Member member; @@ -1076,7 +1076,8 @@ std::vector Room::GetRoomMemberList() const { member.display_name = member_impl.user_data.display_name; member.avatar_url = member_impl.user_data.avatar_url; member.mac_address = member_impl.mac_address; - member.game_info = member_impl.game_info; + member.game_name = member_impl.game_info.name; + member.game_id = member_impl.game_info.id; member_list.push_back(member); } return member_list; diff --git a/src/network/room.h b/src/network/room.h index df2253bf81..f282a5ac32 100644 --- a/src/network/room.h +++ b/src/network/room.h @@ -8,11 +8,17 @@ #include #include #include +#include "common/announce_multiplayer_room.h" #include "common/common_types.h" #include "network/verify_user.h" namespace Network { +using AnnounceMultiplayerRoom::GameInfo; +using AnnounceMultiplayerRoom::MacAddress; +using AnnounceMultiplayerRoom::Member; +using AnnounceMultiplayerRoom::RoomInformation; + constexpr u32 network_version = 1; ///< The version of this Room and RoomMember constexpr u16 DefaultRoomPort = 24872; @@ -24,23 +30,6 @@ static constexpr u32 MaxConcurrentConnections = 254; constexpr std::size_t NumChannels = 1; // Number of channels used for the connection -struct RoomInformation { - std::string name; ///< Name of the server - std::string description; ///< Server description - u32 member_slots; ///< Maximum number of members in this room - u16 port; ///< The port of this room - std::string preferred_game; ///< Game to advertise that you want to play - u64 preferred_game_id; ///< Title ID for the advertised game - std::string host_username; ///< Forum username of the host - bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room -}; - -struct GameInfo { - std::string name{""}; - u64 id{0}; -}; - -using MacAddress = std::array; /// A special MAC address that tells the room we're joining to assign us a MAC address /// automatically. constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; @@ -95,15 +84,6 @@ public: Closed, ///< The room is not opened and can not accept connections. }; - struct Member { - std::string nickname; ///< The nickname of the member. - std::string username; ///< The web services username of the member. Can be empty. - std::string display_name; ///< The web services display name of the member. Can be empty. - std::string avatar_url; ///< Url to the member's avatar. Can be empty. - GameInfo game_info; ///< The current game of the member - MacAddress mac_address; ///< The assigned mac address of the member. - }; - Room(); ~Room(); diff --git a/src/network/room_member.h b/src/network/room_member.h index ee1c921d46..c835ba8635 100644 --- a/src/network/room_member.h +++ b/src/network/room_member.h @@ -9,11 +9,15 @@ #include #include #include +#include "common/announce_multiplayer_room.h" #include "common/common_types.h" #include "network/room.h" namespace Network { +using AnnounceMultiplayerRoom::GameInfo; +using AnnounceMultiplayerRoom::RoomInformation; + /// Information about the received WiFi packets. /// Acts as our own 802.11 header. struct WifiPacket { diff --git a/src/web_service/announce_room_json.cpp b/src/web_service/announce_room_json.cpp index 984a59f777..84220b851a 100644 --- a/src/web_service/announce_room_json.cpp +++ b/src/web_service/announce_room_json.cpp @@ -11,7 +11,7 @@ namespace AnnounceMultiplayerRoom { -static void to_json(nlohmann::json& json, const Room::Member& member) { +static void to_json(nlohmann::json& json, const Member& member) { if (!member.username.empty()) { json["username"] = member.username; } @@ -23,7 +23,7 @@ static void to_json(nlohmann::json& json, const Room::Member& member) { json["gameId"] = member.game_id; } -static void from_json(const nlohmann::json& json, Room::Member& member) { +static void from_json(const nlohmann::json& json, Member& member) { member.nickname = json.at("nickname").get(); member.game_name = json.at("gameName").get(); member.game_id = json.at("gameId").get(); @@ -37,14 +37,14 @@ static void from_json(const nlohmann::json& json, Room::Member& member) { } static void to_json(nlohmann::json& json, const Room& room) { - json["port"] = room.port; - json["name"] = room.name; - if (!room.description.empty()) { - json["description"] = room.description; + json["port"] = room.information.port; + json["name"] = room.information.name; + if (!room.information.description.empty()) { + json["description"] = room.information.description; } - json["preferredGameName"] = room.preferred_game; - json["preferredGameId"] = room.preferred_game_id; - json["maxPlayers"] = room.max_player; + json["preferredGameName"] = room.information.preferred_game; + json["preferredGameId"] = room.information.preferred_game_id; + json["maxPlayers"] = room.information.member_slots; json["netVersion"] = room.net_version; json["hasPassword"] = room.has_password; if (room.members.size() > 0) { @@ -56,22 +56,22 @@ static void to_json(nlohmann::json& json, const Room& room) { static void from_json(const nlohmann::json& json, Room& room) { room.verify_UID = json.at("externalGuid").get(); room.ip = json.at("address").get(); - room.name = json.at("name").get(); + room.information.name = json.at("name").get(); try { - room.description = json.at("description").get(); + room.information.description = json.at("description").get(); } catch (const nlohmann::detail::out_of_range&) { - room.description = ""; - LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.name); + room.information.description = ""; + LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.information.name); } - room.owner = json.at("owner").get(); - room.port = json.at("port").get(); - room.preferred_game = json.at("preferredGameName").get(); - room.preferred_game_id = json.at("preferredGameId").get(); - room.max_player = json.at("maxPlayers").get(); + room.information.host_username = json.at("owner").get(); + room.information.port = json.at("port").get(); + room.information.preferred_game = json.at("preferredGameName").get(); + room.information.preferred_game_id = json.at("preferredGameId").get(); + room.information.member_slots = json.at("maxPlayers").get(); room.net_version = json.at("netVersion").get(); room.has_password = json.at("hasPassword").get(); try { - room.members = json.at("players").get>(); + room.members = json.at("players").get>(); } catch (const nlohmann::detail::out_of_range& e) { LOG_DEBUG(Network, "Out of range {}", e.what()); } @@ -85,26 +85,16 @@ void RoomJson::SetRoomInformation(const std::string& name, const std::string& de 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.description = description; - room.port = port; - room.max_player = max_player; + room.information.name = name; + room.information.description = description; + room.information.port = port; + room.information.member_slots = max_player; room.net_version = net_version; room.has_password = has_password; - room.preferred_game = preferred_game; - room.preferred_game_id = preferred_game_id; + room.information.preferred_game = preferred_game; + room.information.preferred_game_id = preferred_game_id; } -void RoomJson::AddPlayer(const std::string& username_, const std::string& nickname_, - const std::string& avatar_url, - const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id, - const std::string& game_name) { - AnnounceMultiplayerRoom::Room::Member member; - member.username = username_; - member.nickname = nickname_; - member.avatar_url = avatar_url; - member.mac_address = mac_address; - member.game_id = game_id; - member.game_name = game_name; +void RoomJson::AddPlayer(const AnnounceMultiplayerRoom::Member& member) { room.members.push_back(member); } diff --git a/src/web_service/announce_room_json.h b/src/web_service/announce_room_json.h index f65c93214a..811c76fbd2 100644 --- a/src/web_service/announce_room_json.h +++ b/src/web_service/announce_room_json.h @@ -24,10 +24,7 @@ public: const u32 max_player, const u32 net_version, const bool has_password, const std::string& preferred_game, const u64 preferred_game_id) override; - void AddPlayer(const std::string& username_, const std::string& nickname_, - const std::string& avatar_url, - const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id, - const std::string& game_name) override; + void AddPlayer(const AnnounceMultiplayerRoom::Member& member) override; WebResult Update() override; WebResult Register() override; void ClearPlayers() override; diff --git a/src/web_service/verify_user_jwt.cpp b/src/web_service/verify_user_jwt.cpp index 78fe7bed5a..3133dcbe26 100644 --- a/src/web_service/verify_user_jwt.cpp +++ b/src/web_service/verify_user_jwt.cpp @@ -2,8 +2,16 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#endif #include +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + +#include #include "common/logging/log.h" #include "web_service/verify_user_jwt.h" #include "web_service/web_backend.h" diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp index 364b4605e6..6cc5f8f7eb 100644 --- a/src/yuzu/multiplayer/lobby.cpp +++ b/src/yuzu/multiplayer/lobby.cpp @@ -214,7 +214,7 @@ void Lobby::OnRefreshLobby() { for (int r = 0; r < game_list->rowCount(); ++r) { auto index = game_list->index(r, 0); auto game_id = game_list->data(index, GameListItemPath::ProgramIdRole).toULongLong(); - if (game_id != 0 && room.preferred_game_id == game_id) { + if (game_id != 0 && room.information.preferred_game_id == game_id) { smdh_icon = game_list->data(index, Qt::DecorationRole).value(); } } @@ -231,20 +231,21 @@ void Lobby::OnRefreshLobby() { auto first_item = new LobbyItem(); auto row = QList({ first_item, - new LobbyItemName(room.has_password, QString::fromStdString(room.name)), - new LobbyItemGame(room.preferred_game_id, QString::fromStdString(room.preferred_game), - smdh_icon), - new LobbyItemHost(QString::fromStdString(room.owner), QString::fromStdString(room.ip), - room.port, QString::fromStdString(room.verify_UID)), - new LobbyItemMemberList(members, room.max_player), + new LobbyItemName(room.has_password, QString::fromStdString(room.information.name)), + new LobbyItemGame(room.information.preferred_game_id, + QString::fromStdString(room.information.preferred_game), smdh_icon), + new LobbyItemHost(QString::fromStdString(room.information.host_username), + QString::fromStdString(room.ip), room.information.port, + QString::fromStdString(room.verify_UID)), + new LobbyItemMemberList(members, room.information.member_slots), }); model->appendRow(row); // To make the rows expandable, add the member data as a child of the first column of the // rows with people in them and have qt set them to colspan after the model is finished // resetting - if (!room.description.empty()) { + if (!room.information.description.empty()) { first_item->appendRow( - new LobbyItemDescription(QString::fromStdString(room.description))); + new LobbyItemDescription(QString::fromStdString(room.information.description))); } if (!room.members.empty()) { first_item->appendRow(new LobbyItemExpandedMemberList(members));