diff options
| author | 2022-08-01 22:47:39 +0200 | |
|---|---|---|
| committer | 2022-08-15 20:25:42 +0200 | |
| commit | 6d41088153b4b932b4f2524d4252993a5642f998 (patch) | |
| tree | 39ea8d5749f2a5bf9216b885780617e7f41c2a7e | |
| parent | core/socket_proxy: Fix compilation (diff) | |
| download | yuzu-6d41088153b4b932b4f2524d4252993a5642f998.tar.gz yuzu-6d41088153b4b932b4f2524d4252993a5642f998.tar.xz yuzu-6d41088153b4b932b4f2524d4252993a5642f998.zip | |
core, yuzu: Address first part of review comments
| -rw-r--r-- | src/core/announce_multiplayer_session.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/service/nifm/nifm.cpp | 1 | ||||
| -rw-r--r-- | src/core/internal_network/network.cpp | 8 | ||||
| -rw-r--r-- | src/core/internal_network/socket_proxy.cpp | 10 | ||||
| -rw-r--r-- | src/core/internal_network/socket_proxy.h | 3 | ||||
| -rw-r--r-- | src/core/internal_network/sockets.h | 6 | ||||
| -rw-r--r-- | src/dedicated_room/yuzu-room.cpp | 100 | ||||
| -rw-r--r-- | src/yuzu/multiplayer/validation.h | 2 | ||||
| -rw-r--r-- | src/yuzu/uisettings.h | 5 |
9 files changed, 70 insertions, 71 deletions
diff --git a/src/core/announce_multiplayer_session.cpp b/src/core/announce_multiplayer_session.cpp index d73a488cf..6737ce85a 100644 --- a/src/core/announce_multiplayer_session.cpp +++ b/src/core/announce_multiplayer_session.cpp | |||
| @@ -31,7 +31,7 @@ AnnounceMultiplayerSession::AnnounceMultiplayerSession(Network::RoomNetwork& roo | |||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | WebService::WebResult AnnounceMultiplayerSession::Register() { | 33 | WebService::WebResult AnnounceMultiplayerSession::Register() { |
| 34 | std::shared_ptr<Network::Room> room = room_network.GetRoom().lock(); | 34 | auto room = room_network.GetRoom().lock(); |
| 35 | if (!room) { | 35 | if (!room) { |
| 36 | return WebService::WebResult{WebService::WebResult::Code::LibError, | 36 | return WebService::WebResult{WebService::WebResult::Code::LibError, |
| 37 | "Network is not initialized", ""}; | 37 | "Network is not initialized", ""}; |
| @@ -102,7 +102,7 @@ void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room | |||
| 102 | void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { | 102 | void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { |
| 103 | // Invokes all current bound error callbacks. | 103 | // Invokes all current bound error callbacks. |
| 104 | const auto ErrorCallback = [this](WebService::WebResult result) { | 104 | const auto ErrorCallback = [this](WebService::WebResult result) { |
| 105 | std::lock_guard<std::mutex> lock(callback_mutex); | 105 | std::lock_guard lock(callback_mutex); |
| 106 | for (auto callback : error_callbacks) { | 106 | for (auto callback : error_callbacks) { |
| 107 | (*callback)(result); | 107 | (*callback)(result); |
| 108 | } | 108 | } |
| @@ -120,7 +120,7 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { | |||
| 120 | std::future<WebService::WebResult> future; | 120 | std::future<WebService::WebResult> future; |
| 121 | while (!shutdown_event.WaitUntil(update_time)) { | 121 | while (!shutdown_event.WaitUntil(update_time)) { |
| 122 | update_time += announce_time_interval; | 122 | update_time += announce_time_interval; |
| 123 | std::shared_ptr<Network::Room> room = room_network.GetRoom().lock(); | 123 | auto room = room_network.GetRoom().lock(); |
| 124 | if (!room) { | 124 | if (!room) { |
| 125 | break; | 125 | break; |
| 126 | } | 126 | } |
diff --git a/src/core/hle/service/nifm/nifm.cpp b/src/core/hle/service/nifm/nifm.cpp index 42ed17187..e3ef06481 100644 --- a/src/core/hle/service/nifm/nifm.cpp +++ b/src/core/hle/service/nifm/nifm.cpp | |||
| @@ -381,6 +381,7 @@ void IGeneralService::GetCurrentIpAddress(Kernel::HLERequestContext& ctx) { | |||
| 381 | rb.Push(ResultSuccess); | 381 | rb.Push(ResultSuccess); |
| 382 | rb.PushRaw(*ipv4); | 382 | rb.PushRaw(*ipv4); |
| 383 | } | 383 | } |
| 384 | |||
| 384 | void IGeneralService::CreateTemporaryNetworkProfile(Kernel::HLERequestContext& ctx) { | 385 | void IGeneralService::CreateTemporaryNetworkProfile(Kernel::HLERequestContext& ctx) { |
| 385 | LOG_DEBUG(Service_NIFM, "called"); | 386 | LOG_DEBUG(Service_NIFM, "called"); |
| 386 | 387 | ||
diff --git a/src/core/internal_network/network.cpp b/src/core/internal_network/network.cpp index 160cc83e4..3b6906f7d 100644 --- a/src/core/internal_network/network.cpp +++ b/src/core/internal_network/network.cpp | |||
| @@ -352,8 +352,8 @@ std::optional<IPv4Address> GetHostIPv4Address() { | |||
| 352 | return {}; | 352 | return {}; |
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | char ip_addr[16] = {}; | 355 | std::array<char, 16> ip_addr = {}; |
| 356 | ASSERT(inet_ntop(AF_INET, &interface->ip_address, ip_addr, sizeof(ip_addr)) != nullptr); | 356 | ASSERT(inet_ntop(AF_INET, &interface->ip_address, ip_addr.data(), sizeof(ip_addr)) != nullptr); |
| 357 | return TranslateIPv4(interface->ip_address); | 357 | return TranslateIPv4(interface->ip_address); |
| 358 | } | 358 | } |
| 359 | 359 | ||
| @@ -402,9 +402,9 @@ Socket::Socket(Socket&& rhs) noexcept { | |||
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | template <typename T> | 404 | template <typename T> |
| 405 | Errno Socket::SetSockOpt(SOCKET _fd, int option, T value) { | 405 | Errno Socket::SetSockOpt(SOCKET fd_, int option, T value) { |
| 406 | const int result = | 406 | const int result = |
| 407 | setsockopt(_fd, SOL_SOCKET, option, reinterpret_cast<const char*>(&value), sizeof(value)); | 407 | setsockopt(fd_, SOL_SOCKET, option, reinterpret_cast<const char*>(&value), sizeof(value)); |
| 408 | if (result != SOCKET_ERROR) { | 408 | if (result != SOCKET_ERROR) { |
| 409 | return Errno::SUCCESS; | 409 | return Errno::SUCCESS; |
| 410 | } | 410 | } |
diff --git a/src/core/internal_network/socket_proxy.cpp b/src/core/internal_network/socket_proxy.cpp index b9c50430e..216893ba1 100644 --- a/src/core/internal_network/socket_proxy.cpp +++ b/src/core/internal_network/socket_proxy.cpp | |||
| @@ -30,19 +30,19 @@ void ProxySocket::HandleProxyPacket(const ProxyPacket& packet) { | |||
| 30 | closed) { | 30 | closed) { |
| 31 | return; | 31 | return; |
| 32 | } | 32 | } |
| 33 | std::lock_guard<std::mutex> guard(packets_mutex); | 33 | std::lock_guard guard(packets_mutex); |
| 34 | received_packets.push(packet); | 34 | received_packets.push(packet); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | template <typename T> | 37 | template <typename T> |
| 38 | Errno ProxySocket::SetSockOpt(SOCKET _fd, int option, T value) { | 38 | Errno ProxySocket::SetSockOpt(SOCKET fd_, int option, T value) { |
| 39 | socket_options[option] = reinterpret_cast<const char*>(&value); | 39 | socket_options[option] = reinterpret_cast<const char*>(&value); |
| 40 | return Errno::SUCCESS; | 40 | return Errno::SUCCESS; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | Errno ProxySocket::Initialize(Domain domain, Type type, Protocol socket_protocol) { | 43 | Errno ProxySocket::Initialize(Domain domain, Type type, Protocol socket_protocol) { |
| 44 | protocol = socket_protocol; | 44 | protocol = socket_protocol; |
| 45 | socket_options[0x1008] = reinterpret_cast<const char*>(&type); | 45 | SetSockOpt(fd, SO_TYPE, type); |
| 46 | 46 | ||
| 47 | return Errno::SUCCESS; | 47 | return Errno::SUCCESS; |
| 48 | } | 48 | } |
| @@ -101,7 +101,7 @@ std::pair<s32, Errno> ProxySocket::RecvFrom(int flags, std::vector<u8>& message, | |||
| 101 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); | 101 | ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max())); |
| 102 | 102 | ||
| 103 | { | 103 | { |
| 104 | std::lock_guard<std::mutex> guard(packets_mutex); | 104 | std::lock_guard guard(packets_mutex); |
| 105 | if (received_packets.size() > 0) { | 105 | if (received_packets.size() > 0) { |
| 106 | return ReceivePacket(flags, message, addr, message.size()); | 106 | return ReceivePacket(flags, message, addr, message.size()); |
| 107 | } | 107 | } |
| @@ -115,7 +115,7 @@ std::pair<s32, Errno> ProxySocket::RecvFrom(int flags, std::vector<u8>& message, | |||
| 115 | return {-1, Errno::AGAIN}; | 115 | return {-1, Errno::AGAIN}; |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | std::lock_guard<std::mutex> guard(packets_mutex); | 118 | std::lock_guard guard(packets_mutex); |
| 119 | if (received_packets.size() > 0) { | 119 | if (received_packets.size() > 0) { |
| 120 | return ReceivePacket(flags, message, addr, message.size()); | 120 | return ReceivePacket(flags, message, addr, message.size()); |
| 121 | } | 121 | } |
diff --git a/src/core/internal_network/socket_proxy.h b/src/core/internal_network/socket_proxy.h index c9155f1af..ad917cac3 100644 --- a/src/core/internal_network/socket_proxy.h +++ b/src/core/internal_network/socket_proxy.h | |||
| @@ -14,7 +14,7 @@ namespace Network { | |||
| 14 | 14 | ||
| 15 | class ProxySocket : public SocketBase { | 15 | class ProxySocket : public SocketBase { |
| 16 | public: | 16 | public: |
| 17 | ProxySocket(RoomNetwork& room_network_) noexcept; | 17 | explicit ProxySocket(RoomNetwork& room_network_) noexcept; |
| 18 | ~ProxySocket() override; | 18 | ~ProxySocket() override; |
| 19 | 19 | ||
| 20 | ProxySocket(const ProxySocket&) = delete; | 20 | ProxySocket(const ProxySocket&) = delete; |
| @@ -82,6 +82,7 @@ public: | |||
| 82 | 82 | ||
| 83 | bool IsOpened() const override; | 83 | bool IsOpened() const override; |
| 84 | 84 | ||
| 85 | private: | ||
| 85 | bool broadcast = false; | 86 | bool broadcast = false; |
| 86 | bool closed = false; | 87 | bool closed = false; |
| 87 | u32 send_timeout = 0; | 88 | u32 send_timeout = 0; |
diff --git a/src/core/internal_network/sockets.h b/src/core/internal_network/sockets.h index 92dc49993..a70429b19 100644 --- a/src/core/internal_network/sockets.h +++ b/src/core/internal_network/sockets.h | |||
| @@ -32,7 +32,7 @@ public: | |||
| 32 | std::unique_ptr<SocketBase> socket; | 32 | std::unique_ptr<SocketBase> socket; |
| 33 | SockAddrIn sockaddr_in; | 33 | SockAddrIn sockaddr_in; |
| 34 | }; | 34 | }; |
| 35 | virtual ~SocketBase() {} | 35 | virtual ~SocketBase() = default; |
| 36 | 36 | ||
| 37 | virtual SocketBase& operator=(const SocketBase&) = delete; | 37 | virtual SocketBase& operator=(const SocketBase&) = delete; |
| 38 | 38 | ||
| @@ -89,11 +89,7 @@ public: | |||
| 89 | 89 | ||
| 90 | virtual void HandleProxyPacket(const ProxyPacket& packet) = 0; | 90 | virtual void HandleProxyPacket(const ProxyPacket& packet) = 0; |
| 91 | 91 | ||
| 92 | #if defined(_WIN32) | ||
| 93 | SOCKET fd = INVALID_SOCKET; | 92 | SOCKET fd = INVALID_SOCKET; |
| 94 | #elif YUZU_UNIX | ||
| 95 | int fd = -1; | ||
| 96 | #endif | ||
| 97 | }; | 93 | }; |
| 98 | 94 | ||
| 99 | class Socket : public SocketBase { | 95 | class Socket : public SocketBase { |
diff --git a/src/dedicated_room/yuzu-room.cpp b/src/dedicated_room/yuzu-room.cpp index 88645dba7..482e772fb 100644 --- a/src/dedicated_room/yuzu-room.cpp +++ b/src/dedicated_room/yuzu-room.cpp | |||
| @@ -44,28 +44,30 @@ | |||
| 44 | #endif | 44 | #endif |
| 45 | 45 | ||
| 46 | static void PrintHelp(const char* argv0) { | 46 | static void PrintHelp(const char* argv0) { |
| 47 | std::cout << "Usage: " << argv0 | 47 | LOG_INFO(Network, |
| 48 | << " [options] <filename>\n" | 48 | "Usage: {}" |
| 49 | "--room-name The name of the room\n" | 49 | " [options] <filename>\n" |
| 50 | "--room-description The room description\n" | 50 | "--room-name The name of the room\n" |
| 51 | "--port The port used for the room\n" | 51 | "--room-description The room description\n" |
| 52 | "--max_members The maximum number of players for this room\n" | 52 | "--port The port used for the room\n" |
| 53 | "--password The password for the room\n" | 53 | "--max_members The maximum number of players for this room\n" |
| 54 | "--preferred-game The preferred game for this room\n" | 54 | "--password The password for the room\n" |
| 55 | "--preferred-game-id The preferred game-id for this room\n" | 55 | "--preferred-game The preferred game for this room\n" |
| 56 | "--username The username used for announce\n" | 56 | "--preferred-game-id The preferred game-id for this room\n" |
| 57 | "--token The token used for announce\n" | 57 | "--username The username used for announce\n" |
| 58 | "--web-api-url yuzu Web API url\n" | 58 | "--token The token used for announce\n" |
| 59 | "--ban-list-file The file for storing the room ban list\n" | 59 | "--web-api-url yuzu Web API url\n" |
| 60 | "--log-file The file for storing the room log\n" | 60 | "--ban-list-file The file for storing the room ban list\n" |
| 61 | "--enable-yuzu-mods Allow yuzu Community Moderators to moderate on your room\n" | 61 | "--log-file The file for storing the room log\n" |
| 62 | "-h, --help Display this help and exit\n" | 62 | "--enable-yuzu-mods Allow yuzu Community Moderators to moderate on your room\n" |
| 63 | "-v, --version Output version information and exit\n"; | 63 | "-h, --help Display this help and exit\n" |
| 64 | "-v, --version Output version information and exit\n", | ||
| 65 | argv0); | ||
| 64 | } | 66 | } |
| 65 | 67 | ||
| 66 | static void PrintVersion() { | 68 | static void PrintVersion() { |
| 67 | std::cout << "yuzu dedicated room " << Common::g_scm_branch << " " << Common::g_scm_desc | 69 | LOG_INFO(Network, "yuzu dedicated room {} {} Libnetwork: {}", Common::g_scm_branch, |
| 68 | << " Libnetwork: " << Network::network_version << std::endl; | 70 | Common::g_scm_desc, Network::network_version); |
| 69 | } | 71 | } |
| 70 | 72 | ||
| 71 | /// The magic text at the beginning of a yuzu-room ban list file. | 73 | /// The magic text at the beginning of a yuzu-room ban list file. |
| @@ -76,7 +78,7 @@ static constexpr char token_delimiter{':'}; | |||
| 76 | static std::string UsernameFromDisplayToken(const std::string& display_token) { | 78 | static std::string UsernameFromDisplayToken(const std::string& display_token) { |
| 77 | std::size_t outlen; | 79 | std::size_t outlen; |
| 78 | 80 | ||
| 79 | std::array<unsigned char, 512> output; | 81 | std::array<unsigned char, 512> output{}; |
| 80 | mbedtls_base64_decode(output.data(), output.size(), &outlen, | 82 | mbedtls_base64_decode(output.data(), output.size(), &outlen, |
| 81 | reinterpret_cast<const unsigned char*>(display_token.c_str()), | 83 | reinterpret_cast<const unsigned char*>(display_token.c_str()), |
| 82 | display_token.length()); | 84 | display_token.length()); |
| @@ -87,7 +89,7 @@ static std::string UsernameFromDisplayToken(const std::string& display_token) { | |||
| 87 | static std::string TokenFromDisplayToken(const std::string& display_token) { | 89 | static std::string TokenFromDisplayToken(const std::string& display_token) { |
| 88 | std::size_t outlen; | 90 | std::size_t outlen; |
| 89 | 91 | ||
| 90 | std::array<unsigned char, 512> output; | 92 | std::array<unsigned char, 512> output{}; |
| 91 | mbedtls_base64_decode(output.data(), output.size(), &outlen, | 93 | mbedtls_base64_decode(output.data(), output.size(), &outlen, |
| 92 | reinterpret_cast<const unsigned char*>(display_token.c_str()), | 94 | reinterpret_cast<const unsigned char*>(display_token.c_str()), |
| 93 | display_token.length()); | 95 | display_token.length()); |
| @@ -99,13 +101,13 @@ static Network::Room::BanList LoadBanList(const std::string& path) { | |||
| 99 | std::ifstream file; | 101 | std::ifstream file; |
| 100 | Common::FS::OpenFileStream(file, path, std::ios_base::in); | 102 | Common::FS::OpenFileStream(file, path, std::ios_base::in); |
| 101 | if (!file || file.eof()) { | 103 | if (!file || file.eof()) { |
| 102 | std::cout << "Could not open ban list!\n\n"; | 104 | LOG_ERROR(Network, "Could not open ban list!"); |
| 103 | return {}; | 105 | return {}; |
| 104 | } | 106 | } |
| 105 | std::string magic; | 107 | std::string magic; |
| 106 | std::getline(file, magic); | 108 | std::getline(file, magic); |
| 107 | if (magic != BanListMagic) { | 109 | if (magic != BanListMagic) { |
| 108 | std::cout << "Ban list is not valid!\n\n"; | 110 | LOG_ERROR(Network, "Ban list is not valid!"); |
| 109 | return {}; | 111 | return {}; |
| 110 | } | 112 | } |
| 111 | 113 | ||
| @@ -137,7 +139,7 @@ static void SaveBanList(const Network::Room::BanList& ban_list, const std::strin | |||
| 137 | std::ofstream file; | 139 | std::ofstream file; |
| 138 | Common::FS::OpenFileStream(file, path, std::ios_base::out); | 140 | Common::FS::OpenFileStream(file, path, std::ios_base::out); |
| 139 | if (!file) { | 141 | if (!file) { |
| 140 | std::cout << "Could not save ban list!\n\n"; | 142 | LOG_ERROR(Network, "Could not save ban list!"); |
| 141 | return; | 143 | return; |
| 142 | } | 144 | } |
| 143 | 145 | ||
| @@ -153,8 +155,6 @@ static void SaveBanList(const Network::Room::BanList& ban_list, const std::strin | |||
| 153 | for (const auto& ip : ban_list.second) { | 155 | for (const auto& ip : ban_list.second) { |
| 154 | file << ip << "\n"; | 156 | file << ip << "\n"; |
| 155 | } | 157 | } |
| 156 | |||
| 157 | file.flush(); | ||
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | static void InitializeLogging(const std::string& log_file) { | 160 | static void InitializeLogging(const std::string& log_file) { |
| @@ -202,6 +202,8 @@ int main(int argc, char** argv) { | |||
| 202 | {0, 0, 0, 0}, | 202 | {0, 0, 0, 0}, |
| 203 | }; | 203 | }; |
| 204 | 204 | ||
| 205 | InitializeLogging(log_file); | ||
| 206 | |||
| 205 | while (optind < argc) { | 207 | while (optind < argc) { |
| 206 | int arg = getopt_long(argc, argv, "n:d:p:m:w:g:u:t:a:i:l:hv", long_options, &option_index); | 208 | int arg = getopt_long(argc, argv, "n:d:p:m:w:g:u:t:a:i:l:hv", long_options, &option_index); |
| 207 | if (arg != -1) { | 209 | if (arg != -1) { |
| @@ -256,52 +258,53 @@ int main(int argc, char** argv) { | |||
| 256 | } | 258 | } |
| 257 | 259 | ||
| 258 | if (room_name.empty()) { | 260 | if (room_name.empty()) { |
| 259 | std::cout << "room name is empty!\n\n"; | 261 | LOG_ERROR(Network, "Room name is empty!"); |
| 260 | PrintHelp(argv[0]); | 262 | PrintHelp(argv[0]); |
| 261 | return -1; | 263 | return -1; |
| 262 | } | 264 | } |
| 263 | if (preferred_game.empty()) { | 265 | if (preferred_game.empty()) { |
| 264 | std::cout << "preferred game is empty!\n\n"; | 266 | LOG_ERROR(Network, "Preferred game is empty!"); |
| 265 | PrintHelp(argv[0]); | 267 | PrintHelp(argv[0]); |
| 266 | return -1; | 268 | return -1; |
| 267 | } | 269 | } |
| 268 | if (preferred_game_id == 0) { | 270 | if (preferred_game_id == 0) { |
| 269 | std::cout << "preferred-game-id not set!\nThis should get set to allow users to find your " | 271 | LOG_ERROR(Network, |
| 270 | "room.\nSet with --preferred-game-id id\n\n"; | 272 | "preferred-game-id not set!\nThis should get set to allow users to find your " |
| 273 | "room.\nSet with --preferred-game-id id"); | ||
| 271 | } | 274 | } |
| 272 | if (max_members > Network::MaxConcurrentConnections || max_members < 2) { | 275 | if (max_members > Network::MaxConcurrentConnections || max_members < 2) { |
| 273 | std::cout << "max_members needs to be in the range 2 - " | 276 | LOG_ERROR(Network, "max_members needs to be in the range 2 - {}!", |
| 274 | << Network::MaxConcurrentConnections << "!\n\n"; | 277 | Network::MaxConcurrentConnections); |
| 275 | PrintHelp(argv[0]); | 278 | PrintHelp(argv[0]); |
| 276 | return -1; | 279 | return -1; |
| 277 | } | 280 | } |
| 278 | if (port > 65535) { | 281 | if (port > UINT16_MAX) { |
| 279 | std::cout << "port needs to be in the range 0 - 65535!\n\n"; | 282 | LOG_ERROR(Network, "Port needs to be in the range 0 - 65535!"); |
| 280 | PrintHelp(argv[0]); | 283 | PrintHelp(argv[0]); |
| 281 | return -1; | 284 | return -1; |
| 282 | } | 285 | } |
| 283 | if (ban_list_file.empty()) { | 286 | if (ban_list_file.empty()) { |
| 284 | std::cout << "Ban list file not set!\nThis should get set to load and save room ban " | 287 | LOG_ERROR(Network, "Ban list file not set!\nThis should get set to load and save room ban " |
| 285 | "list.\nSet with --ban-list-file <file>\n\n"; | 288 | "list.\nSet with --ban-list-file <file>"); |
| 286 | } | 289 | } |
| 287 | bool announce = true; | 290 | bool announce = true; |
| 288 | if (token.empty() && announce) { | 291 | if (token.empty() && announce) { |
| 289 | announce = false; | 292 | announce = false; |
| 290 | std::cout << "token is empty: Hosting a private room\n\n"; | 293 | LOG_INFO(Network, "Token is empty: Hosting a private room"); |
| 291 | } | 294 | } |
| 292 | if (web_api_url.empty() && announce) { | 295 | if (web_api_url.empty() && announce) { |
| 293 | announce = false; | 296 | announce = false; |
| 294 | std::cout << "endpoint url is empty: Hosting a private room\n\n"; | 297 | LOG_INFO(Network, "Endpoint url is empty: Hosting a private room"); |
| 295 | } | 298 | } |
| 296 | if (announce) { | 299 | if (announce) { |
| 297 | if (username.empty()) { | 300 | if (username.empty()) { |
| 298 | std::cout << "Hosting a public room\n\n"; | 301 | LOG_INFO(Network, "Hosting a public room"); |
| 299 | Settings::values.web_api_url = web_api_url; | 302 | Settings::values.web_api_url = web_api_url; |
| 300 | Settings::values.yuzu_username = UsernameFromDisplayToken(token); | 303 | Settings::values.yuzu_username = UsernameFromDisplayToken(token); |
| 301 | username = Settings::values.yuzu_username.GetValue(); | 304 | username = Settings::values.yuzu_username.GetValue(); |
| 302 | Settings::values.yuzu_token = TokenFromDisplayToken(token); | 305 | Settings::values.yuzu_token = TokenFromDisplayToken(token); |
| 303 | } else { | 306 | } else { |
| 304 | std::cout << "Hosting a public room\n\n"; | 307 | LOG_INFO(Network, "Hosting a public room"); |
| 305 | Settings::values.web_api_url = web_api_url; | 308 | Settings::values.web_api_url = web_api_url; |
| 306 | Settings::values.yuzu_username = username; | 309 | Settings::values.yuzu_username = username; |
| 307 | Settings::values.yuzu_token = token; | 310 | Settings::values.yuzu_token = token; |
| @@ -309,11 +312,9 @@ int main(int argc, char** argv) { | |||
| 309 | } | 312 | } |
| 310 | if (!announce && enable_yuzu_mods) { | 313 | if (!announce && enable_yuzu_mods) { |
| 311 | enable_yuzu_mods = false; | 314 | enable_yuzu_mods = false; |
| 312 | std::cout << "Can not enable yuzu Moderators for private rooms\n\n"; | 315 | LOG_INFO(Network, "Can not enable yuzu Moderators for private rooms"); |
| 313 | } | 316 | } |
| 314 | 317 | ||
| 315 | InitializeLogging(log_file); | ||
| 316 | |||
| 317 | // Load the ban list | 318 | // Load the ban list |
| 318 | Network::Room::BanList ban_list; | 319 | Network::Room::BanList ban_list; |
| 319 | if (!ban_list_file.empty()) { | 320 | if (!ban_list_file.empty()) { |
| @@ -326,27 +327,26 @@ int main(int argc, char** argv) { | |||
| 326 | verify_backend = | 327 | verify_backend = |
| 327 | std::make_unique<WebService::VerifyUserJWT>(Settings::values.web_api_url.GetValue()); | 328 | std::make_unique<WebService::VerifyUserJWT>(Settings::values.web_api_url.GetValue()); |
| 328 | #else | 329 | #else |
| 329 | std::cout | 330 | LOG_INFO(Network, |
| 330 | << "yuzu Web Services is not available with this build: validation is disabled.\n\n"; | 331 | "yuzu Web Services is not available with this build: validation is disabled."); |
| 331 | verify_backend = std::make_unique<Network::VerifyUser::NullBackend>(); | 332 | verify_backend = std::make_unique<Network::VerifyUser::NullBackend>(); |
| 332 | #endif | 333 | #endif |
| 333 | } else { | 334 | } else { |
| 334 | verify_backend = std::make_unique<Network::VerifyUser::NullBackend>(); | 335 | verify_backend = std::make_unique<Network::VerifyUser::NullBackend>(); |
| 335 | } | 336 | } |
| 336 | 337 | ||
| 337 | Core::System system{}; | 338 | Network::RoomNetwork network{}; |
| 338 | auto& network = system.GetRoomNetwork(); | ||
| 339 | network.Init(); | 339 | network.Init(); |
| 340 | if (std::shared_ptr<Network::Room> room = network.GetRoom().lock()) { | 340 | if (auto room = network.GetRoom().lock()) { |
| 341 | AnnounceMultiplayerRoom::GameInfo preferred_game_info{.name = preferred_game, | 341 | AnnounceMultiplayerRoom::GameInfo preferred_game_info{.name = preferred_game, |
| 342 | .id = preferred_game_id}; | 342 | .id = preferred_game_id}; |
| 343 | if (!room->Create(room_name, room_description, "", port, password, max_members, username, | 343 | if (!room->Create(room_name, room_description, "", port, password, max_members, username, |
| 344 | preferred_game_info, std::move(verify_backend), ban_list, | 344 | preferred_game_info, std::move(verify_backend), ban_list, |
| 345 | enable_yuzu_mods)) { | 345 | enable_yuzu_mods)) { |
| 346 | std::cout << "Failed to create room: \n\n"; | 346 | LOG_INFO(Network, "Failed to create room: "); |
| 347 | return -1; | 347 | return -1; |
| 348 | } | 348 | } |
| 349 | std::cout << "Room is open. Close with Q+Enter...\n\n"; | 349 | LOG_INFO(Network, "Room is open. Close with Q+Enter..."); |
| 350 | auto announce_session = std::make_unique<Core::AnnounceMultiplayerSession>(network); | 350 | auto announce_session = std::make_unique<Core::AnnounceMultiplayerSession>(network); |
| 351 | if (announce) { | 351 | if (announce) { |
| 352 | announce_session->Start(); | 352 | announce_session->Start(); |
diff --git a/src/yuzu/multiplayer/validation.h b/src/yuzu/multiplayer/validation.h index 7d48e589d..dabf860be 100644 --- a/src/yuzu/multiplayer/validation.h +++ b/src/yuzu/multiplayer/validation.h | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | class Validation { | 10 | class Validation { |
| 11 | public: | 11 | public: |
| 12 | Validation() | 12 | Validation() |
| 13 | : room_name(room_name_regex), nickname(nickname_regex), ip(ip_regex), port(0, 65535) {} | 13 | : room_name(room_name_regex), nickname(nickname_regex), ip(ip_regex), port(0, UINT16_MAX) {} |
| 14 | 14 | ||
| 15 | ~Validation() = default; | 15 | ~Validation() = default; |
| 16 | 16 | ||
diff --git a/src/yuzu/uisettings.h b/src/yuzu/uisettings.h index 25d1bf1e6..e12d414d9 100644 --- a/src/yuzu/uisettings.h +++ b/src/yuzu/uisettings.h | |||
| @@ -104,11 +104,12 @@ struct Values { | |||
| 104 | // multiplayer settings | 104 | // multiplayer settings |
| 105 | Settings::Setting<QString> multiplayer_nickname{QStringLiteral("yuzu"), "nickname"}; | 105 | Settings::Setting<QString> multiplayer_nickname{QStringLiteral("yuzu"), "nickname"}; |
| 106 | Settings::Setting<QString> multiplayer_ip{{}, "ip"}; | 106 | Settings::Setting<QString> multiplayer_ip{{}, "ip"}; |
| 107 | Settings::SwitchableSetting<uint, true> multiplayer_port{24872, 0, 65535, "port"}; | 107 | Settings::SwitchableSetting<uint, true> multiplayer_port{24872, 0, UINT16_MAX, "port"}; |
| 108 | Settings::Setting<QString> multiplayer_room_nickname{{}, "room_nickname"}; | 108 | Settings::Setting<QString> multiplayer_room_nickname{{}, "room_nickname"}; |
| 109 | Settings::Setting<QString> multiplayer_room_name{{}, "room_name"}; | 109 | Settings::Setting<QString> multiplayer_room_name{{}, "room_name"}; |
| 110 | Settings::SwitchableSetting<uint, true> multiplayer_max_player{8, 0, 8, "max_player"}; | 110 | Settings::SwitchableSetting<uint, true> multiplayer_max_player{8, 0, 8, "max_player"}; |
| 111 | Settings::SwitchableSetting<uint, true> multiplayer_room_port{24872, 0, 65535, "room_port"}; | 111 | Settings::SwitchableSetting<uint, true> multiplayer_room_port{24872, 0, UINT16_MAX, |
| 112 | "room_port"}; | ||
| 112 | Settings::SwitchableSetting<uint, true> multiplayer_host_type{0, 0, 1, "host_type"}; | 113 | Settings::SwitchableSetting<uint, true> multiplayer_host_type{0, 0, 1, "host_type"}; |
| 113 | Settings::Setting<qulonglong> multiplayer_game_id{{}, "game_id"}; | 114 | Settings::Setting<qulonglong> multiplayer_game_id{{}, "game_id"}; |
| 114 | Settings::Setting<QString> multiplayer_room_description{{}, "room_description"}; | 115 | Settings::Setting<QString> multiplayer_room_description{{}, "room_description"}; |