diff options
| author | 2021-12-25 20:27:52 +0100 | |
|---|---|---|
| committer | 2022-07-25 21:59:28 +0200 | |
| commit | 705f7db84dd85555a6aef1e136cf251725cef293 (patch) | |
| tree | e110c6482a11d711d18515afce4fc50adcee76e7 /src | |
| parent | network: Add initial files and enet dependency (diff) | |
| download | yuzu-705f7db84dd85555a6aef1e136cf251725cef293.tar.gz yuzu-705f7db84dd85555a6aef1e136cf251725cef293.tar.xz yuzu-705f7db84dd85555a6aef1e136cf251725cef293.zip | |
yuzu: Add ui files for multiplayer rooms
Diffstat (limited to '')
67 files changed, 4499 insertions, 49 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d574e4b79..05fdfea82 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -41,6 +41,7 @@ add_custom_command(OUTPUT scm_rev.cpp | |||
| 41 | add_library(common STATIC | 41 | add_library(common STATIC |
| 42 | algorithm.h | 42 | algorithm.h |
| 43 | alignment.h | 43 | alignment.h |
| 44 | announce_multiplayer_room.h | ||
| 44 | assert.cpp | 45 | assert.cpp |
| 45 | assert.h | 46 | assert.h |
| 46 | atomic_helpers.h | 47 | atomic_helpers.h |
diff --git a/src/common/announce_multiplayer_room.h b/src/common/announce_multiplayer_room.h new file mode 100644 index 000000000..5ca5893ef --- /dev/null +++ b/src/common/announce_multiplayer_room.h | |||
| @@ -0,0 +1,138 @@ | |||
| 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 "web_service/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 { | ||
| 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 WebService::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 WebService::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; | ||
| 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 {} | ||
| 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 {} | ||
| 122 | WebService::WebResult Update() override { | ||
| 123 | return WebService::WebResult{WebService::WebResult::Code::NoWebservice, | ||
| 124 | "WebService is missing"}; | ||
| 125 | } | ||
| 126 | WebService::WebResult Register() override { | ||
| 127 | return WebService::WebResult{WebService::WebResult::Code::NoWebservice, | ||
| 128 | "WebService is missing"}; | ||
| 129 | } | ||
| 130 | void ClearPlayers() override {} | ||
| 131 | RoomList GetRoomList() override { | ||
| 132 | return RoomList{}; | ||
| 133 | } | ||
| 134 | |||
| 135 | void Delete() override {} | ||
| 136 | }; | ||
| 137 | |||
| 138 | } // namespace AnnounceMultiplayerRoom | ||
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 32cc2f392..48f5c1ee0 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | add_library(core STATIC | 1 | add_library(core STATIC |
| 2 | announce_multiplayer_session.cpp | ||
| 3 | announce_multiplayer_session.h | ||
| 2 | arm/arm_interface.h | 4 | arm/arm_interface.h |
| 3 | arm/arm_interface.cpp | 5 | arm/arm_interface.cpp |
| 4 | arm/cpu_interrupt_handler.cpp | 6 | arm/cpu_interrupt_handler.cpp |
| @@ -741,11 +743,11 @@ add_library(core STATIC | |||
| 741 | memory/dmnt_cheat_vm.h | 743 | memory/dmnt_cheat_vm.h |
| 742 | memory.cpp | 744 | memory.cpp |
| 743 | memory.h | 745 | memory.h |
| 744 | network/network.cpp | 746 | internal_network/network.cpp |
| 745 | network/network.h | 747 | internal_network/network.h |
| 746 | network/network_interface.cpp | 748 | internal_network/network_interface.cpp |
| 747 | network/network_interface.h | 749 | internal_network/network_interface.h |
| 748 | network/sockets.h | 750 | internal_network/sockets.h |
| 749 | perf_stats.cpp | 751 | perf_stats.cpp |
| 750 | perf_stats.h | 752 | perf_stats.h |
| 751 | reporter.cpp | 753 | reporter.cpp |
| @@ -780,7 +782,7 @@ endif() | |||
| 780 | 782 | ||
| 781 | create_target_directory_groups(core) | 783 | create_target_directory_groups(core) |
| 782 | 784 | ||
| 783 | target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) | 785 | target_link_libraries(core PUBLIC common PRIVATE audio_core network video_core) |
| 784 | target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus) | 786 | target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus) |
| 785 | if (MINGW) | 787 | if (MINGW) |
| 786 | target_link_libraries(core PRIVATE ${MSWSOCK_LIBRARY}) | 788 | target_link_libraries(core PRIVATE ${MSWSOCK_LIBRARY}) |
diff --git a/src/core/announce_multiplayer_session.cpp b/src/core/announce_multiplayer_session.cpp new file mode 100644 index 000000000..a680ad202 --- /dev/null +++ b/src/core/announce_multiplayer_session.cpp | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <chrono> | ||
| 6 | #include <future> | ||
| 7 | #include <vector> | ||
| 8 | #include "announce_multiplayer_session.h" | ||
| 9 | #include "common/announce_multiplayer_room.h" | ||
| 10 | #include "common/assert.h" | ||
| 11 | #include "common/settings.h" | ||
| 12 | #include "network/network.h" | ||
| 13 | |||
| 14 | #ifdef ENABLE_WEB_SERVICE | ||
| 15 | #include "web_service/announce_room_json.h" | ||
| 16 | #endif | ||
| 17 | |||
| 18 | namespace Core { | ||
| 19 | |||
| 20 | // Time between room is announced to web_service | ||
| 21 | static constexpr std::chrono::seconds announce_time_interval(15); | ||
| 22 | |||
| 23 | AnnounceMultiplayerSession::AnnounceMultiplayerSession() { | ||
| 24 | #ifdef ENABLE_WEB_SERVICE | ||
| 25 | backend = std::make_unique<WebService::RoomJson>(Settings::values.web_api_url.GetValue(), | ||
| 26 | Settings::values.yuzu_username.GetValue(), | ||
| 27 | Settings::values.yuzu_token.GetValue()); | ||
| 28 | #else | ||
| 29 | backend = std::make_unique<AnnounceMultiplayerRoom::NullBackend>(); | ||
| 30 | #endif | ||
| 31 | } | ||
| 32 | |||
| 33 | WebService::WebResult AnnounceMultiplayerSession::Register() { | ||
| 34 | std::shared_ptr<Network::Room> room = Network::GetRoom().lock(); | ||
| 35 | if (!room) { | ||
| 36 | return WebService::WebResult{WebService::WebResult::Code::LibError, | ||
| 37 | "Network is not initialized"}; | ||
| 38 | } | ||
| 39 | if (room->GetState() != Network::Room::State::Open) { | ||
| 40 | return WebService::WebResult{WebService::WebResult::Code::LibError, "Room is not open"}; | ||
| 41 | } | ||
| 42 | UpdateBackendData(room); | ||
| 43 | WebService::WebResult result = backend->Register(); | ||
| 44 | if (result.result_code != WebService::WebResult::Code::Success) { | ||
| 45 | return result; | ||
| 46 | } | ||
| 47 | LOG_INFO(WebService, "Room has been registered"); | ||
| 48 | room->SetVerifyUID(result.returned_data); | ||
| 49 | registered = true; | ||
| 50 | return WebService::WebResult{WebService::WebResult::Code::Success}; | ||
| 51 | } | ||
| 52 | |||
| 53 | void AnnounceMultiplayerSession::Start() { | ||
| 54 | if (announce_multiplayer_thread) { | ||
| 55 | Stop(); | ||
| 56 | } | ||
| 57 | shutdown_event.Reset(); | ||
| 58 | announce_multiplayer_thread = | ||
| 59 | std::make_unique<std::thread>(&AnnounceMultiplayerSession::AnnounceMultiplayerLoop, this); | ||
| 60 | } | ||
| 61 | |||
| 62 | void AnnounceMultiplayerSession::Stop() { | ||
| 63 | if (announce_multiplayer_thread) { | ||
| 64 | shutdown_event.Set(); | ||
| 65 | announce_multiplayer_thread->join(); | ||
| 66 | announce_multiplayer_thread.reset(); | ||
| 67 | backend->Delete(); | ||
| 68 | registered = false; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | AnnounceMultiplayerSession::CallbackHandle AnnounceMultiplayerSession::BindErrorCallback( | ||
| 73 | std::function<void(const WebService::WebResult&)> function) { | ||
| 74 | std::lock_guard lock(callback_mutex); | ||
| 75 | auto handle = std::make_shared<std::function<void(const WebService::WebResult&)>>(function); | ||
| 76 | error_callbacks.insert(handle); | ||
| 77 | return handle; | ||
| 78 | } | ||
| 79 | |||
| 80 | void AnnounceMultiplayerSession::UnbindErrorCallback(CallbackHandle handle) { | ||
| 81 | std::lock_guard lock(callback_mutex); | ||
| 82 | error_callbacks.erase(handle); | ||
| 83 | } | ||
| 84 | |||
| 85 | AnnounceMultiplayerSession::~AnnounceMultiplayerSession() { | ||
| 86 | Stop(); | ||
| 87 | } | ||
| 88 | |||
| 89 | void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room> room) { | ||
| 90 | Network::RoomInformation room_information = room->GetRoomInformation(); | ||
| 91 | std::vector<Network::Room::Member> memberlist = room->GetRoomMemberList(); | ||
| 92 | backend->SetRoomInformation( | ||
| 93 | room_information.name, room_information.description, room_information.port, | ||
| 94 | room_information.member_slots, Network::network_version, room->HasPassword(), | ||
| 95 | room_information.preferred_game, room_information.preferred_game_id); | ||
| 96 | backend->ClearPlayers(); | ||
| 97 | for (const auto& member : memberlist) { | ||
| 98 | backend->AddPlayer(member.username, member.nickname, member.avatar_url, member.mac_address, | ||
| 99 | member.game_info.id, member.game_info.name); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { | ||
| 104 | // Invokes all current bound error callbacks. | ||
| 105 | const auto ErrorCallback = [this](WebService::WebResult result) { | ||
| 106 | std::lock_guard<std::mutex> lock(callback_mutex); | ||
| 107 | for (auto callback : error_callbacks) { | ||
| 108 | (*callback)(result); | ||
| 109 | } | ||
| 110 | }; | ||
| 111 | |||
| 112 | if (!registered) { | ||
| 113 | WebService::WebResult result = Register(); | ||
| 114 | if (result.result_code != WebService::WebResult::Code::Success) { | ||
| 115 | ErrorCallback(result); | ||
| 116 | return; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | auto update_time = std::chrono::steady_clock::now(); | ||
| 121 | std::future<WebService::WebResult> future; | ||
| 122 | while (!shutdown_event.WaitUntil(update_time)) { | ||
| 123 | update_time += announce_time_interval; | ||
| 124 | std::shared_ptr<Network::Room> room = Network::GetRoom().lock(); | ||
| 125 | if (!room) { | ||
| 126 | break; | ||
| 127 | } | ||
| 128 | if (room->GetState() != Network::Room::State::Open) { | ||
| 129 | break; | ||
| 130 | } | ||
| 131 | UpdateBackendData(room); | ||
| 132 | WebService::WebResult result = backend->Update(); | ||
| 133 | if (result.result_code != WebService::WebResult::Code::Success) { | ||
| 134 | ErrorCallback(result); | ||
| 135 | } | ||
| 136 | if (result.result_string == "404") { | ||
| 137 | registered = false; | ||
| 138 | // Needs to register the room again | ||
| 139 | WebService::WebResult register_result = Register(); | ||
| 140 | if (register_result.result_code != WebService::WebResult::Code::Success) { | ||
| 141 | ErrorCallback(register_result); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | AnnounceMultiplayerRoom::RoomList AnnounceMultiplayerSession::GetRoomList() { | ||
| 148 | return backend->GetRoomList(); | ||
| 149 | } | ||
| 150 | |||
| 151 | bool AnnounceMultiplayerSession::IsRunning() const { | ||
| 152 | return announce_multiplayer_thread != nullptr; | ||
| 153 | } | ||
| 154 | |||
| 155 | void AnnounceMultiplayerSession::UpdateCredentials() { | ||
| 156 | ASSERT_MSG(!IsRunning(), "Credentials can only be updated when session is not running"); | ||
| 157 | |||
| 158 | #ifdef ENABLE_WEB_SERVICE | ||
| 159 | backend = std::make_unique<WebService::RoomJson>(Settings::values.web_api_url.GetValue(), | ||
| 160 | Settings::values.yuzu_username.GetValue(), | ||
| 161 | Settings::values.yuzu_token.GetValue()); | ||
| 162 | #endif | ||
| 163 | } | ||
| 164 | |||
| 165 | } // namespace Core | ||
diff --git a/src/core/announce_multiplayer_session.h b/src/core/announce_multiplayer_session.h new file mode 100644 index 000000000..2aaf55017 --- /dev/null +++ b/src/core/announce_multiplayer_session.h | |||
| @@ -0,0 +1,96 @@ | |||
| 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 <atomic> | ||
| 8 | #include <functional> | ||
| 9 | #include <memory> | ||
| 10 | #include <mutex> | ||
| 11 | #include <set> | ||
| 12 | #include <thread> | ||
| 13 | #include "common/announce_multiplayer_room.h" | ||
| 14 | #include "common/common_types.h" | ||
| 15 | #include "common/thread.h" | ||
| 16 | |||
| 17 | namespace Network { | ||
| 18 | class Room; | ||
| 19 | } | ||
| 20 | |||
| 21 | namespace Core { | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Instruments AnnounceMultiplayerRoom::Backend. | ||
| 25 | * Creates a thread that regularly updates the room information and submits them | ||
| 26 | * An async get of room information is also possible | ||
| 27 | */ | ||
| 28 | class AnnounceMultiplayerSession { | ||
| 29 | public: | ||
| 30 | using CallbackHandle = std::shared_ptr<std::function<void(const WebService::WebResult&)>>; | ||
| 31 | AnnounceMultiplayerSession(); | ||
| 32 | ~AnnounceMultiplayerSession(); | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Allows to bind a function that will get called if the announce encounters an error | ||
| 36 | * @param function The function that gets called | ||
| 37 | * @return A handle that can be used the unbind the function | ||
| 38 | */ | ||
| 39 | CallbackHandle BindErrorCallback(std::function<void(const WebService::WebResult&)> function); | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Unbind a function from the error callbacks | ||
| 43 | * @param handle The handle for the function that should get unbind | ||
| 44 | */ | ||
| 45 | void UnbindErrorCallback(CallbackHandle handle); | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Registers a room to web services | ||
| 49 | * @return The result of the registration attempt. | ||
| 50 | */ | ||
| 51 | WebService::WebResult Register(); | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Starts the announce of a room to web services | ||
| 55 | */ | ||
| 56 | void Start(); | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Stops the announce to web services | ||
| 60 | */ | ||
| 61 | void Stop(); | ||
| 62 | |||
| 63 | /** | ||
| 64 | * Returns a list of all room information the backend got | ||
| 65 | * @param func A function that gets executed when the async get finished, e.g. a signal | ||
| 66 | * @return a list of rooms received from the web service | ||
| 67 | */ | ||
| 68 | AnnounceMultiplayerRoom::RoomList GetRoomList(); | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Whether the announce session is still running | ||
| 72 | */ | ||
| 73 | bool IsRunning() const; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Recreates the backend, updating the credentials. | ||
| 77 | * This can only be used when the announce session is not running. | ||
| 78 | */ | ||
| 79 | void UpdateCredentials(); | ||
| 80 | |||
| 81 | private: | ||
| 82 | Common::Event shutdown_event; | ||
| 83 | std::mutex callback_mutex; | ||
| 84 | std::set<CallbackHandle> error_callbacks; | ||
| 85 | std::unique_ptr<std::thread> announce_multiplayer_thread; | ||
| 86 | |||
| 87 | /// Backend interface that logs fields | ||
| 88 | std::unique_ptr<AnnounceMultiplayerRoom::Backend> backend; | ||
| 89 | |||
| 90 | std::atomic_bool registered = false; ///< Whether the room has been registered | ||
| 91 | |||
| 92 | void UpdateBackendData(std::shared_ptr<Network::Room> room); | ||
| 93 | void AnnounceMultiplayerLoop(); | ||
| 94 | }; | ||
| 95 | |||
| 96 | } // namespace Core | ||
diff --git a/src/core/core.cpp b/src/core/core.cpp index 0ede0d85c..5df32c1e7 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -43,14 +43,15 @@ | |||
| 43 | #include "core/hle/service/service.h" | 43 | #include "core/hle/service/service.h" |
| 44 | #include "core/hle/service/sm/sm.h" | 44 | #include "core/hle/service/sm/sm.h" |
| 45 | #include "core/hle/service/time/time_manager.h" | 45 | #include "core/hle/service/time/time_manager.h" |
| 46 | #include "core/internal_network/network.h" | ||
| 46 | #include "core/loader/loader.h" | 47 | #include "core/loader/loader.h" |
| 47 | #include "core/memory.h" | 48 | #include "core/memory.h" |
| 48 | #include "core/memory/cheat_engine.h" | 49 | #include "core/memory/cheat_engine.h" |
| 49 | #include "core/network/network.h" | ||
| 50 | #include "core/perf_stats.h" | 50 | #include "core/perf_stats.h" |
| 51 | #include "core/reporter.h" | 51 | #include "core/reporter.h" |
| 52 | #include "core/telemetry_session.h" | 52 | #include "core/telemetry_session.h" |
| 53 | #include "core/tools/freezer.h" | 53 | #include "core/tools/freezer.h" |
| 54 | #include "network/network.h" | ||
| 54 | #include "video_core/renderer_base.h" | 55 | #include "video_core/renderer_base.h" |
| 55 | #include "video_core/video_core.h" | 56 | #include "video_core/video_core.h" |
| 56 | 57 | ||
| @@ -315,6 +316,15 @@ struct System::Impl { | |||
| 315 | GetAndResetPerfStats(); | 316 | GetAndResetPerfStats(); |
| 316 | perf_stats->BeginSystemFrame(); | 317 | perf_stats->BeginSystemFrame(); |
| 317 | 318 | ||
| 319 | std::string name = "Unknown Game"; | ||
| 320 | const Loader::ResultStatus res{app_loader->ReadTitle(name)}; | ||
| 321 | if (auto room_member = Network::GetRoomMember().lock()) { | ||
| 322 | Network::GameInfo game_info; | ||
| 323 | game_info.name = name; | ||
| 324 | game_info.id = program_id; | ||
| 325 | room_member->SendGameInfo(game_info); | ||
| 326 | } | ||
| 327 | |||
| 318 | status = SystemResultStatus::Success; | 328 | status = SystemResultStatus::Success; |
| 319 | return status; | 329 | return status; |
| 320 | } | 330 | } |
| @@ -362,6 +372,11 @@ struct System::Impl { | |||
| 362 | memory.Reset(); | 372 | memory.Reset(); |
| 363 | applet_manager.ClearAll(); | 373 | applet_manager.ClearAll(); |
| 364 | 374 | ||
| 375 | if (auto room_member = Network::GetRoomMember().lock()) { | ||
| 376 | Network::GameInfo game_info{}; | ||
| 377 | room_member->SendGameInfo(game_info); | ||
| 378 | } | ||
| 379 | |||
| 365 | LOG_DEBUG(Core, "Shutdown OK"); | 380 | LOG_DEBUG(Core, "Shutdown OK"); |
| 366 | } | 381 | } |
| 367 | 382 | ||
diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index 7055ea93e..2889973e4 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp | |||
| @@ -18,8 +18,8 @@ namespace { | |||
| 18 | 18 | ||
| 19 | } // Anonymous namespace | 19 | } // Anonymous namespace |
| 20 | 20 | ||
| 21 | #include "core/network/network.h" | 21 | #include "core/internal_network/network.h" |
| 22 | #include "core/network/network_interface.h" | 22 | #include "core/internal_network/network_interface.h" |
| 23 | 23 | ||
| 24 | namespace Service::NIFM { | 24 | namespace Service::NIFM { |
| 25 | 25 | ||
diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp index 3e9dc4a13..c7194731e 100644 --- a/src/core/hle/service/sockets/bsd.cpp +++ b/src/core/hle/service/sockets/bsd.cpp | |||
| @@ -13,8 +13,8 @@ | |||
| 13 | #include "core/hle/kernel/k_thread.h" | 13 | #include "core/hle/kernel/k_thread.h" |
| 14 | #include "core/hle/service/sockets/bsd.h" | 14 | #include "core/hle/service/sockets/bsd.h" |
| 15 | #include "core/hle/service/sockets/sockets_translate.h" | 15 | #include "core/hle/service/sockets/sockets_translate.h" |
| 16 | #include "core/network/network.h" | 16 | #include "core/internal_network/network.h" |
| 17 | #include "core/network/sockets.h" | 17 | #include "core/internal_network/sockets.h" |
| 18 | 18 | ||
| 19 | namespace Service::Sockets { | 19 | namespace Service::Sockets { |
| 20 | 20 | ||
diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h index fed740d87..9ea36428d 100644 --- a/src/core/hle/service/sockets/bsd.h +++ b/src/core/hle/service/sockets/bsd.h | |||
| @@ -16,7 +16,7 @@ class System; | |||
| 16 | 16 | ||
| 17 | namespace Network { | 17 | namespace Network { |
| 18 | class Socket; | 18 | class Socket; |
| 19 | } | 19 | } // namespace Network |
| 20 | 20 | ||
| 21 | namespace Service::Sockets { | 21 | namespace Service::Sockets { |
| 22 | 22 | ||
diff --git a/src/core/hle/service/sockets/sockets_translate.cpp b/src/core/hle/service/sockets/sockets_translate.cpp index 9c0936d97..2db10ec81 100644 --- a/src/core/hle/service/sockets/sockets_translate.cpp +++ b/src/core/hle/service/sockets/sockets_translate.cpp | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "core/hle/service/sockets/sockets.h" | 8 | #include "core/hle/service/sockets/sockets.h" |
| 9 | #include "core/hle/service/sockets/sockets_translate.h" | 9 | #include "core/hle/service/sockets/sockets_translate.h" |
| 10 | #include "core/network/network.h" | 10 | #include "core/internal_network/network.h" |
| 11 | 11 | ||
| 12 | namespace Service::Sockets { | 12 | namespace Service::Sockets { |
| 13 | 13 | ||
diff --git a/src/core/hle/service/sockets/sockets_translate.h b/src/core/hle/service/sockets/sockets_translate.h index 5e9809add..c93291d3e 100644 --- a/src/core/hle/service/sockets/sockets_translate.h +++ b/src/core/hle/service/sockets/sockets_translate.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "core/hle/service/sockets/sockets.h" | 9 | #include "core/hle/service/sockets/sockets.h" |
| 10 | #include "core/network/network.h" | 10 | #include "core/internal_network/network.h" |
| 11 | 11 | ||
| 12 | namespace Service::Sockets { | 12 | namespace Service::Sockets { |
| 13 | 13 | ||
diff --git a/src/core/network/network.cpp b/src/core/internal_network/network.cpp index fdafbea92..36c43cc8f 100644 --- a/src/core/network/network.cpp +++ b/src/core/internal_network/network.cpp | |||
| @@ -29,9 +29,9 @@ | |||
| 29 | #include "common/common_types.h" | 29 | #include "common/common_types.h" |
| 30 | #include "common/logging/log.h" | 30 | #include "common/logging/log.h" |
| 31 | #include "common/settings.h" | 31 | #include "common/settings.h" |
| 32 | #include "core/network/network.h" | 32 | #include "core/internal_network/network.h" |
| 33 | #include "core/network/network_interface.h" | 33 | #include "core/internal_network/network_interface.h" |
| 34 | #include "core/network/sockets.h" | 34 | #include "core/internal_network/sockets.h" |
| 35 | 35 | ||
| 36 | namespace Network { | 36 | namespace Network { |
| 37 | 37 | ||
diff --git a/src/core/network/network.h b/src/core/internal_network/network.h index 10e5ef10d..10e5ef10d 100644 --- a/src/core/network/network.h +++ b/src/core/internal_network/network.h | |||
diff --git a/src/core/network/network_interface.cpp b/src/core/internal_network/network_interface.cpp index 15ecc6abf..0f0a66160 100644 --- a/src/core/network/network_interface.cpp +++ b/src/core/internal_network/network_interface.cpp | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 12 | #include "common/settings.h" | 12 | #include "common/settings.h" |
| 13 | #include "common/string_util.h" | 13 | #include "common/string_util.h" |
| 14 | #include "core/network/network_interface.h" | 14 | #include "core/internal_network/network_interface.h" |
| 15 | 15 | ||
| 16 | #ifdef _WIN32 | 16 | #ifdef _WIN32 |
| 17 | #include <iphlpapi.h> | 17 | #include <iphlpapi.h> |
diff --git a/src/core/network/network_interface.h b/src/core/internal_network/network_interface.h index 9b98b6b42..9b98b6b42 100644 --- a/src/core/network/network_interface.h +++ b/src/core/internal_network/network_interface.h | |||
diff --git a/src/core/network/sockets.h b/src/core/internal_network/sockets.h index f889159f5..77e27e928 100644 --- a/src/core/network/sockets.h +++ b/src/core/internal_network/sockets.h | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <map> | ||
| 6 | #include <memory> | 7 | #include <memory> |
| 7 | #include <utility> | 8 | #include <utility> |
| 8 | 9 | ||
| @@ -12,7 +13,7 @@ | |||
| 12 | #endif | 13 | #endif |
| 13 | 14 | ||
| 14 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 15 | #include "core/network/network.h" | 16 | #include "core/internal_network/network.h" |
| 16 | 17 | ||
| 17 | // TODO: C++20 Replace std::vector usages with std::span | 18 | // TODO: C++20 Replace std::vector usages with std::span |
| 18 | 19 | ||
diff --git a/src/network/room.cpp b/src/network/room.cpp index cd0c0ebc4..528867146 100644 --- a/src/network/room.cpp +++ b/src/network/room.cpp | |||
| @@ -251,7 +251,7 @@ public: | |||
| 251 | void Room::RoomImpl::ServerLoop() { | 251 | void Room::RoomImpl::ServerLoop() { |
| 252 | while (state != State::Closed) { | 252 | while (state != State::Closed) { |
| 253 | ENetEvent event; | 253 | ENetEvent event; |
| 254 | if (enet_host_service(server, &event, 50) > 0) { | 254 | if (enet_host_service(server, &event, 16) > 0) { |
| 255 | switch (event.type) { | 255 | switch (event.type) { |
| 256 | case ENET_EVENT_TYPE_RECEIVE: | 256 | case ENET_EVENT_TYPE_RECEIVE: |
| 257 | switch (event.packet->data[0]) { | 257 | switch (event.packet->data[0]) { |
| @@ -599,7 +599,7 @@ bool Room::RoomImpl::HasModPermission(const ENetPeer* client) const { | |||
| 599 | if (sending_member == members.end()) { | 599 | if (sending_member == members.end()) { |
| 600 | return false; | 600 | return false; |
| 601 | } | 601 | } |
| 602 | if (room_information.enable_citra_mods && | 602 | if (room_information.enable_yuzu_mods && |
| 603 | sending_member->user_data.moderator) { // Community moderator | 603 | sending_member->user_data.moderator) { // Community moderator |
| 604 | 604 | ||
| 605 | return true; | 605 | return true; |
| @@ -1014,7 +1014,7 @@ bool Room::Create(const std::string& name, const std::string& description, | |||
| 1014 | const u32 max_connections, const std::string& host_username, | 1014 | const u32 max_connections, const std::string& host_username, |
| 1015 | const std::string& preferred_game, u64 preferred_game_id, | 1015 | const std::string& preferred_game, u64 preferred_game_id, |
| 1016 | std::unique_ptr<VerifyUser::Backend> verify_backend, | 1016 | std::unique_ptr<VerifyUser::Backend> verify_backend, |
| 1017 | const Room::BanList& ban_list, bool enable_citra_mods) { | 1017 | const Room::BanList& ban_list, bool enable_yuzu_mods) { |
| 1018 | ENetAddress address; | 1018 | ENetAddress address; |
| 1019 | address.host = ENET_HOST_ANY; | 1019 | address.host = ENET_HOST_ANY; |
| 1020 | if (!server_address.empty()) { | 1020 | if (!server_address.empty()) { |
| @@ -1037,7 +1037,7 @@ bool Room::Create(const std::string& name, const std::string& description, | |||
| 1037 | room_impl->room_information.preferred_game = preferred_game; | 1037 | room_impl->room_information.preferred_game = preferred_game; |
| 1038 | room_impl->room_information.preferred_game_id = preferred_game_id; | 1038 | room_impl->room_information.preferred_game_id = preferred_game_id; |
| 1039 | room_impl->room_information.host_username = host_username; | 1039 | room_impl->room_information.host_username = host_username; |
| 1040 | room_impl->room_information.enable_citra_mods = enable_citra_mods; | 1040 | room_impl->room_information.enable_yuzu_mods = enable_yuzu_mods; |
| 1041 | room_impl->password = password; | 1041 | room_impl->password = password; |
| 1042 | room_impl->verify_backend = std::move(verify_backend); | 1042 | room_impl->verify_backend = std::move(verify_backend); |
| 1043 | room_impl->username_ban_list = ban_list.first; | 1043 | room_impl->username_ban_list = ban_list.first; |
diff --git a/src/network/room.h b/src/network/room.h index a67984837..5d4371c16 100644 --- a/src/network/room.h +++ b/src/network/room.h | |||
| @@ -32,7 +32,7 @@ struct RoomInformation { | |||
| 32 | std::string preferred_game; ///< Game to advertise that you want to play | 32 | std::string preferred_game; ///< Game to advertise that you want to play |
| 33 | u64 preferred_game_id; ///< Title ID for the advertised game | 33 | u64 preferred_game_id; ///< Title ID for the advertised game |
| 34 | std::string host_username; ///< Forum username of the host | 34 | std::string host_username; ///< Forum username of the host |
| 35 | bool enable_citra_mods; ///< Allow Citra Moderators to moderate on this room | 35 | bool enable_yuzu_mods; ///< Allow yuzu Moderators to moderate on this room |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | struct GameInfo { | 38 | struct GameInfo { |
| @@ -148,7 +148,7 @@ public: | |||
| 148 | const std::string& host_username = "", const std::string& preferred_game = "", | 148 | const std::string& host_username = "", const std::string& preferred_game = "", |
| 149 | u64 preferred_game_id = 0, | 149 | u64 preferred_game_id = 0, |
| 150 | std::unique_ptr<VerifyUser::Backend> verify_backend = nullptr, | 150 | std::unique_ptr<VerifyUser::Backend> verify_backend = nullptr, |
| 151 | const BanList& ban_list = {}, bool enable_citra_mods = false); | 151 | const BanList& ban_list = {}, bool enable_yuzu_mods = false); |
| 152 | 152 | ||
| 153 | /** | 153 | /** |
| 154 | * Sets the verification GUID of the room. | 154 | * Sets the verification GUID of the room. |
diff --git a/src/network/room_member.cpp b/src/network/room_member.cpp index e43004027..d6ace9b39 100644 --- a/src/network/room_member.cpp +++ b/src/network/room_member.cpp | |||
| @@ -86,7 +86,7 @@ public: | |||
| 86 | * @params password The password for the room | 86 | * @params password The password for the room |
| 87 | * the server to assign one for us. | 87 | * the server to assign one for us. |
| 88 | */ | 88 | */ |
| 89 | void SendJoinRequest(const std::string& nickname, const std::string& console_id_hash, | 89 | void SendJoinRequest(const std::string& nickname_, const std::string& console_id_hash, |
| 90 | const MacAddress& preferred_mac = NoPreferredMac, | 90 | const MacAddress& preferred_mac = NoPreferredMac, |
| 91 | const std::string& password = "", const std::string& token = ""); | 91 | const std::string& password = "", const std::string& token = ""); |
| 92 | 92 | ||
| @@ -159,7 +159,7 @@ void RoomMember::RoomMemberImpl::MemberLoop() { | |||
| 159 | while (IsConnected()) { | 159 | while (IsConnected()) { |
| 160 | std::lock_guard lock(network_mutex); | 160 | std::lock_guard lock(network_mutex); |
| 161 | ENetEvent event; | 161 | ENetEvent event; |
| 162 | if (enet_host_service(client, &event, 100) > 0) { | 162 | if (enet_host_service(client, &event, 16) > 0) { |
| 163 | switch (event.type) { | 163 | switch (event.type) { |
| 164 | case ENET_EVENT_TYPE_RECEIVE: | 164 | case ENET_EVENT_TYPE_RECEIVE: |
| 165 | switch (event.packet->data[0]) { | 165 | switch (event.packet->data[0]) { |
| @@ -251,16 +251,17 @@ void RoomMember::RoomMemberImpl::MemberLoop() { | |||
| 251 | break; | 251 | break; |
| 252 | } | 252 | } |
| 253 | } | 253 | } |
| 254 | std::list<Packet> packets; | ||
| 254 | { | 255 | { |
| 255 | std::lock_guard lock(send_list_mutex); | 256 | std::lock_guard send_lock(send_list_mutex); |
| 256 | for (const auto& packet : send_list) { | 257 | packets.swap(send_list); |
| 257 | ENetPacket* enetPacket = enet_packet_create(packet.GetData(), packet.GetDataSize(), | 258 | } |
| 258 | ENET_PACKET_FLAG_RELIABLE); | 259 | for (const auto& packet : packets) { |
| 259 | enet_peer_send(server, 0, enetPacket); | 260 | ENetPacket* enetPacket = enet_packet_create(packet.GetData(), packet.GetDataSize(), |
| 260 | } | 261 | ENET_PACKET_FLAG_RELIABLE); |
| 261 | enet_host_flush(client); | 262 | enet_peer_send(server, 0, enetPacket); |
| 262 | send_list.clear(); | ||
| 263 | } | 263 | } |
| 264 | enet_host_flush(client); | ||
| 264 | } | 265 | } |
| 265 | Disconnect(); | 266 | Disconnect(); |
| 266 | }; | 267 | }; |
| @@ -274,14 +275,14 @@ void RoomMember::RoomMemberImpl::Send(Packet&& packet) { | |||
| 274 | send_list.push_back(std::move(packet)); | 275 | send_list.push_back(std::move(packet)); |
| 275 | } | 276 | } |
| 276 | 277 | ||
| 277 | void RoomMember::RoomMemberImpl::SendJoinRequest(const std::string& nickname, | 278 | void RoomMember::RoomMemberImpl::SendJoinRequest(const std::string& nickname_, |
| 278 | const std::string& console_id_hash, | 279 | const std::string& console_id_hash, |
| 279 | const MacAddress& preferred_mac, | 280 | const MacAddress& preferred_mac, |
| 280 | const std::string& password, | 281 | const std::string& password, |
| 281 | const std::string& token) { | 282 | const std::string& token) { |
| 282 | Packet packet; | 283 | Packet packet; |
| 283 | packet << static_cast<u8>(IdJoinRequest); | 284 | packet << static_cast<u8>(IdJoinRequest); |
| 284 | packet << nickname; | 285 | packet << nickname_; |
| 285 | packet << console_id_hash; | 286 | packet << console_id_hash; |
| 286 | packet << preferred_mac; | 287 | packet << preferred_mac; |
| 287 | packet << network_version; | 288 | packet << network_version; |
diff --git a/src/network/verify_user.h b/src/network/verify_user.h index 01b9877c8..5c3852d4a 100644 --- a/src/network/verify_user.h +++ b/src/network/verify_user.h | |||
| @@ -13,7 +13,7 @@ struct UserData { | |||
| 13 | std::string username; | 13 | std::string username; |
| 14 | std::string display_name; | 14 | std::string display_name; |
| 15 | std::string avatar_url; | 15 | std::string avatar_url; |
| 16 | bool moderator = false; ///< Whether the user is a Citra Moderator. | 16 | bool moderator = false; ///< Whether the user is a yuzu Moderator. |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | /** | 19 | /** |
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index a69ccb264..fbbcf673a 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt | |||
| @@ -7,7 +7,7 @@ add_executable(tests | |||
| 7 | common/ring_buffer.cpp | 7 | common/ring_buffer.cpp |
| 8 | common/unique_function.cpp | 8 | common/unique_function.cpp |
| 9 | core/core_timing.cpp | 9 | core/core_timing.cpp |
| 10 | core/network/network.cpp | 10 | core/internal_network/network.cpp |
| 11 | tests.cpp | 11 | tests.cpp |
| 12 | video_core/buffer_base.cpp | 12 | video_core/buffer_base.cpp |
| 13 | input_common/calibration_configuration_job.cpp | 13 | input_common/calibration_configuration_job.cpp |
diff --git a/src/tests/core/network/network.cpp b/src/tests/core/internal_network/network.cpp index 1bbb8372f..164b0ff24 100644 --- a/src/tests/core/network/network.cpp +++ b/src/tests/core/internal_network/network.cpp | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | 3 | ||
| 4 | #include <catch2/catch.hpp> | 4 | #include <catch2/catch.hpp> |
| 5 | 5 | ||
| 6 | #include "core/network/network.h" | 6 | #include "core/internal_network/network.h" |
| 7 | #include "core/network/sockets.h" | 7 | #include "core/internal_network/sockets.h" |
| 8 | 8 | ||
| 9 | TEST_CASE("Network::Errors", "[core]") { | 9 | TEST_CASE("Network::Errors", "[core]") { |
| 10 | Network::NetworkInstance network_instance; // initialize network | 10 | Network::NetworkInstance network_instance; // initialize network |
diff --git a/src/web_service/CMakeLists.txt b/src/web_service/CMakeLists.txt index ae85a72ea..aff81f26d 100644 --- a/src/web_service/CMakeLists.txt +++ b/src/web_service/CMakeLists.txt | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | add_library(web_service STATIC | 1 | add_library(web_service STATIC |
| 2 | announce_room_json.cpp | ||
| 3 | announce_room_json.h | ||
| 2 | telemetry_json.cpp | 4 | telemetry_json.cpp |
| 3 | telemetry_json.h | 5 | telemetry_json.h |
| 4 | verify_login.cpp | 6 | verify_login.cpp |
| @@ -9,4 +11,4 @@ add_library(web_service STATIC | |||
| 9 | ) | 11 | ) |
| 10 | 12 | ||
| 11 | create_target_directory_groups(web_service) | 13 | create_target_directory_groups(web_service) |
| 12 | target_link_libraries(web_service PRIVATE common nlohmann_json::nlohmann_json httplib) | 14 | target_link_libraries(web_service PRIVATE common network nlohmann_json::nlohmann_json httplib) |
diff --git a/src/web_service/announce_room_json.cpp b/src/web_service/announce_room_json.cpp new file mode 100644 index 000000000..31804d2b1 --- /dev/null +++ b/src/web_service/announce_room_json.cpp | |||
| @@ -0,0 +1,157 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <future> | ||
| 6 | #include <nlohmann/json.hpp> | ||
| 7 | #include "common/detached_tasks.h" | ||
| 8 | #include "common/logging/log.h" | ||
| 9 | #include "web_service/announce_room_json.h" | ||
| 10 | #include "web_service/web_backend.h" | ||
| 11 | |||
| 12 | namespace AnnounceMultiplayerRoom { | ||
| 13 | |||
| 14 | void to_json(nlohmann::json& json, const Room::Member& member) { | ||
| 15 | if (!member.username.empty()) { | ||
| 16 | json["username"] = member.username; | ||
| 17 | } | ||
| 18 | json["nickname"] = member.nickname; | ||
| 19 | if (!member.avatar_url.empty()) { | ||
| 20 | json["avatarUrl"] = member.avatar_url; | ||
| 21 | } | ||
| 22 | json["gameName"] = member.game_name; | ||
| 23 | json["gameId"] = member.game_id; | ||
| 24 | } | ||
| 25 | |||
| 26 | void from_json(const nlohmann::json& json, Room::Member& member) { | ||
| 27 | member.nickname = json.at("nickname").get<std::string>(); | ||
| 28 | member.game_name = json.at("gameName").get<std::string>(); | ||
| 29 | member.game_id = json.at("gameId").get<u64>(); | ||
| 30 | try { | ||
| 31 | member.username = json.at("username").get<std::string>(); | ||
| 32 | member.avatar_url = json.at("avatarUrl").get<std::string>(); | ||
| 33 | } catch (const nlohmann::detail::out_of_range&) { | ||
| 34 | member.username = member.avatar_url = ""; | ||
| 35 | LOG_DEBUG(Network, "Member \'{}\' isn't authenticated", member.nickname); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | void to_json(nlohmann::json& json, const Room& room) { | ||
| 40 | json["port"] = room.port; | ||
| 41 | json["name"] = room.name; | ||
| 42 | if (!room.description.empty()) { | ||
| 43 | json["description"] = room.description; | ||
| 44 | } | ||
| 45 | json["preferredGameName"] = room.preferred_game; | ||
| 46 | json["preferredGameId"] = room.preferred_game_id; | ||
| 47 | json["maxPlayers"] = room.max_player; | ||
| 48 | json["netVersion"] = room.net_version; | ||
| 49 | json["hasPassword"] = room.has_password; | ||
| 50 | if (room.members.size() > 0) { | ||
| 51 | nlohmann::json member_json = room.members; | ||
| 52 | json["players"] = member_json; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | void from_json(const nlohmann::json& json, Room& room) { | ||
| 57 | room.verify_UID = json.at("externalGuid").get<std::string>(); | ||
| 58 | room.ip = json.at("address").get<std::string>(); | ||
| 59 | room.name = json.at("name").get<std::string>(); | ||
| 60 | try { | ||
| 61 | room.description = json.at("description").get<std::string>(); | ||
| 62 | } catch (const nlohmann::detail::out_of_range&) { | ||
| 63 | room.description = ""; | ||
| 64 | LOG_DEBUG(Network, "Room \'{}\' doesn't contain a description", room.name); | ||
| 65 | } | ||
| 66 | room.owner = json.at("owner").get<std::string>(); | ||
| 67 | room.port = json.at("port").get<u16>(); | ||
| 68 | room.preferred_game = json.at("preferredGameName").get<std::string>(); | ||
| 69 | room.preferred_game_id = json.at("preferredGameId").get<u64>(); | ||
| 70 | room.max_player = json.at("maxPlayers").get<u32>(); | ||
| 71 | room.net_version = json.at("netVersion").get<u32>(); | ||
| 72 | room.has_password = json.at("hasPassword").get<bool>(); | ||
| 73 | try { | ||
| 74 | room.members = json.at("players").get<std::vector<Room::Member>>(); | ||
| 75 | } catch (const nlohmann::detail::out_of_range& e) { | ||
| 76 | LOG_DEBUG(Network, "Out of range {}", e.what()); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | } // namespace AnnounceMultiplayerRoom | ||
| 81 | |||
| 82 | namespace WebService { | ||
| 83 | |||
| 84 | void RoomJson::SetRoomInformation(const std::string& name, const std::string& description, | ||
| 85 | const u16 port, const u32 max_player, const u32 net_version, | ||
| 86 | const bool has_password, const std::string& preferred_game, | ||
| 87 | const u64 preferred_game_id) { | ||
| 88 | room.name = name; | ||
| 89 | room.description = description; | ||
| 90 | room.port = port; | ||
| 91 | room.max_player = max_player; | ||
| 92 | room.net_version = net_version; | ||
| 93 | room.has_password = has_password; | ||
| 94 | room.preferred_game = preferred_game; | ||
| 95 | room.preferred_game_id = preferred_game_id; | ||
| 96 | } | ||
| 97 | void RoomJson::AddPlayer(const std::string& username_, const std::string& nickname_, | ||
| 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); | ||
| 109 | } | ||
| 110 | |||
| 111 | WebService::WebResult RoomJson::Update() { | ||
| 112 | if (room_id.empty()) { | ||
| 113 | LOG_ERROR(WebService, "Room must be registered to be updated"); | ||
| 114 | return WebService::WebResult{WebService::WebResult::Code::LibError, | ||
| 115 | "Room is not registered"}; | ||
| 116 | } | ||
| 117 | nlohmann::json json{{"players", room.members}}; | ||
| 118 | return client.PostJson(fmt::format("/lobby/{}", room_id), json.dump(), false); | ||
| 119 | } | ||
| 120 | |||
| 121 | WebService::WebResult RoomJson::Register() { | ||
| 122 | nlohmann::json json = room; | ||
| 123 | auto result = client.PostJson("/lobby", json.dump(), false); | ||
| 124 | if (result.result_code != WebService::WebResult::Code::Success) { | ||
| 125 | return result; | ||
| 126 | } | ||
| 127 | auto reply_json = nlohmann::json::parse(result.returned_data); | ||
| 128 | room = reply_json.get<AnnounceMultiplayerRoom::Room>(); | ||
| 129 | room_id = reply_json.at("id").get<std::string>(); | ||
| 130 | return WebService::WebResult{WebService::WebResult::Code::Success, "", room.verify_UID}; | ||
| 131 | } | ||
| 132 | |||
| 133 | void RoomJson::ClearPlayers() { | ||
| 134 | room.members.clear(); | ||
| 135 | } | ||
| 136 | |||
| 137 | AnnounceMultiplayerRoom::RoomList RoomJson::GetRoomList() { | ||
| 138 | auto reply = client.GetJson("/lobby", true).returned_data; | ||
| 139 | if (reply.empty()) { | ||
| 140 | return {}; | ||
| 141 | } | ||
| 142 | return nlohmann::json::parse(reply).at("rooms").get<AnnounceMultiplayerRoom::RoomList>(); | ||
| 143 | } | ||
| 144 | |||
| 145 | void RoomJson::Delete() { | ||
| 146 | if (room_id.empty()) { | ||
| 147 | LOG_ERROR(WebService, "Room must be registered to be deleted"); | ||
| 148 | return; | ||
| 149 | } | ||
| 150 | Common::DetachedTasks::AddTask( | ||
| 151 | [host{this->host}, username{this->username}, token{this->token}, room_id{this->room_id}]() { | ||
| 152 | // create a new client here because the this->client might be destroyed. | ||
| 153 | Client{host, username, token}.DeleteJson(fmt::format("/lobby/{}", room_id), "", false); | ||
| 154 | }); | ||
| 155 | } | ||
| 156 | |||
| 157 | } // namespace WebService | ||
diff --git a/src/web_service/announce_room_json.h b/src/web_service/announce_room_json.h new file mode 100644 index 000000000..ac02af5b1 --- /dev/null +++ b/src/web_service/announce_room_json.h | |||
| @@ -0,0 +1,46 @@ | |||
| 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 <functional> | ||
| 8 | #include <string> | ||
| 9 | #include "common/announce_multiplayer_room.h" | ||
| 10 | #include "web_service/web_backend.h" | ||
| 11 | |||
| 12 | namespace WebService { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Implementation of AnnounceMultiplayerRoom::Backend that (de)serializes room information into/from | ||
| 16 | * JSON, and submits/gets it to/from the yuzu web service | ||
| 17 | */ | ||
| 18 | class RoomJson : public AnnounceMultiplayerRoom::Backend { | ||
| 19 | public: | ||
| 20 | RoomJson(const std::string& host, const std::string& username, const std::string& token) | ||
| 21 | : client(host, username, token), host(host), username(username), token(token) {} | ||
| 22 | ~RoomJson() = default; | ||
| 23 | void SetRoomInformation(const std::string& name, const std::string& description, const u16 port, | ||
| 24 | const u32 max_player, const u32 net_version, const bool has_password, | ||
| 25 | const std::string& preferred_game, | ||
| 26 | const u64 preferred_game_id) override; | ||
| 27 | void AddPlayer(const std::string& username_, const std::string& nickname_, | ||
| 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; | ||
| 32 | WebResult Register() override; | ||
| 33 | void ClearPlayers() override; | ||
| 34 | AnnounceMultiplayerRoom::RoomList GetRoomList() override; | ||
| 35 | void Delete() override; | ||
| 36 | |||
| 37 | private: | ||
| 38 | AnnounceMultiplayerRoom::Room room; | ||
| 39 | Client client; | ||
| 40 | std::string host; | ||
| 41 | std::string username; | ||
| 42 | std::string token; | ||
| 43 | std::string room_id; | ||
| 44 | }; | ||
| 45 | |||
| 46 | } // namespace WebService | ||
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 57e0e7025..f3cad8f31 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt | |||
| @@ -156,10 +156,36 @@ add_executable(yuzu | |||
| 156 | main.cpp | 156 | main.cpp |
| 157 | main.h | 157 | main.h |
| 158 | main.ui | 158 | main.ui |
| 159 | multiplayer/chat_room.cpp | ||
| 160 | multiplayer/chat_room.h | ||
| 161 | multiplayer/chat_room.ui | ||
| 162 | multiplayer/client_room.h | ||
| 163 | multiplayer/client_room.cpp | ||
| 164 | multiplayer/client_room.ui | ||
| 165 | multiplayer/direct_connect.cpp | ||
| 166 | multiplayer/direct_connect.h | ||
| 167 | multiplayer/direct_connect.ui | ||
| 168 | multiplayer/host_room.cpp | ||
| 169 | multiplayer/host_room.h | ||
| 170 | multiplayer/host_room.ui | ||
| 171 | multiplayer/lobby.cpp | ||
| 172 | multiplayer/lobby.h | ||
| 173 | multiplayer/lobby.ui | ||
| 174 | multiplayer/lobby_p.h | ||
| 175 | multiplayer/message.cpp | ||
| 176 | multiplayer/message.h | ||
| 177 | multiplayer/moderation_dialog.cpp | ||
| 178 | multiplayer/moderation_dialog.h | ||
| 179 | multiplayer/moderation_dialog.ui | ||
| 180 | multiplayer/state.cpp | ||
| 181 | multiplayer/state.h | ||
| 182 | multiplayer/validation.h | ||
| 159 | startup_checks.cpp | 183 | startup_checks.cpp |
| 160 | startup_checks.h | 184 | startup_checks.h |
| 161 | uisettings.cpp | 185 | uisettings.cpp |
| 162 | uisettings.h | 186 | uisettings.h |
| 187 | util/clickable_label.cpp | ||
| 188 | util/clickable_label.h | ||
| 163 | util/controller_navigation.cpp | 189 | util/controller_navigation.cpp |
| 164 | util/controller_navigation.h | 190 | util/controller_navigation.h |
| 165 | util/limitable_input_dialog.cpp | 191 | util/limitable_input_dialog.cpp |
| @@ -256,7 +282,7 @@ endif() | |||
| 256 | 282 | ||
| 257 | create_target_directory_groups(yuzu) | 283 | create_target_directory_groups(yuzu) |
| 258 | 284 | ||
| 259 | target_link_libraries(yuzu PRIVATE common core input_common video_core) | 285 | target_link_libraries(yuzu PRIVATE common core input_common network video_core) |
| 260 | target_link_libraries(yuzu PRIVATE Boost::boost glad Qt::Widgets Qt::Multimedia) | 286 | target_link_libraries(yuzu PRIVATE Boost::boost glad Qt::Widgets Qt::Multimedia) |
| 261 | target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) | 287 | target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) |
| 262 | 288 | ||
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index c841843f0..7c11e2c03 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "core/hle/service/acc/profile_manager.h" | 11 | #include "core/hle/service/acc/profile_manager.h" |
| 12 | #include "core/hle/service/hid/controllers/npad.h" | 12 | #include "core/hle/service/hid/controllers/npad.h" |
| 13 | #include "input_common/main.h" | 13 | #include "input_common/main.h" |
| 14 | #include "network/network.h" | ||
| 14 | #include "yuzu/configuration/config.h" | 15 | #include "yuzu/configuration/config.h" |
| 15 | 16 | ||
| 16 | namespace FS = Common::FS; | 17 | namespace FS = Common::FS; |
| @@ -584,6 +585,48 @@ void Config::ReadMiscellaneousValues() { | |||
| 584 | qt_config->endGroup(); | 585 | qt_config->endGroup(); |
| 585 | } | 586 | } |
| 586 | 587 | ||
| 588 | void Config::ReadMultiplayerValues() { | ||
| 589 | qt_config->beginGroup(QStringLiteral("Multiplayer")); | ||
| 590 | |||
| 591 | UISettings::values.nickname = ReadSetting(QStringLiteral("nickname"), QString{}).toString(); | ||
| 592 | UISettings::values.ip = ReadSetting(QStringLiteral("ip"), QString{}).toString(); | ||
| 593 | UISettings::values.port = | ||
| 594 | ReadSetting(QStringLiteral("port"), Network::DefaultRoomPort).toString(); | ||
| 595 | UISettings::values.room_nickname = | ||
| 596 | ReadSetting(QStringLiteral("room_nickname"), QString{}).toString(); | ||
| 597 | UISettings::values.room_name = ReadSetting(QStringLiteral("room_name"), QString{}).toString(); | ||
| 598 | UISettings::values.room_port = | ||
| 599 | ReadSetting(QStringLiteral("room_port"), QStringLiteral("24872")).toString(); | ||
| 600 | bool ok; | ||
| 601 | UISettings::values.host_type = ReadSetting(QStringLiteral("host_type"), 0).toUInt(&ok); | ||
| 602 | if (!ok) { | ||
| 603 | UISettings::values.host_type = 0; | ||
| 604 | } | ||
| 605 | UISettings::values.max_player = ReadSetting(QStringLiteral("max_player"), 8).toUInt(); | ||
| 606 | UISettings::values.game_id = ReadSetting(QStringLiteral("game_id"), 0).toULongLong(); | ||
| 607 | UISettings::values.room_description = | ||
| 608 | ReadSetting(QStringLiteral("room_description"), QString{}).toString(); | ||
| 609 | // Read ban list back | ||
| 610 | int size = qt_config->beginReadArray(QStringLiteral("username_ban_list")); | ||
| 611 | UISettings::values.ban_list.first.resize(size); | ||
| 612 | for (int i = 0; i < size; ++i) { | ||
| 613 | qt_config->setArrayIndex(i); | ||
| 614 | UISettings::values.ban_list.first[i] = | ||
| 615 | ReadSetting(QStringLiteral("username")).toString().toStdString(); | ||
| 616 | } | ||
| 617 | qt_config->endArray(); | ||
| 618 | size = qt_config->beginReadArray(QStringLiteral("ip_ban_list")); | ||
| 619 | UISettings::values.ban_list.second.resize(size); | ||
| 620 | for (int i = 0; i < size; ++i) { | ||
| 621 | qt_config->setArrayIndex(i); | ||
| 622 | UISettings::values.ban_list.second[i] = | ||
| 623 | ReadSetting(QStringLiteral("ip")).toString().toStdString(); | ||
| 624 | } | ||
| 625 | qt_config->endArray(); | ||
| 626 | |||
| 627 | qt_config->endGroup(); | ||
| 628 | } | ||
| 629 | |||
| 587 | void Config::ReadPathValues() { | 630 | void Config::ReadPathValues() { |
| 588 | qt_config->beginGroup(QStringLiteral("Paths")); | 631 | qt_config->beginGroup(QStringLiteral("Paths")); |
| 589 | 632 | ||
| @@ -794,6 +837,7 @@ void Config::ReadUIValues() { | |||
| 794 | ReadPathValues(); | 837 | ReadPathValues(); |
| 795 | ReadScreenshotValues(); | 838 | ReadScreenshotValues(); |
| 796 | ReadShortcutValues(); | 839 | ReadShortcutValues(); |
| 840 | ReadMultiplayerValues(); | ||
| 797 | 841 | ||
| 798 | ReadBasicSetting(UISettings::values.single_window_mode); | 842 | ReadBasicSetting(UISettings::values.single_window_mode); |
| 799 | ReadBasicSetting(UISettings::values.fullscreen); | 843 | ReadBasicSetting(UISettings::values.fullscreen); |
| @@ -1161,6 +1205,40 @@ void Config::SaveMiscellaneousValues() { | |||
| 1161 | qt_config->endGroup(); | 1205 | qt_config->endGroup(); |
| 1162 | } | 1206 | } |
| 1163 | 1207 | ||
| 1208 | void Config::SaveMultiplayerValues() { | ||
| 1209 | qt_config->beginGroup(QStringLiteral("Multiplayer")); | ||
| 1210 | |||
| 1211 | WriteSetting(QStringLiteral("nickname"), UISettings::values.nickname, QString{}); | ||
| 1212 | WriteSetting(QStringLiteral("ip"), UISettings::values.ip, QString{}); | ||
| 1213 | WriteSetting(QStringLiteral("port"), UISettings::values.port, Network::DefaultRoomPort); | ||
| 1214 | WriteSetting(QStringLiteral("room_nickname"), UISettings::values.room_nickname, QString{}); | ||
| 1215 | WriteSetting(QStringLiteral("room_name"), UISettings::values.room_name, QString{}); | ||
| 1216 | WriteSetting(QStringLiteral("room_port"), UISettings::values.room_port, | ||
| 1217 | QStringLiteral("24872")); | ||
| 1218 | WriteSetting(QStringLiteral("host_type"), UISettings::values.host_type, 0); | ||
| 1219 | WriteSetting(QStringLiteral("max_player"), UISettings::values.max_player, 8); | ||
| 1220 | WriteSetting(QStringLiteral("game_id"), UISettings::values.game_id, 0); | ||
| 1221 | WriteSetting(QStringLiteral("room_description"), UISettings::values.room_description, | ||
| 1222 | QString{}); | ||
| 1223 | // Write ban list | ||
| 1224 | qt_config->beginWriteArray(QStringLiteral("username_ban_list")); | ||
| 1225 | for (std::size_t i = 0; i < UISettings::values.ban_list.first.size(); ++i) { | ||
| 1226 | qt_config->setArrayIndex(static_cast<int>(i)); | ||
| 1227 | WriteSetting(QStringLiteral("username"), | ||
| 1228 | QString::fromStdString(UISettings::values.ban_list.first[i])); | ||
| 1229 | } | ||
| 1230 | qt_config->endArray(); | ||
| 1231 | qt_config->beginWriteArray(QStringLiteral("ip_ban_list")); | ||
| 1232 | for (std::size_t i = 0; i < UISettings::values.ban_list.second.size(); ++i) { | ||
| 1233 | qt_config->setArrayIndex(static_cast<int>(i)); | ||
| 1234 | WriteSetting(QStringLiteral("ip"), | ||
| 1235 | QString::fromStdString(UISettings::values.ban_list.second[i])); | ||
| 1236 | } | ||
| 1237 | qt_config->endArray(); | ||
| 1238 | |||
| 1239 | qt_config->endGroup(); | ||
| 1240 | } | ||
| 1241 | |||
| 1164 | void Config::SavePathValues() { | 1242 | void Config::SavePathValues() { |
| 1165 | qt_config->beginGroup(QStringLiteral("Paths")); | 1243 | qt_config->beginGroup(QStringLiteral("Paths")); |
| 1166 | 1244 | ||
| @@ -1347,6 +1425,7 @@ void Config::SaveUIValues() { | |||
| 1347 | SavePathValues(); | 1425 | SavePathValues(); |
| 1348 | SaveScreenshotValues(); | 1426 | SaveScreenshotValues(); |
| 1349 | SaveShortcutValues(); | 1427 | SaveShortcutValues(); |
| 1428 | SaveMultiplayerValues(); | ||
| 1350 | 1429 | ||
| 1351 | WriteBasicSetting(UISettings::values.single_window_mode); | 1430 | WriteBasicSetting(UISettings::values.single_window_mode); |
| 1352 | WriteBasicSetting(UISettings::values.fullscreen); | 1431 | WriteBasicSetting(UISettings::values.fullscreen); |
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index a71eabe8e..937b2d95b 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -89,6 +89,7 @@ private: | |||
| 89 | void ReadUIGamelistValues(); | 89 | void ReadUIGamelistValues(); |
| 90 | void ReadUILayoutValues(); | 90 | void ReadUILayoutValues(); |
| 91 | void ReadWebServiceValues(); | 91 | void ReadWebServiceValues(); |
| 92 | void ReadMultiplayerValues(); | ||
| 92 | 93 | ||
| 93 | void SaveValues(); | 94 | void SaveValues(); |
| 94 | void SavePlayerValue(std::size_t player_index); | 95 | void SavePlayerValue(std::size_t player_index); |
| @@ -118,6 +119,7 @@ private: | |||
| 118 | void SaveUIGamelistValues(); | 119 | void SaveUIGamelistValues(); |
| 119 | void SaveUILayoutValues(); | 120 | void SaveUILayoutValues(); |
| 120 | void SaveWebServiceValues(); | 121 | void SaveWebServiceValues(); |
| 122 | void SaveMultiplayerValues(); | ||
| 121 | 123 | ||
| 122 | /** | 124 | /** |
| 123 | * Reads a setting from the qt_config. | 125 | * Reads a setting from the qt_config. |
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index e99657bd6..92ef4467b 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp | |||
| @@ -29,9 +29,10 @@ | |||
| 29 | 29 | ||
| 30 | ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, | 30 | ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, |
| 31 | InputCommon::InputSubsystem* input_subsystem, | 31 | InputCommon::InputSubsystem* input_subsystem, |
| 32 | Core::System& system_) | 32 | Core::System& system_, bool enable_web_config) |
| 33 | : QDialog(parent), ui{std::make_unique<Ui::ConfigureDialog>()}, registry{registry_}, | 33 | : QDialog(parent), ui{std::make_unique<Ui::ConfigureDialog>()}, |
| 34 | system{system_}, audio_tab{std::make_unique<ConfigureAudio>(system_, this)}, | 34 | registry(registry_), system{system_}, audio_tab{std::make_unique<ConfigureAudio>(system_, |
| 35 | this)}, | ||
| 35 | cpu_tab{std::make_unique<ConfigureCpu>(system_, this)}, | 36 | cpu_tab{std::make_unique<ConfigureCpu>(system_, this)}, |
| 36 | debug_tab_tab{std::make_unique<ConfigureDebugTab>(system_, this)}, | 37 | debug_tab_tab{std::make_unique<ConfigureDebugTab>(system_, this)}, |
| 37 | filesystem_tab{std::make_unique<ConfigureFilesystem>(this)}, | 38 | filesystem_tab{std::make_unique<ConfigureFilesystem>(this)}, |
| @@ -64,6 +65,7 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, | |||
| 64 | ui->tabWidget->addTab(ui_tab.get(), tr("Game List")); | 65 | ui->tabWidget->addTab(ui_tab.get(), tr("Game List")); |
| 65 | ui->tabWidget->addTab(web_tab.get(), tr("Web")); | 66 | ui->tabWidget->addTab(web_tab.get(), tr("Web")); |
| 66 | 67 | ||
| 68 | web_tab->SetWebServiceConfigEnabled(enable_web_config); | ||
| 67 | hotkeys_tab->Populate(registry); | 69 | hotkeys_tab->Populate(registry); |
| 68 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); | 70 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
| 69 | 71 | ||
diff --git a/src/yuzu/configuration/configure_dialog.h b/src/yuzu/configuration/configure_dialog.h index 12cf25daf..cec1610ad 100644 --- a/src/yuzu/configuration/configure_dialog.h +++ b/src/yuzu/configuration/configure_dialog.h | |||
| @@ -41,7 +41,8 @@ class ConfigureDialog : public QDialog { | |||
| 41 | 41 | ||
| 42 | public: | 42 | public: |
| 43 | explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, | 43 | explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry_, |
| 44 | InputCommon::InputSubsystem* input_subsystem, Core::System& system_); | 44 | InputCommon::InputSubsystem* input_subsystem, Core::System& system_, |
| 45 | bool enable_web_config = true); | ||
| 45 | ~ConfigureDialog() override; | 46 | ~ConfigureDialog() override; |
| 46 | 47 | ||
| 47 | void ApplyConfiguration(); | 48 | void ApplyConfiguration(); |
diff --git a/src/yuzu/configuration/configure_network.cpp b/src/yuzu/configuration/configure_network.cpp index 8ed08fa6a..ba1986eb1 100644 --- a/src/yuzu/configuration/configure_network.cpp +++ b/src/yuzu/configuration/configure_network.cpp | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | #include <QtConcurrent/QtConcurrent> | 4 | #include <QtConcurrent/QtConcurrent> |
| 5 | #include "common/settings.h" | 5 | #include "common/settings.h" |
| 6 | #include "core/core.h" | 6 | #include "core/core.h" |
| 7 | #include "core/network/network_interface.h" | 7 | #include "core/internal_network/network_interface.h" |
| 8 | #include "ui_configure_network.h" | 8 | #include "ui_configure_network.h" |
| 9 | #include "yuzu/configuration/configure_network.h" | 9 | #include "yuzu/configuration/configure_network.h" |
| 10 | 10 | ||
diff --git a/src/yuzu/configuration/configure_web.cpp b/src/yuzu/configuration/configure_web.cpp index d779251b4..ff4bf44f4 100644 --- a/src/yuzu/configuration/configure_web.cpp +++ b/src/yuzu/configuration/configure_web.cpp | |||
| @@ -169,3 +169,8 @@ void ConfigureWeb::OnLoginVerified() { | |||
| 169 | "correctly, and that your internet connection is working.")); | 169 | "correctly, and that your internet connection is working.")); |
| 170 | } | 170 | } |
| 171 | } | 171 | } |
| 172 | |||
| 173 | void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) { | ||
| 174 | ui->label_disable_info->setVisible(!enabled); | ||
| 175 | ui->groupBoxWebConfig->setEnabled(enabled); | ||
| 176 | } | ||
diff --git a/src/yuzu/configuration/configure_web.h b/src/yuzu/configuration/configure_web.h index 9054711ea..041b51149 100644 --- a/src/yuzu/configuration/configure_web.h +++ b/src/yuzu/configuration/configure_web.h | |||
| @@ -20,6 +20,7 @@ public: | |||
| 20 | ~ConfigureWeb() override; | 20 | ~ConfigureWeb() override; |
| 21 | 21 | ||
| 22 | void ApplyConfiguration(); | 22 | void ApplyConfiguration(); |
| 23 | void SetWebServiceConfigEnabled(bool enabled); | ||
| 23 | 24 | ||
| 24 | private: | 25 | private: |
| 25 | void changeEvent(QEvent* event) override; | 26 | void changeEvent(QEvent* event) override; |
diff --git a/src/yuzu/configuration/configure_web.ui b/src/yuzu/configuration/configure_web.ui index 35b4274b0..3ac3864be 100644 --- a/src/yuzu/configuration/configure_web.ui +++ b/src/yuzu/configuration/configure_web.ui | |||
| @@ -113,6 +113,16 @@ | |||
| 113 | </widget> | 113 | </widget> |
| 114 | </item> | 114 | </item> |
| 115 | <item> | 115 | <item> |
| 116 | <widget class="QLabel" name="label_disable_info"> | ||
| 117 | <property name="text"> | ||
| 118 | <string>Web Service configuration can only be changed when a public room isn't being hosted.</string> | ||
| 119 | </property> | ||
| 120 | <property name="wordWrap"> | ||
| 121 | <bool>true</bool> | ||
| 122 | </property> | ||
| 123 | </widget> | ||
| 124 | </item> | ||
| 125 | <item> | ||
| 116 | <widget class="QGroupBox" name="groupBox"> | 126 | <widget class="QGroupBox" name="groupBox"> |
| 117 | <property name="title"> | 127 | <property name="title"> |
| 118 | <string>Telemetry</string> | 128 | <string>Telemetry</string> |
diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index 05d309827..5bcf582bf 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp | |||
| @@ -499,6 +499,8 @@ void GameList::DonePopulating(const QStringList& watch_list) { | |||
| 499 | } | 499 | } |
| 500 | item_model->sort(tree_view->header()->sortIndicatorSection(), | 500 | item_model->sort(tree_view->header()->sortIndicatorSection(), |
| 501 | tree_view->header()->sortIndicatorOrder()); | 501 | tree_view->header()->sortIndicatorOrder()); |
| 502 | |||
| 503 | emit PopulatingCompleted(); | ||
| 502 | } | 504 | } |
| 503 | 505 | ||
| 504 | void GameList::PopupContextMenu(const QPoint& menu_location) { | 506 | void GameList::PopupContextMenu(const QPoint& menu_location) { |
| @@ -752,6 +754,10 @@ void GameList::LoadCompatibilityList() { | |||
| 752 | } | 754 | } |
| 753 | } | 755 | } |
| 754 | 756 | ||
| 757 | QStandardItemModel* GameList::GetModel() const { | ||
| 758 | return item_model; | ||
| 759 | } | ||
| 760 | |||
| 755 | void GameList::PopulateAsync(QVector<UISettings::GameDir>& game_dirs) { | 761 | void GameList::PopulateAsync(QVector<UISettings::GameDir>& game_dirs) { |
| 756 | tree_view->setEnabled(false); | 762 | tree_view->setEnabled(false); |
| 757 | 763 | ||
diff --git a/src/yuzu/game_list.h b/src/yuzu/game_list.h index bc36d015a..9605985cc 100644 --- a/src/yuzu/game_list.h +++ b/src/yuzu/game_list.h | |||
| @@ -16,9 +16,14 @@ | |||
| 16 | #include <QWidget> | 16 | #include <QWidget> |
| 17 | 17 | ||
| 18 | #include "common/common_types.h" | 18 | #include "common/common_types.h" |
| 19 | #include "core/core.h" | ||
| 19 | #include "uisettings.h" | 20 | #include "uisettings.h" |
| 20 | #include "yuzu/compatibility_list.h" | 21 | #include "yuzu/compatibility_list.h" |
| 21 | 22 | ||
| 23 | namespace Core { | ||
| 24 | class System; | ||
| 25 | } | ||
| 26 | |||
| 22 | class ControllerNavigation; | 27 | class ControllerNavigation; |
| 23 | class GameListWorker; | 28 | class GameListWorker; |
| 24 | class GameListSearchField; | 29 | class GameListSearchField; |
| @@ -84,6 +89,8 @@ public: | |||
| 84 | void SaveInterfaceLayout(); | 89 | void SaveInterfaceLayout(); |
| 85 | void LoadInterfaceLayout(); | 90 | void LoadInterfaceLayout(); |
| 86 | 91 | ||
| 92 | QStandardItemModel* GetModel() const; | ||
| 93 | |||
| 87 | /// Disables events from the emulated controller | 94 | /// Disables events from the emulated controller |
| 88 | void UnloadController(); | 95 | void UnloadController(); |
| 89 | 96 | ||
| @@ -108,6 +115,7 @@ signals: | |||
| 108 | void OpenDirectory(const QString& directory); | 115 | void OpenDirectory(const QString& directory); |
| 109 | void AddDirectory(); | 116 | void AddDirectory(); |
| 110 | void ShowList(bool show); | 117 | void ShowList(bool show); |
| 118 | void PopulatingCompleted(); | ||
| 111 | 119 | ||
| 112 | private slots: | 120 | private slots: |
| 113 | void OnItemExpanded(const QModelIndex& item); | 121 | void OnItemExpanded(const QModelIndex& item); |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 2814548eb..5d8132673 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | #include "core/hle/service/am/applet_ae.h" | 32 | #include "core/hle/service/am/applet_ae.h" |
| 33 | #include "core/hle/service/am/applet_oe.h" | 33 | #include "core/hle/service/am/applet_oe.h" |
| 34 | #include "core/hle/service/am/applets/applets.h" | 34 | #include "core/hle/service/am/applets/applets.h" |
| 35 | #include "yuzu/multiplayer/state.h" | ||
| 35 | #include "yuzu/util/controller_navigation.h" | 36 | #include "yuzu/util/controller_navigation.h" |
| 36 | 37 | ||
| 37 | // These are wrappers to avoid the calls to CreateDirectory and CreateFile because of the Windows | 38 | // These are wrappers to avoid the calls to CreateDirectory and CreateFile because of the Windows |
| @@ -132,6 +133,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual | |||
| 132 | #include "yuzu/main.h" | 133 | #include "yuzu/main.h" |
| 133 | #include "yuzu/startup_checks.h" | 134 | #include "yuzu/startup_checks.h" |
| 134 | #include "yuzu/uisettings.h" | 135 | #include "yuzu/uisettings.h" |
| 136 | #include "yuzu/util/clickable_label.h" | ||
| 135 | 137 | ||
| 136 | using namespace Common::Literals; | 138 | using namespace Common::Literals; |
| 137 | 139 | ||
| @@ -271,6 +273,8 @@ GMainWindow::GMainWindow(bool has_broken_vulkan) | |||
| 271 | SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); | 273 | SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); |
| 272 | discord_rpc->Update(); | 274 | discord_rpc->Update(); |
| 273 | 275 | ||
| 276 | Network::Init(); | ||
| 277 | |||
| 274 | RegisterMetaTypes(); | 278 | RegisterMetaTypes(); |
| 275 | 279 | ||
| 276 | InitializeWidgets(); | 280 | InitializeWidgets(); |
| @@ -459,6 +463,7 @@ GMainWindow::~GMainWindow() { | |||
| 459 | if (render_window->parent() == nullptr) { | 463 | if (render_window->parent() == nullptr) { |
| 460 | delete render_window; | 464 | delete render_window; |
| 461 | } | 465 | } |
| 466 | Network::Shutdown(); | ||
| 462 | } | 467 | } |
| 463 | 468 | ||
| 464 | void GMainWindow::RegisterMetaTypes() { | 469 | void GMainWindow::RegisterMetaTypes() { |
| @@ -822,6 +827,10 @@ void GMainWindow::InitializeWidgets() { | |||
| 822 | } | 827 | } |
| 823 | }); | 828 | }); |
| 824 | 829 | ||
| 830 | multiplayer_state = new MultiplayerState(this, game_list->GetModel(), ui->action_Leave_Room, | ||
| 831 | ui->action_Show_Room); | ||
| 832 | multiplayer_state->setVisible(false); | ||
| 833 | |||
| 825 | // Create status bar | 834 | // Create status bar |
| 826 | message_label = new QLabel(); | 835 | message_label = new QLabel(); |
| 827 | // Configured separately for left alignment | 836 | // Configured separately for left alignment |
| @@ -854,6 +863,9 @@ void GMainWindow::InitializeWidgets() { | |||
| 854 | statusBar()->addPermanentWidget(label); | 863 | statusBar()->addPermanentWidget(label); |
| 855 | } | 864 | } |
| 856 | 865 | ||
| 866 | statusBar()->addPermanentWidget(multiplayer_state->GetStatusText(), 0); | ||
| 867 | statusBar()->addPermanentWidget(multiplayer_state->GetStatusIcon(), 0); | ||
| 868 | |||
| 857 | tas_label = new QLabel(); | 869 | tas_label = new QLabel(); |
| 858 | tas_label->setObjectName(QStringLiteral("TASlabel")); | 870 | tas_label->setObjectName(QStringLiteral("TASlabel")); |
| 859 | tas_label->setFocusPolicy(Qt::NoFocus); | 871 | tas_label->setFocusPolicy(Qt::NoFocus); |
| @@ -1163,6 +1175,8 @@ void GMainWindow::ConnectWidgetEvents() { | |||
| 1163 | connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this, | 1175 | connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this, |
| 1164 | &GMainWindow::OnGameListAddDirectory); | 1176 | &GMainWindow::OnGameListAddDirectory); |
| 1165 | connect(game_list, &GameList::ShowList, this, &GMainWindow::OnGameListShowList); | 1177 | connect(game_list, &GameList::ShowList, this, &GMainWindow::OnGameListShowList); |
| 1178 | connect(game_list, &GameList::PopulatingCompleted, | ||
| 1179 | [this] { multiplayer_state->UpdateGameList(game_list->GetModel()); }); | ||
| 1166 | 1180 | ||
| 1167 | connect(game_list, &GameList::OpenPerGameGeneralRequested, this, | 1181 | connect(game_list, &GameList::OpenPerGameGeneralRequested, this, |
| 1168 | &GMainWindow::OnGameListOpenPerGameProperties); | 1182 | &GMainWindow::OnGameListOpenPerGameProperties); |
| @@ -1180,6 +1194,9 @@ void GMainWindow::ConnectWidgetEvents() { | |||
| 1180 | connect(this, &GMainWindow::EmulationStopping, this, &GMainWindow::SoftwareKeyboardExit); | 1194 | connect(this, &GMainWindow::EmulationStopping, this, &GMainWindow::SoftwareKeyboardExit); |
| 1181 | 1195 | ||
| 1182 | connect(&status_bar_update_timer, &QTimer::timeout, this, &GMainWindow::UpdateStatusBar); | 1196 | connect(&status_bar_update_timer, &QTimer::timeout, this, &GMainWindow::UpdateStatusBar); |
| 1197 | |||
| 1198 | connect(this, &GMainWindow::UpdateThemedIcons, multiplayer_state, | ||
| 1199 | &MultiplayerState::UpdateThemedIcons); | ||
| 1183 | } | 1200 | } |
| 1184 | 1201 | ||
| 1185 | void GMainWindow::ConnectMenuEvents() { | 1202 | void GMainWindow::ConnectMenuEvents() { |
| @@ -1223,6 +1240,18 @@ void GMainWindow::ConnectMenuEvents() { | |||
| 1223 | ui->action_Reset_Window_Size_900, | 1240 | ui->action_Reset_Window_Size_900, |
| 1224 | ui->action_Reset_Window_Size_1080}); | 1241 | ui->action_Reset_Window_Size_1080}); |
| 1225 | 1242 | ||
| 1243 | // Multiplayer | ||
| 1244 | connect(ui->action_View_Lobby, &QAction::triggered, multiplayer_state, | ||
| 1245 | &MultiplayerState::OnViewLobby); | ||
| 1246 | connect(ui->action_Start_Room, &QAction::triggered, multiplayer_state, | ||
| 1247 | &MultiplayerState::OnCreateRoom); | ||
| 1248 | connect(ui->action_Leave_Room, &QAction::triggered, multiplayer_state, | ||
| 1249 | &MultiplayerState::OnCloseRoom); | ||
| 1250 | connect(ui->action_Connect_To_Room, &QAction::triggered, multiplayer_state, | ||
| 1251 | &MultiplayerState::OnDirectConnectToRoom); | ||
| 1252 | connect(ui->action_Show_Room, &QAction::triggered, multiplayer_state, | ||
| 1253 | &MultiplayerState::OnOpenNetworkRoom); | ||
| 1254 | |||
| 1226 | // Tools | 1255 | // Tools |
| 1227 | connect_menu(ui->action_Rederive, std::bind(&GMainWindow::OnReinitializeKeys, this, | 1256 | connect_menu(ui->action_Rederive, std::bind(&GMainWindow::OnReinitializeKeys, this, |
| 1228 | ReinitializeKeyBehavior::Warning)); | 1257 | ReinitializeKeyBehavior::Warning)); |
| @@ -2783,7 +2812,8 @@ void GMainWindow::OnConfigure() { | |||
| 2783 | const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); | 2812 | const bool old_discord_presence = UISettings::values.enable_discord_presence.GetValue(); |
| 2784 | 2813 | ||
| 2785 | Settings::SetConfiguringGlobal(true); | 2814 | Settings::SetConfiguringGlobal(true); |
| 2786 | ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), *system); | 2815 | ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), *system, |
| 2816 | !multiplayer_state->IsHostingPublicRoom()); | ||
| 2787 | connect(&configure_dialog, &ConfigureDialog::LanguageChanged, this, | 2817 | connect(&configure_dialog, &ConfigureDialog::LanguageChanged, this, |
| 2788 | &GMainWindow::OnLanguageChanged); | 2818 | &GMainWindow::OnLanguageChanged); |
| 2789 | 2819 | ||
| @@ -2840,6 +2870,11 @@ void GMainWindow::OnConfigure() { | |||
| 2840 | if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) { | 2870 | if (UISettings::values.enable_discord_presence.GetValue() != old_discord_presence) { |
| 2841 | SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); | 2871 | SetDiscordEnabled(UISettings::values.enable_discord_presence.GetValue()); |
| 2842 | } | 2872 | } |
| 2873 | |||
| 2874 | if (!multiplayer_state->IsHostingPublicRoom()) { | ||
| 2875 | multiplayer_state->UpdateCredentials(); | ||
| 2876 | } | ||
| 2877 | |||
| 2843 | emit UpdateThemedIcons(); | 2878 | emit UpdateThemedIcons(); |
| 2844 | 2879 | ||
| 2845 | const auto reload = UISettings::values.is_game_list_reload_pending.exchange(false); | 2880 | const auto reload = UISettings::values.is_game_list_reload_pending.exchange(false); |
| @@ -3660,6 +3695,7 @@ void GMainWindow::closeEvent(QCloseEvent* event) { | |||
| 3660 | } | 3695 | } |
| 3661 | 3696 | ||
| 3662 | render_window->close(); | 3697 | render_window->close(); |
| 3698 | multiplayer_state->Close(); | ||
| 3663 | 3699 | ||
| 3664 | QWidget::closeEvent(event); | 3700 | QWidget::closeEvent(event); |
| 3665 | } | 3701 | } |
| @@ -3856,6 +3892,7 @@ void GMainWindow::OnLanguageChanged(const QString& locale) { | |||
| 3856 | UISettings::values.language = locale; | 3892 | UISettings::values.language = locale; |
| 3857 | LoadTranslation(); | 3893 | LoadTranslation(); |
| 3858 | ui->retranslateUi(this); | 3894 | ui->retranslateUi(this); |
| 3895 | multiplayer_state->retranslateUi(); | ||
| 3859 | UpdateWindowTitle(); | 3896 | UpdateWindowTitle(); |
| 3860 | } | 3897 | } |
| 3861 | 3898 | ||
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 27204f5a2..8d5c1398f 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include <QTimer> | 11 | #include <QTimer> |
| 12 | #include <QTranslator> | 12 | #include <QTranslator> |
| 13 | 13 | ||
| 14 | #include "common/announce_multiplayer_room.h" | ||
| 14 | #include "common/common_types.h" | 15 | #include "common/common_types.h" |
| 15 | #include "yuzu/compatibility_list.h" | 16 | #include "yuzu/compatibility_list.h" |
| 16 | #include "yuzu/hotkeys.h" | 17 | #include "yuzu/hotkeys.h" |
| @@ -22,6 +23,7 @@ | |||
| 22 | #endif | 23 | #endif |
| 23 | 24 | ||
| 24 | class Config; | 25 | class Config; |
| 26 | class ClickableLabel; | ||
| 25 | class EmuThread; | 27 | class EmuThread; |
| 26 | class GameList; | 28 | class GameList; |
| 27 | class GImageInfo; | 29 | class GImageInfo; |
| @@ -31,6 +33,7 @@ class MicroProfileDialog; | |||
| 31 | class ProfilerWidget; | 33 | class ProfilerWidget; |
| 32 | class ControllerDialog; | 34 | class ControllerDialog; |
| 33 | class QLabel; | 35 | class QLabel; |
| 36 | class MultiplayerState; | ||
| 34 | class QPushButton; | 37 | class QPushButton; |
| 35 | class QProgressDialog; | 38 | class QProgressDialog; |
| 36 | class WaitTreeWidget; | 39 | class WaitTreeWidget; |
| @@ -200,6 +203,8 @@ private: | |||
| 200 | void ConnectMenuEvents(); | 203 | void ConnectMenuEvents(); |
| 201 | void UpdateMenuState(); | 204 | void UpdateMenuState(); |
| 202 | 205 | ||
| 206 | MultiplayerState* multiplayer_state = nullptr; | ||
| 207 | |||
| 203 | void PreventOSSleep(); | 208 | void PreventOSSleep(); |
| 204 | void AllowOSSleep(); | 209 | void AllowOSSleep(); |
| 205 | 210 | ||
diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index 6ab95b9a5..60a8deab1 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui | |||
| @@ -120,6 +120,20 @@ | |||
| 120 | <addaction name="menu_Reset_Window_Size"/> | 120 | <addaction name="menu_Reset_Window_Size"/> |
| 121 | <addaction name="menu_View_Debugging"/> | 121 | <addaction name="menu_View_Debugging"/> |
| 122 | </widget> | 122 | </widget> |
| 123 | <widget class="QMenu" name="menu_Multiplayer"> | ||
| 124 | <property name="enabled"> | ||
| 125 | <bool>true</bool> | ||
| 126 | </property> | ||
| 127 | <property name="title"> | ||
| 128 | <string>Multiplayer</string> | ||
| 129 | </property> | ||
| 130 | <addaction name="action_View_Lobby"/> | ||
| 131 | <addaction name="action_Start_Room"/> | ||
| 132 | <addaction name="action_Connect_To_Room"/> | ||
| 133 | <addaction name="separator"/> | ||
| 134 | <addaction name="action_Show_Room"/> | ||
| 135 | <addaction name="action_Leave_Room"/> | ||
| 136 | </widget> | ||
| 123 | <widget class="QMenu" name="menu_Tools"> | 137 | <widget class="QMenu" name="menu_Tools"> |
| 124 | <property name="title"> | 138 | <property name="title"> |
| 125 | <string>&Tools</string> | 139 | <string>&Tools</string> |
| @@ -154,6 +168,7 @@ | |||
| 154 | <addaction name="menu_Emulation"/> | 168 | <addaction name="menu_Emulation"/> |
| 155 | <addaction name="menu_View"/> | 169 | <addaction name="menu_View"/> |
| 156 | <addaction name="menu_Tools"/> | 170 | <addaction name="menu_Tools"/> |
| 171 | <addaction name="menu_Multiplayer"/> | ||
| 157 | <addaction name="menu_Help"/> | 172 | <addaction name="menu_Help"/> |
| 158 | </widget> | 173 | </widget> |
| 159 | <action name="action_Install_File_NAND"> | 174 | <action name="action_Install_File_NAND"> |
| @@ -245,6 +260,43 @@ | |||
| 245 | <string>Show Status Bar</string> | 260 | <string>Show Status Bar</string> |
| 246 | </property> | 261 | </property> |
| 247 | </action> | 262 | </action> |
| 263 | <action name="action_View_Lobby"> | ||
| 264 | <property name="enabled"> | ||
| 265 | <bool>true</bool> | ||
| 266 | </property> | ||
| 267 | <property name="text"> | ||
| 268 | <string>Browse Public Game Lobby</string> | ||
| 269 | </property> | ||
| 270 | </action> | ||
| 271 | <action name="action_Start_Room"> | ||
| 272 | <property name="enabled"> | ||
| 273 | <bool>true</bool> | ||
| 274 | </property> | ||
| 275 | <property name="text"> | ||
| 276 | <string>Create Room</string> | ||
| 277 | </property> | ||
| 278 | </action> | ||
| 279 | <action name="action_Leave_Room"> | ||
| 280 | <property name="enabled"> | ||
| 281 | <bool>false</bool> | ||
| 282 | </property> | ||
| 283 | <property name="text"> | ||
| 284 | <string>Leave Room</string> | ||
| 285 | </property> | ||
| 286 | </action> | ||
| 287 | <action name="action_Connect_To_Room"> | ||
| 288 | <property name="text"> | ||
| 289 | <string>Direct Connect to Room</string> | ||
| 290 | </property> | ||
| 291 | </action> | ||
| 292 | <action name="action_Show_Room"> | ||
| 293 | <property name="enabled"> | ||
| 294 | <bool>false</bool> | ||
| 295 | </property> | ||
| 296 | <property name="text"> | ||
| 297 | <string>Show Current Room</string> | ||
| 298 | </property> | ||
| 299 | </action> | ||
| 248 | <action name="action_Fullscreen"> | 300 | <action name="action_Fullscreen"> |
| 249 | <property name="checkable"> | 301 | <property name="checkable"> |
| 250 | <bool>true</bool> | 302 | <bool>true</bool> |
diff --git a/src/yuzu/multiplayer/chat_room.cpp b/src/yuzu/multiplayer/chat_room.cpp new file mode 100644 index 000000000..6dd4bc36d --- /dev/null +++ b/src/yuzu/multiplayer/chat_room.cpp | |||
| @@ -0,0 +1,490 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <array> | ||
| 6 | #include <future> | ||
| 7 | #include <QColor> | ||
| 8 | #include <QDesktopServices> | ||
| 9 | #include <QFutureWatcher> | ||
| 10 | #include <QImage> | ||
| 11 | #include <QList> | ||
| 12 | #include <QLocale> | ||
| 13 | #include <QMenu> | ||
| 14 | #include <QMessageBox> | ||
| 15 | #include <QMetaType> | ||
| 16 | #include <QTime> | ||
| 17 | #include <QUrl> | ||
| 18 | #include <QtConcurrent/QtConcurrentRun> | ||
| 19 | #include "common/logging/log.h" | ||
| 20 | #include "core/announce_multiplayer_session.h" | ||
| 21 | #include "ui_chat_room.h" | ||
| 22 | #include "yuzu/game_list_p.h" | ||
| 23 | #include "yuzu/multiplayer/chat_room.h" | ||
| 24 | #include "yuzu/multiplayer/message.h" | ||
| 25 | #ifdef ENABLE_WEB_SERVICE | ||
| 26 | #include "web_service/web_backend.h" | ||
| 27 | #endif | ||
| 28 | |||
| 29 | class ChatMessage { | ||
| 30 | public: | ||
| 31 | explicit ChatMessage(const Network::ChatEntry& chat, QTime ts = {}) { | ||
| 32 | /// Convert the time to their default locale defined format | ||
| 33 | QLocale locale; | ||
| 34 | timestamp = locale.toString(ts.isValid() ? ts : QTime::currentTime(), QLocale::ShortFormat); | ||
| 35 | nickname = QString::fromStdString(chat.nickname); | ||
| 36 | username = QString::fromStdString(chat.username); | ||
| 37 | message = QString::fromStdString(chat.message); | ||
| 38 | |||
| 39 | // Check for user pings | ||
| 40 | QString cur_nickname, cur_username; | ||
| 41 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 42 | cur_nickname = QString::fromStdString(room->GetNickname()); | ||
| 43 | cur_username = QString::fromStdString(room->GetUsername()); | ||
| 44 | } | ||
| 45 | |||
| 46 | // Handle pings at the beginning and end of message | ||
| 47 | QString fixed_message = QStringLiteral(" %1 ").arg(message); | ||
| 48 | if (fixed_message.contains(QStringLiteral(" @%1 ").arg(cur_nickname)) || | ||
| 49 | (!cur_username.isEmpty() && | ||
| 50 | fixed_message.contains(QStringLiteral(" @%1 ").arg(cur_username)))) { | ||
| 51 | |||
| 52 | contains_ping = true; | ||
| 53 | } else { | ||
| 54 | contains_ping = false; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | bool ContainsPing() const { | ||
| 59 | return contains_ping; | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Format the message using the players color | ||
| 63 | QString GetPlayerChatMessage(u16 player) const { | ||
| 64 | auto color = player_color[player % 16]; | ||
| 65 | QString name; | ||
| 66 | if (username.isEmpty() || username == nickname) { | ||
| 67 | name = nickname; | ||
| 68 | } else { | ||
| 69 | name = QStringLiteral("%1 (%2)").arg(nickname, username); | ||
| 70 | } | ||
| 71 | |||
| 72 | QString style, text_color; | ||
| 73 | if (ContainsPing()) { | ||
| 74 | // Add a background color to these messages | ||
| 75 | style = QStringLiteral("background-color: %1").arg(QString::fromStdString(ping_color)); | ||
| 76 | // Add a font color | ||
| 77 | text_color = QStringLiteral("color='#000000'"); | ||
| 78 | } | ||
| 79 | |||
| 80 | return QStringLiteral("[%1] <font color='%2'><%3></font> <font style='%4' " | ||
| 81 | "%5>%6</font>") | ||
| 82 | .arg(timestamp, QString::fromStdString(color), name.toHtmlEscaped(), style, text_color, | ||
| 83 | message.toHtmlEscaped()); | ||
| 84 | } | ||
| 85 | |||
| 86 | private: | ||
| 87 | static constexpr std::array<const char*, 16> player_color = { | ||
| 88 | {"#0000FF", "#FF0000", "#8A2BE2", "#FF69B4", "#1E90FF", "#008000", "#00FF7F", "#B22222", | ||
| 89 | "#DAA520", "#FF4500", "#2E8B57", "#5F9EA0", "#D2691E", "#9ACD32", "#FF7F50", "FFFF00"}}; | ||
| 90 | static constexpr char ping_color[] = "#FFFF00"; | ||
| 91 | |||
| 92 | QString timestamp; | ||
| 93 | QString nickname; | ||
| 94 | QString username; | ||
| 95 | QString message; | ||
| 96 | bool contains_ping; | ||
| 97 | }; | ||
| 98 | |||
| 99 | class StatusMessage { | ||
| 100 | public: | ||
| 101 | explicit StatusMessage(const QString& msg, QTime ts = {}) { | ||
| 102 | /// Convert the time to their default locale defined format | ||
| 103 | QLocale locale; | ||
| 104 | timestamp = locale.toString(ts.isValid() ? ts : QTime::currentTime(), QLocale::ShortFormat); | ||
| 105 | message = msg; | ||
| 106 | } | ||
| 107 | |||
| 108 | QString GetSystemChatMessage() const { | ||
| 109 | return QStringLiteral("[%1] <font color='%2'>* %3</font>") | ||
| 110 | .arg(timestamp, QString::fromStdString(system_color), message); | ||
| 111 | } | ||
| 112 | |||
| 113 | private: | ||
| 114 | static constexpr const char system_color[] = "#FF8C00"; | ||
| 115 | QString timestamp; | ||
| 116 | QString message; | ||
| 117 | }; | ||
| 118 | |||
| 119 | class PlayerListItem : public QStandardItem { | ||
| 120 | public: | ||
| 121 | static const int NicknameRole = Qt::UserRole + 1; | ||
| 122 | static const int UsernameRole = Qt::UserRole + 2; | ||
| 123 | static const int AvatarUrlRole = Qt::UserRole + 3; | ||
| 124 | static const int GameNameRole = Qt::UserRole + 4; | ||
| 125 | |||
| 126 | PlayerListItem() = default; | ||
| 127 | explicit PlayerListItem(const std::string& nickname, const std::string& username, | ||
| 128 | const std::string& avatar_url, const std::string& game_name) { | ||
| 129 | setEditable(false); | ||
| 130 | setData(QString::fromStdString(nickname), NicknameRole); | ||
| 131 | setData(QString::fromStdString(username), UsernameRole); | ||
| 132 | setData(QString::fromStdString(avatar_url), AvatarUrlRole); | ||
| 133 | if (game_name.empty()) { | ||
| 134 | setData(QObject::tr("Not playing a game"), GameNameRole); | ||
| 135 | } else { | ||
| 136 | setData(QString::fromStdString(game_name), GameNameRole); | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | QVariant data(int role) const override { | ||
| 141 | if (role != Qt::DisplayRole) { | ||
| 142 | return QStandardItem::data(role); | ||
| 143 | } | ||
| 144 | QString name; | ||
| 145 | const QString nickname = data(NicknameRole).toString(); | ||
| 146 | const QString username = data(UsernameRole).toString(); | ||
| 147 | if (username.isEmpty() || username == nickname) { | ||
| 148 | name = nickname; | ||
| 149 | } else { | ||
| 150 | name = QStringLiteral("%1 (%2)").arg(nickname, username); | ||
| 151 | } | ||
| 152 | return QStringLiteral("%1\n %2").arg(name, data(GameNameRole).toString()); | ||
| 153 | } | ||
| 154 | }; | ||
| 155 | |||
| 156 | ChatRoom::ChatRoom(QWidget* parent) : QWidget(parent), ui(std::make_unique<Ui::ChatRoom>()) { | ||
| 157 | ui->setupUi(this); | ||
| 158 | |||
| 159 | // set the item_model for player_view | ||
| 160 | |||
| 161 | player_list = new QStandardItemModel(ui->player_view); | ||
| 162 | ui->player_view->setModel(player_list); | ||
| 163 | ui->player_view->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 164 | // set a header to make it look better though there is only one column | ||
| 165 | player_list->insertColumns(0, 1); | ||
| 166 | player_list->setHeaderData(0, Qt::Horizontal, tr("Members")); | ||
| 167 | |||
| 168 | ui->chat_history->document()->setMaximumBlockCount(max_chat_lines); | ||
| 169 | |||
| 170 | // register the network structs to use in slots and signals | ||
| 171 | qRegisterMetaType<Network::ChatEntry>(); | ||
| 172 | qRegisterMetaType<Network::StatusMessageEntry>(); | ||
| 173 | qRegisterMetaType<Network::RoomInformation>(); | ||
| 174 | qRegisterMetaType<Network::RoomMember::State>(); | ||
| 175 | |||
| 176 | // setup the callbacks for network updates | ||
| 177 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 178 | member->BindOnChatMessageRecieved( | ||
| 179 | [this](const Network::ChatEntry& chat) { emit ChatReceived(chat); }); | ||
| 180 | member->BindOnStatusMessageReceived( | ||
| 181 | [this](const Network::StatusMessageEntry& status_message) { | ||
| 182 | emit StatusMessageReceived(status_message); | ||
| 183 | }); | ||
| 184 | connect(this, &ChatRoom::ChatReceived, this, &ChatRoom::OnChatReceive); | ||
| 185 | connect(this, &ChatRoom::StatusMessageReceived, this, &ChatRoom::OnStatusMessageReceive); | ||
| 186 | } else { | ||
| 187 | // TODO (jroweboy) network was not initialized? | ||
| 188 | } | ||
| 189 | |||
| 190 | // Connect all the widgets to the appropriate events | ||
| 191 | connect(ui->player_view, &QTreeView::customContextMenuRequested, this, | ||
| 192 | &ChatRoom::PopupContextMenu); | ||
| 193 | connect(ui->chat_message, &QLineEdit::returnPressed, this, &ChatRoom::OnSendChat); | ||
| 194 | connect(ui->chat_message, &QLineEdit::textChanged, this, &ChatRoom::OnChatTextChanged); | ||
| 195 | connect(ui->send_message, &QPushButton::clicked, this, &ChatRoom::OnSendChat); | ||
| 196 | } | ||
| 197 | |||
| 198 | ChatRoom::~ChatRoom() = default; | ||
| 199 | |||
| 200 | void ChatRoom::SetModPerms(bool is_mod) { | ||
| 201 | has_mod_perms = is_mod; | ||
| 202 | } | ||
| 203 | |||
| 204 | void ChatRoom::RetranslateUi() { | ||
| 205 | ui->retranslateUi(this); | ||
| 206 | } | ||
| 207 | |||
| 208 | void ChatRoom::Clear() { | ||
| 209 | ui->chat_history->clear(); | ||
| 210 | block_list.clear(); | ||
| 211 | } | ||
| 212 | |||
| 213 | void ChatRoom::AppendStatusMessage(const QString& msg) { | ||
| 214 | ui->chat_history->append(StatusMessage(msg).GetSystemChatMessage()); | ||
| 215 | } | ||
| 216 | |||
| 217 | void ChatRoom::AppendChatMessage(const QString& msg) { | ||
| 218 | ui->chat_history->append(msg); | ||
| 219 | } | ||
| 220 | |||
| 221 | void ChatRoom::SendModerationRequest(Network::RoomMessageTypes type, const std::string& nickname) { | ||
| 222 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 223 | auto members = room->GetMemberInformation(); | ||
| 224 | auto it = std::find_if(members.begin(), members.end(), | ||
| 225 | [&nickname](const Network::RoomMember::MemberInformation& member) { | ||
| 226 | return member.nickname == nickname; | ||
| 227 | }); | ||
| 228 | if (it == members.end()) { | ||
| 229 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::NO_SUCH_USER); | ||
| 230 | return; | ||
| 231 | } | ||
| 232 | room->SendModerationRequest(type, nickname); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | bool ChatRoom::ValidateMessage(const std::string& msg) { | ||
| 237 | return !msg.empty(); | ||
| 238 | } | ||
| 239 | |||
| 240 | void ChatRoom::OnRoomUpdate(const Network::RoomInformation& info) { | ||
| 241 | // TODO(B3N30): change title | ||
| 242 | if (auto room_member = Network::GetRoomMember().lock()) { | ||
| 243 | SetPlayerList(room_member->GetMemberInformation()); | ||
| 244 | } | ||
| 245 | } | ||
| 246 | |||
| 247 | void ChatRoom::Disable() { | ||
| 248 | ui->send_message->setDisabled(true); | ||
| 249 | ui->chat_message->setDisabled(true); | ||
| 250 | } | ||
| 251 | |||
| 252 | void ChatRoom::Enable() { | ||
| 253 | ui->send_message->setEnabled(true); | ||
| 254 | ui->chat_message->setEnabled(true); | ||
| 255 | } | ||
| 256 | |||
| 257 | void ChatRoom::OnChatReceive(const Network::ChatEntry& chat) { | ||
| 258 | if (!ValidateMessage(chat.message)) { | ||
| 259 | return; | ||
| 260 | } | ||
| 261 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 262 | // get the id of the player | ||
| 263 | auto members = room->GetMemberInformation(); | ||
| 264 | auto it = std::find_if(members.begin(), members.end(), | ||
| 265 | [&chat](const Network::RoomMember::MemberInformation& member) { | ||
| 266 | return member.nickname == chat.nickname && | ||
| 267 | member.username == chat.username; | ||
| 268 | }); | ||
| 269 | if (it == members.end()) { | ||
| 270 | LOG_INFO(Network, "Chat message received from unknown player. Ignoring it."); | ||
| 271 | return; | ||
| 272 | } | ||
| 273 | if (block_list.count(chat.nickname)) { | ||
| 274 | LOG_INFO(Network, "Chat message received from blocked player {}. Ignoring it.", | ||
| 275 | chat.nickname); | ||
| 276 | return; | ||
| 277 | } | ||
| 278 | auto player = std::distance(members.begin(), it); | ||
| 279 | ChatMessage m(chat); | ||
| 280 | if (m.ContainsPing()) { | ||
| 281 | emit UserPinged(); | ||
| 282 | } | ||
| 283 | AppendChatMessage(m.GetPlayerChatMessage(player)); | ||
| 284 | } | ||
| 285 | } | ||
| 286 | |||
| 287 | void ChatRoom::OnStatusMessageReceive(const Network::StatusMessageEntry& status_message) { | ||
| 288 | QString name; | ||
| 289 | if (status_message.username.empty() || status_message.username == status_message.nickname) { | ||
| 290 | name = QString::fromStdString(status_message.nickname); | ||
| 291 | } else { | ||
| 292 | name = QStringLiteral("%1 (%2)").arg(QString::fromStdString(status_message.nickname), | ||
| 293 | QString::fromStdString(status_message.username)); | ||
| 294 | } | ||
| 295 | QString message; | ||
| 296 | switch (status_message.type) { | ||
| 297 | case Network::IdMemberJoin: | ||
| 298 | message = tr("%1 has joined").arg(name); | ||
| 299 | break; | ||
| 300 | case Network::IdMemberLeave: | ||
| 301 | message = tr("%1 has left").arg(name); | ||
| 302 | break; | ||
| 303 | case Network::IdMemberKicked: | ||
| 304 | message = tr("%1 has been kicked").arg(name); | ||
| 305 | break; | ||
| 306 | case Network::IdMemberBanned: | ||
| 307 | message = tr("%1 has been banned").arg(name); | ||
| 308 | break; | ||
| 309 | case Network::IdAddressUnbanned: | ||
| 310 | message = tr("%1 has been unbanned").arg(name); | ||
| 311 | break; | ||
| 312 | } | ||
| 313 | if (!message.isEmpty()) | ||
| 314 | AppendStatusMessage(message); | ||
| 315 | } | ||
| 316 | |||
| 317 | void ChatRoom::OnSendChat() { | ||
| 318 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 319 | if (room->GetState() != Network::RoomMember::State::Joined && | ||
| 320 | room->GetState() != Network::RoomMember::State::Moderator) { | ||
| 321 | |||
| 322 | return; | ||
| 323 | } | ||
| 324 | auto message = ui->chat_message->text().toStdString(); | ||
| 325 | if (!ValidateMessage(message)) { | ||
| 326 | return; | ||
| 327 | } | ||
| 328 | auto nick = room->GetNickname(); | ||
| 329 | auto username = room->GetUsername(); | ||
| 330 | Network::ChatEntry chat{nick, username, message}; | ||
| 331 | |||
| 332 | auto members = room->GetMemberInformation(); | ||
| 333 | auto it = std::find_if(members.begin(), members.end(), | ||
| 334 | [&chat](const Network::RoomMember::MemberInformation& member) { | ||
| 335 | return member.nickname == chat.nickname && | ||
| 336 | member.username == chat.username; | ||
| 337 | }); | ||
| 338 | if (it == members.end()) { | ||
| 339 | LOG_INFO(Network, "Cannot find self in the player list when sending a message."); | ||
| 340 | } | ||
| 341 | auto player = std::distance(members.begin(), it); | ||
| 342 | ChatMessage m(chat); | ||
| 343 | room->SendChatMessage(message); | ||
| 344 | AppendChatMessage(m.GetPlayerChatMessage(player)); | ||
| 345 | ui->chat_message->clear(); | ||
| 346 | } | ||
| 347 | } | ||
| 348 | |||
| 349 | void ChatRoom::UpdateIconDisplay() { | ||
| 350 | for (int row = 0; row < player_list->invisibleRootItem()->rowCount(); ++row) { | ||
| 351 | QStandardItem* item = player_list->invisibleRootItem()->child(row); | ||
| 352 | const std::string avatar_url = | ||
| 353 | item->data(PlayerListItem::AvatarUrlRole).toString().toStdString(); | ||
| 354 | if (icon_cache.count(avatar_url)) { | ||
| 355 | item->setData(icon_cache.at(avatar_url), Qt::DecorationRole); | ||
| 356 | } else { | ||
| 357 | item->setData(QIcon::fromTheme(QStringLiteral("no_avatar")).pixmap(48), | ||
| 358 | Qt::DecorationRole); | ||
| 359 | } | ||
| 360 | } | ||
| 361 | } | ||
| 362 | |||
| 363 | void ChatRoom::SetPlayerList(const Network::RoomMember::MemberList& member_list) { | ||
| 364 | // TODO(B3N30): Remember which row is selected | ||
| 365 | player_list->removeRows(0, player_list->rowCount()); | ||
| 366 | for (const auto& member : member_list) { | ||
| 367 | if (member.nickname.empty()) | ||
| 368 | continue; | ||
| 369 | QStandardItem* name_item = new PlayerListItem(member.nickname, member.username, | ||
| 370 | member.avatar_url, member.game_info.name); | ||
| 371 | |||
| 372 | #ifdef ENABLE_WEB_SERVICE | ||
| 373 | if (!icon_cache.count(member.avatar_url) && !member.avatar_url.empty()) { | ||
| 374 | // Start a request to get the member's avatar | ||
| 375 | const QUrl url(QString::fromStdString(member.avatar_url)); | ||
| 376 | QFuture<std::string> future = QtConcurrent::run([url] { | ||
| 377 | WebService::Client client( | ||
| 378 | QStringLiteral("%1://%2").arg(url.scheme(), url.host()).toStdString(), "", ""); | ||
| 379 | auto result = client.GetImage(url.path().toStdString(), true); | ||
| 380 | if (result.returned_data.empty()) { | ||
| 381 | LOG_ERROR(WebService, "Failed to get avatar"); | ||
| 382 | } | ||
| 383 | return result.returned_data; | ||
| 384 | }); | ||
| 385 | auto* future_watcher = new QFutureWatcher<std::string>(this); | ||
| 386 | connect(future_watcher, &QFutureWatcher<std::string>::finished, this, | ||
| 387 | [this, future_watcher, avatar_url = member.avatar_url] { | ||
| 388 | const std::string result = future_watcher->result(); | ||
| 389 | if (result.empty()) | ||
| 390 | return; | ||
| 391 | QPixmap pixmap; | ||
| 392 | if (!pixmap.loadFromData(reinterpret_cast<const u8*>(result.data()), | ||
| 393 | result.size())) | ||
| 394 | return; | ||
| 395 | icon_cache[avatar_url] = | ||
| 396 | pixmap.scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | ||
| 397 | // Update all the displayed icons with the new icon_cache | ||
| 398 | UpdateIconDisplay(); | ||
| 399 | }); | ||
| 400 | future_watcher->setFuture(future); | ||
| 401 | } | ||
| 402 | #endif | ||
| 403 | |||
| 404 | player_list->invisibleRootItem()->appendRow(name_item); | ||
| 405 | } | ||
| 406 | UpdateIconDisplay(); | ||
| 407 | // TODO(B3N30): Restore row selection | ||
| 408 | } | ||
| 409 | |||
| 410 | void ChatRoom::OnChatTextChanged() { | ||
| 411 | if (ui->chat_message->text().length() > static_cast<int>(Network::MaxMessageSize)) | ||
| 412 | ui->chat_message->setText( | ||
| 413 | ui->chat_message->text().left(static_cast<int>(Network::MaxMessageSize))); | ||
| 414 | } | ||
| 415 | |||
| 416 | void ChatRoom::PopupContextMenu(const QPoint& menu_location) { | ||
| 417 | QModelIndex item = ui->player_view->indexAt(menu_location); | ||
| 418 | if (!item.isValid()) | ||
| 419 | return; | ||
| 420 | |||
| 421 | std::string nickname = | ||
| 422 | player_list->item(item.row())->data(PlayerListItem::NicknameRole).toString().toStdString(); | ||
| 423 | |||
| 424 | QMenu context_menu; | ||
| 425 | |||
| 426 | QString username = player_list->item(item.row())->data(PlayerListItem::UsernameRole).toString(); | ||
| 427 | if (!username.isEmpty()) { | ||
| 428 | QAction* view_profile_action = context_menu.addAction(tr("View Profile")); | ||
| 429 | connect(view_profile_action, &QAction::triggered, [username] { | ||
| 430 | QDesktopServices::openUrl( | ||
| 431 | QUrl(QStringLiteral("https://community.citra-emu.org/u/%1").arg(username))); | ||
| 432 | }); | ||
| 433 | } | ||
| 434 | |||
| 435 | std::string cur_nickname; | ||
| 436 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 437 | cur_nickname = room->GetNickname(); | ||
| 438 | } | ||
| 439 | |||
| 440 | if (nickname != cur_nickname) { // You can't block yourself | ||
| 441 | QAction* block_action = context_menu.addAction(tr("Block Player")); | ||
| 442 | |||
| 443 | block_action->setCheckable(true); | ||
| 444 | block_action->setChecked(block_list.count(nickname) > 0); | ||
| 445 | |||
| 446 | connect(block_action, &QAction::triggered, [this, nickname] { | ||
| 447 | if (block_list.count(nickname)) { | ||
| 448 | block_list.erase(nickname); | ||
| 449 | } else { | ||
| 450 | QMessageBox::StandardButton result = QMessageBox::question( | ||
| 451 | this, tr("Block Player"), | ||
| 452 | tr("When you block a player, you will no longer receive chat messages from " | ||
| 453 | "them.<br><br>Are you sure you would like to block %1?") | ||
| 454 | .arg(QString::fromStdString(nickname)), | ||
| 455 | QMessageBox::Yes | QMessageBox::No); | ||
| 456 | if (result == QMessageBox::Yes) | ||
| 457 | block_list.emplace(nickname); | ||
| 458 | } | ||
| 459 | }); | ||
| 460 | } | ||
| 461 | |||
| 462 | if (has_mod_perms && nickname != cur_nickname) { // You can't kick or ban yourself | ||
| 463 | context_menu.addSeparator(); | ||
| 464 | |||
| 465 | QAction* kick_action = context_menu.addAction(tr("Kick")); | ||
| 466 | QAction* ban_action = context_menu.addAction(tr("Ban")); | ||
| 467 | |||
| 468 | connect(kick_action, &QAction::triggered, [this, nickname] { | ||
| 469 | QMessageBox::StandardButton result = | ||
| 470 | QMessageBox::question(this, tr("Kick Player"), | ||
| 471 | tr("Are you sure you would like to <b>kick</b> %1?") | ||
| 472 | .arg(QString::fromStdString(nickname)), | ||
| 473 | QMessageBox::Yes | QMessageBox::No); | ||
| 474 | if (result == QMessageBox::Yes) | ||
| 475 | SendModerationRequest(Network::IdModKick, nickname); | ||
| 476 | }); | ||
| 477 | connect(ban_action, &QAction::triggered, [this, nickname] { | ||
| 478 | QMessageBox::StandardButton result = QMessageBox::question( | ||
| 479 | this, tr("Ban Player"), | ||
| 480 | tr("Are you sure you would like to <b>kick and ban</b> %1?\n\nThis would " | ||
| 481 | "ban both their forum username and their IP address.") | ||
| 482 | .arg(QString::fromStdString(nickname)), | ||
| 483 | QMessageBox::Yes | QMessageBox::No); | ||
| 484 | if (result == QMessageBox::Yes) | ||
| 485 | SendModerationRequest(Network::IdModBan, nickname); | ||
| 486 | }); | ||
| 487 | } | ||
| 488 | |||
| 489 | context_menu.exec(ui->player_view->viewport()->mapToGlobal(menu_location)); | ||
| 490 | } | ||
diff --git a/src/yuzu/multiplayer/chat_room.h b/src/yuzu/multiplayer/chat_room.h new file mode 100644 index 000000000..a810377f7 --- /dev/null +++ b/src/yuzu/multiplayer/chat_room.h | |||
| @@ -0,0 +1,74 @@ | |||
| 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 <memory> | ||
| 8 | #include <unordered_set> | ||
| 9 | #include <QDialog> | ||
| 10 | #include <QSortFilterProxyModel> | ||
| 11 | #include <QStandardItemModel> | ||
| 12 | #include <QVariant> | ||
| 13 | #include "network/network.h" | ||
| 14 | |||
| 15 | namespace Ui { | ||
| 16 | class ChatRoom; | ||
| 17 | } | ||
| 18 | |||
| 19 | namespace Core { | ||
| 20 | class AnnounceMultiplayerSession; | ||
| 21 | } | ||
| 22 | |||
| 23 | class ConnectionError; | ||
| 24 | class ComboBoxProxyModel; | ||
| 25 | |||
| 26 | class ChatMessage; | ||
| 27 | |||
| 28 | class ChatRoom : public QWidget { | ||
| 29 | Q_OBJECT | ||
| 30 | |||
| 31 | public: | ||
| 32 | explicit ChatRoom(QWidget* parent); | ||
| 33 | void RetranslateUi(); | ||
| 34 | void SetPlayerList(const Network::RoomMember::MemberList& member_list); | ||
| 35 | void Clear(); | ||
| 36 | void AppendStatusMessage(const QString& msg); | ||
| 37 | ~ChatRoom(); | ||
| 38 | |||
| 39 | void SetModPerms(bool is_mod); | ||
| 40 | void UpdateIconDisplay(); | ||
| 41 | |||
| 42 | public slots: | ||
| 43 | void OnRoomUpdate(const Network::RoomInformation& info); | ||
| 44 | void OnChatReceive(const Network::ChatEntry&); | ||
| 45 | void OnStatusMessageReceive(const Network::StatusMessageEntry&); | ||
| 46 | void OnSendChat(); | ||
| 47 | void OnChatTextChanged(); | ||
| 48 | void PopupContextMenu(const QPoint& menu_location); | ||
| 49 | void Disable(); | ||
| 50 | void Enable(); | ||
| 51 | |||
| 52 | signals: | ||
| 53 | void ChatReceived(const Network::ChatEntry&); | ||
| 54 | void StatusMessageReceived(const Network::StatusMessageEntry&); | ||
| 55 | void UserPinged(); | ||
| 56 | |||
| 57 | private: | ||
| 58 | static constexpr u32 max_chat_lines = 1000; | ||
| 59 | void AppendChatMessage(const QString&); | ||
| 60 | bool ValidateMessage(const std::string&); | ||
| 61 | void SendModerationRequest(Network::RoomMessageTypes type, const std::string& nickname); | ||
| 62 | |||
| 63 | bool has_mod_perms = false; | ||
| 64 | QStandardItemModel* player_list; | ||
| 65 | std::unique_ptr<Ui::ChatRoom> ui; | ||
| 66 | std::unordered_set<std::string> block_list; | ||
| 67 | std::unordered_map<std::string, QPixmap> icon_cache; | ||
| 68 | }; | ||
| 69 | |||
| 70 | Q_DECLARE_METATYPE(Network::ChatEntry); | ||
| 71 | Q_DECLARE_METATYPE(Network::StatusMessageEntry); | ||
| 72 | Q_DECLARE_METATYPE(Network::RoomInformation); | ||
| 73 | Q_DECLARE_METATYPE(Network::RoomMember::State); | ||
| 74 | Q_DECLARE_METATYPE(Network::RoomMember::Error); | ||
diff --git a/src/yuzu/multiplayer/chat_room.ui b/src/yuzu/multiplayer/chat_room.ui new file mode 100644 index 000000000..f2b31b5da --- /dev/null +++ b/src/yuzu/multiplayer/chat_room.ui | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>ChatRoom</class> | ||
| 4 | <widget class="QWidget" name="ChatRoom"> | ||
| 5 | <property name="geometry"> | ||
| 6 | <rect> | ||
| 7 | <x>0</x> | ||
| 8 | <y>0</y> | ||
| 9 | <width>807</width> | ||
| 10 | <height>432</height> | ||
| 11 | </rect> | ||
| 12 | </property> | ||
| 13 | <property name="windowTitle"> | ||
| 14 | <string>Room Window</string> | ||
| 15 | </property> | ||
| 16 | <layout class="QHBoxLayout" name="horizontalLayout"> | ||
| 17 | <item> | ||
| 18 | <widget class="QTreeView" name="player_view"/> | ||
| 19 | </item> | ||
| 20 | <item> | ||
| 21 | <layout class="QVBoxLayout" name="verticalLayout_4"> | ||
| 22 | <item> | ||
| 23 | <widget class="QTextEdit" name="chat_history"> | ||
| 24 | <property name="undoRedoEnabled"> | ||
| 25 | <bool>false</bool> | ||
| 26 | </property> | ||
| 27 | <property name="readOnly"> | ||
| 28 | <bool>true</bool> | ||
| 29 | </property> | ||
| 30 | <property name="textInteractionFlags"> | ||
| 31 | <set>Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> | ||
| 32 | </property> | ||
| 33 | </widget> | ||
| 34 | </item> | ||
| 35 | <item> | ||
| 36 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
| 37 | <item> | ||
| 38 | <widget class="QLineEdit" name="chat_message"> | ||
| 39 | <property name="placeholderText"> | ||
| 40 | <string>Send Chat Message</string> | ||
| 41 | </property> | ||
| 42 | </widget> | ||
| 43 | </item> | ||
| 44 | <item> | ||
| 45 | <widget class="QPushButton" name="send_message"> | ||
| 46 | <property name="text"> | ||
| 47 | <string>Send Message</string> | ||
| 48 | </property> | ||
| 49 | </widget> | ||
| 50 | </item> | ||
| 51 | </layout> | ||
| 52 | </item> | ||
| 53 | </layout> | ||
| 54 | </item> | ||
| 55 | </layout> | ||
| 56 | </widget> | ||
| 57 | <resources/> | ||
| 58 | <connections/> | ||
| 59 | </ui> | ||
diff --git a/src/yuzu/multiplayer/client_room.cpp b/src/yuzu/multiplayer/client_room.cpp new file mode 100644 index 000000000..7b2e16e06 --- /dev/null +++ b/src/yuzu/multiplayer/client_room.cpp | |||
| @@ -0,0 +1,115 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <future> | ||
| 6 | #include <QColor> | ||
| 7 | #include <QImage> | ||
| 8 | #include <QList> | ||
| 9 | #include <QLocale> | ||
| 10 | #include <QMetaType> | ||
| 11 | #include <QTime> | ||
| 12 | #include <QtConcurrent/QtConcurrentRun> | ||
| 13 | #include "common/logging/log.h" | ||
| 14 | #include "core/announce_multiplayer_session.h" | ||
| 15 | #include "ui_client_room.h" | ||
| 16 | #include "yuzu/game_list_p.h" | ||
| 17 | #include "yuzu/multiplayer/client_room.h" | ||
| 18 | #include "yuzu/multiplayer/message.h" | ||
| 19 | #include "yuzu/multiplayer/moderation_dialog.h" | ||
| 20 | #include "yuzu/multiplayer/state.h" | ||
| 21 | |||
| 22 | ClientRoomWindow::ClientRoomWindow(QWidget* parent) | ||
| 23 | : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), | ||
| 24 | ui(std::make_unique<Ui::ClientRoom>()) { | ||
| 25 | ui->setupUi(this); | ||
| 26 | |||
| 27 | // setup the callbacks for network updates | ||
| 28 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 29 | member->BindOnRoomInformationChanged( | ||
| 30 | [this](const Network::RoomInformation& info) { emit RoomInformationChanged(info); }); | ||
| 31 | member->BindOnStateChanged( | ||
| 32 | [this](const Network::RoomMember::State& state) { emit StateChanged(state); }); | ||
| 33 | |||
| 34 | connect(this, &ClientRoomWindow::RoomInformationChanged, this, | ||
| 35 | &ClientRoomWindow::OnRoomUpdate); | ||
| 36 | connect(this, &ClientRoomWindow::StateChanged, this, &::ClientRoomWindow::OnStateChange); | ||
| 37 | // Update the state | ||
| 38 | OnStateChange(member->GetState()); | ||
| 39 | } else { | ||
| 40 | // TODO (jroweboy) network was not initialized? | ||
| 41 | } | ||
| 42 | |||
| 43 | connect(ui->disconnect, &QPushButton::clicked, this, &ClientRoomWindow::Disconnect); | ||
| 44 | ui->disconnect->setDefault(false); | ||
| 45 | ui->disconnect->setAutoDefault(false); | ||
| 46 | connect(ui->moderation, &QPushButton::clicked, [this] { | ||
| 47 | ModerationDialog dialog(this); | ||
| 48 | dialog.exec(); | ||
| 49 | }); | ||
| 50 | ui->moderation->setDefault(false); | ||
| 51 | ui->moderation->setAutoDefault(false); | ||
| 52 | connect(ui->chat, &ChatRoom::UserPinged, this, &ClientRoomWindow::ShowNotification); | ||
| 53 | UpdateView(); | ||
| 54 | } | ||
| 55 | |||
| 56 | ClientRoomWindow::~ClientRoomWindow() = default; | ||
| 57 | |||
| 58 | void ClientRoomWindow::SetModPerms(bool is_mod) { | ||
| 59 | ui->chat->SetModPerms(is_mod); | ||
| 60 | ui->moderation->setVisible(is_mod); | ||
| 61 | ui->moderation->setDefault(false); | ||
| 62 | ui->moderation->setAutoDefault(false); | ||
| 63 | } | ||
| 64 | |||
| 65 | void ClientRoomWindow::RetranslateUi() { | ||
| 66 | ui->retranslateUi(this); | ||
| 67 | ui->chat->RetranslateUi(); | ||
| 68 | } | ||
| 69 | |||
| 70 | void ClientRoomWindow::OnRoomUpdate(const Network::RoomInformation& info) { | ||
| 71 | UpdateView(); | ||
| 72 | } | ||
| 73 | |||
| 74 | void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) { | ||
| 75 | if (state == Network::RoomMember::State::Joined || | ||
| 76 | state == Network::RoomMember::State::Moderator) { | ||
| 77 | |||
| 78 | ui->chat->Clear(); | ||
| 79 | ui->chat->AppendStatusMessage(tr("Connected")); | ||
| 80 | SetModPerms(state == Network::RoomMember::State::Moderator); | ||
| 81 | } | ||
| 82 | UpdateView(); | ||
| 83 | } | ||
| 84 | |||
| 85 | void ClientRoomWindow::Disconnect() { | ||
| 86 | auto parent = static_cast<MultiplayerState*>(parentWidget()); | ||
| 87 | if (parent->OnCloseRoom()) { | ||
| 88 | ui->chat->AppendStatusMessage(tr("Disconnected")); | ||
| 89 | close(); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | void ClientRoomWindow::UpdateView() { | ||
| 94 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 95 | if (member->IsConnected()) { | ||
| 96 | ui->chat->Enable(); | ||
| 97 | ui->disconnect->setEnabled(true); | ||
| 98 | auto memberlist = member->GetMemberInformation(); | ||
| 99 | ui->chat->SetPlayerList(memberlist); | ||
| 100 | const auto information = member->GetRoomInformation(); | ||
| 101 | setWindowTitle(QString(tr("%1 (%2/%3 members) - connected")) | ||
| 102 | .arg(QString::fromStdString(information.name)) | ||
| 103 | .arg(memberlist.size()) | ||
| 104 | .arg(information.member_slots)); | ||
| 105 | ui->description->setText(QString::fromStdString(information.description)); | ||
| 106 | return; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | // TODO(B3N30): can't get RoomMember*, show error and close window | ||
| 110 | close(); | ||
| 111 | } | ||
| 112 | |||
| 113 | void ClientRoomWindow::UpdateIconDisplay() { | ||
| 114 | ui->chat->UpdateIconDisplay(); | ||
| 115 | } | ||
diff --git a/src/yuzu/multiplayer/client_room.h b/src/yuzu/multiplayer/client_room.h new file mode 100644 index 000000000..607b4073d --- /dev/null +++ b/src/yuzu/multiplayer/client_room.h | |||
| @@ -0,0 +1,39 @@ | |||
| 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 "yuzu/multiplayer/chat_room.h" | ||
| 8 | |||
| 9 | namespace Ui { | ||
| 10 | class ClientRoom; | ||
| 11 | } | ||
| 12 | |||
| 13 | class ClientRoomWindow : public QDialog { | ||
| 14 | Q_OBJECT | ||
| 15 | |||
| 16 | public: | ||
| 17 | explicit ClientRoomWindow(QWidget* parent); | ||
| 18 | ~ClientRoomWindow(); | ||
| 19 | |||
| 20 | void RetranslateUi(); | ||
| 21 | void UpdateIconDisplay(); | ||
| 22 | |||
| 23 | public slots: | ||
| 24 | void OnRoomUpdate(const Network::RoomInformation&); | ||
| 25 | void OnStateChange(const Network::RoomMember::State&); | ||
| 26 | |||
| 27 | signals: | ||
| 28 | void RoomInformationChanged(const Network::RoomInformation&); | ||
| 29 | void StateChanged(const Network::RoomMember::State&); | ||
| 30 | void ShowNotification(); | ||
| 31 | |||
| 32 | private: | ||
| 33 | void Disconnect(); | ||
| 34 | void UpdateView(); | ||
| 35 | void SetModPerms(bool is_mod); | ||
| 36 | |||
| 37 | QStandardItemModel* player_list; | ||
| 38 | std::unique_ptr<Ui::ClientRoom> ui; | ||
| 39 | }; | ||
diff --git a/src/yuzu/multiplayer/client_room.ui b/src/yuzu/multiplayer/client_room.ui new file mode 100644 index 000000000..97e88b502 --- /dev/null +++ b/src/yuzu/multiplayer/client_room.ui | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>ClientRoom</class> | ||
| 4 | <widget class="QWidget" name="ClientRoom"> | ||
| 5 | <property name="geometry"> | ||
| 6 | <rect> | ||
| 7 | <x>0</x> | ||
| 8 | <y>0</y> | ||
| 9 | <width>807</width> | ||
| 10 | <height>432</height> | ||
| 11 | </rect> | ||
| 12 | </property> | ||
| 13 | <property name="windowTitle"> | ||
| 14 | <string>Room Window</string> | ||
| 15 | </property> | ||
| 16 | <layout class="QVBoxLayout" name="verticalLayout"> | ||
| 17 | <item> | ||
| 18 | <layout class="QVBoxLayout" name="verticalLayout_3"> | ||
| 19 | <item> | ||
| 20 | <layout class="QHBoxLayout" name="horizontalLayout"> | ||
| 21 | <property name="rightMargin"> | ||
| 22 | <number>0</number> | ||
| 23 | </property> | ||
| 24 | <item> | ||
| 25 | <widget class="QLabel" name="description"> | ||
| 26 | <property name="text"> | ||
| 27 | <string>Room Description</string> | ||
| 28 | </property> | ||
| 29 | </widget> | ||
| 30 | </item> | ||
| 31 | <item> | ||
| 32 | <spacer name="horizontalSpacer"> | ||
| 33 | <property name="orientation"> | ||
| 34 | <enum>Qt::Horizontal</enum> | ||
| 35 | </property> | ||
| 36 | <property name="sizeHint" stdset="0"> | ||
| 37 | <size> | ||
| 38 | <width>40</width> | ||
| 39 | <height>20</height> | ||
| 40 | </size> | ||
| 41 | </property> | ||
| 42 | </spacer> | ||
| 43 | </item> | ||
| 44 | <item> | ||
| 45 | <widget class="QPushButton" name="moderation"> | ||
| 46 | <property name="text"> | ||
| 47 | <string>Moderation...</string> | ||
| 48 | </property> | ||
| 49 | <property name="visible"> | ||
| 50 | <bool>false</bool> | ||
| 51 | </property> | ||
| 52 | </widget> | ||
| 53 | </item> | ||
| 54 | <item> | ||
| 55 | <widget class="QPushButton" name="disconnect"> | ||
| 56 | <property name="text"> | ||
| 57 | <string>Leave Room</string> | ||
| 58 | </property> | ||
| 59 | </widget> | ||
| 60 | </item> | ||
| 61 | </layout> | ||
| 62 | </item> | ||
| 63 | <item> | ||
| 64 | <widget class="ChatRoom" name="chat" native="true"/> | ||
| 65 | </item> | ||
| 66 | </layout> | ||
| 67 | </item> | ||
| 68 | </layout> | ||
| 69 | </widget> | ||
| 70 | <customwidgets> | ||
| 71 | <customwidget> | ||
| 72 | <class>ChatRoom</class> | ||
| 73 | <extends>QWidget</extends> | ||
| 74 | <header>multiplayer/chat_room.h</header> | ||
| 75 | <container>1</container> | ||
| 76 | </customwidget> | ||
| 77 | </customwidgets> | ||
| 78 | <resources/> | ||
| 79 | <connections/> | ||
| 80 | </ui> | ||
diff --git a/src/yuzu/multiplayer/direct_connect.cpp b/src/yuzu/multiplayer/direct_connect.cpp new file mode 100644 index 000000000..27741d657 --- /dev/null +++ b/src/yuzu/multiplayer/direct_connect.cpp | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QComboBox> | ||
| 6 | #include <QFuture> | ||
| 7 | #include <QIntValidator> | ||
| 8 | #include <QRegExpValidator> | ||
| 9 | #include <QString> | ||
| 10 | #include <QtConcurrent/QtConcurrentRun> | ||
| 11 | #include "common/settings.h" | ||
| 12 | #include "network/network.h" | ||
| 13 | #include "ui_direct_connect.h" | ||
| 14 | #include "yuzu/main.h" | ||
| 15 | #include "yuzu/multiplayer/client_room.h" | ||
| 16 | #include "yuzu/multiplayer/direct_connect.h" | ||
| 17 | #include "yuzu/multiplayer/message.h" | ||
| 18 | #include "yuzu/multiplayer/state.h" | ||
| 19 | #include "yuzu/multiplayer/validation.h" | ||
| 20 | #include "yuzu/uisettings.h" | ||
| 21 | |||
| 22 | enum class ConnectionType : u8 { TraversalServer, IP }; | ||
| 23 | |||
| 24 | DirectConnectWindow::DirectConnectWindow(QWidget* parent) | ||
| 25 | : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), | ||
| 26 | ui(std::make_unique<Ui::DirectConnect>()) { | ||
| 27 | |||
| 28 | ui->setupUi(this); | ||
| 29 | |||
| 30 | // setup the watcher for background connections | ||
| 31 | watcher = new QFutureWatcher<void>; | ||
| 32 | connect(watcher, &QFutureWatcher<void>::finished, this, &DirectConnectWindow::OnConnection); | ||
| 33 | |||
| 34 | ui->nickname->setValidator(validation.GetNickname()); | ||
| 35 | ui->nickname->setText(UISettings::values.nickname); | ||
| 36 | if (ui->nickname->text().isEmpty() && !Settings::values.yuzu_username.GetValue().empty()) { | ||
| 37 | // Use yuzu Web Service user name as nickname by default | ||
| 38 | ui->nickname->setText(QString::fromStdString(Settings::values.yuzu_username.GetValue())); | ||
| 39 | } | ||
| 40 | ui->ip->setValidator(validation.GetIP()); | ||
| 41 | ui->ip->setText(UISettings::values.ip); | ||
| 42 | ui->port->setValidator(validation.GetPort()); | ||
| 43 | ui->port->setText(UISettings::values.port); | ||
| 44 | |||
| 45 | // TODO(jroweboy): Show or hide the connection options based on the current value of the combo | ||
| 46 | // box. Add this back in when the traversal server support is added. | ||
| 47 | connect(ui->connect, &QPushButton::clicked, this, &DirectConnectWindow::Connect); | ||
| 48 | } | ||
| 49 | |||
| 50 | DirectConnectWindow::~DirectConnectWindow() = default; | ||
| 51 | |||
| 52 | void DirectConnectWindow::RetranslateUi() { | ||
| 53 | ui->retranslateUi(this); | ||
| 54 | } | ||
| 55 | |||
| 56 | void DirectConnectWindow::Connect() { | ||
| 57 | if (!ui->nickname->hasAcceptableInput()) { | ||
| 58 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::USERNAME_NOT_VALID); | ||
| 59 | return; | ||
| 60 | } | ||
| 61 | if (const auto member = Network::GetRoomMember().lock()) { | ||
| 62 | // Prevent the user from trying to join a room while they are already joining. | ||
| 63 | if (member->GetState() == Network::RoomMember::State::Joining) { | ||
| 64 | return; | ||
| 65 | } else if (member->IsConnected()) { | ||
| 66 | // And ask if they want to leave the room if they are already in one. | ||
| 67 | if (!NetworkMessage::WarnDisconnect()) { | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | switch (static_cast<ConnectionType>(ui->connection_type->currentIndex())) { | ||
| 73 | case ConnectionType::TraversalServer: | ||
| 74 | break; | ||
| 75 | case ConnectionType::IP: | ||
| 76 | if (!ui->ip->hasAcceptableInput()) { | ||
| 77 | NetworkMessage::ErrorManager::ShowError( | ||
| 78 | NetworkMessage::ErrorManager::IP_ADDRESS_NOT_VALID); | ||
| 79 | return; | ||
| 80 | } | ||
| 81 | if (!ui->port->hasAcceptableInput()) { | ||
| 82 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::PORT_NOT_VALID); | ||
| 83 | return; | ||
| 84 | } | ||
| 85 | break; | ||
| 86 | } | ||
| 87 | |||
| 88 | // Store settings | ||
| 89 | UISettings::values.nickname = ui->nickname->text(); | ||
| 90 | UISettings::values.ip = ui->ip->text(); | ||
| 91 | UISettings::values.port = (ui->port->isModified() && !ui->port->text().isEmpty()) | ||
| 92 | ? ui->port->text() | ||
| 93 | : UISettings::values.port; | ||
| 94 | |||
| 95 | // attempt to connect in a different thread | ||
| 96 | QFuture<void> f = QtConcurrent::run([&] { | ||
| 97 | if (auto room_member = Network::GetRoomMember().lock()) { | ||
| 98 | auto port = UISettings::values.port.toUInt(); | ||
| 99 | room_member->Join(ui->nickname->text().toStdString(), "", | ||
| 100 | ui->ip->text().toStdString().c_str(), port, 0, | ||
| 101 | Network::NoPreferredMac, ui->password->text().toStdString().c_str()); | ||
| 102 | } | ||
| 103 | }); | ||
| 104 | watcher->setFuture(f); | ||
| 105 | // and disable widgets and display a connecting while we wait | ||
| 106 | BeginConnecting(); | ||
| 107 | } | ||
| 108 | |||
| 109 | void DirectConnectWindow::BeginConnecting() { | ||
| 110 | ui->connect->setEnabled(false); | ||
| 111 | ui->connect->setText(tr("Connecting")); | ||
| 112 | } | ||
| 113 | |||
| 114 | void DirectConnectWindow::EndConnecting() { | ||
| 115 | ui->connect->setEnabled(true); | ||
| 116 | ui->connect->setText(tr("Connect")); | ||
| 117 | } | ||
| 118 | |||
| 119 | void DirectConnectWindow::OnConnection() { | ||
| 120 | EndConnecting(); | ||
| 121 | |||
| 122 | if (auto room_member = Network::GetRoomMember().lock()) { | ||
| 123 | if (room_member->GetState() == Network::RoomMember::State::Joined || | ||
| 124 | room_member->GetState() == Network::RoomMember::State::Moderator) { | ||
| 125 | |||
| 126 | close(); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | } | ||
diff --git a/src/yuzu/multiplayer/direct_connect.h b/src/yuzu/multiplayer/direct_connect.h new file mode 100644 index 000000000..e38961ed0 --- /dev/null +++ b/src/yuzu/multiplayer/direct_connect.h | |||
| @@ -0,0 +1,43 @@ | |||
| 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 <memory> | ||
| 8 | #include <QDialog> | ||
| 9 | #include <QFutureWatcher> | ||
| 10 | #include "yuzu/multiplayer/validation.h" | ||
| 11 | |||
| 12 | namespace Ui { | ||
| 13 | class DirectConnect; | ||
| 14 | } | ||
| 15 | |||
| 16 | class DirectConnectWindow : public QDialog { | ||
| 17 | Q_OBJECT | ||
| 18 | |||
| 19 | public: | ||
| 20 | explicit DirectConnectWindow(QWidget* parent = nullptr); | ||
| 21 | ~DirectConnectWindow(); | ||
| 22 | |||
| 23 | void RetranslateUi(); | ||
| 24 | |||
| 25 | signals: | ||
| 26 | /** | ||
| 27 | * Signalled by this widget when it is closing itself and destroying any state such as | ||
| 28 | * connections that it might have. | ||
| 29 | */ | ||
| 30 | void Closed(); | ||
| 31 | |||
| 32 | private slots: | ||
| 33 | void OnConnection(); | ||
| 34 | |||
| 35 | private: | ||
| 36 | void Connect(); | ||
| 37 | void BeginConnecting(); | ||
| 38 | void EndConnecting(); | ||
| 39 | |||
| 40 | QFutureWatcher<void>* watcher; | ||
| 41 | std::unique_ptr<Ui::DirectConnect> ui; | ||
| 42 | Validation validation; | ||
| 43 | }; | ||
diff --git a/src/yuzu/multiplayer/direct_connect.ui b/src/yuzu/multiplayer/direct_connect.ui new file mode 100644 index 000000000..681b6bf69 --- /dev/null +++ b/src/yuzu/multiplayer/direct_connect.ui | |||
| @@ -0,0 +1,168 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>DirectConnect</class> | ||
| 4 | <widget class="QWidget" name="DirectConnect"> | ||
| 5 | <property name="geometry"> | ||
| 6 | <rect> | ||
| 7 | <x>0</x> | ||
| 8 | <y>0</y> | ||
| 9 | <width>455</width> | ||
| 10 | <height>161</height> | ||
| 11 | </rect> | ||
| 12 | </property> | ||
| 13 | <property name="windowTitle"> | ||
| 14 | <string>Direct Connect</string> | ||
| 15 | </property> | ||
| 16 | <layout class="QVBoxLayout" name="verticalLayout"> | ||
| 17 | <item> | ||
| 18 | <layout class="QVBoxLayout" name="verticalLayout_3"> | ||
| 19 | <item> | ||
| 20 | <layout class="QVBoxLayout" name="verticalLayout_2"> | ||
| 21 | <item> | ||
| 22 | <layout class="QHBoxLayout" name="horizontalLayout"> | ||
| 23 | <property name="spacing"> | ||
| 24 | <number>0</number> | ||
| 25 | </property> | ||
| 26 | <property name="leftMargin"> | ||
| 27 | <number>0</number> | ||
| 28 | </property> | ||
| 29 | <item> | ||
| 30 | <widget class="QComboBox" name="connection_type"> | ||
| 31 | <item> | ||
| 32 | <property name="text"> | ||
| 33 | <string>IP Address</string> | ||
| 34 | </property> | ||
| 35 | </item> | ||
| 36 | </widget> | ||
| 37 | </item> | ||
| 38 | <item> | ||
| 39 | <widget class="QWidget" name="ip_container" native="true"> | ||
| 40 | <layout class="QHBoxLayout" name="ip_layout"> | ||
| 41 | <property name="leftMargin"> | ||
| 42 | <number>5</number> | ||
| 43 | </property> | ||
| 44 | <property name="topMargin"> | ||
| 45 | <number>0</number> | ||
| 46 | </property> | ||
| 47 | <property name="rightMargin"> | ||
| 48 | <number>0</number> | ||
| 49 | </property> | ||
| 50 | <property name="bottomMargin"> | ||
| 51 | <number>0</number> | ||
| 52 | </property> | ||
| 53 | <item> | ||
| 54 | <widget class="QLabel" name="label_2"> | ||
| 55 | <property name="text"> | ||
| 56 | <string>IP</string> | ||
| 57 | </property> | ||
| 58 | </widget> | ||
| 59 | </item> | ||
| 60 | <item> | ||
| 61 | <widget class="QLineEdit" name="ip"> | ||
| 62 | <property name="toolTip"> | ||
| 63 | <string><html><head/><body><p>IPv4 address of the host</p></body></html></string> | ||
| 64 | </property> | ||
| 65 | <property name="maxLength"> | ||
| 66 | <number>16</number> | ||
| 67 | </property> | ||
| 68 | </widget> | ||
| 69 | </item> | ||
| 70 | <item> | ||
| 71 | <widget class="QLabel" name="label_3"> | ||
| 72 | <property name="text"> | ||
| 73 | <string>Port</string> | ||
| 74 | </property> | ||
| 75 | </widget> | ||
| 76 | </item> | ||
| 77 | <item> | ||
| 78 | <widget class="QLineEdit" name="port"> | ||
| 79 | <property name="toolTip"> | ||
| 80 | <string><html><head/><body><p>Port number the host is listening on</p></body></html></string> | ||
| 81 | </property> | ||
| 82 | <property name="maxLength"> | ||
| 83 | <number>5</number> | ||
| 84 | </property> | ||
| 85 | <property name="placeholderText"> | ||
| 86 | <string>24872</string> | ||
| 87 | </property> | ||
| 88 | </widget> | ||
| 89 | </item> | ||
| 90 | </layout> | ||
| 91 | </widget> | ||
| 92 | </item> | ||
| 93 | </layout> | ||
| 94 | </item> | ||
| 95 | <item> | ||
| 96 | <layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
| 97 | <item> | ||
| 98 | <widget class="QLabel" name="label_5"> | ||
| 99 | <property name="text"> | ||
| 100 | <string>Nickname</string> | ||
| 101 | </property> | ||
| 102 | </widget> | ||
| 103 | </item> | ||
| 104 | <item> | ||
| 105 | <widget class="QLineEdit" name="nickname"> | ||
| 106 | <property name="maxLength"> | ||
| 107 | <number>20</number> | ||
| 108 | </property> | ||
| 109 | </widget> | ||
| 110 | </item> | ||
| 111 | <item> | ||
| 112 | <widget class="QLabel" name="label"> | ||
| 113 | <property name="text"> | ||
| 114 | <string>Password</string> | ||
| 115 | </property> | ||
| 116 | </widget> | ||
| 117 | </item> | ||
| 118 | <item> | ||
| 119 | <widget class="QLineEdit" name="password"/> | ||
| 120 | </item> | ||
| 121 | </layout> | ||
| 122 | </item> | ||
| 123 | </layout> | ||
| 124 | </item> | ||
| 125 | <item> | ||
| 126 | <spacer name="verticalSpacer"> | ||
| 127 | <property name="orientation"> | ||
| 128 | <enum>Qt::Vertical</enum> | ||
| 129 | </property> | ||
| 130 | <property name="sizeHint" stdset="0"> | ||
| 131 | <size> | ||
| 132 | <width>20</width> | ||
| 133 | <height>20</height> | ||
| 134 | </size> | ||
| 135 | </property> | ||
| 136 | </spacer> | ||
| 137 | </item> | ||
| 138 | <item> | ||
| 139 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
| 140 | <item> | ||
| 141 | <spacer name="horizontalSpacer"> | ||
| 142 | <property name="orientation"> | ||
| 143 | <enum>Qt::Horizontal</enum> | ||
| 144 | </property> | ||
| 145 | <property name="sizeHint" stdset="0"> | ||
| 146 | <size> | ||
| 147 | <width>40</width> | ||
| 148 | <height>20</height> | ||
| 149 | </size> | ||
| 150 | </property> | ||
| 151 | </spacer> | ||
| 152 | </item> | ||
| 153 | <item> | ||
| 154 | <widget class="QPushButton" name="connect"> | ||
| 155 | <property name="text"> | ||
| 156 | <string>Connect</string> | ||
| 157 | </property> | ||
| 158 | </widget> | ||
| 159 | </item> | ||
| 160 | </layout> | ||
| 161 | </item> | ||
| 162 | </layout> | ||
| 163 | </item> | ||
| 164 | </layout> | ||
| 165 | </widget> | ||
| 166 | <resources/> | ||
| 167 | <connections/> | ||
| 168 | </ui> | ||
diff --git a/src/yuzu/multiplayer/host_room.cpp b/src/yuzu/multiplayer/host_room.cpp new file mode 100644 index 000000000..1b73e2bec --- /dev/null +++ b/src/yuzu/multiplayer/host_room.cpp | |||
| @@ -0,0 +1,237 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <future> | ||
| 6 | #include <QColor> | ||
| 7 | #include <QImage> | ||
| 8 | #include <QList> | ||
| 9 | #include <QLocale> | ||
| 10 | #include <QMessageBox> | ||
| 11 | #include <QMetaType> | ||
| 12 | #include <QTime> | ||
| 13 | #include <QtConcurrent/QtConcurrentRun> | ||
| 14 | #include "common/logging/log.h" | ||
| 15 | #include "common/settings.h" | ||
| 16 | #include "core/announce_multiplayer_session.h" | ||
| 17 | #include "ui_host_room.h" | ||
| 18 | #include "yuzu/game_list_p.h" | ||
| 19 | #include "yuzu/main.h" | ||
| 20 | #include "yuzu/multiplayer/host_room.h" | ||
| 21 | #include "yuzu/multiplayer/message.h" | ||
| 22 | #include "yuzu/multiplayer/state.h" | ||
| 23 | #include "yuzu/multiplayer/validation.h" | ||
| 24 | #include "yuzu/uisettings.h" | ||
| 25 | #ifdef ENABLE_WEB_SERVICE | ||
| 26 | #include "web_service/verify_user_jwt.h" | ||
| 27 | #endif | ||
| 28 | |||
| 29 | HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list, | ||
| 30 | std::shared_ptr<Core::AnnounceMultiplayerSession> session) | ||
| 31 | : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), | ||
| 32 | ui(std::make_unique<Ui::HostRoom>()), announce_multiplayer_session(session) { | ||
| 33 | ui->setupUi(this); | ||
| 34 | |||
| 35 | // set up validation for all of the fields | ||
| 36 | ui->room_name->setValidator(validation.GetRoomName()); | ||
| 37 | ui->username->setValidator(validation.GetNickname()); | ||
| 38 | ui->port->setValidator(validation.GetPort()); | ||
| 39 | ui->port->setPlaceholderText(QString::number(Network::DefaultRoomPort)); | ||
| 40 | |||
| 41 | // Create a proxy to the game list to display the list of preferred games | ||
| 42 | game_list = new QStandardItemModel; | ||
| 43 | UpdateGameList(list); | ||
| 44 | |||
| 45 | proxy = new ComboBoxProxyModel; | ||
| 46 | proxy->setSourceModel(game_list); | ||
| 47 | proxy->sort(0, Qt::AscendingOrder); | ||
| 48 | ui->game_list->setModel(proxy); | ||
| 49 | |||
| 50 | // Connect all the widgets to the appropriate events | ||
| 51 | connect(ui->host, &QPushButton::clicked, this, &HostRoomWindow::Host); | ||
| 52 | |||
| 53 | // Restore the settings: | ||
| 54 | ui->username->setText(UISettings::values.room_nickname); | ||
| 55 | if (ui->username->text().isEmpty() && !Settings::values.yuzu_username.GetValue().empty()) { | ||
| 56 | // Use yuzu Web Service user name as nickname by default | ||
| 57 | ui->username->setText(QString::fromStdString(Settings::values.yuzu_username.GetValue())); | ||
| 58 | } | ||
| 59 | ui->room_name->setText(UISettings::values.room_name); | ||
| 60 | ui->port->setText(UISettings::values.room_port); | ||
| 61 | ui->max_player->setValue(UISettings::values.max_player); | ||
| 62 | int index = UISettings::values.host_type; | ||
| 63 | if (index < ui->host_type->count()) { | ||
| 64 | ui->host_type->setCurrentIndex(index); | ||
| 65 | } | ||
| 66 | index = ui->game_list->findData(UISettings::values.game_id, GameListItemPath::ProgramIdRole); | ||
| 67 | if (index != -1) { | ||
| 68 | ui->game_list->setCurrentIndex(index); | ||
| 69 | } | ||
| 70 | ui->room_description->setText(UISettings::values.room_description); | ||
| 71 | } | ||
| 72 | |||
| 73 | HostRoomWindow::~HostRoomWindow() = default; | ||
| 74 | |||
| 75 | void HostRoomWindow::UpdateGameList(QStandardItemModel* list) { | ||
| 76 | game_list->clear(); | ||
| 77 | for (int i = 0; i < list->rowCount(); i++) { | ||
| 78 | auto parent = list->item(i, 0); | ||
| 79 | for (int j = 0; j < parent->rowCount(); j++) { | ||
| 80 | game_list->appendRow(parent->child(j)->clone()); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | void HostRoomWindow::RetranslateUi() { | ||
| 86 | ui->retranslateUi(this); | ||
| 87 | } | ||
| 88 | |||
| 89 | std::unique_ptr<Network::VerifyUser::Backend> HostRoomWindow::CreateVerifyBackend( | ||
| 90 | bool use_validation) const { | ||
| 91 | std::unique_ptr<Network::VerifyUser::Backend> verify_backend; | ||
| 92 | if (use_validation) { | ||
| 93 | #ifdef ENABLE_WEB_SERVICE | ||
| 94 | verify_backend = std::make_unique<WebService::VerifyUserJWT>(Settings::values.web_api_url); | ||
| 95 | #else | ||
| 96 | verify_backend = std::make_unique<Network::VerifyUser::NullBackend>(); | ||
| 97 | #endif | ||
| 98 | } else { | ||
| 99 | verify_backend = std::make_unique<Network::VerifyUser::NullBackend>(); | ||
| 100 | } | ||
| 101 | return verify_backend; | ||
| 102 | } | ||
| 103 | |||
| 104 | void HostRoomWindow::Host() { | ||
| 105 | if (!ui->username->hasAcceptableInput()) { | ||
| 106 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::USERNAME_NOT_VALID); | ||
| 107 | return; | ||
| 108 | } | ||
| 109 | if (!ui->room_name->hasAcceptableInput()) { | ||
| 110 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::ROOMNAME_NOT_VALID); | ||
| 111 | return; | ||
| 112 | } | ||
| 113 | if (!ui->port->hasAcceptableInput()) { | ||
| 114 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::PORT_NOT_VALID); | ||
| 115 | return; | ||
| 116 | } | ||
| 117 | if (ui->game_list->currentIndex() == -1) { | ||
| 118 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::GAME_NOT_SELECTED); | ||
| 119 | return; | ||
| 120 | } | ||
| 121 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 122 | if (member->GetState() == Network::RoomMember::State::Joining) { | ||
| 123 | return; | ||
| 124 | } else if (member->IsConnected()) { | ||
| 125 | auto parent = static_cast<MultiplayerState*>(parentWidget()); | ||
| 126 | if (!parent->OnCloseRoom()) { | ||
| 127 | close(); | ||
| 128 | return; | ||
| 129 | } | ||
| 130 | } | ||
| 131 | ui->host->setDisabled(true); | ||
| 132 | |||
| 133 | auto game_name = ui->game_list->currentData(Qt::DisplayRole).toString(); | ||
| 134 | auto game_id = ui->game_list->currentData(GameListItemPath::ProgramIdRole).toLongLong(); | ||
| 135 | auto port = ui->port->isModified() ? ui->port->text().toInt() : Network::DefaultRoomPort; | ||
| 136 | auto password = ui->password->text().toStdString(); | ||
| 137 | const bool is_public = ui->host_type->currentIndex() == 0; | ||
| 138 | Network::Room::BanList ban_list{}; | ||
| 139 | if (ui->load_ban_list->isChecked()) { | ||
| 140 | ban_list = UISettings::values.ban_list; | ||
| 141 | } | ||
| 142 | if (auto room = Network::GetRoom().lock()) { | ||
| 143 | bool created = room->Create( | ||
| 144 | ui->room_name->text().toStdString(), | ||
| 145 | ui->room_description->toPlainText().toStdString(), "", port, password, | ||
| 146 | ui->max_player->value(), Settings::values.yuzu_username.GetValue(), | ||
| 147 | game_name.toStdString(), game_id, CreateVerifyBackend(is_public), ban_list); | ||
| 148 | if (!created) { | ||
| 149 | NetworkMessage::ErrorManager::ShowError( | ||
| 150 | NetworkMessage::ErrorManager::COULD_NOT_CREATE_ROOM); | ||
| 151 | LOG_ERROR(Network, "Could not create room!"); | ||
| 152 | ui->host->setEnabled(true); | ||
| 153 | return; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | // Start the announce session if they chose Public | ||
| 157 | if (is_public) { | ||
| 158 | if (auto session = announce_multiplayer_session.lock()) { | ||
| 159 | // Register the room first to ensure verify_UID is present when we connect | ||
| 160 | WebService::WebResult result = session->Register(); | ||
| 161 | if (result.result_code != WebService::WebResult::Code::Success) { | ||
| 162 | QMessageBox::warning( | ||
| 163 | this, tr("Error"), | ||
| 164 | tr("Failed to announce the room to the public lobby. In order to host a " | ||
| 165 | "room publicly, you must have a valid yuzu account configured in " | ||
| 166 | "Emulation -> Configure -> Web. If you do not want to publish a room in " | ||
| 167 | "the public lobby, then select Unlisted instead.\nDebug Message: ") + | ||
| 168 | QString::fromStdString(result.result_string), | ||
| 169 | QMessageBox::Ok); | ||
| 170 | ui->host->setEnabled(true); | ||
| 171 | if (auto room = Network::GetRoom().lock()) { | ||
| 172 | room->Destroy(); | ||
| 173 | } | ||
| 174 | return; | ||
| 175 | } | ||
| 176 | session->Start(); | ||
| 177 | } else { | ||
| 178 | LOG_ERROR(Network, "Starting announce session failed"); | ||
| 179 | } | ||
| 180 | } | ||
| 181 | std::string token; | ||
| 182 | #ifdef ENABLE_WEB_SERVICE | ||
| 183 | if (is_public) { | ||
| 184 | WebService::Client client(Settings::values.web_api_url, Settings::values.yuzu_username, | ||
| 185 | Settings::values.yuzu_token); | ||
| 186 | if (auto room = Network::GetRoom().lock()) { | ||
| 187 | token = client.GetExternalJWT(room->GetVerifyUID()).returned_data; | ||
| 188 | } | ||
| 189 | if (token.empty()) { | ||
| 190 | LOG_ERROR(WebService, "Could not get external JWT, verification may fail"); | ||
| 191 | } else { | ||
| 192 | LOG_INFO(WebService, "Successfully requested external JWT: size={}", token.size()); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | #endif | ||
| 196 | // TODO: Check what to do with this | ||
| 197 | member->Join(ui->username->text().toStdString(), "", "127.0.0.1", port, 0, | ||
| 198 | Network::NoPreferredMac, password, token); | ||
| 199 | |||
| 200 | // Store settings | ||
| 201 | UISettings::values.room_nickname = ui->username->text(); | ||
| 202 | UISettings::values.room_name = ui->room_name->text(); | ||
| 203 | UISettings::values.game_id = | ||
| 204 | ui->game_list->currentData(GameListItemPath::ProgramIdRole).toLongLong(); | ||
| 205 | UISettings::values.max_player = ui->max_player->value(); | ||
| 206 | |||
| 207 | UISettings::values.host_type = ui->host_type->currentIndex(); | ||
| 208 | UISettings::values.room_port = (ui->port->isModified() && !ui->port->text().isEmpty()) | ||
| 209 | ? ui->port->text() | ||
| 210 | : QString::number(Network::DefaultRoomPort); | ||
| 211 | UISettings::values.room_description = ui->room_description->toPlainText(); | ||
| 212 | ui->host->setEnabled(true); | ||
| 213 | close(); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | |||
| 217 | QVariant ComboBoxProxyModel::data(const QModelIndex& idx, int role) const { | ||
| 218 | if (role != Qt::DisplayRole) { | ||
| 219 | auto val = QSortFilterProxyModel::data(idx, role); | ||
| 220 | // If its the icon, shrink it to 16x16 | ||
| 221 | if (role == Qt::DecorationRole) | ||
| 222 | val = val.value<QImage>().scaled(16, 16, Qt::KeepAspectRatio); | ||
| 223 | return val; | ||
| 224 | } | ||
| 225 | std::string filename; | ||
| 226 | Common::SplitPath( | ||
| 227 | QSortFilterProxyModel::data(idx, GameListItemPath::FullPathRole).toString().toStdString(), | ||
| 228 | nullptr, &filename, nullptr); | ||
| 229 | QString title = QSortFilterProxyModel::data(idx, GameListItemPath::TitleRole).toString(); | ||
| 230 | return title.isEmpty() ? QString::fromStdString(filename) : title; | ||
| 231 | } | ||
| 232 | |||
| 233 | bool ComboBoxProxyModel::lessThan(const QModelIndex& left, const QModelIndex& right) const { | ||
| 234 | auto leftData = left.data(GameListItemPath::TitleRole).toString(); | ||
| 235 | auto rightData = right.data(GameListItemPath::TitleRole).toString(); | ||
| 236 | return leftData.compare(rightData) < 0; | ||
| 237 | } | ||
diff --git a/src/yuzu/multiplayer/host_room.h b/src/yuzu/multiplayer/host_room.h new file mode 100644 index 000000000..d84f93ffd --- /dev/null +++ b/src/yuzu/multiplayer/host_room.h | |||
| @@ -0,0 +1,74 @@ | |||
| 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 <memory> | ||
| 8 | #include <QDialog> | ||
| 9 | #include <QSortFilterProxyModel> | ||
| 10 | #include <QStandardItemModel> | ||
| 11 | #include <QVariant> | ||
| 12 | #include "network/network.h" | ||
| 13 | #include "yuzu/multiplayer/chat_room.h" | ||
| 14 | #include "yuzu/multiplayer/validation.h" | ||
| 15 | |||
| 16 | namespace Ui { | ||
| 17 | class HostRoom; | ||
| 18 | } | ||
| 19 | |||
| 20 | namespace Core { | ||
| 21 | class AnnounceMultiplayerSession; | ||
| 22 | } | ||
| 23 | |||
| 24 | class ConnectionError; | ||
| 25 | class ComboBoxProxyModel; | ||
| 26 | |||
| 27 | class ChatMessage; | ||
| 28 | |||
| 29 | namespace Network::VerifyUser { | ||
| 30 | class Backend; | ||
| 31 | }; | ||
| 32 | |||
| 33 | class HostRoomWindow : public QDialog { | ||
| 34 | Q_OBJECT | ||
| 35 | |||
| 36 | public: | ||
| 37 | explicit HostRoomWindow(QWidget* parent, QStandardItemModel* list, | ||
| 38 | std::shared_ptr<Core::AnnounceMultiplayerSession> session); | ||
| 39 | ~HostRoomWindow(); | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Updates the dialog with a new game list model. | ||
| 43 | * This model should be the original model of the game list. | ||
| 44 | */ | ||
| 45 | void UpdateGameList(QStandardItemModel* list); | ||
| 46 | void RetranslateUi(); | ||
| 47 | |||
| 48 | private: | ||
| 49 | void Host(); | ||
| 50 | std::unique_ptr<Network::VerifyUser::Backend> CreateVerifyBackend(bool use_validation) const; | ||
| 51 | |||
| 52 | std::unique_ptr<Ui::HostRoom> ui; | ||
| 53 | std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; | ||
| 54 | QStandardItemModel* game_list; | ||
| 55 | ComboBoxProxyModel* proxy; | ||
| 56 | Validation validation; | ||
| 57 | }; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Proxy Model for the game list combo box so we can reuse the game list model while still | ||
| 61 | * displaying the fields slightly differently | ||
| 62 | */ | ||
| 63 | class ComboBoxProxyModel : public QSortFilterProxyModel { | ||
| 64 | Q_OBJECT | ||
| 65 | |||
| 66 | public: | ||
| 67 | int columnCount(const QModelIndex& idx) const override { | ||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | |||
| 71 | QVariant data(const QModelIndex& idx, int role) const override; | ||
| 72 | |||
| 73 | bool lessThan(const QModelIndex& left, const QModelIndex& right) const override; | ||
| 74 | }; | ||
diff --git a/src/yuzu/multiplayer/host_room.ui b/src/yuzu/multiplayer/host_room.ui new file mode 100644 index 000000000..d54cf49c6 --- /dev/null +++ b/src/yuzu/multiplayer/host_room.ui | |||
| @@ -0,0 +1,207 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>HostRoom</class> | ||
| 4 | <widget class="QWidget" name="HostRoom"> | ||
| 5 | <property name="geometry"> | ||
| 6 | <rect> | ||
| 7 | <x>0</x> | ||
| 8 | <y>0</y> | ||
| 9 | <width>607</width> | ||
| 10 | <height>211</height> | ||
| 11 | </rect> | ||
| 12 | </property> | ||
| 13 | <property name="windowTitle"> | ||
| 14 | <string>Create Room</string> | ||
| 15 | </property> | ||
| 16 | <layout class="QVBoxLayout" name="verticalLayout_3"> | ||
| 17 | <item> | ||
| 18 | <widget class="QWidget" name="settings" native="true"> | ||
| 19 | <layout class="QHBoxLayout"> | ||
| 20 | <property name="leftMargin"> | ||
| 21 | <number>0</number> | ||
| 22 | </property> | ||
| 23 | <property name="topMargin"> | ||
| 24 | <number>0</number> | ||
| 25 | </property> | ||
| 26 | <property name="rightMargin"> | ||
| 27 | <number>0</number> | ||
| 28 | </property> | ||
| 29 | <item> | ||
| 30 | <layout class="QFormLayout" name="formLayout_2"> | ||
| 31 | <property name="labelAlignment"> | ||
| 32 | <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | ||
| 33 | </property> | ||
| 34 | <item row="0" column="0"> | ||
| 35 | <widget class="QLabel" name="label"> | ||
| 36 | <property name="text"> | ||
| 37 | <string>Room Name</string> | ||
| 38 | </property> | ||
| 39 | </widget> | ||
| 40 | </item> | ||
| 41 | <item row="0" column="1"> | ||
| 42 | <widget class="QLineEdit" name="room_name"> | ||
| 43 | <property name="maxLength"> | ||
| 44 | <number>50</number> | ||
| 45 | </property> | ||
| 46 | </widget> | ||
| 47 | </item> | ||
| 48 | <item row="1" column="0"> | ||
| 49 | <widget class="QLabel" name="label_3"> | ||
| 50 | <property name="text"> | ||
| 51 | <string>Preferred Game</string> | ||
| 52 | </property> | ||
| 53 | </widget> | ||
| 54 | </item> | ||
| 55 | <item row="1" column="1"> | ||
| 56 | <widget class="QComboBox" name="game_list"/> | ||
| 57 | </item> | ||
| 58 | <item row="2" column="0"> | ||
| 59 | <widget class="QLabel" name="label_2"> | ||
| 60 | <property name="text"> | ||
| 61 | <string>Max Players</string> | ||
| 62 | </property> | ||
| 63 | </widget> | ||
| 64 | </item> | ||
| 65 | <item row="2" column="1"> | ||
| 66 | <widget class="QSpinBox" name="max_player"> | ||
| 67 | <property name="minimum"> | ||
| 68 | <number>2</number> | ||
| 69 | </property> | ||
| 70 | <property name="maximum"> | ||
| 71 | <number>16</number> | ||
| 72 | </property> | ||
| 73 | <property name="value"> | ||
| 74 | <number>8</number> | ||
| 75 | </property> | ||
| 76 | </widget> | ||
| 77 | </item> | ||
| 78 | </layout> | ||
| 79 | </item> | ||
| 80 | <item> | ||
| 81 | <layout class="QFormLayout" name="formLayout"> | ||
| 82 | <property name="labelAlignment"> | ||
| 83 | <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> | ||
| 84 | </property> | ||
| 85 | <item row="0" column="1"> | ||
| 86 | <widget class="QLineEdit" name="username"/> | ||
| 87 | </item> | ||
| 88 | <item row="0" column="0"> | ||
| 89 | <widget class="QLabel" name="label_6"> | ||
| 90 | <property name="text"> | ||
| 91 | <string>Username</string> | ||
| 92 | </property> | ||
| 93 | </widget> | ||
| 94 | </item> | ||
| 95 | <item row="1" column="1"> | ||
| 96 | <widget class="QLineEdit" name="password"> | ||
| 97 | <property name="echoMode"> | ||
| 98 | <enum>QLineEdit::PasswordEchoOnEdit</enum> | ||
| 99 | </property> | ||
| 100 | <property name="placeholderText"> | ||
| 101 | <string>(Leave blank for open game)</string> | ||
| 102 | </property> | ||
| 103 | </widget> | ||
| 104 | </item> | ||
| 105 | <item row="2" column="1"> | ||
| 106 | <widget class="QLineEdit" name="port"> | ||
| 107 | <property name="inputMethodHints"> | ||
| 108 | <set>Qt::ImhDigitsOnly</set> | ||
| 109 | </property> | ||
| 110 | <property name="maxLength"> | ||
| 111 | <number>5</number> | ||
| 112 | </property> | ||
| 113 | </widget> | ||
| 114 | </item> | ||
| 115 | <item row="1" column="0"> | ||
| 116 | <widget class="QLabel" name="label_5"> | ||
| 117 | <property name="text"> | ||
| 118 | <string>Password</string> | ||
| 119 | </property> | ||
| 120 | </widget> | ||
| 121 | </item> | ||
| 122 | <item row="2" column="0"> | ||
| 123 | <widget class="QLabel" name="label_4"> | ||
| 124 | <property name="text"> | ||
| 125 | <string>Port</string> | ||
| 126 | </property> | ||
| 127 | </widget> | ||
| 128 | </item> | ||
| 129 | </layout> | ||
| 130 | </item> | ||
| 131 | </layout> | ||
| 132 | </widget> | ||
| 133 | </item> | ||
| 134 | <item> | ||
| 135 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
| 136 | <item> | ||
| 137 | <widget class="QLabel" name="label_7"> | ||
| 138 | <property name="text"> | ||
| 139 | <string>Room Description</string> | ||
| 140 | </property> | ||
| 141 | </widget> | ||
| 142 | </item> | ||
| 143 | <item> | ||
| 144 | <widget class="QTextEdit" name="room_description"/> | ||
| 145 | </item> | ||
| 146 | </layout> | ||
| 147 | </item> | ||
| 148 | <item> | ||
| 149 | <layout class="QHBoxLayout"> | ||
| 150 | <item> | ||
| 151 | <widget class="QCheckBox" name="load_ban_list"> | ||
| 152 | <property name="text"> | ||
| 153 | <string>Load Previous Ban List</string> | ||
| 154 | </property> | ||
| 155 | <property name="checked"> | ||
| 156 | <bool>true</bool> | ||
| 157 | </property> | ||
| 158 | </widget> | ||
| 159 | </item> | ||
| 160 | </layout> | ||
| 161 | </item> | ||
| 162 | <item> | ||
| 163 | <layout class="QHBoxLayout" name="horizontalLayout"> | ||
| 164 | <property name="rightMargin"> | ||
| 165 | <number>0</number> | ||
| 166 | </property> | ||
| 167 | <item> | ||
| 168 | <spacer name="horizontalSpacer"> | ||
| 169 | <property name="orientation"> | ||
| 170 | <enum>Qt::Horizontal</enum> | ||
| 171 | </property> | ||
| 172 | <property name="sizeHint" stdset="0"> | ||
| 173 | <size> | ||
| 174 | <width>40</width> | ||
| 175 | <height>20</height> | ||
| 176 | </size> | ||
| 177 | </property> | ||
| 178 | </spacer> | ||
| 179 | </item> | ||
| 180 | <item> | ||
| 181 | <widget class="QComboBox" name="host_type"> | ||
| 182 | <item> | ||
| 183 | <property name="text"> | ||
| 184 | <string>Public</string> | ||
| 185 | </property> | ||
| 186 | </item> | ||
| 187 | <item> | ||
| 188 | <property name="text"> | ||
| 189 | <string>Unlisted</string> | ||
| 190 | </property> | ||
| 191 | </item> | ||
| 192 | </widget> | ||
| 193 | </item> | ||
| 194 | <item> | ||
| 195 | <widget class="QPushButton" name="host"> | ||
| 196 | <property name="text"> | ||
| 197 | <string>Host Room</string> | ||
| 198 | </property> | ||
| 199 | </widget> | ||
| 200 | </item> | ||
| 201 | </layout> | ||
| 202 | </item> | ||
| 203 | </layout> | ||
| 204 | </widget> | ||
| 205 | <resources/> | ||
| 206 | <connections/> | ||
| 207 | </ui> | ||
diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp new file mode 100644 index 000000000..fcaa7b517 --- /dev/null +++ b/src/yuzu/multiplayer/lobby.cpp | |||
| @@ -0,0 +1,360 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QInputDialog> | ||
| 6 | #include <QList> | ||
| 7 | #include <QtConcurrent/QtConcurrentRun> | ||
| 8 | #include "common/logging/log.h" | ||
| 9 | #include "common/settings.h" | ||
| 10 | #include "network/network.h" | ||
| 11 | #include "ui_lobby.h" | ||
| 12 | #include "yuzu/game_list_p.h" | ||
| 13 | #include "yuzu/main.h" | ||
| 14 | #include "yuzu/multiplayer/client_room.h" | ||
| 15 | #include "yuzu/multiplayer/lobby.h" | ||
| 16 | #include "yuzu/multiplayer/lobby_p.h" | ||
| 17 | #include "yuzu/multiplayer/message.h" | ||
| 18 | #include "yuzu/multiplayer/state.h" | ||
| 19 | #include "yuzu/multiplayer/validation.h" | ||
| 20 | #include "yuzu/uisettings.h" | ||
| 21 | #ifdef ENABLE_WEB_SERVICE | ||
| 22 | #include "web_service/web_backend.h" | ||
| 23 | #endif | ||
| 24 | |||
| 25 | Lobby::Lobby(QWidget* parent, QStandardItemModel* list, | ||
| 26 | std::shared_ptr<Core::AnnounceMultiplayerSession> session) | ||
| 27 | : QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), | ||
| 28 | ui(std::make_unique<Ui::Lobby>()), announce_multiplayer_session(session) { | ||
| 29 | ui->setupUi(this); | ||
| 30 | |||
| 31 | // setup the watcher for background connections | ||
| 32 | watcher = new QFutureWatcher<void>; | ||
| 33 | |||
| 34 | model = new QStandardItemModel(ui->room_list); | ||
| 35 | |||
| 36 | // Create a proxy to the game list to get the list of games owned | ||
| 37 | game_list = new QStandardItemModel; | ||
| 38 | UpdateGameList(list); | ||
| 39 | |||
| 40 | proxy = new LobbyFilterProxyModel(this, game_list); | ||
| 41 | proxy->setSourceModel(model); | ||
| 42 | proxy->setDynamicSortFilter(true); | ||
| 43 | proxy->setFilterCaseSensitivity(Qt::CaseInsensitive); | ||
| 44 | proxy->setSortLocaleAware(true); | ||
| 45 | ui->room_list->setModel(proxy); | ||
| 46 | ui->room_list->header()->setSectionResizeMode(QHeaderView::Interactive); | ||
| 47 | ui->room_list->header()->stretchLastSection(); | ||
| 48 | ui->room_list->setAlternatingRowColors(true); | ||
| 49 | ui->room_list->setSelectionMode(QHeaderView::SingleSelection); | ||
| 50 | ui->room_list->setSelectionBehavior(QHeaderView::SelectRows); | ||
| 51 | ui->room_list->setVerticalScrollMode(QHeaderView::ScrollPerPixel); | ||
| 52 | ui->room_list->setHorizontalScrollMode(QHeaderView::ScrollPerPixel); | ||
| 53 | ui->room_list->setSortingEnabled(true); | ||
| 54 | ui->room_list->setEditTriggers(QHeaderView::NoEditTriggers); | ||
| 55 | ui->room_list->setExpandsOnDoubleClick(false); | ||
| 56 | ui->room_list->setContextMenuPolicy(Qt::CustomContextMenu); | ||
| 57 | |||
| 58 | ui->nickname->setValidator(validation.GetNickname()); | ||
| 59 | ui->nickname->setText(UISettings::values.nickname); | ||
| 60 | if (ui->nickname->text().isEmpty() && !Settings::values.yuzu_username.GetValue().empty()) { | ||
| 61 | // Use yuzu Web Service user name as nickname by default | ||
| 62 | ui->nickname->setText(QString::fromStdString(Settings::values.yuzu_username.GetValue())); | ||
| 63 | } | ||
| 64 | |||
| 65 | // UI Buttons | ||
| 66 | connect(ui->refresh_list, &QPushButton::clicked, this, &Lobby::RefreshLobby); | ||
| 67 | connect(ui->games_owned, &QCheckBox::toggled, proxy, &LobbyFilterProxyModel::SetFilterOwned); | ||
| 68 | connect(ui->hide_full, &QCheckBox::toggled, proxy, &LobbyFilterProxyModel::SetFilterFull); | ||
| 69 | connect(ui->search, &QLineEdit::textChanged, proxy, &LobbyFilterProxyModel::SetFilterSearch); | ||
| 70 | connect(ui->room_list, &QTreeView::doubleClicked, this, &Lobby::OnJoinRoom); | ||
| 71 | connect(ui->room_list, &QTreeView::clicked, this, &Lobby::OnExpandRoom); | ||
| 72 | |||
| 73 | // Actions | ||
| 74 | connect(&room_list_watcher, &QFutureWatcher<AnnounceMultiplayerRoom::RoomList>::finished, this, | ||
| 75 | &Lobby::OnRefreshLobby); | ||
| 76 | |||
| 77 | // manually start a refresh when the window is opening | ||
| 78 | // TODO(jroweboy): if this refresh is slow for people with bad internet, then don't do it as | ||
| 79 | // part of the constructor, but offload the refresh until after the window shown. perhaps emit a | ||
| 80 | // refreshroomlist signal from places that open the lobby | ||
| 81 | RefreshLobby(); | ||
| 82 | } | ||
| 83 | |||
| 84 | Lobby::~Lobby() = default; | ||
| 85 | |||
| 86 | void Lobby::UpdateGameList(QStandardItemModel* list) { | ||
| 87 | game_list->clear(); | ||
| 88 | for (int i = 0; i < list->rowCount(); i++) { | ||
| 89 | auto parent = list->item(i, 0); | ||
| 90 | for (int j = 0; j < parent->rowCount(); j++) { | ||
| 91 | game_list->appendRow(parent->child(j)->clone()); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | if (proxy) | ||
| 95 | proxy->UpdateGameList(game_list); | ||
| 96 | } | ||
| 97 | |||
| 98 | void Lobby::RetranslateUi() { | ||
| 99 | ui->retranslateUi(this); | ||
| 100 | } | ||
| 101 | |||
| 102 | QString Lobby::PasswordPrompt() { | ||
| 103 | bool ok; | ||
| 104 | const QString text = | ||
| 105 | QInputDialog::getText(this, tr("Password Required to Join"), tr("Password:"), | ||
| 106 | QLineEdit::Password, QString(), &ok); | ||
| 107 | return ok ? text : QString(); | ||
| 108 | } | ||
| 109 | |||
| 110 | void Lobby::OnExpandRoom(const QModelIndex& index) { | ||
| 111 | QModelIndex member_index = proxy->index(index.row(), Column::MEMBER); | ||
| 112 | auto member_list = proxy->data(member_index, LobbyItemMemberList::MemberListRole).toList(); | ||
| 113 | } | ||
| 114 | |||
| 115 | void Lobby::OnJoinRoom(const QModelIndex& source) { | ||
| 116 | if (const auto member = Network::GetRoomMember().lock()) { | ||
| 117 | // Prevent the user from trying to join a room while they are already joining. | ||
| 118 | if (member->GetState() == Network::RoomMember::State::Joining) { | ||
| 119 | return; | ||
| 120 | } else if (member->IsConnected()) { | ||
| 121 | // And ask if they want to leave the room if they are already in one. | ||
| 122 | if (!NetworkMessage::WarnDisconnect()) { | ||
| 123 | return; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
| 127 | QModelIndex index = source; | ||
| 128 | // If the user double clicks on a child row (aka the player list) then use the parent instead | ||
| 129 | if (source.parent() != QModelIndex()) { | ||
| 130 | index = source.parent(); | ||
| 131 | } | ||
| 132 | if (!ui->nickname->hasAcceptableInput()) { | ||
| 133 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::USERNAME_NOT_VALID); | ||
| 134 | return; | ||
| 135 | } | ||
| 136 | |||
| 137 | // Get a password to pass if the room is password protected | ||
| 138 | QModelIndex password_index = proxy->index(index.row(), Column::ROOM_NAME); | ||
| 139 | bool has_password = proxy->data(password_index, LobbyItemName::PasswordRole).toBool(); | ||
| 140 | const std::string password = has_password ? PasswordPrompt().toStdString() : ""; | ||
| 141 | if (has_password && password.empty()) { | ||
| 142 | return; | ||
| 143 | } | ||
| 144 | |||
| 145 | QModelIndex connection_index = proxy->index(index.row(), Column::HOST); | ||
| 146 | const std::string nickname = ui->nickname->text().toStdString(); | ||
| 147 | const std::string ip = | ||
| 148 | proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString(); | ||
| 149 | int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt(); | ||
| 150 | const std::string verify_UID = | ||
| 151 | proxy->data(connection_index, LobbyItemHost::HostVerifyUIDRole).toString().toStdString(); | ||
| 152 | |||
| 153 | // attempt to connect in a different thread | ||
| 154 | QFuture<void> f = QtConcurrent::run([nickname, ip, port, password, verify_UID] { | ||
| 155 | std::string token; | ||
| 156 | #ifdef ENABLE_WEB_SERVICE | ||
| 157 | if (!Settings::values.yuzu_username.empty() && !Settings::values.yuzu_token.empty()) { | ||
| 158 | WebService::Client client(Settings::values.web_api_url, Settings::values.yuzu_username, | ||
| 159 | Settings::values.yuzu_token); | ||
| 160 | token = client.GetExternalJWT(verify_UID).returned_data; | ||
| 161 | if (token.empty()) { | ||
| 162 | LOG_ERROR(WebService, "Could not get external JWT, verification may fail"); | ||
| 163 | } else { | ||
| 164 | LOG_INFO(WebService, "Successfully requested external JWT: size={}", token.size()); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | #endif | ||
| 168 | if (auto room_member = Network::GetRoomMember().lock()) { | ||
| 169 | room_member->Join(nickname, "", ip.c_str(), port, 0, Network::NoPreferredMac, password, | ||
| 170 | token); | ||
| 171 | } | ||
| 172 | }); | ||
| 173 | watcher->setFuture(f); | ||
| 174 | |||
| 175 | // TODO(jroweboy): disable widgets and display a connecting while we wait | ||
| 176 | |||
| 177 | // Save settings | ||
| 178 | UISettings::values.nickname = ui->nickname->text(); | ||
| 179 | UISettings::values.ip = proxy->data(connection_index, LobbyItemHost::HostIPRole).toString(); | ||
| 180 | UISettings::values.port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toString(); | ||
| 181 | } | ||
| 182 | |||
| 183 | void Lobby::ResetModel() { | ||
| 184 | model->clear(); | ||
| 185 | model->insertColumns(0, Column::TOTAL); | ||
| 186 | model->setHeaderData(Column::EXPAND, Qt::Horizontal, QString(), Qt::DisplayRole); | ||
| 187 | model->setHeaderData(Column::ROOM_NAME, Qt::Horizontal, tr("Room Name"), Qt::DisplayRole); | ||
| 188 | model->setHeaderData(Column::GAME_NAME, Qt::Horizontal, tr("Preferred Game"), Qt::DisplayRole); | ||
| 189 | model->setHeaderData(Column::HOST, Qt::Horizontal, tr("Host"), Qt::DisplayRole); | ||
| 190 | model->setHeaderData(Column::MEMBER, Qt::Horizontal, tr("Players"), Qt::DisplayRole); | ||
| 191 | } | ||
| 192 | |||
| 193 | void Lobby::RefreshLobby() { | ||
| 194 | if (auto session = announce_multiplayer_session.lock()) { | ||
| 195 | ResetModel(); | ||
| 196 | ui->refresh_list->setEnabled(false); | ||
| 197 | ui->refresh_list->setText(tr("Refreshing")); | ||
| 198 | room_list_watcher.setFuture( | ||
| 199 | QtConcurrent::run([session]() { return session->GetRoomList(); })); | ||
| 200 | } else { | ||
| 201 | // TODO(jroweboy): Display an error box about announce couldn't be started | ||
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | void Lobby::OnRefreshLobby() { | ||
| 206 | AnnounceMultiplayerRoom::RoomList new_room_list = room_list_watcher.result(); | ||
| 207 | for (auto room : new_room_list) { | ||
| 208 | // find the icon for the game if this person owns that game. | ||
| 209 | QPixmap smdh_icon; | ||
| 210 | for (int r = 0; r < game_list->rowCount(); ++r) { | ||
| 211 | auto index = game_list->index(r, 0); | ||
| 212 | auto game_id = game_list->data(index, GameListItemPath::ProgramIdRole).toULongLong(); | ||
| 213 | if (game_id != 0 && room.preferred_game_id == game_id) { | ||
| 214 | smdh_icon = game_list->data(index, Qt::DecorationRole).value<QPixmap>(); | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | QList<QVariant> members; | ||
| 219 | for (auto member : room.members) { | ||
| 220 | QVariant var; | ||
| 221 | var.setValue(LobbyMember{QString::fromStdString(member.username), | ||
| 222 | QString::fromStdString(member.nickname), member.game_id, | ||
| 223 | QString::fromStdString(member.game_name)}); | ||
| 224 | members.append(var); | ||
| 225 | } | ||
| 226 | |||
| 227 | auto first_item = new LobbyItem(); | ||
| 228 | auto row = QList<QStandardItem*>({ | ||
| 229 | first_item, | ||
| 230 | new LobbyItemName(room.has_password, QString::fromStdString(room.name)), | ||
| 231 | new LobbyItemGame(room.preferred_game_id, QString::fromStdString(room.preferred_game), | ||
| 232 | smdh_icon), | ||
| 233 | new LobbyItemHost(QString::fromStdString(room.owner), QString::fromStdString(room.ip), | ||
| 234 | room.port, QString::fromStdString(room.verify_UID)), | ||
| 235 | new LobbyItemMemberList(members, room.max_player), | ||
| 236 | }); | ||
| 237 | model->appendRow(row); | ||
| 238 | // To make the rows expandable, add the member data as a child of the first column of the | ||
| 239 | // rows with people in them and have qt set them to colspan after the model is finished | ||
| 240 | // resetting | ||
| 241 | if (!room.description.empty()) { | ||
| 242 | first_item->appendRow( | ||
| 243 | new LobbyItemDescription(QString::fromStdString(room.description))); | ||
| 244 | } | ||
| 245 | if (!room.members.empty()) { | ||
| 246 | first_item->appendRow(new LobbyItemExpandedMemberList(members)); | ||
| 247 | } | ||
| 248 | } | ||
| 249 | |||
| 250 | // Reenable the refresh button and resize the columns | ||
| 251 | ui->refresh_list->setEnabled(true); | ||
| 252 | ui->refresh_list->setText(tr("Refresh List")); | ||
| 253 | ui->room_list->header()->stretchLastSection(); | ||
| 254 | for (int i = 0; i < Column::TOTAL - 1; ++i) { | ||
| 255 | ui->room_list->resizeColumnToContents(i); | ||
| 256 | } | ||
| 257 | |||
| 258 | // Set the member list child items to span all columns | ||
| 259 | for (int i = 0; i < proxy->rowCount(); i++) { | ||
| 260 | auto parent = model->item(i, 0); | ||
| 261 | for (int j = 0; j < parent->rowCount(); j++) { | ||
| 262 | ui->room_list->setFirstColumnSpanned(j, proxy->index(i, 0), true); | ||
| 263 | } | ||
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 267 | LobbyFilterProxyModel::LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list) | ||
| 268 | : QSortFilterProxyModel(parent), game_list(list) {} | ||
| 269 | |||
| 270 | void LobbyFilterProxyModel::UpdateGameList(QStandardItemModel* list) { | ||
| 271 | game_list = list; | ||
| 272 | } | ||
| 273 | |||
| 274 | bool LobbyFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { | ||
| 275 | // Prioritize filters by fastest to compute | ||
| 276 | |||
| 277 | // pass over any child rows (aka row that shows the players in the room) | ||
| 278 | if (sourceParent != QModelIndex()) { | ||
| 279 | return true; | ||
| 280 | } | ||
| 281 | |||
| 282 | // filter by filled rooms | ||
| 283 | if (filter_full) { | ||
| 284 | QModelIndex member_list = sourceModel()->index(sourceRow, Column::MEMBER, sourceParent); | ||
| 285 | int player_count = | ||
| 286 | sourceModel()->data(member_list, LobbyItemMemberList::MemberListRole).toList().size(); | ||
| 287 | int max_players = | ||
| 288 | sourceModel()->data(member_list, LobbyItemMemberList::MaxPlayerRole).toInt(); | ||
| 289 | if (player_count >= max_players) { | ||
| 290 | return false; | ||
| 291 | } | ||
| 292 | } | ||
| 293 | |||
| 294 | // filter by search parameters | ||
| 295 | if (!filter_search.isEmpty()) { | ||
| 296 | QModelIndex game_name = sourceModel()->index(sourceRow, Column::GAME_NAME, sourceParent); | ||
| 297 | QModelIndex room_name = sourceModel()->index(sourceRow, Column::ROOM_NAME, sourceParent); | ||
| 298 | QModelIndex host_name = sourceModel()->index(sourceRow, Column::HOST, sourceParent); | ||
| 299 | bool preferred_game_match = sourceModel() | ||
| 300 | ->data(game_name, LobbyItemGame::GameNameRole) | ||
| 301 | .toString() | ||
| 302 | .contains(filter_search, filterCaseSensitivity()); | ||
| 303 | bool room_name_match = sourceModel() | ||
| 304 | ->data(room_name, LobbyItemName::NameRole) | ||
| 305 | .toString() | ||
| 306 | .contains(filter_search, filterCaseSensitivity()); | ||
| 307 | bool username_match = sourceModel() | ||
| 308 | ->data(host_name, LobbyItemHost::HostUsernameRole) | ||
| 309 | .toString() | ||
| 310 | .contains(filter_search, filterCaseSensitivity()); | ||
| 311 | if (!preferred_game_match && !room_name_match && !username_match) { | ||
| 312 | return false; | ||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | // filter by game owned | ||
| 317 | if (filter_owned) { | ||
| 318 | QModelIndex game_name = sourceModel()->index(sourceRow, Column::GAME_NAME, sourceParent); | ||
| 319 | QList<QModelIndex> owned_games; | ||
| 320 | for (int r = 0; r < game_list->rowCount(); ++r) { | ||
| 321 | owned_games.append(QModelIndex(game_list->index(r, 0))); | ||
| 322 | } | ||
| 323 | auto current_id = sourceModel()->data(game_name, LobbyItemGame::TitleIDRole).toLongLong(); | ||
| 324 | if (current_id == 0) { | ||
| 325 | // TODO(jroweboy): homebrew often doesn't have a game id and this hides them | ||
| 326 | return false; | ||
| 327 | } | ||
| 328 | bool owned = false; | ||
| 329 | for (const auto& game : owned_games) { | ||
| 330 | auto game_id = game_list->data(game, GameListItemPath::ProgramIdRole).toLongLong(); | ||
| 331 | if (current_id == game_id) { | ||
| 332 | owned = true; | ||
| 333 | } | ||
| 334 | } | ||
| 335 | if (!owned) { | ||
| 336 | return false; | ||
| 337 | } | ||
| 338 | } | ||
| 339 | |||
| 340 | return true; | ||
| 341 | } | ||
| 342 | |||
| 343 | void LobbyFilterProxyModel::sort(int column, Qt::SortOrder order) { | ||
| 344 | sourceModel()->sort(column, order); | ||
| 345 | } | ||
| 346 | |||
| 347 | void LobbyFilterProxyModel::SetFilterOwned(bool filter) { | ||
| 348 | filter_owned = filter; | ||
| 349 | invalidate(); | ||
| 350 | } | ||
| 351 | |||
| 352 | void LobbyFilterProxyModel::SetFilterFull(bool filter) { | ||
| 353 | filter_full = filter; | ||
| 354 | invalidate(); | ||
| 355 | } | ||
| 356 | |||
| 357 | void LobbyFilterProxyModel::SetFilterSearch(const QString& filter) { | ||
| 358 | filter_search = filter; | ||
| 359 | invalidate(); | ||
| 360 | } | ||
diff --git a/src/yuzu/multiplayer/lobby.h b/src/yuzu/multiplayer/lobby.h new file mode 100644 index 000000000..aea4a0e4e --- /dev/null +++ b/src/yuzu/multiplayer/lobby.h | |||
| @@ -0,0 +1,127 @@ | |||
| 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 <memory> | ||
| 8 | #include <QDialog> | ||
| 9 | #include <QFutureWatcher> | ||
| 10 | #include <QSortFilterProxyModel> | ||
| 11 | #include <QStandardItemModel> | ||
| 12 | #include "common/announce_multiplayer_room.h" | ||
| 13 | #include "core/announce_multiplayer_session.h" | ||
| 14 | #include "network/network.h" | ||
| 15 | #include "yuzu/multiplayer/validation.h" | ||
| 16 | |||
| 17 | namespace Ui { | ||
| 18 | class Lobby; | ||
| 19 | } | ||
| 20 | |||
| 21 | class LobbyModel; | ||
| 22 | class LobbyFilterProxyModel; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * Listing of all public games pulled from services. The lobby should be simple enough for users to | ||
| 26 | * find the game they want to play, and join it. | ||
| 27 | */ | ||
| 28 | class Lobby : public QDialog { | ||
| 29 | Q_OBJECT | ||
| 30 | |||
| 31 | public: | ||
| 32 | explicit Lobby(QWidget* parent, QStandardItemModel* list, | ||
| 33 | std::shared_ptr<Core::AnnounceMultiplayerSession> session); | ||
| 34 | ~Lobby() override; | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Updates the lobby with a new game list model. | ||
| 38 | * This model should be the original model of the game list. | ||
| 39 | */ | ||
| 40 | void UpdateGameList(QStandardItemModel* list); | ||
| 41 | void RetranslateUi(); | ||
| 42 | |||
| 43 | public slots: | ||
| 44 | /** | ||
| 45 | * Begin the process to pull the latest room list from web services. After the listing is | ||
| 46 | * returned from web services, `LobbyRefreshed` will be signalled | ||
| 47 | */ | ||
| 48 | void RefreshLobby(); | ||
| 49 | |||
| 50 | private slots: | ||
| 51 | /** | ||
| 52 | * Pulls the list of rooms from network and fills out the lobby model with the results | ||
| 53 | */ | ||
| 54 | void OnRefreshLobby(); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Handler for single clicking on a room in the list. Expands the treeitem to show player | ||
| 58 | * information for the people in the room | ||
| 59 | * | ||
| 60 | * index - The row of the proxy model that the user wants to join. | ||
| 61 | */ | ||
| 62 | void OnExpandRoom(const QModelIndex&); | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Handler for double clicking on a room in the list. Gathers the host ip and port and attempts | ||
| 66 | * to connect. Will also prompt for a password in case one is required. | ||
| 67 | * | ||
| 68 | * index - The row of the proxy model that the user wants to join. | ||
| 69 | */ | ||
| 70 | void OnJoinRoom(const QModelIndex&); | ||
| 71 | |||
| 72 | signals: | ||
| 73 | void StateChanged(const Network::RoomMember::State&); | ||
| 74 | |||
| 75 | private: | ||
| 76 | /** | ||
| 77 | * Removes all entries in the Lobby before refreshing. | ||
| 78 | */ | ||
| 79 | void ResetModel(); | ||
| 80 | |||
| 81 | /** | ||
| 82 | * Prompts for a password. Returns an empty QString if the user either did not provide a | ||
| 83 | * password or if the user closed the window. | ||
| 84 | */ | ||
| 85 | QString PasswordPrompt(); | ||
| 86 | |||
| 87 | std::unique_ptr<Ui::Lobby> ui; | ||
| 88 | |||
| 89 | QStandardItemModel* model{}; | ||
| 90 | QStandardItemModel* game_list{}; | ||
| 91 | LobbyFilterProxyModel* proxy{}; | ||
| 92 | |||
| 93 | QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher; | ||
| 94 | std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; | ||
| 95 | QFutureWatcher<void>* watcher; | ||
| 96 | Validation validation; | ||
| 97 | }; | ||
| 98 | |||
| 99 | /** | ||
| 100 | * Proxy Model for filtering the lobby | ||
| 101 | */ | ||
| 102 | class LobbyFilterProxyModel : public QSortFilterProxyModel { | ||
| 103 | Q_OBJECT; | ||
| 104 | |||
| 105 | public: | ||
| 106 | explicit LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list); | ||
| 107 | |||
| 108 | /** | ||
| 109 | * Updates the filter with a new game list model. | ||
| 110 | * This model should be the processed one created by the Lobby. | ||
| 111 | */ | ||
| 112 | void UpdateGameList(QStandardItemModel* list); | ||
| 113 | |||
| 114 | bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; | ||
| 115 | void sort(int column, Qt::SortOrder order) override; | ||
| 116 | |||
| 117 | public slots: | ||
| 118 | void SetFilterOwned(bool); | ||
| 119 | void SetFilterFull(bool); | ||
| 120 | void SetFilterSearch(const QString&); | ||
| 121 | |||
| 122 | private: | ||
| 123 | QStandardItemModel* game_list; | ||
| 124 | bool filter_owned = false; | ||
| 125 | bool filter_full = false; | ||
| 126 | QString filter_search; | ||
| 127 | }; | ||
diff --git a/src/yuzu/multiplayer/lobby.ui b/src/yuzu/multiplayer/lobby.ui new file mode 100644 index 000000000..4c9901c9a --- /dev/null +++ b/src/yuzu/multiplayer/lobby.ui | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>Lobby</class> | ||
| 4 | <widget class="QWidget" name="Lobby"> | ||
| 5 | <property name="geometry"> | ||
| 6 | <rect> | ||
| 7 | <x>0</x> | ||
| 8 | <y>0</y> | ||
| 9 | <width>903</width> | ||
| 10 | <height>487</height> | ||
| 11 | </rect> | ||
| 12 | </property> | ||
| 13 | <property name="windowTitle"> | ||
| 14 | <string>Public Room Browser</string> | ||
| 15 | </property> | ||
| 16 | <layout class="QVBoxLayout" name="verticalLayout"> | ||
| 17 | <item> | ||
| 18 | <layout class="QVBoxLayout" name="verticalLayout_2"> | ||
| 19 | <property name="spacing"> | ||
| 20 | <number>3</number> | ||
| 21 | </property> | ||
| 22 | <item> | ||
| 23 | <layout class="QHBoxLayout" name="horizontalLayout_3"> | ||
| 24 | <property name="spacing"> | ||
| 25 | <number>6</number> | ||
| 26 | </property> | ||
| 27 | <item> | ||
| 28 | <layout class="QHBoxLayout" name="horizontalLayout_5"> | ||
| 29 | <item> | ||
| 30 | <widget class="QLabel" name="label"> | ||
| 31 | <property name="text"> | ||
| 32 | <string>Nickname</string> | ||
| 33 | </property> | ||
| 34 | </widget> | ||
| 35 | </item> | ||
| 36 | <item> | ||
| 37 | <widget class="QLineEdit" name="nickname"> | ||
| 38 | <property name="placeholderText"> | ||
| 39 | <string>Nickname</string> | ||
| 40 | </property> | ||
| 41 | </widget> | ||
| 42 | </item> | ||
| 43 | <item> | ||
| 44 | <spacer name="horizontalSpacer_2"> | ||
| 45 | <property name="orientation"> | ||
| 46 | <enum>Qt::Horizontal</enum> | ||
| 47 | </property> | ||
| 48 | <property name="sizeHint" stdset="0"> | ||
| 49 | <size> | ||
| 50 | <width>40</width> | ||
| 51 | <height>20</height> | ||
| 52 | </size> | ||
| 53 | </property> | ||
| 54 | </spacer> | ||
| 55 | </item> | ||
| 56 | <item> | ||
| 57 | <widget class="QLabel" name="label_2"> | ||
| 58 | <property name="text"> | ||
| 59 | <string>Filters</string> | ||
| 60 | </property> | ||
| 61 | </widget> | ||
| 62 | </item> | ||
| 63 | <item> | ||
| 64 | <widget class="QLineEdit" name="search"> | ||
| 65 | <property name="placeholderText"> | ||
| 66 | <string>Search</string> | ||
| 67 | </property> | ||
| 68 | <property name="clearButtonEnabled"> | ||
| 69 | <bool>true</bool> | ||
| 70 | </property> | ||
| 71 | </widget> | ||
| 72 | </item> | ||
| 73 | <item> | ||
| 74 | <widget class="QCheckBox" name="games_owned"> | ||
| 75 | <property name="text"> | ||
| 76 | <string>Games I Own</string> | ||
| 77 | </property> | ||
| 78 | </widget> | ||
| 79 | </item> | ||
| 80 | <item> | ||
| 81 | <widget class="QCheckBox" name="hide_full"> | ||
| 82 | <property name="text"> | ||
| 83 | <string>Hide Full Rooms</string> | ||
| 84 | </property> | ||
| 85 | </widget> | ||
| 86 | </item> | ||
| 87 | <item> | ||
| 88 | <spacer name="horizontalSpacer"> | ||
| 89 | <property name="orientation"> | ||
| 90 | <enum>Qt::Horizontal</enum> | ||
| 91 | </property> | ||
| 92 | <property name="sizeHint" stdset="0"> | ||
| 93 | <size> | ||
| 94 | <width>40</width> | ||
| 95 | <height>20</height> | ||
| 96 | </size> | ||
| 97 | </property> | ||
| 98 | </spacer> | ||
| 99 | </item> | ||
| 100 | <item> | ||
| 101 | <widget class="QPushButton" name="refresh_list"> | ||
| 102 | <property name="text"> | ||
| 103 | <string>Refresh Lobby</string> | ||
| 104 | </property> | ||
| 105 | </widget> | ||
| 106 | </item> | ||
| 107 | </layout> | ||
| 108 | </item> | ||
| 109 | </layout> | ||
| 110 | </item> | ||
| 111 | <item> | ||
| 112 | <widget class="QTreeView" name="room_list"/> | ||
| 113 | </item> | ||
| 114 | <item> | ||
| 115 | <widget class="QWidget" name="widget" native="true"/> | ||
| 116 | </item> | ||
| 117 | </layout> | ||
| 118 | </item> | ||
| 119 | </layout> | ||
| 120 | </widget> | ||
| 121 | <resources/> | ||
| 122 | <connections/> | ||
| 123 | </ui> | ||
diff --git a/src/yuzu/multiplayer/lobby_p.h b/src/yuzu/multiplayer/lobby_p.h new file mode 100644 index 000000000..749ca627f --- /dev/null +++ b/src/yuzu/multiplayer/lobby_p.h | |||
| @@ -0,0 +1,239 @@ | |||
| 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 <utility> | ||
| 8 | #include <QPixmap> | ||
| 9 | #include <QStandardItem> | ||
| 10 | #include <QStandardItemModel> | ||
| 11 | #include "common/common_types.h" | ||
| 12 | |||
| 13 | namespace Column { | ||
| 14 | enum List { | ||
| 15 | EXPAND, | ||
| 16 | ROOM_NAME, | ||
| 17 | GAME_NAME, | ||
| 18 | HOST, | ||
| 19 | MEMBER, | ||
| 20 | TOTAL, | ||
| 21 | }; | ||
| 22 | } | ||
| 23 | |||
| 24 | class LobbyItem : public QStandardItem { | ||
| 25 | public: | ||
| 26 | LobbyItem() = default; | ||
| 27 | explicit LobbyItem(const QString& string) : QStandardItem(string) {} | ||
| 28 | virtual ~LobbyItem() override = default; | ||
| 29 | }; | ||
| 30 | |||
| 31 | class LobbyItemName : public LobbyItem { | ||
| 32 | public: | ||
| 33 | static const int NameRole = Qt::UserRole + 1; | ||
| 34 | static const int PasswordRole = Qt::UserRole + 2; | ||
| 35 | |||
| 36 | LobbyItemName() = default; | ||
| 37 | explicit LobbyItemName(bool has_password, QString name) : LobbyItem() { | ||
| 38 | setData(name, NameRole); | ||
| 39 | setData(has_password, PasswordRole); | ||
| 40 | } | ||
| 41 | |||
| 42 | QVariant data(int role) const override { | ||
| 43 | if (role == Qt::DecorationRole) { | ||
| 44 | bool has_password = data(PasswordRole).toBool(); | ||
| 45 | return has_password ? QIcon::fromTheme(QStringLiteral("lock")).pixmap(16) : QIcon(); | ||
| 46 | } | ||
| 47 | if (role != Qt::DisplayRole) { | ||
| 48 | return LobbyItem::data(role); | ||
| 49 | } | ||
| 50 | return data(NameRole).toString(); | ||
| 51 | } | ||
| 52 | |||
| 53 | bool operator<(const QStandardItem& other) const override { | ||
| 54 | return data(NameRole).toString().localeAwareCompare(other.data(NameRole).toString()) < 0; | ||
| 55 | } | ||
| 56 | }; | ||
| 57 | |||
| 58 | class LobbyItemDescription : public LobbyItem { | ||
| 59 | public: | ||
| 60 | static const int DescriptionRole = Qt::UserRole + 1; | ||
| 61 | |||
| 62 | LobbyItemDescription() = default; | ||
| 63 | explicit LobbyItemDescription(QString description) { | ||
| 64 | setData(description, DescriptionRole); | ||
| 65 | } | ||
| 66 | |||
| 67 | QVariant data(int role) const override { | ||
| 68 | if (role != Qt::DisplayRole) { | ||
| 69 | return LobbyItem::data(role); | ||
| 70 | } | ||
| 71 | auto description = data(DescriptionRole).toString(); | ||
| 72 | description.prepend(QStringLiteral("Description: ")); | ||
| 73 | return description; | ||
| 74 | } | ||
| 75 | |||
| 76 | bool operator<(const QStandardItem& other) const override { | ||
| 77 | return data(DescriptionRole) | ||
| 78 | .toString() | ||
| 79 | .localeAwareCompare(other.data(DescriptionRole).toString()) < 0; | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | |||
| 83 | class LobbyItemGame : public LobbyItem { | ||
| 84 | public: | ||
| 85 | static const int TitleIDRole = Qt::UserRole + 1; | ||
| 86 | static const int GameNameRole = Qt::UserRole + 2; | ||
| 87 | static const int GameIconRole = Qt::UserRole + 3; | ||
| 88 | |||
| 89 | LobbyItemGame() = default; | ||
| 90 | explicit LobbyItemGame(u64 title_id, QString game_name, QPixmap smdh_icon) { | ||
| 91 | setData(static_cast<unsigned long long>(title_id), TitleIDRole); | ||
| 92 | setData(game_name, GameNameRole); | ||
| 93 | if (!smdh_icon.isNull()) { | ||
| 94 | setData(smdh_icon, GameIconRole); | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | QVariant data(int role) const override { | ||
| 99 | if (role == Qt::DecorationRole) { | ||
| 100 | auto val = data(GameIconRole); | ||
| 101 | if (val.isValid()) { | ||
| 102 | val = val.value<QPixmap>().scaled(16, 16, Qt::KeepAspectRatio); | ||
| 103 | } | ||
| 104 | return val; | ||
| 105 | } else if (role != Qt::DisplayRole) { | ||
| 106 | return LobbyItem::data(role); | ||
| 107 | } | ||
| 108 | return data(GameNameRole).toString(); | ||
| 109 | } | ||
| 110 | |||
| 111 | bool operator<(const QStandardItem& other) const override { | ||
| 112 | return data(GameNameRole) | ||
| 113 | .toString() | ||
| 114 | .localeAwareCompare(other.data(GameNameRole).toString()) < 0; | ||
| 115 | } | ||
| 116 | }; | ||
| 117 | |||
| 118 | class LobbyItemHost : public LobbyItem { | ||
| 119 | public: | ||
| 120 | static const int HostUsernameRole = Qt::UserRole + 1; | ||
| 121 | static const int HostIPRole = Qt::UserRole + 2; | ||
| 122 | static const int HostPortRole = Qt::UserRole + 3; | ||
| 123 | static const int HostVerifyUIDRole = Qt::UserRole + 4; | ||
| 124 | |||
| 125 | LobbyItemHost() = default; | ||
| 126 | explicit LobbyItemHost(QString username, QString ip, u16 port, QString verify_UID) { | ||
| 127 | setData(username, HostUsernameRole); | ||
| 128 | setData(ip, HostIPRole); | ||
| 129 | setData(port, HostPortRole); | ||
| 130 | setData(verify_UID, HostVerifyUIDRole); | ||
| 131 | } | ||
| 132 | |||
| 133 | QVariant data(int role) const override { | ||
| 134 | if (role != Qt::DisplayRole) { | ||
| 135 | return LobbyItem::data(role); | ||
| 136 | } | ||
| 137 | return data(HostUsernameRole).toString(); | ||
| 138 | } | ||
| 139 | |||
| 140 | bool operator<(const QStandardItem& other) const override { | ||
| 141 | return data(HostUsernameRole) | ||
| 142 | .toString() | ||
| 143 | .localeAwareCompare(other.data(HostUsernameRole).toString()) < 0; | ||
| 144 | } | ||
| 145 | }; | ||
| 146 | |||
| 147 | class LobbyMember { | ||
| 148 | public: | ||
| 149 | LobbyMember() = default; | ||
| 150 | LobbyMember(const LobbyMember& other) = default; | ||
| 151 | explicit LobbyMember(QString username, QString nickname, u64 title_id, QString game_name) | ||
| 152 | : username(std::move(username)), nickname(std::move(nickname)), title_id(title_id), | ||
| 153 | game_name(std::move(game_name)) {} | ||
| 154 | ~LobbyMember() = default; | ||
| 155 | |||
| 156 | QString GetName() const { | ||
| 157 | if (username.isEmpty() || username == nickname) { | ||
| 158 | return nickname; | ||
| 159 | } else { | ||
| 160 | return QStringLiteral("%1 (%2)").arg(nickname, username); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | u64 GetTitleId() const { | ||
| 164 | return title_id; | ||
| 165 | } | ||
| 166 | QString GetGameName() const { | ||
| 167 | return game_name; | ||
| 168 | } | ||
| 169 | |||
| 170 | private: | ||
| 171 | QString username; | ||
| 172 | QString nickname; | ||
| 173 | u64 title_id; | ||
| 174 | QString game_name; | ||
| 175 | }; | ||
| 176 | |||
| 177 | Q_DECLARE_METATYPE(LobbyMember); | ||
| 178 | |||
| 179 | class LobbyItemMemberList : public LobbyItem { | ||
| 180 | public: | ||
| 181 | static const int MemberListRole = Qt::UserRole + 1; | ||
| 182 | static const int MaxPlayerRole = Qt::UserRole + 2; | ||
| 183 | |||
| 184 | LobbyItemMemberList() = default; | ||
| 185 | explicit LobbyItemMemberList(QList<QVariant> members, u32 max_players) { | ||
| 186 | setData(members, MemberListRole); | ||
| 187 | setData(max_players, MaxPlayerRole); | ||
| 188 | } | ||
| 189 | |||
| 190 | QVariant data(int role) const override { | ||
| 191 | if (role != Qt::DisplayRole) { | ||
| 192 | return LobbyItem::data(role); | ||
| 193 | } | ||
| 194 | auto members = data(MemberListRole).toList(); | ||
| 195 | return QStringLiteral("%1 / %2").arg(QString::number(members.size()), | ||
| 196 | data(MaxPlayerRole).toString()); | ||
| 197 | } | ||
| 198 | |||
| 199 | bool operator<(const QStandardItem& other) const override { | ||
| 200 | // sort by rooms that have the most players | ||
| 201 | int left_members = data(MemberListRole).toList().size(); | ||
| 202 | int right_members = other.data(MemberListRole).toList().size(); | ||
| 203 | return left_members < right_members; | ||
| 204 | } | ||
| 205 | }; | ||
| 206 | |||
| 207 | /** | ||
| 208 | * Member information for when a lobby is expanded in the UI | ||
| 209 | */ | ||
| 210 | class LobbyItemExpandedMemberList : public LobbyItem { | ||
| 211 | public: | ||
| 212 | static const int MemberListRole = Qt::UserRole + 1; | ||
| 213 | |||
| 214 | LobbyItemExpandedMemberList() = default; | ||
| 215 | explicit LobbyItemExpandedMemberList(QList<QVariant> members) { | ||
| 216 | setData(members, MemberListRole); | ||
| 217 | } | ||
| 218 | |||
| 219 | QVariant data(int role) const override { | ||
| 220 | if (role != Qt::DisplayRole) { | ||
| 221 | return LobbyItem::data(role); | ||
| 222 | } | ||
| 223 | auto members = data(MemberListRole).toList(); | ||
| 224 | QString out; | ||
| 225 | bool first = true; | ||
| 226 | for (const auto& member : members) { | ||
| 227 | if (!first) | ||
| 228 | out.append(QStringLiteral("\n")); | ||
| 229 | const auto& m = member.value<LobbyMember>(); | ||
| 230 | if (m.GetGameName().isEmpty()) { | ||
| 231 | out += QString(QObject::tr("%1 is not playing a game")).arg(m.GetName()); | ||
| 232 | } else { | ||
| 233 | out += QString(QObject::tr("%1 is playing %2")).arg(m.GetName(), m.GetGameName()); | ||
| 234 | } | ||
| 235 | first = false; | ||
| 236 | } | ||
| 237 | return out; | ||
| 238 | } | ||
| 239 | }; | ||
diff --git a/src/yuzu/multiplayer/message.cpp b/src/yuzu/multiplayer/message.cpp new file mode 100644 index 000000000..458f1e7d1 --- /dev/null +++ b/src/yuzu/multiplayer/message.cpp | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QMessageBox> | ||
| 6 | #include <QString> | ||
| 7 | |||
| 8 | #include "yuzu/multiplayer/message.h" | ||
| 9 | |||
| 10 | namespace NetworkMessage { | ||
| 11 | const ConnectionError ErrorManager::USERNAME_NOT_VALID( | ||
| 12 | QT_TR_NOOP("Username is not valid. Must be 4 to 20 alphanumeric characters.")); | ||
| 13 | const ConnectionError ErrorManager::ROOMNAME_NOT_VALID( | ||
| 14 | QT_TR_NOOP("Room name is not valid. Must be 4 to 20 alphanumeric characters.")); | ||
| 15 | const ConnectionError ErrorManager::USERNAME_NOT_VALID_SERVER( | ||
| 16 | QT_TR_NOOP("Username is already in use or not valid. Please choose another.")); | ||
| 17 | const ConnectionError ErrorManager::IP_ADDRESS_NOT_VALID( | ||
| 18 | QT_TR_NOOP("IP is not a valid IPv4 address.")); | ||
| 19 | const ConnectionError ErrorManager::PORT_NOT_VALID( | ||
| 20 | QT_TR_NOOP("Port must be a number between 0 to 65535.")); | ||
| 21 | const ConnectionError ErrorManager::GAME_NOT_SELECTED(QT_TR_NOOP( | ||
| 22 | "You must choose a Preferred Game to host a room. If you do not have any games in your game " | ||
| 23 | "list yet, add a game folder by clicking on the plus icon in the game list.")); | ||
| 24 | const ConnectionError ErrorManager::NO_INTERNET( | ||
| 25 | QT_TR_NOOP("Unable to find an internet connection. Check your internet settings.")); | ||
| 26 | const ConnectionError ErrorManager::UNABLE_TO_CONNECT( | ||
| 27 | QT_TR_NOOP("Unable to connect to the host. Verify that the connection settings are correct. If " | ||
| 28 | "you still cannot connect, contact the room host and verify that the host is " | ||
| 29 | "properly configured with the external port forwarded.")); | ||
| 30 | const ConnectionError ErrorManager::ROOM_IS_FULL( | ||
| 31 | QT_TR_NOOP("Unable to connect to the room because it is already full.")); | ||
| 32 | const ConnectionError ErrorManager::COULD_NOT_CREATE_ROOM( | ||
| 33 | QT_TR_NOOP("Creating a room failed. Please retry. Restarting yuzu might be necessary.")); | ||
| 34 | const ConnectionError ErrorManager::HOST_BANNED( | ||
| 35 | QT_TR_NOOP("The host of the room has banned you. Speak with the host to unban you " | ||
| 36 | "or try a different room.")); | ||
| 37 | const ConnectionError ErrorManager::WRONG_VERSION( | ||
| 38 | QT_TR_NOOP("Version mismatch! Please update to the latest version of yuzu. If the problem " | ||
| 39 | "persists, contact the room host and ask them to update the server.")); | ||
| 40 | const ConnectionError ErrorManager::WRONG_PASSWORD(QT_TR_NOOP("Incorrect password.")); | ||
| 41 | const ConnectionError ErrorManager::GENERIC_ERROR(QT_TR_NOOP( | ||
| 42 | "An unknown error occurred. If this error continues to occur, please open an issue")); | ||
| 43 | const ConnectionError ErrorManager::LOST_CONNECTION( | ||
| 44 | QT_TR_NOOP("Connection to room lost. Try to reconnect.")); | ||
| 45 | const ConnectionError ErrorManager::HOST_KICKED( | ||
| 46 | QT_TR_NOOP("You have been kicked by the room host.")); | ||
| 47 | const ConnectionError ErrorManager::MAC_COLLISION( | ||
| 48 | QT_TR_NOOP("MAC address is already in use. Please choose another.")); | ||
| 49 | const ConnectionError ErrorManager::CONSOLE_ID_COLLISION(QT_TR_NOOP( | ||
| 50 | "Your Console ID conflicted with someone else's in the room.\n\nPlease go to Emulation " | ||
| 51 | "> Configure > System to regenerate your Console ID.")); | ||
| 52 | const ConnectionError ErrorManager::PERMISSION_DENIED( | ||
| 53 | QT_TR_NOOP("You do not have enough permission to perform this action.")); | ||
| 54 | const ConnectionError ErrorManager::NO_SUCH_USER(QT_TR_NOOP( | ||
| 55 | "The user you are trying to kick/ban could not be found.\nThey may have left the room.")); | ||
| 56 | |||
| 57 | static bool WarnMessage(const std::string& title, const std::string& text) { | ||
| 58 | return QMessageBox::Ok == QMessageBox::warning(nullptr, QObject::tr(title.c_str()), | ||
| 59 | QObject::tr(text.c_str()), | ||
| 60 | QMessageBox::Ok | QMessageBox::Cancel); | ||
| 61 | } | ||
| 62 | |||
| 63 | void ErrorManager::ShowError(const ConnectionError& e) { | ||
| 64 | QMessageBox::critical(nullptr, tr("Error"), tr(e.GetString().c_str())); | ||
| 65 | } | ||
| 66 | |||
| 67 | bool WarnCloseRoom() { | ||
| 68 | return WarnMessage( | ||
| 69 | QT_TR_NOOP("Leave Room"), | ||
| 70 | QT_TR_NOOP("You are about to close the room. Any network connections will be closed.")); | ||
| 71 | } | ||
| 72 | |||
| 73 | bool WarnDisconnect() { | ||
| 74 | return WarnMessage( | ||
| 75 | QT_TR_NOOP("Disconnect"), | ||
| 76 | QT_TR_NOOP("You are about to leave the room. Any network connections will be closed.")); | ||
| 77 | } | ||
| 78 | |||
| 79 | } // namespace NetworkMessage | ||
diff --git a/src/yuzu/multiplayer/message.h b/src/yuzu/multiplayer/message.h new file mode 100644 index 000000000..49a31997d --- /dev/null +++ b/src/yuzu/multiplayer/message.h | |||
| @@ -0,0 +1,65 @@ | |||
| 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 <utility> | ||
| 8 | |||
| 9 | namespace NetworkMessage { | ||
| 10 | |||
| 11 | class ConnectionError { | ||
| 12 | |||
| 13 | public: | ||
| 14 | explicit ConnectionError(std::string str) : err(std::move(str)) {} | ||
| 15 | const std::string& GetString() const { | ||
| 16 | return err; | ||
| 17 | } | ||
| 18 | |||
| 19 | private: | ||
| 20 | std::string err; | ||
| 21 | }; | ||
| 22 | |||
| 23 | class ErrorManager : QObject { | ||
| 24 | Q_OBJECT | ||
| 25 | public: | ||
| 26 | /// When the nickname is considered invalid by the client | ||
| 27 | static const ConnectionError USERNAME_NOT_VALID; | ||
| 28 | static const ConnectionError ROOMNAME_NOT_VALID; | ||
| 29 | /// When the nickname is considered invalid by the room server | ||
| 30 | static const ConnectionError USERNAME_NOT_VALID_SERVER; | ||
| 31 | static const ConnectionError IP_ADDRESS_NOT_VALID; | ||
| 32 | static const ConnectionError PORT_NOT_VALID; | ||
| 33 | static const ConnectionError GAME_NOT_SELECTED; | ||
| 34 | static const ConnectionError NO_INTERNET; | ||
| 35 | static const ConnectionError UNABLE_TO_CONNECT; | ||
| 36 | static const ConnectionError ROOM_IS_FULL; | ||
| 37 | static const ConnectionError COULD_NOT_CREATE_ROOM; | ||
| 38 | static const ConnectionError HOST_BANNED; | ||
| 39 | static const ConnectionError WRONG_VERSION; | ||
| 40 | static const ConnectionError WRONG_PASSWORD; | ||
| 41 | static const ConnectionError GENERIC_ERROR; | ||
| 42 | static const ConnectionError LOST_CONNECTION; | ||
| 43 | static const ConnectionError HOST_KICKED; | ||
| 44 | static const ConnectionError MAC_COLLISION; | ||
| 45 | static const ConnectionError CONSOLE_ID_COLLISION; | ||
| 46 | static const ConnectionError PERMISSION_DENIED; | ||
| 47 | static const ConnectionError NO_SUCH_USER; | ||
| 48 | /** | ||
| 49 | * Shows a standard QMessageBox with a error message | ||
| 50 | */ | ||
| 51 | static void ShowError(const ConnectionError& e); | ||
| 52 | }; | ||
| 53 | /** | ||
| 54 | * Show a standard QMessageBox with a warning message about leaving the room | ||
| 55 | * return true if the user wants to close the network connection | ||
| 56 | */ | ||
| 57 | bool WarnCloseRoom(); | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Show a standard QMessageBox with a warning message about disconnecting from the room | ||
| 61 | * return true if the user wants to disconnect | ||
| 62 | */ | ||
| 63 | bool WarnDisconnect(); | ||
| 64 | |||
| 65 | } // namespace NetworkMessage | ||
diff --git a/src/yuzu/multiplayer/moderation_dialog.cpp b/src/yuzu/multiplayer/moderation_dialog.cpp new file mode 100644 index 000000000..e97f30ee5 --- /dev/null +++ b/src/yuzu/multiplayer/moderation_dialog.cpp | |||
| @@ -0,0 +1,113 @@ | |||
| 1 | // Copyright 2018 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QStandardItem> | ||
| 6 | #include <QStandardItemModel> | ||
| 7 | #include "network/network.h" | ||
| 8 | #include "network/room_member.h" | ||
| 9 | #include "ui_moderation_dialog.h" | ||
| 10 | #include "yuzu/multiplayer/moderation_dialog.h" | ||
| 11 | |||
| 12 | namespace Column { | ||
| 13 | enum { | ||
| 14 | SUBJECT, | ||
| 15 | TYPE, | ||
| 16 | COUNT, | ||
| 17 | }; | ||
| 18 | } | ||
| 19 | |||
| 20 | ModerationDialog::ModerationDialog(QWidget* parent) | ||
| 21 | : QDialog(parent), ui(std::make_unique<Ui::ModerationDialog>()) { | ||
| 22 | ui->setupUi(this); | ||
| 23 | |||
| 24 | qRegisterMetaType<Network::Room::BanList>(); | ||
| 25 | |||
| 26 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 27 | callback_handle_status_message = member->BindOnStatusMessageReceived( | ||
| 28 | [this](const Network::StatusMessageEntry& status_message) { | ||
| 29 | emit StatusMessageReceived(status_message); | ||
| 30 | }); | ||
| 31 | connect(this, &ModerationDialog::StatusMessageReceived, this, | ||
| 32 | &ModerationDialog::OnStatusMessageReceived); | ||
| 33 | callback_handle_ban_list = member->BindOnBanListReceived( | ||
| 34 | [this](const Network::Room::BanList& ban_list) { emit BanListReceived(ban_list); }); | ||
| 35 | connect(this, &ModerationDialog::BanListReceived, this, &ModerationDialog::PopulateBanList); | ||
| 36 | } | ||
| 37 | |||
| 38 | // Initialize the UI | ||
| 39 | model = new QStandardItemModel(ui->ban_list_view); | ||
| 40 | model->insertColumns(0, Column::COUNT); | ||
| 41 | model->setHeaderData(Column::SUBJECT, Qt::Horizontal, tr("Subject")); | ||
| 42 | model->setHeaderData(Column::TYPE, Qt::Horizontal, tr("Type")); | ||
| 43 | |||
| 44 | ui->ban_list_view->setModel(model); | ||
| 45 | |||
| 46 | // Load the ban list in background | ||
| 47 | LoadBanList(); | ||
| 48 | |||
| 49 | connect(ui->refresh, &QPushButton::clicked, this, [this] { LoadBanList(); }); | ||
| 50 | connect(ui->unban, &QPushButton::clicked, this, [this] { | ||
| 51 | auto index = ui->ban_list_view->currentIndex(); | ||
| 52 | SendUnbanRequest(model->item(index.row(), 0)->text()); | ||
| 53 | }); | ||
| 54 | connect(ui->ban_list_view, &QTreeView::clicked, [this] { ui->unban->setEnabled(true); }); | ||
| 55 | } | ||
| 56 | |||
| 57 | ModerationDialog::~ModerationDialog() { | ||
| 58 | if (callback_handle_status_message) { | ||
| 59 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 60 | room->Unbind(callback_handle_status_message); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | if (callback_handle_ban_list) { | ||
| 65 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 66 | room->Unbind(callback_handle_ban_list); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | void ModerationDialog::LoadBanList() { | ||
| 72 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 73 | ui->refresh->setEnabled(false); | ||
| 74 | ui->refresh->setText(tr("Refreshing")); | ||
| 75 | ui->unban->setEnabled(false); | ||
| 76 | room->RequestBanList(); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | void ModerationDialog::PopulateBanList(const Network::Room::BanList& ban_list) { | ||
| 81 | model->removeRows(0, model->rowCount()); | ||
| 82 | for (const auto& username : ban_list.first) { | ||
| 83 | QStandardItem* subject_item = new QStandardItem(QString::fromStdString(username)); | ||
| 84 | QStandardItem* type_item = new QStandardItem(tr("Forum Username")); | ||
| 85 | model->invisibleRootItem()->appendRow({subject_item, type_item}); | ||
| 86 | } | ||
| 87 | for (const auto& ip : ban_list.second) { | ||
| 88 | QStandardItem* subject_item = new QStandardItem(QString::fromStdString(ip)); | ||
| 89 | QStandardItem* type_item = new QStandardItem(tr("IP Address")); | ||
| 90 | model->invisibleRootItem()->appendRow({subject_item, type_item}); | ||
| 91 | } | ||
| 92 | for (int i = 0; i < Column::COUNT - 1; ++i) { | ||
| 93 | ui->ban_list_view->resizeColumnToContents(i); | ||
| 94 | } | ||
| 95 | ui->refresh->setEnabled(true); | ||
| 96 | ui->refresh->setText(tr("Refresh")); | ||
| 97 | ui->unban->setEnabled(false); | ||
| 98 | } | ||
| 99 | |||
| 100 | void ModerationDialog::SendUnbanRequest(const QString& subject) { | ||
| 101 | if (auto room = Network::GetRoomMember().lock()) { | ||
| 102 | room->SendModerationRequest(Network::IdModUnban, subject.toStdString()); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | void ModerationDialog::OnStatusMessageReceived(const Network::StatusMessageEntry& status_message) { | ||
| 107 | if (status_message.type != Network::IdMemberBanned && | ||
| 108 | status_message.type != Network::IdAddressUnbanned) | ||
| 109 | return; | ||
| 110 | |||
| 111 | // Update the ban list for ban/unban | ||
| 112 | LoadBanList(); | ||
| 113 | } | ||
diff --git a/src/yuzu/multiplayer/moderation_dialog.h b/src/yuzu/multiplayer/moderation_dialog.h new file mode 100644 index 000000000..d10083d5b --- /dev/null +++ b/src/yuzu/multiplayer/moderation_dialog.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | // Copyright 2018 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 <memory> | ||
| 8 | #include <optional> | ||
| 9 | #include <QDialog> | ||
| 10 | #include "network/room.h" | ||
| 11 | #include "network/room_member.h" | ||
| 12 | |||
| 13 | namespace Ui { | ||
| 14 | class ModerationDialog; | ||
| 15 | } | ||
| 16 | |||
| 17 | class QStandardItemModel; | ||
| 18 | |||
| 19 | class ModerationDialog : public QDialog { | ||
| 20 | Q_OBJECT | ||
| 21 | |||
| 22 | public: | ||
| 23 | explicit ModerationDialog(QWidget* parent = nullptr); | ||
| 24 | ~ModerationDialog(); | ||
| 25 | |||
| 26 | signals: | ||
| 27 | void StatusMessageReceived(const Network::StatusMessageEntry&); | ||
| 28 | void BanListReceived(const Network::Room::BanList&); | ||
| 29 | |||
| 30 | private: | ||
| 31 | void LoadBanList(); | ||
| 32 | void PopulateBanList(const Network::Room::BanList& ban_list); | ||
| 33 | void SendUnbanRequest(const QString& subject); | ||
| 34 | void OnStatusMessageReceived(const Network::StatusMessageEntry& status_message); | ||
| 35 | |||
| 36 | std::unique_ptr<Ui::ModerationDialog> ui; | ||
| 37 | QStandardItemModel* model; | ||
| 38 | Network::RoomMember::CallbackHandle<Network::StatusMessageEntry> callback_handle_status_message; | ||
| 39 | Network::RoomMember::CallbackHandle<Network::Room::BanList> callback_handle_ban_list; | ||
| 40 | }; | ||
| 41 | |||
| 42 | Q_DECLARE_METATYPE(Network::Room::BanList); | ||
diff --git a/src/yuzu/multiplayer/moderation_dialog.ui b/src/yuzu/multiplayer/moderation_dialog.ui new file mode 100644 index 000000000..808d99414 --- /dev/null +++ b/src/yuzu/multiplayer/moderation_dialog.ui | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>ModerationDialog</class> | ||
| 4 | <widget class="QDialog" name="ModerationDialog"> | ||
| 5 | <property name="windowTitle"> | ||
| 6 | <string>Moderation</string> | ||
| 7 | </property> | ||
| 8 | <property name="geometry"> | ||
| 9 | <rect> | ||
| 10 | <x>0</x> | ||
| 11 | <y>0</y> | ||
| 12 | <width>500</width> | ||
| 13 | <height>300</height> | ||
| 14 | </rect> | ||
| 15 | </property> | ||
| 16 | <layout class="QVBoxLayout"> | ||
| 17 | <item> | ||
| 18 | <widget class="QGroupBox" name="ban_list_group_box"> | ||
| 19 | <property name="title"> | ||
| 20 | <string>Ban List</string> | ||
| 21 | </property> | ||
| 22 | <layout class="QVBoxLayout"> | ||
| 23 | <item> | ||
| 24 | <layout class="QHBoxLayout"> | ||
| 25 | <item> | ||
| 26 | <spacer name="horizontalSpacer"> | ||
| 27 | <property name="orientation"> | ||
| 28 | <enum>Qt::Horizontal</enum> | ||
| 29 | </property> | ||
| 30 | <property name="sizeHint" stdset="0"> | ||
| 31 | <size> | ||
| 32 | <width>40</width> | ||
| 33 | <height>20</height> | ||
| 34 | </size> | ||
| 35 | </property> | ||
| 36 | </spacer> | ||
| 37 | </item> | ||
| 38 | <item> | ||
| 39 | <widget class="QPushButton" name="refresh"> | ||
| 40 | <property name="text"> | ||
| 41 | <string>Refreshing</string> | ||
| 42 | </property> | ||
| 43 | <property name="enabled"> | ||
| 44 | <bool>false</bool> | ||
| 45 | </property> | ||
| 46 | </widget> | ||
| 47 | </item> | ||
| 48 | <item> | ||
| 49 | <widget class="QPushButton" name="unban"> | ||
| 50 | <property name="text"> | ||
| 51 | <string>Unban</string> | ||
| 52 | </property> | ||
| 53 | <property name="enabled"> | ||
| 54 | <bool>false</bool> | ||
| 55 | </property> | ||
| 56 | </widget> | ||
| 57 | </item> | ||
| 58 | </layout> | ||
| 59 | </item> | ||
| 60 | <item> | ||
| 61 | <widget class="QTreeView" name="ban_list_view"/> | ||
| 62 | </item> | ||
| 63 | </layout> | ||
| 64 | </widget> | ||
| 65 | </item> | ||
| 66 | <item> | ||
| 67 | <widget class="QDialogButtonBox" name="buttonBox"> | ||
| 68 | <property name="standardButtons"> | ||
| 69 | <set>QDialogButtonBox::Ok</set> | ||
| 70 | </property> | ||
| 71 | </widget> | ||
| 72 | </item> | ||
| 73 | </layout> | ||
| 74 | </widget> | ||
| 75 | <connections> | ||
| 76 | <connection> | ||
| 77 | <sender>buttonBox</sender> | ||
| 78 | <signal>accepted()</signal> | ||
| 79 | <receiver>ModerationDialog</receiver> | ||
| 80 | <slot>accept()</slot> | ||
| 81 | </connection> | ||
| 82 | </connections> | ||
| 83 | <resources/> | ||
| 84 | </ui> | ||
diff --git a/src/yuzu/multiplayer/state.cpp b/src/yuzu/multiplayer/state.cpp new file mode 100644 index 000000000..b2aaed982 --- /dev/null +++ b/src/yuzu/multiplayer/state.cpp | |||
| @@ -0,0 +1,299 @@ | |||
| 1 | // Copyright 2018 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QAction> | ||
| 6 | #include <QApplication> | ||
| 7 | #include <QIcon> | ||
| 8 | #include <QMessageBox> | ||
| 9 | #include <QStandardItemModel> | ||
| 10 | #include "common/announce_multiplayer_room.h" | ||
| 11 | #include "common/logging/log.h" | ||
| 12 | #include "yuzu/game_list.h" | ||
| 13 | #include "yuzu/multiplayer/client_room.h" | ||
| 14 | #include "yuzu/multiplayer/direct_connect.h" | ||
| 15 | #include "yuzu/multiplayer/host_room.h" | ||
| 16 | #include "yuzu/multiplayer/lobby.h" | ||
| 17 | #include "yuzu/multiplayer/message.h" | ||
| 18 | #include "yuzu/multiplayer/state.h" | ||
| 19 | #include "yuzu/uisettings.h" | ||
| 20 | #include "yuzu/util/clickable_label.h" | ||
| 21 | |||
| 22 | MultiplayerState::MultiplayerState(QWidget* parent, QStandardItemModel* game_list_model, | ||
| 23 | QAction* leave_room, QAction* show_room) | ||
| 24 | : QWidget(parent), game_list_model(game_list_model), leave_room(leave_room), | ||
| 25 | show_room(show_room) { | ||
| 26 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 27 | // register the network structs to use in slots and signals | ||
| 28 | state_callback_handle = member->BindOnStateChanged( | ||
| 29 | [this](const Network::RoomMember::State& state) { emit NetworkStateChanged(state); }); | ||
| 30 | connect(this, &MultiplayerState::NetworkStateChanged, this, | ||
| 31 | &MultiplayerState::OnNetworkStateChanged); | ||
| 32 | error_callback_handle = member->BindOnError( | ||
| 33 | [this](const Network::RoomMember::Error& error) { emit NetworkError(error); }); | ||
| 34 | connect(this, &MultiplayerState::NetworkError, this, &MultiplayerState::OnNetworkError); | ||
| 35 | } | ||
| 36 | |||
| 37 | qRegisterMetaType<Network::RoomMember::State>(); | ||
| 38 | qRegisterMetaType<Network::RoomMember::Error>(); | ||
| 39 | qRegisterMetaType<WebService::WebResult>(); | ||
| 40 | announce_multiplayer_session = std::make_shared<Core::AnnounceMultiplayerSession>(); | ||
| 41 | announce_multiplayer_session->BindErrorCallback( | ||
| 42 | [this](const WebService::WebResult& result) { emit AnnounceFailed(result); }); | ||
| 43 | connect(this, &MultiplayerState::AnnounceFailed, this, &MultiplayerState::OnAnnounceFailed); | ||
| 44 | |||
| 45 | status_text = new ClickableLabel(this); | ||
| 46 | status_icon = new ClickableLabel(this); | ||
| 47 | status_text->setToolTip(tr("Current connection status")); | ||
| 48 | status_text->setText(tr("Not Connected. Click here to find a room!")); | ||
| 49 | status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16)); | ||
| 50 | |||
| 51 | connect(status_text, &ClickableLabel::clicked, this, &MultiplayerState::OnOpenNetworkRoom); | ||
| 52 | connect(status_icon, &ClickableLabel::clicked, this, &MultiplayerState::OnOpenNetworkRoom); | ||
| 53 | |||
| 54 | connect(static_cast<QApplication*>(QApplication::instance()), &QApplication::focusChanged, this, | ||
| 55 | [this](QWidget* /*old*/, QWidget* now) { | ||
| 56 | if (client_room && client_room->isAncestorOf(now)) { | ||
| 57 | HideNotification(); | ||
| 58 | } | ||
| 59 | }); | ||
| 60 | } | ||
| 61 | |||
| 62 | MultiplayerState::~MultiplayerState() { | ||
| 63 | if (state_callback_handle) { | ||
| 64 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 65 | member->Unbind(state_callback_handle); | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | if (error_callback_handle) { | ||
| 70 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 71 | member->Unbind(error_callback_handle); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | void MultiplayerState::Close() { | ||
| 77 | if (host_room) | ||
| 78 | host_room->close(); | ||
| 79 | if (direct_connect) | ||
| 80 | direct_connect->close(); | ||
| 81 | if (client_room) | ||
| 82 | client_room->close(); | ||
| 83 | if (lobby) | ||
| 84 | lobby->close(); | ||
| 85 | } | ||
| 86 | |||
| 87 | void MultiplayerState::retranslateUi() { | ||
| 88 | status_text->setToolTip(tr("Current connection status")); | ||
| 89 | |||
| 90 | if (current_state == Network::RoomMember::State::Uninitialized) { | ||
| 91 | status_text->setText(tr("Not Connected. Click here to find a room!")); | ||
| 92 | } else if (current_state == Network::RoomMember::State::Joined || | ||
| 93 | current_state == Network::RoomMember::State::Moderator) { | ||
| 94 | |||
| 95 | status_text->setText(tr("Connected")); | ||
| 96 | } else { | ||
| 97 | status_text->setText(tr("Not Connected")); | ||
| 98 | } | ||
| 99 | |||
| 100 | if (lobby) | ||
| 101 | lobby->RetranslateUi(); | ||
| 102 | if (host_room) | ||
| 103 | host_room->RetranslateUi(); | ||
| 104 | if (client_room) | ||
| 105 | client_room->RetranslateUi(); | ||
| 106 | if (direct_connect) | ||
| 107 | direct_connect->RetranslateUi(); | ||
| 108 | } | ||
| 109 | |||
| 110 | void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) { | ||
| 111 | LOG_DEBUG(Frontend, "Network State: {}", Network::GetStateStr(state)); | ||
| 112 | if (state == Network::RoomMember::State::Joined || | ||
| 113 | state == Network::RoomMember::State::Moderator) { | ||
| 114 | |||
| 115 | OnOpenNetworkRoom(); | ||
| 116 | status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16)); | ||
| 117 | status_text->setText(tr("Connected")); | ||
| 118 | leave_room->setEnabled(true); | ||
| 119 | show_room->setEnabled(true); | ||
| 120 | } else { | ||
| 121 | status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16)); | ||
| 122 | status_text->setText(tr("Not Connected")); | ||
| 123 | leave_room->setEnabled(false); | ||
| 124 | show_room->setEnabled(false); | ||
| 125 | } | ||
| 126 | |||
| 127 | current_state = state; | ||
| 128 | } | ||
| 129 | |||
| 130 | void MultiplayerState::OnNetworkError(const Network::RoomMember::Error& error) { | ||
| 131 | LOG_DEBUG(Frontend, "Network Error: {}", Network::GetErrorStr(error)); | ||
| 132 | switch (error) { | ||
| 133 | case Network::RoomMember::Error::LostConnection: | ||
| 134 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::LOST_CONNECTION); | ||
| 135 | break; | ||
| 136 | case Network::RoomMember::Error::HostKicked: | ||
| 137 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::HOST_KICKED); | ||
| 138 | break; | ||
| 139 | case Network::RoomMember::Error::CouldNotConnect: | ||
| 140 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::UNABLE_TO_CONNECT); | ||
| 141 | break; | ||
| 142 | case Network::RoomMember::Error::NameCollision: | ||
| 143 | NetworkMessage::ErrorManager::ShowError( | ||
| 144 | NetworkMessage::ErrorManager::USERNAME_NOT_VALID_SERVER); | ||
| 145 | break; | ||
| 146 | case Network::RoomMember::Error::MacCollision: | ||
| 147 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::MAC_COLLISION); | ||
| 148 | break; | ||
| 149 | case Network::RoomMember::Error::ConsoleIdCollision: | ||
| 150 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::CONSOLE_ID_COLLISION); | ||
| 151 | break; | ||
| 152 | case Network::RoomMember::Error::RoomIsFull: | ||
| 153 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::ROOM_IS_FULL); | ||
| 154 | break; | ||
| 155 | case Network::RoomMember::Error::WrongPassword: | ||
| 156 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::WRONG_PASSWORD); | ||
| 157 | break; | ||
| 158 | case Network::RoomMember::Error::WrongVersion: | ||
| 159 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::WRONG_VERSION); | ||
| 160 | break; | ||
| 161 | case Network::RoomMember::Error::HostBanned: | ||
| 162 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::HOST_BANNED); | ||
| 163 | break; | ||
| 164 | case Network::RoomMember::Error::UnknownError: | ||
| 165 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::UNABLE_TO_CONNECT); | ||
| 166 | break; | ||
| 167 | case Network::RoomMember::Error::PermissionDenied: | ||
| 168 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::PERMISSION_DENIED); | ||
| 169 | break; | ||
| 170 | case Network::RoomMember::Error::NoSuchUser: | ||
| 171 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::NO_SUCH_USER); | ||
| 172 | break; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | void MultiplayerState::OnAnnounceFailed(const WebService::WebResult& result) { | ||
| 177 | announce_multiplayer_session->Stop(); | ||
| 178 | QMessageBox::warning(this, tr("Error"), | ||
| 179 | tr("Failed to update the room information. Please check your Internet " | ||
| 180 | "connection and try hosting the room again.\nDebug Message: ") + | ||
| 181 | QString::fromStdString(result.result_string), | ||
| 182 | QMessageBox::Ok); | ||
| 183 | } | ||
| 184 | |||
| 185 | void MultiplayerState::UpdateThemedIcons() { | ||
| 186 | if (show_notification) { | ||
| 187 | status_icon->setPixmap( | ||
| 188 | QIcon::fromTheme(QStringLiteral("connected_notification")).pixmap(16)); | ||
| 189 | } else if (current_state == Network::RoomMember::State::Joined || | ||
| 190 | current_state == Network::RoomMember::State::Moderator) { | ||
| 191 | |||
| 192 | status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16)); | ||
| 193 | } else { | ||
| 194 | status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16)); | ||
| 195 | } | ||
| 196 | if (client_room) | ||
| 197 | client_room->UpdateIconDisplay(); | ||
| 198 | } | ||
| 199 | |||
| 200 | static void BringWidgetToFront(QWidget* widget) { | ||
| 201 | widget->show(); | ||
| 202 | widget->activateWindow(); | ||
| 203 | widget->raise(); | ||
| 204 | } | ||
| 205 | |||
| 206 | void MultiplayerState::OnViewLobby() { | ||
| 207 | if (lobby == nullptr) { | ||
| 208 | lobby = new Lobby(this, game_list_model, announce_multiplayer_session); | ||
| 209 | } | ||
| 210 | BringWidgetToFront(lobby); | ||
| 211 | } | ||
| 212 | |||
| 213 | void MultiplayerState::OnCreateRoom() { | ||
| 214 | if (host_room == nullptr) { | ||
| 215 | host_room = new HostRoomWindow(this, game_list_model, announce_multiplayer_session); | ||
| 216 | } | ||
| 217 | BringWidgetToFront(host_room); | ||
| 218 | } | ||
| 219 | |||
| 220 | bool MultiplayerState::OnCloseRoom() { | ||
| 221 | if (!NetworkMessage::WarnCloseRoom()) | ||
| 222 | return false; | ||
| 223 | if (auto room = Network::GetRoom().lock()) { | ||
| 224 | // if you are in a room, leave it | ||
| 225 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 226 | member->Leave(); | ||
| 227 | LOG_DEBUG(Frontend, "Left the room (as a client)"); | ||
| 228 | } | ||
| 229 | |||
| 230 | // if you are hosting a room, also stop hosting | ||
| 231 | if (room->GetState() != Network::Room::State::Open) { | ||
| 232 | return true; | ||
| 233 | } | ||
| 234 | // Save ban list | ||
| 235 | UISettings::values.ban_list = std::move(room->GetBanList()); | ||
| 236 | |||
| 237 | room->Destroy(); | ||
| 238 | announce_multiplayer_session->Stop(); | ||
| 239 | LOG_DEBUG(Frontend, "Closed the room (as a server)"); | ||
| 240 | } | ||
| 241 | return true; | ||
| 242 | } | ||
| 243 | |||
| 244 | void MultiplayerState::ShowNotification() { | ||
| 245 | if (client_room && client_room->isAncestorOf(QApplication::focusWidget())) | ||
| 246 | return; // Do not show notification if the chat window currently has focus | ||
| 247 | show_notification = true; | ||
| 248 | QApplication::alert(nullptr); | ||
| 249 | status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected_notification")).pixmap(16)); | ||
| 250 | status_text->setText(tr("New Messages Received")); | ||
| 251 | } | ||
| 252 | |||
| 253 | void MultiplayerState::HideNotification() { | ||
| 254 | show_notification = false; | ||
| 255 | status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16)); | ||
| 256 | status_text->setText(tr("Connected")); | ||
| 257 | } | ||
| 258 | |||
| 259 | void MultiplayerState::OnOpenNetworkRoom() { | ||
| 260 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 261 | if (member->IsConnected()) { | ||
| 262 | if (client_room == nullptr) { | ||
| 263 | client_room = new ClientRoomWindow(this); | ||
| 264 | connect(client_room, &ClientRoomWindow::ShowNotification, this, | ||
| 265 | &MultiplayerState::ShowNotification); | ||
| 266 | } | ||
| 267 | BringWidgetToFront(client_room); | ||
| 268 | return; | ||
| 269 | } | ||
| 270 | } | ||
| 271 | // If the user is not a member of a room, show the lobby instead. | ||
| 272 | // This is currently only used on the clickable label in the status bar | ||
| 273 | OnViewLobby(); | ||
| 274 | } | ||
| 275 | |||
| 276 | void MultiplayerState::OnDirectConnectToRoom() { | ||
| 277 | if (direct_connect == nullptr) { | ||
| 278 | direct_connect = new DirectConnectWindow(this); | ||
| 279 | } | ||
| 280 | BringWidgetToFront(direct_connect); | ||
| 281 | } | ||
| 282 | |||
| 283 | bool MultiplayerState::IsHostingPublicRoom() const { | ||
| 284 | return announce_multiplayer_session->IsRunning(); | ||
| 285 | } | ||
| 286 | |||
| 287 | void MultiplayerState::UpdateCredentials() { | ||
| 288 | announce_multiplayer_session->UpdateCredentials(); | ||
| 289 | } | ||
| 290 | |||
| 291 | void MultiplayerState::UpdateGameList(QStandardItemModel* game_list) { | ||
| 292 | game_list_model = game_list; | ||
| 293 | if (lobby) { | ||
| 294 | lobby->UpdateGameList(game_list); | ||
| 295 | } | ||
| 296 | if (host_room) { | ||
| 297 | host_room->UpdateGameList(game_list); | ||
| 298 | } | ||
| 299 | } | ||
diff --git a/src/yuzu/multiplayer/state.h b/src/yuzu/multiplayer/state.h new file mode 100644 index 000000000..414454acb --- /dev/null +++ b/src/yuzu/multiplayer/state.h | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | // Copyright 2018 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 <QWidget> | ||
| 8 | #include "core/announce_multiplayer_session.h" | ||
| 9 | #include "network/network.h" | ||
| 10 | |||
| 11 | class QStandardItemModel; | ||
| 12 | class Lobby; | ||
| 13 | class HostRoomWindow; | ||
| 14 | class ClientRoomWindow; | ||
| 15 | class DirectConnectWindow; | ||
| 16 | class ClickableLabel; | ||
| 17 | |||
| 18 | class MultiplayerState : public QWidget { | ||
| 19 | Q_OBJECT; | ||
| 20 | |||
| 21 | public: | ||
| 22 | explicit MultiplayerState(QWidget* parent, QStandardItemModel* game_list, QAction* leave_room, | ||
| 23 | QAction* show_room); | ||
| 24 | ~MultiplayerState(); | ||
| 25 | |||
| 26 | /** | ||
| 27 | * Close all open multiplayer related dialogs | ||
| 28 | */ | ||
| 29 | void Close(); | ||
| 30 | |||
| 31 | ClickableLabel* GetStatusText() const { | ||
| 32 | return status_text; | ||
| 33 | } | ||
| 34 | |||
| 35 | ClickableLabel* GetStatusIcon() const { | ||
| 36 | return status_icon; | ||
| 37 | } | ||
| 38 | |||
| 39 | void retranslateUi(); | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Whether a public room is being hosted or not. | ||
| 43 | * When this is true, Web Services configuration should be disabled. | ||
| 44 | */ | ||
| 45 | bool IsHostingPublicRoom() const; | ||
| 46 | |||
| 47 | void UpdateCredentials(); | ||
| 48 | |||
| 49 | /** | ||
| 50 | * Updates the multiplayer dialogs with a new game list model. | ||
| 51 | * This model should be the original model of the game list. | ||
| 52 | */ | ||
| 53 | void UpdateGameList(QStandardItemModel* game_list); | ||
| 54 | |||
| 55 | public slots: | ||
| 56 | void OnNetworkStateChanged(const Network::RoomMember::State& state); | ||
| 57 | void OnNetworkError(const Network::RoomMember::Error& error); | ||
| 58 | void OnViewLobby(); | ||
| 59 | void OnCreateRoom(); | ||
| 60 | bool OnCloseRoom(); | ||
| 61 | void OnOpenNetworkRoom(); | ||
| 62 | void OnDirectConnectToRoom(); | ||
| 63 | void OnAnnounceFailed(const WebService::WebResult&); | ||
| 64 | void UpdateThemedIcons(); | ||
| 65 | void ShowNotification(); | ||
| 66 | void HideNotification(); | ||
| 67 | |||
| 68 | signals: | ||
| 69 | void NetworkStateChanged(const Network::RoomMember::State&); | ||
| 70 | void NetworkError(const Network::RoomMember::Error&); | ||
| 71 | void AnnounceFailed(const WebService::WebResult&); | ||
| 72 | |||
| 73 | private: | ||
| 74 | Lobby* lobby = nullptr; | ||
| 75 | HostRoomWindow* host_room = nullptr; | ||
| 76 | ClientRoomWindow* client_room = nullptr; | ||
| 77 | DirectConnectWindow* direct_connect = nullptr; | ||
| 78 | ClickableLabel* status_icon = nullptr; | ||
| 79 | ClickableLabel* status_text = nullptr; | ||
| 80 | QStandardItemModel* game_list_model = nullptr; | ||
| 81 | QAction* leave_room; | ||
| 82 | QAction* show_room; | ||
| 83 | std::shared_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; | ||
| 84 | Network::RoomMember::State current_state = Network::RoomMember::State::Uninitialized; | ||
| 85 | bool has_mod_perms = false; | ||
| 86 | Network::RoomMember::CallbackHandle<Network::RoomMember::State> state_callback_handle; | ||
| 87 | Network::RoomMember::CallbackHandle<Network::RoomMember::Error> error_callback_handle; | ||
| 88 | |||
| 89 | bool show_notification = false; | ||
| 90 | }; | ||
| 91 | |||
| 92 | Q_DECLARE_METATYPE(WebService::WebResult); | ||
diff --git a/src/yuzu/multiplayer/validation.h b/src/yuzu/multiplayer/validation.h new file mode 100644 index 000000000..1c215a190 --- /dev/null +++ b/src/yuzu/multiplayer/validation.h | |||
| @@ -0,0 +1,49 @@ | |||
| 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 <QRegExp> | ||
| 8 | #include <QString> | ||
| 9 | #include <QValidator> | ||
| 10 | |||
| 11 | class Validation { | ||
| 12 | public: | ||
| 13 | Validation() | ||
| 14 | : room_name(room_name_regex), nickname(nickname_regex), ip(ip_regex), port(0, 65535) {} | ||
| 15 | |||
| 16 | ~Validation() = default; | ||
| 17 | |||
| 18 | const QValidator* GetRoomName() const { | ||
| 19 | return &room_name; | ||
| 20 | } | ||
| 21 | const QValidator* GetNickname() const { | ||
| 22 | return &nickname; | ||
| 23 | } | ||
| 24 | const QValidator* GetIP() const { | ||
| 25 | return &ip; | ||
| 26 | } | ||
| 27 | const QValidator* GetPort() const { | ||
| 28 | return &port; | ||
| 29 | } | ||
| 30 | |||
| 31 | private: | ||
| 32 | /// room name can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20 | ||
| 33 | QRegExp room_name_regex = QRegExp(QStringLiteral("^[a-zA-Z0-9._- ]{4,20}$")); | ||
| 34 | QRegExpValidator room_name; | ||
| 35 | |||
| 36 | /// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20 | ||
| 37 | QRegExp nickname_regex = QRegExp(QStringLiteral("^[a-zA-Z0-9._- ]{4,20}$")); | ||
| 38 | QRegExpValidator nickname; | ||
| 39 | |||
| 40 | /// ipv4 address only | ||
| 41 | // TODO remove this when we support hostnames in direct connect | ||
| 42 | QRegExp ip_regex = QRegExp(QStringLiteral( | ||
| 43 | "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|" | ||
| 44 | "2[0-4][0-9]|25[0-5])")); | ||
| 45 | QRegExpValidator ip; | ||
| 46 | |||
| 47 | /// port must be between 0 and 65535 | ||
| 48 | QIntValidator port; | ||
| 49 | }; | ||
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h index 2f6948243..aca1a28e1 100644 --- a/src/yuzu/uisettings.h +++ b/src/yuzu/uisettings.h | |||
| @@ -102,6 +102,19 @@ struct Values { | |||
| 102 | 102 | ||
| 103 | Settings::Setting<uint32_t> callout_flags{0, "calloutFlags"}; | 103 | Settings::Setting<uint32_t> callout_flags{0, "calloutFlags"}; |
| 104 | 104 | ||
| 105 | // multiplayer settings | ||
| 106 | QString nickname; | ||
| 107 | QString ip; | ||
| 108 | QString port; | ||
| 109 | QString room_nickname; | ||
| 110 | QString room_name; | ||
| 111 | quint32 max_player; | ||
| 112 | QString room_port; | ||
| 113 | uint host_type; | ||
| 114 | qulonglong game_id; | ||
| 115 | QString room_description; | ||
| 116 | std::pair<std::vector<std::string>, std::vector<std::string>> ban_list; | ||
| 117 | |||
| 105 | // logging | 118 | // logging |
| 106 | Settings::Setting<bool> show_console{false, "showConsole"}; | 119 | Settings::Setting<bool> show_console{false, "showConsole"}; |
| 107 | 120 | ||
diff --git a/src/yuzu/util/clickable_label.cpp b/src/yuzu/util/clickable_label.cpp new file mode 100644 index 000000000..5bde838ca --- /dev/null +++ b/src/yuzu/util/clickable_label.cpp | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "yuzu/util/clickable_label.h" | ||
| 6 | |||
| 7 | ClickableLabel::ClickableLabel(QWidget* parent, [[maybe_unused]] Qt::WindowFlags f) | ||
| 8 | : QLabel(parent) {} | ||
| 9 | |||
| 10 | void ClickableLabel::mouseReleaseEvent([[maybe_unused]] QMouseEvent* event) { | ||
| 11 | emit clicked(); | ||
| 12 | } | ||
diff --git a/src/yuzu/util/clickable_label.h b/src/yuzu/util/clickable_label.h new file mode 100644 index 000000000..3c65a74be --- /dev/null +++ b/src/yuzu/util/clickable_label.h | |||
| @@ -0,0 +1,22 @@ | |||
| 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 <QLabel> | ||
| 8 | #include <QWidget> | ||
| 9 | |||
| 10 | class ClickableLabel : public QLabel { | ||
| 11 | Q_OBJECT | ||
| 12 | |||
| 13 | public: | ||
| 14 | explicit ClickableLabel(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); | ||
| 15 | ~ClickableLabel() = default; | ||
| 16 | |||
| 17 | signals: | ||
| 18 | void clicked(); | ||
| 19 | |||
| 20 | protected: | ||
| 21 | void mouseReleaseEvent(QMouseEvent* event); | ||
| 22 | }; | ||
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index cb301e78b..0194940be 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <chrono> | 5 | #include <chrono> |
| 6 | #include <iostream> | 6 | #include <iostream> |
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <regex> | ||
| 8 | #include <string> | 9 | #include <string> |
| 9 | #include <thread> | 10 | #include <thread> |
| 10 | 11 | ||
| @@ -29,6 +30,7 @@ | |||
| 29 | #include "core/loader/loader.h" | 30 | #include "core/loader/loader.h" |
| 30 | #include "core/telemetry_session.h" | 31 | #include "core/telemetry_session.h" |
| 31 | #include "input_common/main.h" | 32 | #include "input_common/main.h" |
| 33 | #include "network/network.h" | ||
| 32 | #include "video_core/renderer_base.h" | 34 | #include "video_core/renderer_base.h" |
| 33 | #include "yuzu_cmd/config.h" | 35 | #include "yuzu_cmd/config.h" |
| 34 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" | 36 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" |
| @@ -60,6 +62,8 @@ __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1; | |||
| 60 | static void PrintHelp(const char* argv0) { | 62 | static void PrintHelp(const char* argv0) { |
| 61 | std::cout << "Usage: " << argv0 | 63 | std::cout << "Usage: " << argv0 |
| 62 | << " [options] <filename>\n" | 64 | << " [options] <filename>\n" |
| 65 | "-m, --multiplayer=nick:password@address:port" | ||
| 66 | " Nickname, password, address and port for multiplayer\n" | ||
| 63 | "-f, --fullscreen Start in fullscreen mode\n" | 67 | "-f, --fullscreen Start in fullscreen mode\n" |
| 64 | "-h, --help Display this help and exit\n" | 68 | "-h, --help Display this help and exit\n" |
| 65 | "-v, --version Output version information and exit\n" | 69 | "-v, --version Output version information and exit\n" |
| @@ -71,6 +75,107 @@ static void PrintVersion() { | |||
| 71 | std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl; | 75 | std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl; |
| 72 | } | 76 | } |
| 73 | 77 | ||
| 78 | static void OnStateChanged(const Network::RoomMember::State& state) { | ||
| 79 | switch (state) { | ||
| 80 | case Network::RoomMember::State::Idle: | ||
| 81 | LOG_DEBUG(Network, "Network is idle"); | ||
| 82 | break; | ||
| 83 | case Network::RoomMember::State::Joining: | ||
| 84 | LOG_DEBUG(Network, "Connection sequence to room started"); | ||
| 85 | break; | ||
| 86 | case Network::RoomMember::State::Joined: | ||
| 87 | LOG_DEBUG(Network, "Successfully joined to the room"); | ||
| 88 | break; | ||
| 89 | case Network::RoomMember::State::Moderator: | ||
| 90 | LOG_DEBUG(Network, "Successfully joined the room as a moderator"); | ||
| 91 | break; | ||
| 92 | default: | ||
| 93 | break; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | static void OnNetworkError(const Network::RoomMember::Error& error) { | ||
| 98 | switch (error) { | ||
| 99 | case Network::RoomMember::Error::LostConnection: | ||
| 100 | LOG_DEBUG(Network, "Lost connection to the room"); | ||
| 101 | break; | ||
| 102 | case Network::RoomMember::Error::CouldNotConnect: | ||
| 103 | LOG_ERROR(Network, "Error: Could not connect"); | ||
| 104 | exit(1); | ||
| 105 | break; | ||
| 106 | case Network::RoomMember::Error::NameCollision: | ||
| 107 | LOG_ERROR( | ||
| 108 | Network, | ||
| 109 | "You tried to use the same nickname as another user that is connected to the Room"); | ||
| 110 | exit(1); | ||
| 111 | break; | ||
| 112 | case Network::RoomMember::Error::MacCollision: | ||
| 113 | LOG_ERROR(Network, "You tried to use the same MAC-Address as another user that is " | ||
| 114 | "connected to the Room"); | ||
| 115 | exit(1); | ||
| 116 | break; | ||
| 117 | case Network::RoomMember::Error::ConsoleIdCollision: | ||
| 118 | LOG_ERROR(Network, "Your Console ID conflicted with someone else in the Room"); | ||
| 119 | exit(1); | ||
| 120 | break; | ||
| 121 | case Network::RoomMember::Error::WrongPassword: | ||
| 122 | LOG_ERROR(Network, "Room replied with: Wrong password"); | ||
| 123 | exit(1); | ||
| 124 | break; | ||
| 125 | case Network::RoomMember::Error::WrongVersion: | ||
| 126 | LOG_ERROR(Network, | ||
| 127 | "You are using a different version than the room you are trying to connect to"); | ||
| 128 | exit(1); | ||
| 129 | break; | ||
| 130 | case Network::RoomMember::Error::RoomIsFull: | ||
| 131 | LOG_ERROR(Network, "The room is full"); | ||
| 132 | exit(1); | ||
| 133 | break; | ||
| 134 | case Network::RoomMember::Error::HostKicked: | ||
| 135 | LOG_ERROR(Network, "You have been kicked by the host"); | ||
| 136 | break; | ||
| 137 | case Network::RoomMember::Error::HostBanned: | ||
| 138 | LOG_ERROR(Network, "You have been banned by the host"); | ||
| 139 | break; | ||
| 140 | case Network::RoomMember::Error::UnknownError: | ||
| 141 | LOG_ERROR(Network, "UnknownError"); | ||
| 142 | break; | ||
| 143 | case Network::RoomMember::Error::PermissionDenied: | ||
| 144 | LOG_ERROR(Network, "PermissionDenied"); | ||
| 145 | break; | ||
| 146 | case Network::RoomMember::Error::NoSuchUser: | ||
| 147 | LOG_ERROR(Network, "NoSuchUser"); | ||
| 148 | break; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | |||
| 152 | static void OnMessageReceived(const Network::ChatEntry& msg) { | ||
| 153 | std::cout << std::endl << msg.nickname << ": " << msg.message << std::endl << std::endl; | ||
| 154 | } | ||
| 155 | |||
| 156 | static void OnStatusMessageReceived(const Network::StatusMessageEntry& msg) { | ||
| 157 | std::string message; | ||
| 158 | switch (msg.type) { | ||
| 159 | case Network::IdMemberJoin: | ||
| 160 | message = fmt::format("{} has joined", msg.nickname); | ||
| 161 | break; | ||
| 162 | case Network::IdMemberLeave: | ||
| 163 | message = fmt::format("{} has left", msg.nickname); | ||
| 164 | break; | ||
| 165 | case Network::IdMemberKicked: | ||
| 166 | message = fmt::format("{} has been kicked", msg.nickname); | ||
| 167 | break; | ||
| 168 | case Network::IdMemberBanned: | ||
| 169 | message = fmt::format("{} has been banned", msg.nickname); | ||
| 170 | break; | ||
| 171 | case Network::IdAddressUnbanned: | ||
| 172 | message = fmt::format("{} has been unbanned", msg.nickname); | ||
| 173 | break; | ||
| 174 | } | ||
| 175 | if (!message.empty()) | ||
| 176 | std::cout << std::endl << "* " << message << std::endl << std::endl; | ||
| 177 | } | ||
| 178 | |||
| 74 | /// Application entry point | 179 | /// Application entry point |
| 75 | int main(int argc, char** argv) { | 180 | int main(int argc, char** argv) { |
| 76 | Common::Log::Initialize(); | 181 | Common::Log::Initialize(); |
| @@ -92,10 +197,16 @@ int main(int argc, char** argv) { | |||
| 92 | std::optional<std::string> config_path; | 197 | std::optional<std::string> config_path; |
| 93 | std::string program_args; | 198 | std::string program_args; |
| 94 | 199 | ||
| 200 | bool use_multiplayer = false; | ||
| 95 | bool fullscreen = false; | 201 | bool fullscreen = false; |
| 202 | std::string nickname{}; | ||
| 203 | std::string password{}; | ||
| 204 | std::string address{}; | ||
| 205 | u16 port = Network::DefaultRoomPort; | ||
| 96 | 206 | ||
| 97 | static struct option long_options[] = { | 207 | static struct option long_options[] = { |
| 98 | // clang-format off | 208 | // clang-format off |
| 209 | {"multiplayer", required_argument, 0, 'm'}, | ||
| 99 | {"fullscreen", no_argument, 0, 'f'}, | 210 | {"fullscreen", no_argument, 0, 'f'}, |
| 100 | {"help", no_argument, 0, 'h'}, | 211 | {"help", no_argument, 0, 'h'}, |
| 101 | {"version", no_argument, 0, 'v'}, | 212 | {"version", no_argument, 0, 'v'}, |
| @@ -109,6 +220,38 @@ int main(int argc, char** argv) { | |||
| 109 | int arg = getopt_long(argc, argv, "g:fhvp::c:", long_options, &option_index); | 220 | int arg = getopt_long(argc, argv, "g:fhvp::c:", long_options, &option_index); |
| 110 | if (arg != -1) { | 221 | if (arg != -1) { |
| 111 | switch (static_cast<char>(arg)) { | 222 | switch (static_cast<char>(arg)) { |
| 223 | case 'm': { | ||
| 224 | use_multiplayer = true; | ||
| 225 | const std::string str_arg(optarg); | ||
| 226 | // regex to check if the format is nickname:password@ip:port | ||
| 227 | // with optional :password | ||
| 228 | const std::regex re("^([^:]+)(?::(.+))?@([^:]+)(?::([0-9]+))?$"); | ||
| 229 | if (!std::regex_match(str_arg, re)) { | ||
| 230 | std::cout << "Wrong format for option --multiplayer\n"; | ||
| 231 | PrintHelp(argv[0]); | ||
| 232 | return 0; | ||
| 233 | } | ||
| 234 | |||
| 235 | std::smatch match; | ||
| 236 | std::regex_search(str_arg, match, re); | ||
| 237 | ASSERT(match.size() == 5); | ||
| 238 | nickname = match[1]; | ||
| 239 | password = match[2]; | ||
| 240 | address = match[3]; | ||
| 241 | if (!match[4].str().empty()) | ||
| 242 | port = std::stoi(match[4]); | ||
| 243 | std::regex nickname_re("^[a-zA-Z0-9._\\- ]+$"); | ||
| 244 | if (!std::regex_match(nickname, nickname_re)) { | ||
| 245 | std::cout | ||
| 246 | << "Nickname is not valid. Must be 4 to 20 alphanumeric characters.\n"; | ||
| 247 | return 0; | ||
| 248 | } | ||
| 249 | if (address.empty()) { | ||
| 250 | std::cout << "Address to room must not be empty.\n"; | ||
| 251 | return 0; | ||
| 252 | } | ||
| 253 | break; | ||
| 254 | } | ||
| 112 | case 'f': | 255 | case 'f': |
| 113 | fullscreen = true; | 256 | fullscreen = true; |
| 114 | LOG_INFO(Frontend, "Starting in fullscreen mode..."); | 257 | LOG_INFO(Frontend, "Starting in fullscreen mode..."); |
| @@ -215,6 +358,21 @@ int main(int argc, char** argv) { | |||
| 215 | 358 | ||
| 216 | system.TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "SDL"); | 359 | system.TelemetrySession().AddField(Common::Telemetry::FieldType::App, "Frontend", "SDL"); |
| 217 | 360 | ||
| 361 | if (use_multiplayer) { | ||
| 362 | if (auto member = Network::GetRoomMember().lock()) { | ||
| 363 | member->BindOnChatMessageRecieved(OnMessageReceived); | ||
| 364 | member->BindOnStatusMessageReceived(OnStatusMessageReceived); | ||
| 365 | member->BindOnStateChanged(OnStateChanged); | ||
| 366 | member->BindOnError(OnNetworkError); | ||
| 367 | LOG_DEBUG(Network, "Start connection to {}:{} with nickname {}", address, port, | ||
| 368 | nickname); | ||
| 369 | member->Join(nickname, "", address.c_str(), port, 0, Network::NoPreferredMac, password); | ||
| 370 | } else { | ||
| 371 | LOG_ERROR(Network, "Could not access RoomMember"); | ||
| 372 | return 0; | ||
| 373 | } | ||
| 374 | } | ||
| 375 | |||
| 218 | // Core is loaded, start the GPU (makes the GPU contexts current to this thread) | 376 | // Core is loaded, start the GPU (makes the GPU contexts current to this thread) |
| 219 | system.GPU().Start(); | 377 | system.GPU().Start(); |
| 220 | system.GetCpuManager().OnGpuReady(); | 378 | system.GetCpuManager().OnGpuReady(); |