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 "common/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 : NonCopyable { 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 Common::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 Common::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; SetRoomInformation(const std::string &,const std::string &,const u16,const u32,const u32,const bool,const std::string &,const u64)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 {} AddPlayer(const std::string &,const std::string &,const std::string &,const MacAddress &,const u64,const std::string &)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 {} Update()122 Common::WebResult Update() override { 123 return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"}; 124 } Register()125 Common::WebResult Register() override { 126 return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"}; 127 } ClearPlayers()128 void ClearPlayers() override {} GetRoomList()129 RoomList GetRoomList() override { 130 return RoomList{}; 131 } 132 Delete()133 void Delete() override {} 134 }; 135 136 } // namespace AnnounceMultiplayerRoom 137