summaryrefslogtreecommitdiff
path: root/src/web_service/announce_room_json.cpp
diff options
context:
space:
mode:
authorGravatar FearlessTobi2022-07-15 21:11:09 +0200
committerGravatar FearlessTobi2022-07-25 21:59:30 +0200
commit4b404191cf054ec3206676f1fccc452bc0a0e223 (patch)
tree8a1582246c41260fe82804bf4dcb9abf77176e27 /src/web_service/announce_room_json.cpp
parentAddress first part of review comments (diff)
downloadyuzu-4b404191cf054ec3206676f1fccc452bc0a0e223.tar.gz
yuzu-4b404191cf054ec3206676f1fccc452bc0a0e223.tar.xz
yuzu-4b404191cf054ec3206676f1fccc452bc0a0e223.zip
Address second part of review comments
Diffstat (limited to 'src/web_service/announce_room_json.cpp')
-rw-r--r--src/web_service/announce_room_json.cpp62
1 files changed, 26 insertions, 36 deletions
diff --git a/src/web_service/announce_room_json.cpp b/src/web_service/announce_room_json.cpp
index 984a59f77..84220b851 100644
--- a/src/web_service/announce_room_json.cpp
+++ b/src/web_service/announce_room_json.cpp
@@ -11,7 +11,7 @@
11 11
12namespace AnnounceMultiplayerRoom { 12namespace AnnounceMultiplayerRoom {
13 13
14static void to_json(nlohmann::json& json, const Room::Member& member) { 14static void to_json(nlohmann::json& json, const Member& member) {
15 if (!member.username.empty()) { 15 if (!member.username.empty()) {
16 json["username"] = member.username; 16 json["username"] = member.username;
17 } 17 }
@@ -23,7 +23,7 @@ static void to_json(nlohmann::json& json, const Room::Member& member) {
23 json["gameId"] = member.game_id; 23 json["gameId"] = member.game_id;
24} 24}
25 25
26static void from_json(const nlohmann::json& json, Room::Member& member) { 26static void from_json(const nlohmann::json& json, Member& member) {
27 member.nickname = json.at("nickname").get<std::string>(); 27 member.nickname = json.at("nickname").get<std::string>();
28 member.game_name = json.at("gameName").get<std::string>(); 28 member.game_name = json.at("gameName").get<std::string>();
29 member.game_id = json.at("gameId").get<u64>(); 29 member.game_id = json.at("gameId").get<u64>();
@@ -37,14 +37,14 @@ static void from_json(const nlohmann::json& json, Room::Member& member) {
37} 37}
38 38
39static void to_json(nlohmann::json& json, const Room& room) { 39static void to_json(nlohmann::json& json, const Room& room) {
40 json["port"] = room.port; 40 json["port"] = room.information.port;
41 json["name"] = room.name; 41 json["name"] = room.information.name;
42 if (!room.description.empty()) { 42 if (!room.information.description.empty()) {
43 json["description"] = room.description; 43 json["description"] = room.information.description;
44 } 44 }
45 json["preferredGameName"] = room.preferred_game; 45 json["preferredGameName"] = room.information.preferred_game;
46 json["preferredGameId"] = room.preferred_game_id; 46 json["preferredGameId"] = room.information.preferred_game_id;
47 json["maxPlayers"] = room.max_player; 47 json["maxPlayers"] = room.information.member_slots;
48 json["netVersion"] = room.net_version; 48 json["netVersion"] = room.net_version;
49 json["hasPassword"] = room.has_password; 49 json["hasPassword"] = room.has_password;
50 if (room.members.size() > 0) { 50 if (room.members.size() > 0) {
@@ -56,22 +56,22 @@ static void to_json(nlohmann::json& json, const Room& room) {
56static void from_json(const nlohmann::json& json, Room& room) { 56static void from_json(const nlohmann::json& json, Room& room) {
57 room.verify_UID = json.at("externalGuid").get<std::string>(); 57 room.verify_UID = json.at("externalGuid").get<std::string>();
58 room.ip = json.at("address").get<std::string>(); 58 room.ip = json.at("address").get<std::string>();
59 room.name = json.at("name").get<std::string>(); 59 room.information.name = json.at("name").get<std::string>();
60 try { 60 try {
61 room.description = json.at("description").get<std::string>(); 61 room.information.description = json.at("description").get<std::string>();
62 } catch (const nlohmann::detail::out_of_range&) { 62 } catch (const nlohmann::detail::out_of_range&) {
63 room.description = ""; 63 room.information.description = "";
64 LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.name); 64 LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.information.name);
65 } 65 }
66 room.owner = json.at("owner").get<std::string>(); 66 room.information.host_username = json.at("owner").get<std::string>();
67 room.port = json.at("port").get<u16>(); 67 room.information.port = json.at("port").get<u16>();
68 room.preferred_game = json.at("preferredGameName").get<std::string>(); 68 room.information.preferred_game = json.at("preferredGameName").get<std::string>();
69 room.preferred_game_id = json.at("preferredGameId").get<u64>(); 69 room.information.preferred_game_id = json.at("preferredGameId").get<u64>();
70 room.max_player = json.at("maxPlayers").get<u32>(); 70 room.information.member_slots = json.at("maxPlayers").get<u32>();
71 room.net_version = json.at("netVersion").get<u32>(); 71 room.net_version = json.at("netVersion").get<u32>();
72 room.has_password = json.at("hasPassword").get<bool>(); 72 room.has_password = json.at("hasPassword").get<bool>();
73 try { 73 try {
74 room.members = json.at("players").get<std::vector<Room::Member>>(); 74 room.members = json.at("players").get<std::vector<Member>>();
75 } catch (const nlohmann::detail::out_of_range& e) { 75 } catch (const nlohmann::detail::out_of_range& e) {
76 LOG_DEBUG(Network, "Out of range {}", e.what()); 76 LOG_DEBUG(Network, "Out of range {}", e.what());
77 } 77 }
@@ -85,26 +85,16 @@ void RoomJson::SetRoomInformation(const std::string& name, const std::string& de
85 const u16 port, const u32 max_player, const u32 net_version, 85 const u16 port, const u32 max_player, const u32 net_version,
86 const bool has_password, const std::string& preferred_game, 86 const bool has_password, const std::string& preferred_game,
87 const u64 preferred_game_id) { 87 const u64 preferred_game_id) {
88 room.name = name; 88 room.information.name = name;
89 room.description = description; 89 room.information.description = description;
90 room.port = port; 90 room.information.port = port;
91 room.max_player = max_player; 91 room.information.member_slots = max_player;
92 room.net_version = net_version; 92 room.net_version = net_version;
93 room.has_password = has_password; 93 room.has_password = has_password;
94 room.preferred_game = preferred_game; 94 room.information.preferred_game = preferred_game;
95 room.preferred_game_id = preferred_game_id; 95 room.information.preferred_game_id = preferred_game_id;
96} 96}
97void RoomJson::AddPlayer(const std::string& username_, const std::string& nickname_, 97void RoomJson::AddPlayer(const AnnounceMultiplayerRoom::Member& member) {
98 const std::string& avatar_url,
99 const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id,
100 const std::string& game_name) {
101 AnnounceMultiplayerRoom::Room::Member member;
102 member.username = username_;
103 member.nickname = nickname_;
104 member.avatar_url = avatar_url;
105 member.mac_address = mac_address;
106 member.game_id = game_id;
107 member.game_name = game_name;
108 room.members.push_back(member); 98 room.members.push_back(member);
109} 99}
110 100