common: multiplayer: Use GameInfo type

This commit is contained in:
german77 2022-07-17 22:53:44 -05:00 committed by FearlessTobi
parent 4b404191cf
commit 899c8bb330
11 changed files with 60 additions and 62 deletions

View file

@ -19,14 +19,14 @@ static void to_json(nlohmann::json& json, const Member& member) {
if (!member.avatar_url.empty()) {
json["avatarUrl"] = member.avatar_url;
}
json["gameName"] = member.game_name;
json["gameId"] = member.game_id;
json["gameName"] = member.game.name;
json["gameId"] = member.game.id;
}
static void from_json(const nlohmann::json& json, Member& member) {
member.nickname = json.at("nickname").get<std::string>();
member.game_name = json.at("gameName").get<std::string>();
member.game_id = json.at("gameId").get<u64>();
member.game.name = json.at("gameName").get<std::string>();
member.game.id = json.at("gameId").get<u64>();
try {
member.username = json.at("username").get<std::string>();
member.avatar_url = json.at("avatarUrl").get<std::string>();
@ -42,8 +42,8 @@ static void to_json(nlohmann::json& json, const Room& room) {
if (!room.information.description.empty()) {
json["description"] = room.information.description;
}
json["preferredGameName"] = room.information.preferred_game;
json["preferredGameId"] = room.information.preferred_game_id;
json["preferredGameName"] = room.information.preferred_game.name;
json["preferredGameId"] = room.information.preferred_game.id;
json["maxPlayers"] = room.information.member_slots;
json["netVersion"] = room.net_version;
json["hasPassword"] = room.has_password;
@ -65,8 +65,8 @@ static void from_json(const nlohmann::json& json, Room& room) {
}
room.information.host_username = json.at("owner").get<std::string>();
room.information.port = json.at("port").get<u16>();
room.information.preferred_game = json.at("preferredGameName").get<std::string>();
room.information.preferred_game_id = json.at("preferredGameId").get<u64>();
room.information.preferred_game.name = json.at("preferredGameName").get<std::string>();
room.information.preferred_game.id = json.at("preferredGameId").get<u64>();
room.information.member_slots = json.at("maxPlayers").get<u32>();
room.net_version = json.at("netVersion").get<u32>();
room.has_password = json.at("hasPassword").get<bool>();
@ -83,8 +83,8 @@ namespace WebService {
void RoomJson::SetRoomInformation(const std::string& name, const std::string& description,
const u16 port, const u32 max_player, const u32 net_version,
const bool has_password, const std::string& preferred_game,
const u64 preferred_game_id) {
const bool has_password,
const AnnounceMultiplayerRoom::GameInfo& preferred_game) {
room.information.name = name;
room.information.description = description;
room.information.port = port;
@ -92,7 +92,6 @@ void RoomJson::SetRoomInformation(const std::string& name, const std::string& de
room.net_version = net_version;
room.has_password = has_password;
room.information.preferred_game = preferred_game;
room.information.preferred_game_id = preferred_game_id;
}
void RoomJson::AddPlayer(const AnnounceMultiplayerRoom::Member& member) {
room.members.push_back(member);

View file

@ -22,8 +22,7 @@ public:
~RoomJson() = default;
void SetRoomInformation(const std::string& name, const std::string& description, const u16 port,
const u32 max_player, const u32 net_version, const bool has_password,
const std::string& preferred_game,
const u64 preferred_game_id) override;
const AnnounceMultiplayerRoom::GameInfo& preferred_game) override;
void AddPlayer(const AnnounceMultiplayerRoom::Member& member) override;
WebResult Update() override;
WebResult Register() override;

View file

@ -10,6 +10,8 @@
namespace WebService {
std::string GetPublicKey(const std::string& host);
class VerifyUserJWT final : public Network::VerifyUser::Backend {
public:
VerifyUserJWT(const std::string& host);