diff options
| author | 2022-07-25 18:31:45 -0400 | |
|---|---|---|
| committer | 2022-07-25 18:31:45 -0400 | |
| commit | 1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2 (patch) | |
| tree | 999411f1ca76390654d1034c6d0bd2c47c3f101c /src/network/room.h | |
| parent | Merge pull request #8564 from lat9nq/dinner-fork (diff) | |
| parent | network: Address review comments (diff) | |
| download | yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar.gz yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.tar.xz yuzu-1e67d2b59f6dfd561768db3fb9a8e0c6a16ec9f2.zip | |
Merge pull request #8541 from FearlessTobi/multiplayer-part1
yuzu, network: Add room service and UI configuration
Diffstat (limited to 'src/network/room.h')
| -rw-r--r-- | src/network/room.h | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/network/room.h b/src/network/room.h new file mode 100644 index 000000000..6f7e3b5b5 --- /dev/null +++ b/src/network/room.h | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <array> | ||
| 7 | #include <memory> | ||
| 8 | #include <string> | ||
| 9 | #include <vector> | ||
| 10 | #include "common/announce_multiplayer_room.h" | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "network/verify_user.h" | ||
| 13 | |||
| 14 | namespace Network { | ||
| 15 | |||
| 16 | using AnnounceMultiplayerRoom::GameInfo; | ||
| 17 | using AnnounceMultiplayerRoom::MacAddress; | ||
| 18 | using AnnounceMultiplayerRoom::Member; | ||
| 19 | using AnnounceMultiplayerRoom::RoomInformation; | ||
| 20 | |||
| 21 | constexpr u32 network_version = 1; ///< The version of this Room and RoomMember | ||
| 22 | |||
| 23 | constexpr u16 DefaultRoomPort = 24872; | ||
| 24 | |||
| 25 | constexpr u32 MaxMessageSize = 500; | ||
| 26 | |||
| 27 | /// Maximum number of concurrent connections allowed to this room. | ||
| 28 | static constexpr u32 MaxConcurrentConnections = 254; | ||
| 29 | |||
| 30 | constexpr std::size_t NumChannels = 1; // Number of channels used for the connection | ||
| 31 | |||
| 32 | /// A special MAC address that tells the room we're joining to assign us a MAC address | ||
| 33 | /// automatically. | ||
| 34 | constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | ||
| 35 | |||
| 36 | // 802.11 broadcast MAC address | ||
| 37 | constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | ||
| 38 | |||
| 39 | // The different types of messages that can be sent. The first byte of each packet defines the type | ||
| 40 | enum RoomMessageTypes : u8 { | ||
| 41 | IdJoinRequest = 1, | ||
| 42 | IdJoinSuccess, | ||
| 43 | IdRoomInformation, | ||
| 44 | IdSetGameInfo, | ||
| 45 | IdWifiPacket, | ||
| 46 | IdChatMessage, | ||
| 47 | IdNameCollision, | ||
| 48 | IdMacCollision, | ||
| 49 | IdVersionMismatch, | ||
| 50 | IdWrongPassword, | ||
| 51 | IdCloseRoom, | ||
| 52 | IdRoomIsFull, | ||
| 53 | IdConsoleIdCollision, | ||
| 54 | IdStatusMessage, | ||
| 55 | IdHostKicked, | ||
| 56 | IdHostBanned, | ||
| 57 | /// Moderation requests | ||
| 58 | IdModKick, | ||
| 59 | IdModBan, | ||
| 60 | IdModUnban, | ||
| 61 | IdModGetBanList, | ||
| 62 | // Moderation responses | ||
| 63 | IdModBanListResponse, | ||
| 64 | IdModPermissionDenied, | ||
| 65 | IdModNoSuchUser, | ||
| 66 | IdJoinSuccessAsMod, | ||
| 67 | }; | ||
| 68 | |||
| 69 | /// Types of system status messages | ||
| 70 | enum StatusMessageTypes : u8 { | ||
| 71 | IdMemberJoin = 1, ///< Member joining | ||
| 72 | IdMemberLeave, ///< Member leaving | ||
| 73 | IdMemberKicked, ///< A member is kicked from the room | ||
| 74 | IdMemberBanned, ///< A member is banned from the room | ||
| 75 | IdAddressUnbanned, ///< A username / ip address is unbanned from the room | ||
| 76 | }; | ||
| 77 | |||
| 78 | /// This is what a server [person creating a server] would use. | ||
| 79 | class Room final { | ||
| 80 | public: | ||
| 81 | enum class State : u8 { | ||
| 82 | Open, ///< The room is open and ready to accept connections. | ||
| 83 | Closed, ///< The room is not opened and can not accept connections. | ||
| 84 | }; | ||
| 85 | |||
| 86 | Room(); | ||
| 87 | ~Room(); | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Gets the current state of the room. | ||
| 91 | */ | ||
| 92 | State GetState() const; | ||
| 93 | |||
| 94 | /** | ||
| 95 | * Gets the room information of the room. | ||
| 96 | */ | ||
| 97 | const RoomInformation& GetRoomInformation() const; | ||
| 98 | |||
| 99 | /** | ||
| 100 | * Gets the verify UID of this room. | ||
| 101 | */ | ||
| 102 | std::string GetVerifyUID() const; | ||
| 103 | |||
| 104 | /** | ||
| 105 | * Gets a list of the mbmers connected to the room. | ||
| 106 | */ | ||
| 107 | std::vector<Member> GetRoomMemberList() const; | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Checks if the room is password protected | ||
| 111 | */ | ||
| 112 | bool HasPassword() const; | ||
| 113 | |||
| 114 | using UsernameBanList = std::vector<std::string>; | ||
| 115 | using IPBanList = std::vector<std::string>; | ||
| 116 | |||
| 117 | using BanList = std::pair<UsernameBanList, IPBanList>; | ||
| 118 | |||
| 119 | /** | ||
| 120 | * Creates the socket for this room. Will bind to default address if | ||
| 121 | * server is empty string. | ||
| 122 | */ | ||
| 123 | bool Create(const std::string& name, const std::string& description = "", | ||
| 124 | const std::string& server = "", u16 server_port = DefaultRoomPort, | ||
| 125 | const std::string& password = "", | ||
| 126 | const u32 max_connections = MaxConcurrentConnections, | ||
| 127 | const std::string& host_username = "", const GameInfo = {}, | ||
| 128 | std::unique_ptr<VerifyUser::Backend> verify_backend = nullptr, | ||
| 129 | const BanList& ban_list = {}, bool enable_yuzu_mods = false); | ||
| 130 | |||
| 131 | /** | ||
| 132 | * Sets the verification GUID of the room. | ||
| 133 | */ | ||
| 134 | void SetVerifyUID(const std::string& uid); | ||
| 135 | |||
| 136 | /** | ||
| 137 | * Gets the ban list (including banned forum usernames and IPs) of the room. | ||
| 138 | */ | ||
| 139 | BanList GetBanList() const; | ||
| 140 | |||
| 141 | /** | ||
| 142 | * Destroys the socket | ||
| 143 | */ | ||
| 144 | void Destroy(); | ||
| 145 | |||
| 146 | private: | ||
| 147 | class RoomImpl; | ||
| 148 | std::unique_ptr<RoomImpl> room_impl; | ||
| 149 | }; | ||
| 150 | |||
| 151 | } // namespace Network | ||