summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/announce_multiplayer_room.h51
-rw-r--r--src/core/announce_multiplayer_session.cpp5
-rw-r--r--src/network/room.cpp7
-rw-r--r--src/network/room.h32
-rw-r--r--src/network/room_member.h4
-rw-r--r--src/web_service/announce_room_json.cpp62
-rw-r--r--src/web_service/announce_room_json.h5
-rw-r--r--src/web_service/verify_user_jwt.cpp10
-rw-r--r--src/yuzu/multiplayer/lobby.cpp19
9 files changed, 92 insertions, 103 deletions
diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h
index 8773ce4db..2ff38b6cf 100644
--- a/src/common/announce_multiplayer_room.h
+++ b/src/common/announce_multiplayer_room.h
@@ -15,27 +15,40 @@ namespace AnnounceMultiplayerRoom {
15 15
16using MacAddress = std::array<u8, 6>; 16using MacAddress = std::array<u8, 6>;
17 17
18struct Member {
19 std::string username;
20 std::string nickname;
21 std::string display_name;
22 std::string avatar_url;
23 MacAddress mac_address;
24 std::string game_name;
25 u64 game_id;
26};
27
28struct RoomInformation {
29 std::string name; ///< Name of the server
30 std::string description; ///< Server description
31 u32 member_slots; ///< Maximum number of members in this room
32 u16 port; ///< The port of this room
33 std::string preferred_game; ///< Game to advertise that you want to play
34 u64 preferred_game_id; ///< Title ID for the advertised game
35 std::string host_username; ///< Forum username of the host
36 bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room
37};
38
39struct GameInfo {
40 std::string name{""};
41 u64 id{0};
42};
43
18struct Room { 44struct Room {
19 struct Member { 45 RoomInformation information;
20 std::string username; 46
21 std::string nickname;
22 std::string avatar_url;
23 MacAddress mac_address;
24 std::string game_name;
25 u64 game_id;
26 };
27 std::string id; 47 std::string id;
28 std::string verify_UID; ///< UID used for verification 48 std::string verify_UID; ///< UID used for verification
29 std::string name;
30 std::string description;
31 std::string owner;
32 std::string ip; 49 std::string ip;
33 u16 port;
34 u32 max_player;
35 u32 net_version; 50 u32 net_version;
36 bool has_password; 51 bool has_password;
37 std::string preferred_game;
38 u64 preferred_game_id;
39 52
40 std::vector<Member> members; 53 std::vector<Member> members;
41}; 54};
@@ -71,9 +84,7 @@ public:
71 * @param game_id The title id of the game the player plays 84 * @param game_id The title id of the game the player plays
72 * @param game_name The name of the game the player plays 85 * @param game_name The name of the game the player plays
73 */ 86 */
74 virtual void AddPlayer(const std::string& username, const std::string& nickname, 87 virtual void AddPlayer(const Member& member) = 0;
75 const std::string& avatar_url, const MacAddress& mac_address,
76 const u64 game_id, const std::string& game_name) = 0;
77 88
78 /** 89 /**
79 * Updates the data in the announce service. Re-register the room when required. 90 * Updates the data in the announce service. Re-register the room when required.
@@ -116,9 +127,7 @@ public:
116 const u16 /*port*/, const u32 /*max_player*/, const u32 /*net_version*/, 127 const u16 /*port*/, const u32 /*max_player*/, const u32 /*net_version*/,
117 const bool /*has_password*/, const std::string& /*preferred_game*/, 128 const bool /*has_password*/, const std::string& /*preferred_game*/,
118 const u64 /*preferred_game_id*/) override {} 129 const u64 /*preferred_game_id*/) override {}
119 void AddPlayer(const std::string& /*username*/, const std::string& /*nickname*/, 130 void AddPlayer(const Member& /*member*/) override {}
120 const std::string& /*avatar_url*/, const MacAddress& /*mac_address*/,
121 const u64 /*game_id*/, const std::string& /*game_name*/) override {}
122 WebService::WebResult Update() override { 131 WebService::WebResult Update() override {
123 return WebService::WebResult{WebService::WebResult::Code::NoWebservice, 132 return WebService::WebResult{WebService::WebResult::Code::NoWebservice,
124 "WebService is missing", ""}; 133 "WebService is missing", ""};
diff --git a/src/core/announce_multiplayer_session.cpp b/src/core/announce_multiplayer_session.cpp
index aeca87aac..f8aa9bb0b 100644
--- a/src/core/announce_multiplayer_session.cpp
+++ b/src/core/announce_multiplayer_session.cpp
@@ -88,15 +88,14 @@ AnnounceMultiplayerSession::~AnnounceMultiplayerSession() {
88 88
89void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room> room) { 89void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room> room) {
90 Network::RoomInformation room_information = room->GetRoomInformation(); 90 Network::RoomInformation room_information = room->GetRoomInformation();
91 std::vector<Network::Room::Member> memberlist = room->GetRoomMemberList(); 91 std::vector<AnnounceMultiplayerRoom::Member> memberlist = room->GetRoomMemberList();
92 backend->SetRoomInformation( 92 backend->SetRoomInformation(
93 room_information.name, room_information.description, room_information.port, 93 room_information.name, room_information.description, room_information.port,
94 room_information.member_slots, Network::network_version, room->HasPassword(), 94 room_information.member_slots, Network::network_version, room->HasPassword(),
95 room_information.preferred_game, room_information.preferred_game_id); 95 room_information.preferred_game, room_information.preferred_game_id);
96 backend->ClearPlayers(); 96 backend->ClearPlayers();
97 for (const auto& member : memberlist) { 97 for (const auto& member : memberlist) {
98 backend->AddPlayer(member.username, member.nickname, member.avatar_url, member.mac_address, 98 backend->AddPlayer(member);
99 member.game_info.id, member.game_info.name);
100 } 99 }
101} 100}
102 101
diff --git a/src/network/room.cpp b/src/network/room.cpp
index b82a75749..fe55d194c 100644
--- a/src/network/room.cpp
+++ b/src/network/room.cpp
@@ -1066,8 +1066,8 @@ Room::BanList Room::GetBanList() const {
1066 return {room_impl->username_ban_list, room_impl->ip_ban_list}; 1066 return {room_impl->username_ban_list, room_impl->ip_ban_list};
1067} 1067}
1068 1068
1069std::vector<Room::Member> Room::GetRoomMemberList() const { 1069std::vector<Member> Room::GetRoomMemberList() const {
1070 std::vector<Room::Member> member_list; 1070 std::vector<Member> member_list;
1071 std::lock_guard lock(room_impl->member_mutex); 1071 std::lock_guard lock(room_impl->member_mutex);
1072 for (const auto& member_impl : room_impl->members) { 1072 for (const auto& member_impl : room_impl->members) {
1073 Member member; 1073 Member member;
@@ -1076,7 +1076,8 @@ std::vector<Room::Member> Room::GetRoomMemberList() const {
1076 member.display_name = member_impl.user_data.display_name; 1076 member.display_name = member_impl.user_data.display_name;
1077 member.avatar_url = member_impl.user_data.avatar_url; 1077 member.avatar_url = member_impl.user_data.avatar_url;
1078 member.mac_address = member_impl.mac_address; 1078 member.mac_address = member_impl.mac_address;
1079 member.game_info = member_impl.game_info; 1079 member.game_name = member_impl.game_info.name;
1080 member.game_id = member_impl.game_info.id;
1080 member_list.push_back(member); 1081 member_list.push_back(member);
1081 } 1082 }
1082 return member_list; 1083 return member_list;
diff --git a/src/network/room.h b/src/network/room.h
index df2253bf8..f282a5ac3 100644
--- a/src/network/room.h
+++ b/src/network/room.h
@@ -8,11 +8,17 @@
8#include <memory> 8#include <memory>
9#include <string> 9#include <string>
10#include <vector> 10#include <vector>
11#include "common/announce_multiplayer_room.h"
11#include "common/common_types.h" 12#include "common/common_types.h"
12#include "network/verify_user.h" 13#include "network/verify_user.h"
13 14
14namespace Network { 15namespace Network {
15 16
17using AnnounceMultiplayerRoom::GameInfo;
18using AnnounceMultiplayerRoom::MacAddress;
19using AnnounceMultiplayerRoom::Member;
20using AnnounceMultiplayerRoom::RoomInformation;
21
16constexpr u32 network_version = 1; ///< The version of this Room and RoomMember 22constexpr u32 network_version = 1; ///< The version of this Room and RoomMember
17 23
18constexpr u16 DefaultRoomPort = 24872; 24constexpr u16 DefaultRoomPort = 24872;
@@ -24,23 +30,6 @@ static constexpr u32 MaxConcurrentConnections = 254;
24 30
25constexpr std::size_t NumChannels = 1; // Number of channels used for the connection 31constexpr std::size_t NumChannels = 1; // Number of channels used for the connection
26 32
27struct RoomInformation {
28 std::string name; ///< Name of the server
29 std::string description; ///< Server description
30 u32 member_slots; ///< Maximum number of members in this room
31 u16 port; ///< The port of this room
32 std::string preferred_game; ///< Game to advertise that you want to play
33 u64 preferred_game_id; ///< Title ID for the advertised game
34 std::string host_username; ///< Forum username of the host
35 bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room
36};
37
38struct GameInfo {
39 std::string name{""};
40 u64 id{0};
41};
42
43using MacAddress = std::array<u8, 6>;
44/// A special MAC address that tells the room we're joining to assign us a MAC address 33/// A special MAC address that tells the room we're joining to assign us a MAC address
45/// automatically. 34/// automatically.
46constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 35constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
@@ -95,15 +84,6 @@ public:
95 Closed, ///< The room is not opened and can not accept connections. 84 Closed, ///< The room is not opened and can not accept connections.
96 }; 85 };
97 86
98 struct Member {
99 std::string nickname; ///< The nickname of the member.
100 std::string username; ///< The web services username of the member. Can be empty.
101 std::string display_name; ///< The web services display name of the member. Can be empty.
102 std::string avatar_url; ///< Url to the member's avatar. Can be empty.
103 GameInfo game_info; ///< The current game of the member
104 MacAddress mac_address; ///< The assigned mac address of the member.
105 };
106
107 Room(); 87 Room();
108 ~Room(); 88 ~Room();
109 89
diff --git a/src/network/room_member.h b/src/network/room_member.h
index ee1c921d4..c835ba863 100644
--- a/src/network/room_member.h
+++ b/src/network/room_member.h
@@ -9,11 +9,15 @@
9#include <string> 9#include <string>
10#include <vector> 10#include <vector>
11#include <boost/serialization/vector.hpp> 11#include <boost/serialization/vector.hpp>
12#include "common/announce_multiplayer_room.h"
12#include "common/common_types.h" 13#include "common/common_types.h"
13#include "network/room.h" 14#include "network/room.h"
14 15
15namespace Network { 16namespace Network {
16 17
18using AnnounceMultiplayerRoom::GameInfo;
19using AnnounceMultiplayerRoom::RoomInformation;
20
17/// Information about the received WiFi packets. 21/// Information about the received WiFi packets.
18/// Acts as our own 802.11 header. 22/// Acts as our own 802.11 header.
19struct WifiPacket { 23struct WifiPacket {
diff --git a/src/web_service/announce_room_json.cpp b/src/web_service/announce_room_json.cpp
index 984a59f77..84220b851 100644
--- a/src/web_service/announce_room_json.cpp
+++ b/src/web_service/announce_room_json.cpp
@@ -11,7 +11,7 @@
11 11
12namespace AnnounceMultiplayerRoom { 12namespace AnnounceMultiplayerRoom {
13 13
14static void to_json(nlohmann::json& json, const Room::Member& member) { 14static void to_json(nlohmann::json& json, const Member& member) {
15 if (!member.username.empty()) { 15 if (!member.username.empty()) {
16 json["username"] = member.username; 16 json["username"] = member.username;
17 } 17 }
@@ -23,7 +23,7 @@ static void to_json(nlohmann::json& json, const Room::Member& member) {
23 json["gameId"] = member.game_id; 23 json["gameId"] = member.game_id;
24} 24}
25 25
26static void from_json(const nlohmann::json& json, Room::Member& member) { 26static void from_json(const nlohmann::json& json, Member& member) {
27 member.nickname = json.at("nickname").get<std::string>(); 27 member.nickname = json.at("nickname").get<std::string>();
28 member.game_name = json.at("gameName").get<std::string>(); 28 member.game_name = json.at("gameName").get<std::string>();
29 member.game_id = json.at("gameId").get<u64>(); 29 member.game_id = json.at("gameId").get<u64>();
@@ -37,14 +37,14 @@ static void from_json(const nlohmann::json& json, Room::Member& member) {
37} 37}
38 38
39static void to_json(nlohmann::json& json, const Room& room) { 39static void to_json(nlohmann::json& json, const Room& room) {
40 json["port"] = room.port; 40 json["port"] = room.information.port;
41 json["name"] = room.name; 41 json["name"] = room.information.name;
42 if (!room.description.empty()) { 42 if (!room.information.description.empty()) {
43 json["description"] = room.description; 43 json["description"] = room.information.description;
44 } 44 }
45 json["preferredGameName"] = room.preferred_game; 45 json["preferredGameName"] = room.information.preferred_game;
46 json["preferredGameId"] = room.preferred_game_id; 46 json["preferredGameId"] = room.information.preferred_game_id;
47 json["maxPlayers"] = room.max_player; 47 json["maxPlayers"] = room.information.member_slots;
48 json["netVersion"] = room.net_version; 48 json["netVersion"] = room.net_version;
49 json["hasPassword"] = room.has_password; 49 json["hasPassword"] = room.has_password;
50 if (room.members.size() > 0) { 50 if (room.members.size() > 0) {
@@ -56,22 +56,22 @@ static void to_json(nlohmann::json& json, const Room& room) {
56static void from_json(const nlohmann::json& json, Room& room) { 56static void from_json(const nlohmann::json& json, Room& room) {
57 room.verify_UID = json.at("externalGuid").get<std::string>(); 57 room.verify_UID = json.at("externalGuid").get<std::string>();
58 room.ip = json.at("address").get<std::string>(); 58 room.ip = json.at("address").get<std::string>();
59 room.name = json.at("name").get<std::string>(); 59 room.information.name = json.at("name").get<std::string>();
60 try { 60 try {
61 room.description = json.at("description").get<std::string>(); 61 room.information.description = json.at("description").get<std::string>();
62 } catch (const nlohmann::detail::out_of_range&) { 62 } catch (const nlohmann::detail::out_of_range&) {
63 room.description = ""; 63 room.information.description = "";
64 LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.name); 64 LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.information.name);
65 } 65 }
66 room.owner = json.at("owner").get<std::string>(); 66 room.information.host_username = json.at("owner").get<std::string>();
67 room.port = json.at("port").get<u16>(); 67 room.information.port = json.at("port").get<u16>();
68 room.preferred_game = json.at("preferredGameName").get<std::string>(); 68 room.information.preferred_game = json.at("preferredGameName").get<std::string>();
69 room.preferred_game_id = json.at("preferredGameId").get<u64>(); 69 room.information.preferred_game_id = json.at("preferredGameId").get<u64>();
70 room.max_player = json.at("maxPlayers").get<u32>(); 70 room.information.member_slots = json.at("maxPlayers").get<u32>();
71 room.net_version = json.at("netVersion").get<u32>(); 71 room.net_version = json.at("netVersion").get<u32>();
72 room.has_password = json.at("hasPassword").get<bool>(); 72 room.has_password = json.at("hasPassword").get<bool>();
73 try { 73 try {
74 room.members = json.at("players").get<std::vector<Room::Member>>(); 74 room.members = json.at("players").get<std::vector<Member>>();
75 } catch (const nlohmann::detail::out_of_range& e) { 75 } catch (const nlohmann::detail::out_of_range& e) {
76 LOG_DEBUG(Network, "Out of range {}", e.what()); 76 LOG_DEBUG(Network, "Out of range {}", e.what());
77 } 77 }
@@ -85,26 +85,16 @@ void RoomJson::SetRoomInformation(const std::string& name, const std::string& de
85 const u16 port, const u32 max_player, const u32 net_version, 85 const u16 port, const u32 max_player, const u32 net_version,
86 const bool has_password, const std::string& preferred_game, 86 const bool has_password, const std::string& preferred_game,
87 const u64 preferred_game_id) { 87 const u64 preferred_game_id) {
88 room.name = name; 88 room.information.name = name;
89 room.description = description; 89 room.information.description = description;
90 room.port = port; 90 room.information.port = port;
91 room.max_player = max_player; 91 room.information.member_slots = max_player;
92 room.net_version = net_version; 92 room.net_version = net_version;
93 room.has_password = has_password; 93 room.has_password = has_password;
94 room.preferred_game = preferred_game; 94 room.information.preferred_game = preferred_game;
95 room.preferred_game_id = preferred_game_id; 95 room.information.preferred_game_id = preferred_game_id;
96} 96}
97void RoomJson::AddPlayer(const std::string& username_, const std::string& nickname_, 97void RoomJson::AddPlayer(const AnnounceMultiplayerRoom::Member& member) {
98 const std::string& avatar_url,
99 const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id,
100 const std::string& game_name) {
101 AnnounceMultiplayerRoom::Room::Member member;
102 member.username = username_;
103 member.nickname = nickname_;
104 member.avatar_url = avatar_url;
105 member.mac_address = mac_address;
106 member.game_id = game_id;
107 member.game_name = game_name;
108 room.members.push_back(member); 98 room.members.push_back(member);
109} 99}
110 100
diff --git a/src/web_service/announce_room_json.h b/src/web_service/announce_room_json.h
index f65c93214..811c76fbd 100644
--- a/src/web_service/announce_room_json.h
+++ b/src/web_service/announce_room_json.h
@@ -24,10 +24,7 @@ public:
24 const u32 max_player, const u32 net_version, const bool has_password, 24 const u32 max_player, const u32 net_version, const bool has_password,
25 const std::string& preferred_game, 25 const std::string& preferred_game,
26 const u64 preferred_game_id) override; 26 const u64 preferred_game_id) override;
27 void AddPlayer(const std::string& username_, const std::string& nickname_, 27 void AddPlayer(const AnnounceMultiplayerRoom::Member& member) override;
28 const std::string& avatar_url,
29 const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id,
30 const std::string& game_name) override;
31 WebResult Update() override; 28 WebResult Update() override;
32 WebResult Register() override; 29 WebResult Register() override;
33 void ClearPlayers() override; 30 void ClearPlayers() override;
diff --git a/src/web_service/verify_user_jwt.cpp b/src/web_service/verify_user_jwt.cpp
index 78fe7bed5..3133dcbe2 100644
--- a/src/web_service/verify_user_jwt.cpp
+++ b/src/web_service/verify_user_jwt.cpp
@@ -2,8 +2,16 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <system_error> 5#if defined(__GNUC__) || defined(__clang__)
6#pragma GCC diagnostic push
7#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
8#endif
6#include <jwt/jwt.hpp> 9#include <jwt/jwt.hpp>
10#if defined(__GNUC__) || defined(__clang__)
11#pragma GCC diagnostic pop
12#endif
13
14#include <system_error>
7#include "common/logging/log.h" 15#include "common/logging/log.h"
8#include "web_service/verify_user_jwt.h" 16#include "web_service/verify_user_jwt.h"
9#include "web_service/web_backend.h" 17#include "web_service/web_backend.h"
diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp
index 364b4605e..6cc5f8f7e 100644
--- a/src/yuzu/multiplayer/lobby.cpp
+++ b/src/yuzu/multiplayer/lobby.cpp
@@ -214,7 +214,7 @@ void Lobby::OnRefreshLobby() {
214 for (int r = 0; r < game_list->rowCount(); ++r) { 214 for (int r = 0; r < game_list->rowCount(); ++r) {
215 auto index = game_list->index(r, 0); 215 auto index = game_list->index(r, 0);
216 auto game_id = game_list->data(index, GameListItemPath::ProgramIdRole).toULongLong(); 216 auto game_id = game_list->data(index, GameListItemPath::ProgramIdRole).toULongLong();
217 if (game_id != 0 && room.preferred_game_id == game_id) { 217 if (game_id != 0 && room.information.preferred_game_id == game_id) {
218 smdh_icon = game_list->data(index, Qt::DecorationRole).value<QPixmap>(); 218 smdh_icon = game_list->data(index, Qt::DecorationRole).value<QPixmap>();
219 } 219 }
220 } 220 }
@@ -231,20 +231,21 @@ void Lobby::OnRefreshLobby() {
231 auto first_item = new LobbyItem(); 231 auto first_item = new LobbyItem();
232 auto row = QList<QStandardItem*>({ 232 auto row = QList<QStandardItem*>({
233 first_item, 233 first_item,
234 new LobbyItemName(room.has_password, QString::fromStdString(room.name)), 234 new LobbyItemName(room.has_password, QString::fromStdString(room.information.name)),
235 new LobbyItemGame(room.preferred_game_id, QString::fromStdString(room.preferred_game), 235 new LobbyItemGame(room.information.preferred_game_id,
236 smdh_icon), 236 QString::fromStdString(room.information.preferred_game), smdh_icon),
237 new LobbyItemHost(QString::fromStdString(room.owner), QString::fromStdString(room.ip), 237 new LobbyItemHost(QString::fromStdString(room.information.host_username),
238 room.port, QString::fromStdString(room.verify_UID)), 238 QString::fromStdString(room.ip), room.information.port,
239 new LobbyItemMemberList(members, room.max_player), 239 QString::fromStdString(room.verify_UID)),
240 new LobbyItemMemberList(members, room.information.member_slots),
240 }); 241 });
241 model->appendRow(row); 242 model->appendRow(row);
242 // To make the rows expandable, add the member data as a child of the first column of the 243 // To make the rows expandable, add the member data as a child of the first column of the
243 // rows with people in them and have qt set them to colspan after the model is finished 244 // rows with people in them and have qt set them to colspan after the model is finished
244 // resetting 245 // resetting
245 if (!room.description.empty()) { 246 if (!room.information.description.empty()) {
246 first_item->appendRow( 247 first_item->appendRow(
247 new LobbyItemDescription(QString::fromStdString(room.description))); 248 new LobbyItemDescription(QString::fromStdString(room.information.description)));
248 } 249 }
249 if (!room.members.empty()) { 250 if (!room.members.empty()) {
250 first_item->appendRow(new LobbyItemExpandedMemberList(members)); 251 first_item->appendRow(new LobbyItemExpandedMemberList(members));