From 8c2cd2f60d90afc6e3c23e0e26b43aa9fddbbd68 Mon Sep 17 00:00:00 2001 From: loki-47-6F-64 Date: Sat, 7 Aug 2021 00:05:38 +0200 Subject: [PATCH 1/7] Load mDNS at runtime on Windows --- CMakeLists.txt | 4 -- sunshine/platform/windows/publish.cpp | 59 +++++++++++++++------------ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 704334bf..cd4e7037 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,15 +89,11 @@ if(WIN32) libstdc++.a libwinpthread.a libssp.a - Qwave - winmm ksuser wsock32 ws2_32 - iphlpapi d3d11 dxgi D3DCompiler setupapi - dnsapi ) set_source_files_properties(third-party/ViGEmClient/src/ViGEmClient.cpp PROPERTIES COMPILE_DEFINITIONS "UNICODE=1;ERROR_INVALID_DEVICE_OBJECT_PARAMETER=650") diff --git a/sunshine/platform/windows/publish.cpp b/sunshine/platform/windows/publish.cpp index 652785d0..d981593d 100644 --- a/sunshine/platform/windows/publish.cpp +++ b/sunshine/platform/windows/publish.cpp @@ -15,6 +15,9 @@ #include "sunshine/platform/common.h" #include "sunshine/thread_safe.h" +#define _FN(x, ret, args) \ + typedef ret(*x##_fn) args; \ + static x##_fn x using namespace std::literals; @@ -72,28 +75,9 @@ typedef struct _DNS_SERVICE_REGISTER_REQUEST { BOOL unicastEnabled; } DNS_SERVICE_REGISTER_REQUEST, *PDNS_SERVICE_REGISTER_REQUEST; -VOID DnsServiceFreeInstance( - _In_ PDNS_SERVICE_INSTANCE pInstance); - -DWORD DnsServiceDeRegister( - _In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, - _Inout_opt_ PDNS_SERVICE_CANCEL pCancel); - -DWORD DnsServiceRegister( - _In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, - _Inout_opt_ PDNS_SERVICE_CANCEL pCancel); - -PDNS_SERVICE_INSTANCE DnsServiceConstructInstance( - _In_ PCWSTR pServiceName, - _In_ PCWSTR pHostName, - _In_opt_ PIP4_ADDRESS pIp4, - _In_opt_ PIP6_ADDRESS pIp6, - _In_ WORD wPort, - _In_ WORD wPriority, - _In_ WORD wWeight, - _In_ DWORD dwPropertiesCount, - _In_reads_(dwPropertiesCount) PCWSTR *keys, - _In_reads_(dwPropertiesCount) PCWSTR *values); +_FN(_DnsServiceFreeInstance, VOID, (_In_ PDNS_SERVICE_INSTANCE pInstance)); +_FN(_DnsServiceDeRegister, DWORD, (_In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, _Inout_opt_ PDNS_SERVICE_CANCEL pCancel)); +_FN(_DnsServiceRegister, DWORD, (_In_ PDNS_SERVICE_REGISTER_REQUEST pRequest, _Inout_opt_ PDNS_SERVICE_CANCEL pCancel)); } /* extern "C" */ namespace platf::publish { @@ -102,7 +86,7 @@ VOID WINAPI register_cb(DWORD status, PVOID pQueryContext, PDNS_SERVICE_INSTANCE auto fg = util::fail_guard([&]() { if(pInstance) { - DnsServiceFreeInstance(pInstance); + _DnsServiceFreeInstance(pInstance); } }); @@ -140,10 +124,10 @@ static int service(bool enable) { DNS_STATUS status {}; if(enable) { - status = DnsServiceRegister(&req, nullptr); + status = _DnsServiceRegister(&req, nullptr); } else { - status = DnsServiceDeRegister(&req, nullptr); + status = _DnsServiceDeRegister(&req, nullptr); } alarm->wait(); @@ -168,7 +152,32 @@ public: } }; +int load_funcs(HMODULE handle) { + auto fg = util::fail_guard([handle]() { + FreeLibrary(handle); + }); + + _DnsServiceFreeInstance = (_DnsServiceFreeInstance_fn)GetProcAddress(handle, "DnsServiceFreeInstance"); + _DnsServiceDeRegister = (_DnsServiceDeRegister_fn)GetProcAddress(handle, "DnsServiceDeRegister"); + _DnsServiceRegister = (_DnsServiceRegister_fn)GetProcAddress(handle, "DnsServiceRegister"); + + if(!(_DnsServiceFreeInstance && _DnsServiceDeRegister && _DnsServiceRegister)) { + BOOST_LOG(error) << "mDNS service not available in dnsapi.dll"sv; + return -1; + } + + fg.disable(); + return 0; +} + std::unique_ptr<::platf::deinit_t> start() { + HMODULE handle = LoadLibrary("dnsapi.dll"); + + if(!handle || load_funcs(handle)) { + BOOST_LOG(error) << "Couldn't load dnsapi.dll, You'll need to add PC manually from Moonlight"sv; + return nullptr; + } + if(service(true)) { return nullptr; } From 62db9ae01aa2cf3320f0598f6e000176f8b3693e Mon Sep 17 00:00:00 2001 From: loki Date: Sat, 7 Aug 2021 12:12:18 +0200 Subject: [PATCH 2/7] fix reading config option for log level --- sunshine/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunshine/config.cpp b/sunshine/config.cpp index 3008047f..18083d9a 100644 --- a/sunshine/config.cpp +++ b/sunshine/config.cpp @@ -742,7 +742,7 @@ void apply_config(std::unordered_map &&vars) { } std::string log_level_string; - string_restricted_f(vars, "min_log_level", log_level_string, { "verbose"sv, "debug"sv, "info"sv, "warning"sv, "error"sv, "fatal"sv, "none"sv }); + string_f(vars, "min_log_level", log_level_string); if(!log_level_string.empty()) { if(log_level_string == "verbose"sv) { From 0629fe7846352598b162fa0e39440b2a96e841e7 Mon Sep 17 00:00:00 2001 From: GuanZhang <44019025+guanzhangrtk@users.noreply.github.com> Date: Sun, 8 Aug 2021 18:04:48 +0900 Subject: [PATCH 3/7] Add missing requirements for clean MSYS2 environment --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a476a86..2ff7f820 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ sunshine needs access to uinput to create mouse and gamepad events: ### Requirements: - mingw-w64-x86_64-openssl mingw-w64-x86_64-cmake mingw-w64-x86_64-toolchain mingw-w64-x86_64-opus mingw-w64-x86_64-x265 mingw-w64-x86_64-boost git mingw-w64-x86_64-make + mingw-w64-x86_64-openssl mingw-w64-x86_64-cmake mingw-w64-x86_64-toolchain mingw-w64-x86_64-opus mingw-w64-x86_64-x265 mingw-w64-x86_64-boost git mingw-w64-x86_64-make cmake make gcc ### Compilation: - `git clone https://github.com/loki-47-6F-64/sunshine.git --recursive` From dce64fc4873ccd95b808209d9d3acd05ba75ba90 Mon Sep 17 00:00:00 2001 From: GuanZhang <44019025+guanzhangrtk@users.noreply.github.com> Date: Sun, 8 Aug 2021 18:20:43 +0900 Subject: [PATCH 4/7] Add more detailed log message when config::nvhttp.file_state doesn't exist upon first run --- sunshine/nvhttp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunshine/nvhttp.cpp b/sunshine/nvhttp.cpp index 68806106..004ce6a7 100644 --- a/sunshine/nvhttp.cpp +++ b/sunshine/nvhttp.cpp @@ -132,7 +132,7 @@ void save_state() { void load_state() { if(!fs::exists(config::nvhttp.file_state)) { - BOOST_LOG(info) << "DOENST EXIST"sv; + BOOST_LOG(info) << "File "sv << config::nvhttp.file_state << " doesn't exist"; http::unique_id = util::uuid_t::generate().string(); return; } From 03837a9308f03a21a819af9051e5406b71afa4be Mon Sep 17 00:00:00 2001 From: Elia Zammuto Date: Sun, 8 Aug 2021 16:47:38 +0200 Subject: [PATCH 5/7] Password Validation --- assets/web/welcome.html | 4 ++-- sunshine/confighttp.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/web/welcome.html b/assets/web/welcome.html index 8dd40a83..5570de50 100644 --- a/assets/web/welcome.html +++ b/assets/web/welcome.html @@ -13,11 +13,11 @@
- +
- +
Error: {{error}}
diff --git a/sunshine/confighttp.cpp b/sunshine/confighttp.cpp index 97f2f04b..3e624809 100644 --- a/sunshine/confighttp.cpp +++ b/sunshine/confighttp.cpp @@ -419,8 +419,8 @@ void savePassword(resp_https_t response, req_https_t request) { auto username = inputTree.count("currentUsername") > 0 ? inputTree.get("currentUsername") : ""; auto newUsername = inputTree.get("newUsername"); auto password = inputTree.count("currentPassword") > 0 ? inputTree.get("currentPassword") : ""; - auto newPassword = inputTree.get("newPassword"); - auto confirmPassword = inputTree.get("confirmNewPassword"); + auto newPassword = inputTree.count("newPassword") > 0 ? inputTree.get("newPassword") : ""; + auto confirmPassword = inputTree.count("confirmNewPassword") > 0 ? inputTree.get("confirmNewPassword") : ""; if(newUsername.length() == 0) newUsername = username; if(newUsername.length() == 0){ outputTree.put("status", false); @@ -428,7 +428,7 @@ void savePassword(resp_https_t response, req_https_t request) { } else { auto hash = util::hex(crypto::hash(password + config::sunshine.salt)).to_string(); if(config::sunshine.username.empty() || (username == config::sunshine.username && hash == config::sunshine.password)) { - if(newPassword != confirmPassword) { + if(newPassword.empty() || newPassword != confirmPassword) { outputTree.put("status", false); outputTree.put("error", "Password Mismatch"); } else { From 948500ae41295fa457fcb84b7dce4f2ace239f4a Mon Sep 17 00:00:00 2001 From: GuanZhang <44019025+guanzhangrtk@users.noreply.github.com> Date: Mon, 9 Aug 2021 11:38:12 +0900 Subject: [PATCH 6/7] Added missing sv as requested by loki-47-6F-64 --- sunshine/nvhttp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunshine/nvhttp.cpp b/sunshine/nvhttp.cpp index 004ce6a7..0d854fdb 100644 --- a/sunshine/nvhttp.cpp +++ b/sunshine/nvhttp.cpp @@ -132,7 +132,7 @@ void save_state() { void load_state() { if(!fs::exists(config::nvhttp.file_state)) { - BOOST_LOG(info) << "File "sv << config::nvhttp.file_state << " doesn't exist"; + BOOST_LOG(info) << "File "sv << config::nvhttp.file_state << " doesn't exist"sv; http::unique_id = util::uuid_t::generate().string(); return; } From 3382a5d03cae0d656169d9ae58e4cafb8591f2af Mon Sep 17 00:00:00 2001 From: GuanZhang <44019025+guanzhangrtk@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:52:49 +0900 Subject: [PATCH 7/7] MSYS2 is needed to build under Windows --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2ff7f820..b78bc234 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ sunshine needs access to uinput to create mouse and gamepad events: ### Requirements: +First you need to install [MSYS2](https://www.msys2.org), then startup "MSYS2 MinGW 64-bit" and install the following packages using `pacman -S`: + mingw-w64-x86_64-openssl mingw-w64-x86_64-cmake mingw-w64-x86_64-toolchain mingw-w64-x86_64-opus mingw-w64-x86_64-x265 mingw-w64-x86_64-boost git mingw-w64-x86_64-make cmake make gcc ### Compilation: