summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/announce_multiplayer_room.h143
2 files changed, 144 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index d574e4b79..05fdfea82 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -41,6 +41,7 @@ add_custom_command(OUTPUT scm_rev.cpp
41add_library(common STATIC 41add_library(common STATIC
42 algorithm.h 42 algorithm.h
43 alignment.h 43 alignment.h
44 announce_multiplayer_room.h
44 assert.cpp 45 assert.cpp
45 assert.h 46 assert.h
46 atomic_helpers.h 47 atomic_helpers.h
diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h
new file mode 100644
index 000000000..0ad9da2be
--- /dev/null
+++ b/src/common/announce_multiplayer_room.h
@@ -0,0 +1,143 @@
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 <functional>
8#include <string>
9#include <vector>
10#include "common/common_types.h"
11#include "web_service/web_result.h"
12
13namespace AnnounceMultiplayerRoom {
14
15using MacAddress = std::array<u8, 6>;
16
17struct GameInfo {
18 std::string name{""};
19 u64 id{0};
20};
21
22struct Member {
23 std::string username;
24 std::string nickname;
25 std::string display_name;
26 std::string avatar_url;
27 MacAddress mac_address;
28 GameInfo game;
29};
30
31struct RoomInformation {
32 std::string name; ///< Name of the server
33 std::string description; ///< Server description
34 u32 member_slots; ///< Maximum number of members in this room
35 u16 port; ///< The port of this room
36 GameInfo preferred_game; ///< Game to advertise that you want to play
37 std::string host_username; ///< Forum username of the host
38 bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room
39};
40
41struct Room {
42 RoomInformation information;
43
44 std::string id;
45 std::string verify_uid; ///< UID used for verification
46 std::string ip;
47 u32 net_version;
48 bool has_password;
49
50 std::vector<Member> members;
51};
52using RoomList = std::vector<Room>;
53
54/**
55 * A AnnounceMultiplayerRoom interface class. A backend to submit/get to/from a web service should
56 * implement this interface.
57 */
58class Backend {
59public:
60 virtual ~Backend() = default;
61
62 /**
63 * Sets the Information that gets used for the announce
64 * @param uid The Id of the room
65 * @param name The name of the room
66 * @param description The room description
67 * @param port The port of the room
68 * @param net_version The version of the libNetwork that gets used
69 * @param has_password True if the room is passowrd protected
70 * @param preferred_game The preferred game of the room
71 * @param preferred_game_id The title id of the preferred game
72 */
73 virtual void SetRoomInformation(const std::string& name, const std::string& description,
74 const u16 port, const u32 max_player, const u32 net_version,
75 const bool has_password, const GameInfo& preferred_game) = 0;
76 /**
77 * Adds a player information to the data that gets announced
78 * @param nickname The nickname of the player
79 * @param mac_address The MAC Address of the player
80 * @param game_id The title id of the game the player plays
81 * @param game_name The name of the game the player plays
82 */
83 virtual void AddPlayer(const Member& member) = 0;
84
85 /**
86 * Updates the data in the announce service. Re-register the room when required.
87 * @result The result of the update attempt
88 */
89 virtual WebService::WebResult Update() = 0;
90
91 /**
92 * Registers the data in the announce service
93 * @result The result of the register attempt. When the result code is Success, A global Guid of
94 * the room which may be used for verification will be in the result's returned_data.
95 */
96 virtual WebService::WebResult Register() = 0;
97
98 /**
99 * Empties the stored players
100 */
101 virtual void ClearPlayers() = 0;
102
103 /**
104 * Get the room information from the announce service
105 * @result A list of all rooms the announce service has
106 */
107 virtual RoomList GetRoomList() = 0;
108
109 /**
110 * Sends a delete message to the announce service
111 */
112 virtual void Delete() = 0;
113};
114
115/**
116 * Empty implementation of AnnounceMultiplayerRoom interface that drops all data. Used when a
117 * functional backend implementation is not available.
118 */
119class NullBackend : public Backend {
120public:
121 ~NullBackend() = default;
122 void SetRoomInformation(const std::string& /*name*/, const std::string& /*description*/,
123 const u16 /*port*/, const u32 /*max_player*/, const u32 /*net_version*/,
124 const bool /*has_password*/,
125 const GameInfo& /*preferred_game*/) override {}
126 void AddPlayer(const Member& /*member*/) override {}
127 WebService::WebResult Update() override {
128 return WebService::WebResult{WebService::WebResult::Code::NoWebservice,
129 "WebService is missing", ""};
130 }
131 WebService::WebResult Register() override {
132 return WebService::WebResult{WebService::WebResult::Code::NoWebservice,
133 "WebService is missing", ""};
134 }
135 void ClearPlayers() override {}
136 RoomList GetRoomList() override {
137 return RoomList{};
138 }
139
140 void Delete() override {}
141};
142
143} // namespace AnnounceMultiplayerRoom