From 705f7db84dd85555a6aef1e136cf251725cef293 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sat, 25 Dec 2021 20:27:52 +0100 Subject: yuzu: Add ui files for multiplayer rooms --- src/common/announce_multiplayer_room.h | 138 +++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/common/announce_multiplayer_room.h (limited to 'src/common/announce_multiplayer_room.h') diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h new file mode 100644 index 000000000..5ca5893ef --- /dev/null +++ b/src/common/announce_multiplayer_room.h @@ -0,0 +1,138 @@ +// Copyright 2017 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include +#include "common/common_types.h" +#include "web_service/web_result.h" + +namespace AnnounceMultiplayerRoom { + +using MacAddress = std::array; + +struct Room { + struct Member { + std::string username; + std::string nickname; + std::string avatar_url; + MacAddress mac_address; + std::string game_name; + u64 game_id; + }; + 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; +}; +using RoomList = std::vector; + +/** + * A AnnounceMultiplayerRoom interface class. A backend to submit/get to/from a web service should + * implement this interface. + */ +class Backend { +public: + virtual ~Backend() = default; + + /** + * Sets the Information that gets used for the announce + * @param uid The Id of the room + * @param name The name of the room + * @param description The room description + * @param port The port of the room + * @param net_version The version of the libNetwork that gets used + * @param has_password True if the room is passowrd protected + * @param preferred_game The preferred game of the room + * @param preferred_game_id The title id of the preferred game + */ + virtual void SetRoomInformation(const std::string& name, const std::string& description, + 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; + /** + * Adds a player information to the data that gets announced + * @param nickname The nickname of the player + * @param mac_address The MAC Address of the player + * @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; + + /** + * Updates the data in the announce service. Re-register the room when required. + * @result The result of the update attempt + */ + virtual WebService::WebResult Update() = 0; + + /** + * Registers the data in the announce service + * @result The result of the register attempt. When the result code is Success, A global Guid of + * the room which may be used for verification will be in the result's returned_data. + */ + virtual WebService::WebResult Register() = 0; + + /** + * Empties the stored players + */ + virtual void ClearPlayers() = 0; + + /** + * Get the room information from the announce service + * @result A list of all rooms the announce service has + */ + virtual RoomList GetRoomList() = 0; + + /** + * Sends a delete message to the announce service + */ + virtual void Delete() = 0; +}; + +/** + * Empty implementation of AnnounceMultiplayerRoom interface that drops all data. Used when a + * functional backend implementation is not available. + */ +class NullBackend : public Backend { +public: + ~NullBackend() = default; + void SetRoomInformation(const std::string& /*name*/, const std::string& /*description*/, + 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 {} + WebService::WebResult Update() override { + return WebService::WebResult{WebService::WebResult::Code::NoWebservice, + "WebService is missing"}; + } + WebService::WebResult Register() override { + return WebService::WebResult{WebService::WebResult::Code::NoWebservice, + "WebService is missing"}; + } + void ClearPlayers() override {} + RoomList GetRoomList() override { + return RoomList{}; + } + + void Delete() override {} +}; + +} // namespace AnnounceMultiplayerRoom -- cgit v1.2.3 From 7c3d241f0d03304df2c4d4449c2c8f1f9c7a16d3 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Thu, 7 Jul 2022 04:12:12 +0200 Subject: common, core: fix -Wmissing-field-initializers --- src/common/announce_multiplayer_room.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common/announce_multiplayer_room.h') diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index 5ca5893ef..8773ce4db 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -121,11 +121,11 @@ public: const u64 /*game_id*/, const std::string& /*game_name*/) override {} WebService::WebResult Update() override { return WebService::WebResult{WebService::WebResult::Code::NoWebservice, - "WebService is missing"}; + "WebService is missing", ""}; } WebService::WebResult Register() override { return WebService::WebResult{WebService::WebResult::Code::NoWebservice, - "WebService is missing"}; + "WebService is missing", ""}; } void ClearPlayers() override {} RoomList GetRoomList() override { -- cgit v1.2.3 From 4b404191cf054ec3206676f1fccc452bc0a0e223 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Fri, 15 Jul 2022 21:11:09 +0200 Subject: Address second part of review comments --- src/common/announce_multiplayer_room.h | 51 ++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'src/common/announce_multiplayer_room.h') 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 { 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", ""}; -- cgit v1.2.3 From 899c8bb33094f43fbd8df9afb4ca84718ebac87e Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 17 Jul 2022 22:53:44 -0500 Subject: common: multiplayer: Use GameInfo type --- src/common/announce_multiplayer_room.h | 35 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'src/common/announce_multiplayer_room.h') diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index 2ff38b6cf..a9e2f89b7 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -15,30 +15,28 @@ namespace AnnounceMultiplayerRoom { using MacAddress = std::array; +struct GameInfo { + std::string name{""}; + u64 id{0}; +}; + 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; + GameInfo game; }; 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}; + 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 + GameInfo preferred_game; ///< Game to advertise that you want to play + std::string host_username; ///< Forum username of the host + bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room }; struct Room { @@ -75,8 +73,7 @@ public: */ virtual void SetRoomInformation(const std::string& name, const std::string& description, 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; + const bool has_password, const GameInfo& preferred_game) = 0; /** * Adds a player information to the data that gets announced * @param nickname The nickname of the player @@ -125,8 +122,8 @@ public: ~NullBackend() = default; void SetRoomInformation(const std::string& /*name*/, const std::string& /*description*/, 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 {} + const bool /*has_password*/, + const GameInfo& /*preferred_game*/) override {} void AddPlayer(const Member& /*member*/) override {} WebService::WebResult Update() override { return WebService::WebResult{WebService::WebResult::Code::NoWebservice, -- cgit v1.2.3 From 6a2dcc8b3d4ed0940e33d60fee701bcdb063eb6b Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Mon, 25 Jul 2022 17:08:20 +0200 Subject: network, yuzu: Improve variable naming and style consistency --- src/common/announce_multiplayer_room.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/common/announce_multiplayer_room.h') diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index a9e2f89b7..11a80aa8e 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -43,7 +43,7 @@ struct Room { RoomInformation information; std::string id; - std::string verify_UID; ///< UID used for verification + std::string verify_uid; ///< UID used for verification std::string ip; u32 net_version; bool has_password; -- cgit v1.2.3 From 61ce57b5242984c297283de5868ea4938391a911 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Mon, 25 Jul 2022 17:18:30 +0200 Subject: network, yuzu: Make copyright headers SPDX-compliant --- src/common/announce_multiplayer_room.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/common/announce_multiplayer_room.h') diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h index 11a80aa8e..0ad9da2be 100644 --- a/src/common/announce_multiplayer_room.h +++ b/src/common/announce_multiplayer_room.h @@ -1,6 +1,5 @@ -// Copyright 2017 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later #pragma once -- cgit v1.2.3