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