From dcfe0a5febb252e3a4f40c1b25765740a269467f Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Wed, 6 Jul 2022 02:20:39 +0200 Subject: network: Add initial files and enet dependency --- src/network/room.h | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/network/room.h (limited to 'src/network/room.h') diff --git a/src/network/room.h b/src/network/room.h new file mode 100644 index 000000000..a67984837 --- /dev/null +++ b/src/network/room.h @@ -0,0 +1,173 @@ +// 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 "network/verify_user.h" + +namespace Network { + +constexpr u32 network_version = 4; ///< The version of this Room and RoomMember + +constexpr u16 DefaultRoomPort = 24872; + +constexpr u32 MaxMessageSize = 500; + +/// Maximum number of concurrent connections allowed to this room. +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_citra_mods; ///< Allow Citra 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}; + +// 802.11 broadcast MAC address +constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + +// The different types of messages that can be sent. The first byte of each packet defines the type +enum RoomMessageTypes : u8 { + IdJoinRequest = 1, + IdJoinSuccess, + IdRoomInformation, + IdSetGameInfo, + IdWifiPacket, + IdChatMessage, + IdNameCollision, + IdMacCollision, + IdVersionMismatch, + IdWrongPassword, + IdCloseRoom, + IdRoomIsFull, + IdConsoleIdCollision, + IdStatusMessage, + IdHostKicked, + IdHostBanned, + /// Moderation requests + IdModKick, + IdModBan, + IdModUnban, + IdModGetBanList, + // Moderation responses + IdModBanListResponse, + IdModPermissionDenied, + IdModNoSuchUser, + IdJoinSuccessAsMod, +}; + +/// Types of system status messages +enum StatusMessageTypes : u8 { + IdMemberJoin = 1, ///< Member joining + IdMemberLeave, ///< Member leaving + IdMemberKicked, ///< A member is kicked from the room + IdMemberBanned, ///< A member is banned from the room + IdAddressUnbanned, ///< A username / ip address is unbanned from the room +}; + +/// This is what a server [person creating a server] would use. +class Room final { +public: + enum class State : u8 { + Open, ///< The room is open and ready to accept connections. + 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(); + + /** + * Gets the current state of the room. + */ + State GetState() const; + + /** + * Gets the room information of the room. + */ + const RoomInformation& GetRoomInformation() const; + + /** + * Gets the verify UID of this room. + */ + std::string GetVerifyUID() const; + + /** + * Gets a list of the mbmers connected to the room. + */ + std::vector GetRoomMemberList() const; + + /** + * Checks if the room is password protected + */ + bool HasPassword() const; + + using UsernameBanList = std::vector; + using IPBanList = std::vector; + + using BanList = std::pair; + + /** + * Creates the socket for this room. Will bind to default address if + * server is empty string. + */ + bool Create(const std::string& name, const std::string& description = "", + const std::string& server = "", u16 server_port = DefaultRoomPort, + const std::string& password = "", + const u32 max_connections = MaxConcurrentConnections, + const std::string& host_username = "", const std::string& preferred_game = "", + u64 preferred_game_id = 0, + std::unique_ptr verify_backend = nullptr, + const BanList& ban_list = {}, bool enable_citra_mods = false); + + /** + * Sets the verification GUID of the room. + */ + void SetVerifyUID(const std::string& uid); + + /** + * Gets the ban list (including banned forum usernames and IPs) of the room. + */ + BanList GetBanList() const; + + /** + * Destroys the socket + */ + void Destroy(); + +private: + class RoomImpl; + std::unique_ptr room_impl; +}; + +} // namespace Network -- cgit v1.2.3 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/network/room.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/network/room.h') diff --git a/src/network/room.h b/src/network/room.h index a67984837..5d4371c16 100644 --- a/src/network/room.h +++ b/src/network/room.h @@ -32,7 +32,7 @@ struct RoomInformation { 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_citra_mods; ///< Allow Citra Moderators to moderate on this room + bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room }; struct GameInfo { @@ -148,7 +148,7 @@ public: const std::string& host_username = "", const std::string& preferred_game = "", u64 preferred_game_id = 0, std::unique_ptr verify_backend = nullptr, - const BanList& ban_list = {}, bool enable_citra_mods = false); + const BanList& ban_list = {}, bool enable_yuzu_mods = false); /** * Sets the verification GUID of the room. -- cgit v1.2.3 From 6c8e45618578de1406c0bf4a7f976bd4903c339c Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Fri, 15 Jul 2022 19:45:35 +0200 Subject: Address first part of review comments --- src/network/room.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/network/room.h') diff --git a/src/network/room.h b/src/network/room.h index 5d4371c16..df2253bf8 100644 --- a/src/network/room.h +++ b/src/network/room.h @@ -13,7 +13,7 @@ namespace Network { -constexpr u32 network_version = 4; ///< The version of this Room and RoomMember +constexpr u32 network_version = 1; ///< The version of this Room and RoomMember constexpr u16 DefaultRoomPort = 24872; -- 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/network/room.h | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'src/network/room.h') 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 @@ #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(); -- 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/network/room.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/network/room.h') diff --git a/src/network/room.h b/src/network/room.h index f282a5ac3..90a82563f 100644 --- a/src/network/room.h +++ b/src/network/room.h @@ -125,8 +125,7 @@ public: const std::string& server = "", u16 server_port = DefaultRoomPort, const std::string& password = "", const u32 max_connections = MaxConcurrentConnections, - const std::string& host_username = "", const std::string& preferred_game = "", - u64 preferred_game_id = 0, + const std::string& host_username = "", const GameInfo = {}, std::unique_ptr verify_backend = nullptr, const BanList& ban_list = {}, bool enable_yuzu_mods = false); -- 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/network/room.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/network/room.h') diff --git a/src/network/room.h b/src/network/room.h index 90a82563f..6f7e3b5b5 100644 --- a/src/network/room.h +++ b/src/network/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