diff options
| author | 2021-12-25 20:27:52 +0100 | |
|---|---|---|
| committer | 2022-07-25 21:59:28 +0200 | |
| commit | 705f7db84dd85555a6aef1e136cf251725cef293 (patch) | |
| tree | e110c6482a11d711d18515afce4fc50adcee76e7 /src/common/announce_multiplayer_room.h | |
| parent | network: Add initial files and enet dependency (diff) | |
| download | yuzu-705f7db84dd85555a6aef1e136cf251725cef293.tar.gz yuzu-705f7db84dd85555a6aef1e136cf251725cef293.tar.xz yuzu-705f7db84dd85555a6aef1e136cf251725cef293.zip | |
yuzu: Add ui files for multiplayer rooms
Diffstat (limited to 'src/common/announce_multiplayer_room.h')
| -rw-r--r-- | src/common/announce_multiplayer_room.h | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h new file mode 100644 index 000000000..5ca5893ef --- /dev/null +++ b/src/common/announce_multiplayer_room.h | |||
| @@ -0,0 +1,138 @@ | |||
| 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 <functional> | ||
| 9 | #include <string> | ||
| 10 | #include <vector> | ||
| 11 | #include "common/common_types.h" | ||
| 12 | #include "web_service/web_result.h" | ||
| 13 | |||
| 14 | namespace AnnounceMultiplayerRoom { | ||
| 15 | |||
| 16 | using MacAddress = std::array<u8, 6>; | ||
| 17 | |||
| 18 | struct Room { | ||
| 19 | struct Member { | ||
| 20 | std::string username; | ||
| 21 | std::string nickname; | ||
| 22 | std::string avatar_url; | ||
| 23 | MacAddress mac_address; | ||
| 24 | std::string game_name; | ||
| 25 | u64 game_id; | ||
| 26 | }; | ||
| 27 | std::string id; | ||
| 28 | std::string verify_UID; ///< UID used for verification | ||
| 29 | std::string name; | ||
| 30 | std::string description; | ||
| 31 | std::string owner; | ||
| 32 | std::string ip; | ||
| 33 | u16 port; | ||
| 34 | u32 max_player; | ||
| 35 | u32 net_version; | ||
| 36 | bool has_password; | ||
| 37 | std::string preferred_game; | ||
| 38 | u64 preferred_game_id; | ||
| 39 | |||
| 40 | std::vector<Member> members; | ||
| 41 | }; | ||
| 42 | using RoomList = std::vector<Room>; | ||
| 43 | |||
| 44 | /** | ||
| 45 | * A AnnounceMultiplayerRoom interface class. A backend to submit/get to/from a web service should | ||
| 46 | * implement this interface. | ||
| 47 | */ | ||
| 48 | class Backend { | ||
| 49 | public: | ||
| 50 | virtual ~Backend() = default; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Sets the Information that gets used for the announce | ||
| 54 | * @param uid The Id of the room | ||
| 55 | * @param name The name of the room | ||
| 56 | * @param description The room description | ||
| 57 | * @param port The port of the room | ||
| 58 | * @param net_version The version of the libNetwork that gets used | ||
| 59 | * @param has_password True if the room is passowrd protected | ||
| 60 | * @param preferred_game The preferred game of the room | ||
| 61 | * @param preferred_game_id The title id of the preferred game | ||
| 62 | */ | ||
| 63 | virtual void SetRoomInformation(const std::string& name, const std::string& description, | ||
| 64 | const u16 port, const u32 max_player, const u32 net_version, | ||
| 65 | const bool has_password, const std::string& preferred_game, | ||
| 66 | const u64 preferred_game_id) = 0; | ||
| 67 | /** | ||
| 68 | * Adds a player information to the data that gets announced | ||
| 69 | * @param nickname The nickname of the player | ||
| 70 | * @param mac_address The MAC Address of the player | ||
| 71 | * @param game_id The title id of the game the player plays | ||
| 72 | * @param game_name The name of the game the player plays | ||
| 73 | */ | ||
| 74 | virtual void AddPlayer(const std::string& username, const std::string& nickname, | ||
| 75 | const std::string& avatar_url, const MacAddress& mac_address, | ||
| 76 | const u64 game_id, const std::string& game_name) = 0; | ||
| 77 | |||
| 78 | /** | ||
| 79 | * Updates the data in the announce service. Re-register the room when required. | ||
| 80 | * @result The result of the update attempt | ||
| 81 | */ | ||
| 82 | virtual WebService::WebResult Update() = 0; | ||
| 83 | |||
| 84 | /** | ||
| 85 | * Registers the data in the announce service | ||
| 86 | * @result The result of the register attempt. When the result code is Success, A global Guid of | ||
| 87 | * the room which may be used for verification will be in the result's returned_data. | ||
| 88 | */ | ||
| 89 | virtual WebService::WebResult Register() = 0; | ||
| 90 | |||
| 91 | /** | ||
| 92 | * Empties the stored players | ||
| 93 | */ | ||
| 94 | virtual void ClearPlayers() = 0; | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Get the room information from the announce service | ||
| 98 | * @result A list of all rooms the announce service has | ||
| 99 | */ | ||
| 100 | virtual RoomList GetRoomList() = 0; | ||
| 101 | |||
| 102 | /** | ||
| 103 | * Sends a delete message to the announce service | ||
| 104 | */ | ||
| 105 | virtual void Delete() = 0; | ||
| 106 | }; | ||
| 107 | |||
| 108 | /** | ||
| 109 | * Empty implementation of AnnounceMultiplayerRoom interface that drops all data. Used when a | ||
| 110 | * functional backend implementation is not available. | ||
| 111 | */ | ||
| 112 | class NullBackend : public Backend { | ||
| 113 | public: | ||
| 114 | ~NullBackend() = default; | ||
| 115 | void SetRoomInformation(const std::string& /*name*/, const std::string& /*description*/, | ||
| 116 | const u16 /*port*/, const u32 /*max_player*/, const u32 /*net_version*/, | ||
| 117 | const bool /*has_password*/, const std::string& /*preferred_game*/, | ||
| 118 | const u64 /*preferred_game_id*/) override {} | ||
| 119 | void AddPlayer(const std::string& /*username*/, const std::string& /*nickname*/, | ||
| 120 | const std::string& /*avatar_url*/, const MacAddress& /*mac_address*/, | ||
| 121 | const u64 /*game_id*/, const std::string& /*game_name*/) override {} | ||
| 122 | WebService::WebResult Update() override { | ||
| 123 | return WebService::WebResult{WebService::WebResult::Code::NoWebservice, | ||
| 124 | "WebService is missing"}; | ||
| 125 | } | ||
| 126 | WebService::WebResult Register() override { | ||
| 127 | return WebService::WebResult{WebService::WebResult::Code::NoWebservice, | ||
| 128 | "WebService is missing"}; | ||
| 129 | } | ||
| 130 | void ClearPlayers() override {} | ||
| 131 | RoomList GetRoomList() override { | ||
| 132 | return RoomList{}; | ||
| 133 | } | ||
| 134 | |||
| 135 | void Delete() override {} | ||
| 136 | }; | ||
| 137 | |||
| 138 | } // namespace AnnounceMultiplayerRoom | ||