mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-09-04 01:09:02 +00:00
Address second part of review comments
This commit is contained in:
parent
6c8e456185
commit
4b404191cf
@ -15,27 +15,40 @@ namespace AnnounceMultiplayerRoom {
|
||||
|
||||
using MacAddress = std::array<u8, 6>;
|
||||
|
||||
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<Member> 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", ""};
|
||||
|
@ -88,15 +88,14 @@ AnnounceMultiplayerSession::~AnnounceMultiplayerSession() {
|
||||
|
||||
void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room> room) {
|
||||
Network::RoomInformation room_information = room->GetRoomInformation();
|
||||
std::vector<Network::Room::Member> memberlist = room->GetRoomMemberList();
|
||||
std::vector<AnnounceMultiplayerRoom::Member> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1066,8 +1066,8 @@ Room::BanList Room::GetBanList() const {
|
||||
return {room_impl->username_ban_list, room_impl->ip_ban_list};
|
||||
}
|
||||
|
||||
std::vector<Room::Member> Room::GetRoomMemberList() const {
|
||||
std::vector<Room::Member> member_list;
|
||||
std::vector<Member> Room::GetRoomMemberList() const {
|
||||
std::vector<Member> 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::Member> 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;
|
||||
|
@ -8,11 +8,17 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#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<u8, 6>;
|
||||
/// 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();
|
||||
|
||||
|
@ -9,11 +9,15 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
#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 {
|
||||
|
@ -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<std::string>();
|
||||
member.game_name = json.at("gameName").get<std::string>();
|
||||
member.game_id = json.at("gameId").get<u64>();
|
||||
@ -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<std::string>();
|
||||
room.ip = json.at("address").get<std::string>();
|
||||
room.name = json.at("name").get<std::string>();
|
||||
room.information.name = json.at("name").get<std::string>();
|
||||
try {
|
||||
room.description = json.at("description").get<std::string>();
|
||||
room.information.description = json.at("description").get<std::string>();
|
||||
} 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<std::string>();
|
||||
room.port = json.at("port").get<u16>();
|
||||
room.preferred_game = json.at("preferredGameName").get<std::string>();
|
||||
room.preferred_game_id = json.at("preferredGameId").get<u64>();
|
||||
room.max_player = json.at("maxPlayers").get<u32>();
|
||||
room.information.host_username = json.at("owner").get<std::string>();
|
||||
room.information.port = json.at("port").get<u16>();
|
||||
room.information.preferred_game = json.at("preferredGameName").get<std::string>();
|
||||
room.information.preferred_game_id = json.at("preferredGameId").get<u64>();
|
||||
room.information.member_slots = json.at("maxPlayers").get<u32>();
|
||||
room.net_version = json.at("netVersion").get<u32>();
|
||||
room.has_password = json.at("hasPassword").get<bool>();
|
||||
try {
|
||||
room.members = json.at("players").get<std::vector<Room::Member>>();
|
||||
room.members = json.at("players").get<std::vector<Member>>();
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -2,8 +2,16 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <system_error>
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#endif
|
||||
#include <jwt/jwt.hpp>
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include <system_error>
|
||||
#include "common/logging/log.h"
|
||||
#include "web_service/verify_user_jwt.h"
|
||||
#include "web_service/web_backend.h"
|
||||
|
@ -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<QPixmap>();
|
||||
}
|
||||
}
|
||||
@ -231,20 +231,21 @@ void Lobby::OnRefreshLobby() {
|
||||
auto first_item = new LobbyItem();
|
||||
auto row = QList<QStandardItem*>({
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user