diff options
Diffstat (limited to 'src/network/room.h')
| -rw-r--r-- | src/network/room.h | 173 |
1 files changed, 173 insertions, 0 deletions
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 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <memory> | ||
| 9 | #include <string> | ||
| 10 | #include <vector> | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "network/verify_user.h" | ||
| 13 | |||
| 14 | namespace Network { | ||
| 15 | |||
| 16 | constexpr u32 network_version = 4; ///< The version of this Room and RoomMember | ||
| 17 | |||
| 18 | constexpr u16 DefaultRoomPort = 24872; | ||
| 19 | |||
| 20 | constexpr u32 MaxMessageSize = 500; | ||
| 21 | |||
| 22 | /// Maximum number of concurrent connections allowed to this room. | ||
| 23 | static constexpr u32 MaxConcurrentConnections = 254; | ||
| 24 | |||
| 25 | constexpr std::size_t NumChannels = 1; // Number of channels used for the connection | ||
| 26 | |||
| 27 | struct 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_citra_mods; ///< Allow Citra Moderators to moderate on this room | ||
| 36 | }; | ||
| 37 | |||
| 38 | struct GameInfo { | ||
| 39 | std::string name{""}; | ||
| 40 | u64 id{0}; | ||
| 41 | }; | ||
| 42 | |||
| 43 | using MacAddress = std::array<u8, 6>; | ||
| 44 | /// A special MAC address that tells the room we're joining to assign us a MAC address | ||
| 45 | /// automatically. | ||
| 46 | constexpr MacAddress NoPreferredMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | ||
| 47 | |||
| 48 | // 802.11 broadcast MAC address | ||
| 49 | constexpr MacAddress BroadcastMac = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | ||
| 50 | |||
| 51 | // The different types of messages that can be sent. The first byte of each packet defines the type | ||
| 52 | enum RoomMessageTypes : u8 { | ||
| 53 | IdJoinRequest = 1, | ||
| 54 | IdJoinSuccess, | ||
| 55 | IdRoomInformation, | ||
| 56 | IdSetGameInfo, | ||
| 57 | IdWifiPacket, | ||
| 58 | IdChatMessage, | ||
| 59 | IdNameCollision, | ||
| 60 | IdMacCollision, | ||
| 61 | IdVersionMismatch, | ||
| 62 | IdWrongPassword, | ||
| 63 | IdCloseRoom, | ||
| 64 | IdRoomIsFull, | ||
| 65 | IdConsoleIdCollision, | ||
| 66 | IdStatusMessage, | ||
| 67 | IdHostKicked, | ||
| 68 | IdHostBanned, | ||
| 69 | /// Moderation requests | ||
| 70 | IdModKick, | ||
| 71 | IdModBan, | ||
| 72 | IdModUnban, | ||
| 73 | IdModGetBanList, | ||
| 74 | // Moderation responses | ||
| 75 | IdModBanListResponse, | ||
| 76 | IdModPermissionDenied, | ||
| 77 | IdModNoSuchUser, | ||
| 78 | IdJoinSuccessAsMod, | ||
| 79 | }; | ||
| 80 | |||
| 81 | /// Types of system status messages | ||
| 82 | enum StatusMessageTypes : u8 { | ||
| 83 | IdMemberJoin = 1, ///< Member joining | ||
| 84 | IdMemberLeave, ///< Member leaving | ||
| 85 | IdMemberKicked, ///< A member is kicked from the room | ||
| 86 | IdMemberBanned, ///< A member is banned from the room | ||
| 87 | IdAddressUnbanned, ///< A username / ip address is unbanned from the room | ||
| 88 | }; | ||
| 89 | |||
| 90 | /// This is what a server [person creating a server] would use. | ||
| 91 | class Room final { | ||
| 92 | public: | ||
| 93 | enum class State : u8 { | ||
| 94 | Open, ///< The room is open and ready to accept connections. | ||
| 95 | Closed, ///< The room is not opened and can not accept connections. | ||
| 96 | }; | ||
| 97 | |||
| 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(); | ||
| 108 | ~Room(); | ||
| 109 | |||
| 110 | /** | ||
| 111 | * Gets the current state of the room. | ||
| 112 | */ | ||
| 113 | State GetState() const; | ||
| 114 | |||
| 115 | /** | ||
| 116 | * Gets the room information of the room. | ||
| 117 | */ | ||
| 118 | const RoomInformation& GetRoomInformation() const; | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Gets the verify UID of this room. | ||
| 122 | */ | ||
| 123 | std::string GetVerifyUID() const; | ||
| 124 | |||
| 125 | /** | ||
| 126 | * Gets a list of the mbmers connected to the room. | ||
| 127 | */ | ||
| 128 | std::vector<Member> GetRoomMemberList() const; | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Checks if the room is password protected | ||
| 132 | */ | ||
| 133 | bool HasPassword() const; | ||
| 134 | |||
| 135 | using UsernameBanList = std::vector<std::string>; | ||
| 136 | using IPBanList = std::vector<std::string>; | ||
| 137 | |||
| 138 | using BanList = std::pair<UsernameBanList, IPBanList>; | ||
| 139 | |||
| 140 | /** | ||
| 141 | * Creates the socket for this room. Will bind to default address if | ||
| 142 | * server is empty string. | ||
| 143 | */ | ||
| 144 | bool Create(const std::string& name, const std::string& description = "", | ||
| 145 | const std::string& server = "", u16 server_port = DefaultRoomPort, | ||
| 146 | const std::string& password = "", | ||
| 147 | const u32 max_connections = MaxConcurrentConnections, | ||
| 148 | const std::string& host_username = "", const std::string& preferred_game = "", | ||
| 149 | u64 preferred_game_id = 0, | ||
| 150 | std::unique_ptr<VerifyUser::Backend> verify_backend = nullptr, | ||
| 151 | const BanList& ban_list = {}, bool enable_citra_mods = false); | ||
| 152 | |||
| 153 | /** | ||
| 154 | * Sets the verification GUID of the room. | ||
| 155 | */ | ||
| 156 | void SetVerifyUID(const std::string& uid); | ||
| 157 | |||
| 158 | /** | ||
| 159 | * Gets the ban list (including banned forum usernames and IPs) of the room. | ||
| 160 | */ | ||
| 161 | BanList GetBanList() const; | ||
| 162 | |||
| 163 | /** | ||
| 164 | * Destroys the socket | ||
| 165 | */ | ||
| 166 | void Destroy(); | ||
| 167 | |||
| 168 | private: | ||
| 169 | class RoomImpl; | ||
| 170 | std::unique_ptr<RoomImpl> room_impl; | ||
| 171 | }; | ||
| 172 | |||
| 173 | } // namespace Network | ||