diff options
Diffstat (limited to 'src/web_service')
| -rw-r--r-- | src/web_service/announce_room_json.cpp | 62 | ||||
| -rw-r--r-- | src/web_service/announce_room_json.h | 5 | ||||
| -rw-r--r-- | src/web_service/verify_user_jwt.cpp | 10 |
3 files changed, 36 insertions, 41 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 | ||
| 12 | namespace AnnounceMultiplayerRoom { | 12 | namespace AnnounceMultiplayerRoom { |
| 13 | 13 | ||
| 14 | static void to_json(nlohmann::json& json, const Room::Member& member) { | 14 | static 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 | ||
| 26 | static void from_json(const nlohmann::json& json, Room::Member& member) { | 26 | static 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 | ||
| 39 | static void to_json(nlohmann::json& json, const Room& room) { | 39 | static 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) { | |||
| 56 | static void from_json(const nlohmann::json& json, Room& room) { | 56 | static 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 | } |
| 97 | void RoomJson::AddPlayer(const std::string& username_, const std::string& nickname_, | 97 | void 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 | ||
diff --git a/src/web_service/announce_room_json.h b/src/web_service/announce_room_json.h index f65c93214..811c76fbd 100644 --- a/src/web_service/announce_room_json.h +++ b/src/web_service/announce_room_json.h | |||
| @@ -24,10 +24,7 @@ public: | |||
| 24 | const u32 max_player, const u32 net_version, const bool has_password, | 24 | const u32 max_player, const u32 net_version, const bool has_password, |
| 25 | const std::string& preferred_game, | 25 | const std::string& preferred_game, |
| 26 | const u64 preferred_game_id) override; | 26 | const u64 preferred_game_id) override; |
| 27 | void AddPlayer(const std::string& username_, const std::string& nickname_, | 27 | void AddPlayer(const AnnounceMultiplayerRoom::Member& member) override; |
| 28 | const std::string& avatar_url, | ||
| 29 | const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id, | ||
| 30 | const std::string& game_name) override; | ||
| 31 | WebResult Update() override; | 28 | WebResult Update() override; |
| 32 | WebResult Register() override; | 29 | WebResult Register() override; |
| 33 | void ClearPlayers() override; | 30 | void ClearPlayers() override; |
diff --git a/src/web_service/verify_user_jwt.cpp b/src/web_service/verify_user_jwt.cpp index 78fe7bed5..3133dcbe2 100644 --- a/src/web_service/verify_user_jwt.cpp +++ b/src/web_service/verify_user_jwt.cpp | |||
| @@ -2,8 +2,16 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <system_error> | 5 | #if defined(__GNUC__) || defined(__clang__) |
| 6 | #pragma GCC diagnostic push | ||
| 7 | #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" | ||
| 8 | #endif | ||
| 6 | #include <jwt/jwt.hpp> | 9 | #include <jwt/jwt.hpp> |
| 10 | #if defined(__GNUC__) || defined(__clang__) | ||
| 11 | #pragma GCC diagnostic pop | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #include <system_error> | ||
| 7 | #include "common/logging/log.h" | 15 | #include "common/logging/log.h" |
| 8 | #include "web_service/verify_user_jwt.h" | 16 | #include "web_service/verify_user_jwt.h" |
| 9 | #include "web_service/web_backend.h" | 17 | #include "web_service/web_backend.h" |