2017-10-31 04:02:42 -05:00
|
|
|
// Copyright 2017 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include "common/common_types.h"
|
2018-10-26 10:01:00 -05:00
|
|
|
#include "common/web_result.h"
|
2017-10-31 04:02:42 -05:00
|
|
|
|
|
|
|
namespace AnnounceMultiplayerRoom {
|
|
|
|
|
|
|
|
using MacAddress = std::array<u8, 6>;
|
|
|
|
|
|
|
|
struct Room {
|
|
|
|
struct Member {
|
2018-10-27 02:40:15 -05:00
|
|
|
std::string username;
|
|
|
|
std::string nickname;
|
|
|
|
std::string avatar_url;
|
2017-10-31 04:02:42 -05:00
|
|
|
MacAddress mac_address;
|
|
|
|
std::string game_name;
|
|
|
|
u64 game_id;
|
|
|
|
};
|
2018-10-27 02:40:15 -05:00
|
|
|
std::string id;
|
|
|
|
std::string verify_UID; ///< UID used for verification
|
2017-10-31 04:02:42 -05:00
|
|
|
std::string name;
|
2018-04-30 02:40:51 -05:00
|
|
|
std::string description;
|
2017-10-31 04:02:42 -05:00
|
|
|
std::string owner;
|
|
|
|
std::string ip;
|
|
|
|
u16 port;
|
|
|
|
u32 max_player;
|
|
|
|
u32 net_version;
|
|
|
|
bool has_password;
|
|
|
|
std::string preferred_game;
|
|
|
|
u64 preferred_game_id;
|
|
|
|
|
|
|
|
std::vector<Member> members;
|
|
|
|
};
|
|
|
|
using RoomList = std::vector<Room>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A AnnounceMultiplayerRoom interface class. A backend to submit/get to/from a web service should
|
|
|
|
* implement this interface.
|
|
|
|
*/
|
|
|
|
class Backend : NonCopyable {
|
|
|
|
public:
|
|
|
|
virtual ~Backend() = default;
|
2017-11-07 14:51:11 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Information that gets used for the announce
|
|
|
|
* @param uid The Id of the room
|
|
|
|
* @param name The name of the room
|
2018-04-30 02:40:51 -05:00
|
|
|
* @param description The room description
|
2017-11-07 14:51:11 -06:00
|
|
|
* @param port The port of the room
|
|
|
|
* @param net_version The version of the libNetwork that gets used
|
|
|
|
* @param has_password True if the room is passowrd protected
|
|
|
|
* @param preferred_game The preferred game of the room
|
|
|
|
* @param preferred_game_id The title id of the preferred game
|
|
|
|
*/
|
2018-10-27 02:40:15 -05:00
|
|
|
virtual void SetRoomInformation(const std::string& name, const std::string& description,
|
|
|
|
const u16 port, const u32 max_player, const u32 net_version,
|
2017-10-31 04:02:42 -05:00
|
|
|
const bool has_password, const std::string& preferred_game,
|
|
|
|
const u64 preferred_game_id) = 0;
|
2017-11-07 14:51:11 -06:00
|
|
|
/**
|
|
|
|
* Adds a player information to the data that gets announced
|
|
|
|
* @param nickname The nickname of the player
|
|
|
|
* @param mac_address The MAC Address of the player
|
|
|
|
* @param game_id The title id of the game the player plays
|
|
|
|
* @param game_name The name of the game the player plays
|
|
|
|
*/
|
2018-10-27 02:40:15 -05:00
|
|
|
virtual void AddPlayer(const std::string& username, const std::string& nickname,
|
|
|
|
const std::string& avatar_url, const MacAddress& mac_address,
|
2017-10-31 04:02:42 -05:00
|
|
|
const u64 game_id, const std::string& game_name) = 0;
|
2017-11-07 14:51:11 -06:00
|
|
|
|
|
|
|
/**
|
2018-10-27 02:40:15 -05:00
|
|
|
* Updates the data in the announce service. Re-register the room when required.
|
|
|
|
* @result The result of the update attempt
|
2017-11-07 14:51:11 -06:00
|
|
|
*/
|
2018-10-27 02:40:15 -05:00
|
|
|
virtual Common::WebResult Update() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the data in the announce service
|
2019-04-19 09:55:49 -05:00
|
|
|
* @result The result of the register attempt. When the result code is Success, A global Guid of
|
|
|
|
* the room which may be used for verification will be in the result's returned_data.
|
2018-10-27 02:40:15 -05:00
|
|
|
*/
|
2019-04-19 09:55:49 -05:00
|
|
|
virtual Common::WebResult Register() = 0;
|
2017-11-07 14:51:11 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Empties the stored players
|
|
|
|
*/
|
2017-10-31 04:02:42 -05:00
|
|
|
virtual void ClearPlayers() = 0;
|
2017-11-07 14:51:11 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the room information from the announce service
|
|
|
|
* @result A list of all rooms the announce service has
|
|
|
|
*/
|
2018-09-12 11:22:48 -05:00
|
|
|
virtual RoomList GetRoomList() = 0;
|
2017-11-07 14:51:11 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a delete message to the announce service
|
|
|
|
*/
|
2017-10-31 04:02:42 -05:00
|
|
|
virtual void Delete() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Empty implementation of AnnounceMultiplayerRoom interface that drops all data. Used when a
|
|
|
|
* functional backend implementation is not available.
|
|
|
|
*/
|
|
|
|
class NullBackend : public Backend {
|
|
|
|
public:
|
|
|
|
~NullBackend() = default;
|
2018-10-27 02:40:15 -05:00
|
|
|
void SetRoomInformation(const std::string& /*name*/, const std::string& /*description*/,
|
|
|
|
const u16 /*port*/, const u32 /*max_player*/, const u32 /*net_version*/,
|
2017-10-31 04:02:42 -05:00
|
|
|
const bool /*has_password*/, const std::string& /*preferred_game*/,
|
|
|
|
const u64 /*preferred_game_id*/) override {}
|
2018-10-27 02:40:15 -05:00
|
|
|
void AddPlayer(const std::string& /*username*/, const std::string& /*nickname*/,
|
|
|
|
const std::string& /*avatar_url*/, const MacAddress& /*mac_address*/,
|
2017-10-31 04:02:42 -05:00
|
|
|
const u64 /*game_id*/, const std::string& /*game_name*/) override {}
|
2018-10-27 02:40:15 -05:00
|
|
|
Common::WebResult Update() override {
|
2018-09-12 11:22:48 -05:00
|
|
|
return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"};
|
2017-10-31 04:02:42 -05:00
|
|
|
}
|
2019-04-19 09:55:49 -05:00
|
|
|
Common::WebResult Register() override {
|
|
|
|
return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"};
|
2018-10-27 02:40:15 -05:00
|
|
|
}
|
2017-10-31 04:02:42 -05:00
|
|
|
void ClearPlayers() override {}
|
2018-09-12 11:22:48 -05:00
|
|
|
RoomList GetRoomList() override {
|
|
|
|
return RoomList{};
|
2017-10-31 04:02:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Delete() override {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace AnnounceMultiplayerRoom
|