Compare commits

...
7 Commits
5 changed files with 55 additions and 33 deletions
+5
View File
@@ -117,6 +117,11 @@
Port="48010" Port="48010"
Protocol="udp" Protocol="udp"
Name="Moonlight - RTSPU"/> Name="Moonlight - RTSPU"/>
<fire:FirewallException Id="MdnsFwException"
Scope="any"
Port="5353"
Protocol="udp"
Name="Moonlight - mDNS"/>
</Component> </Component>
<Component Id="Shortcuts" Guid="*"> <Component Id="Shortcuts" Guid="*">
<Shortcut Id="StartMenuShortcut" <Shortcut Id="StartMenuShortcut"
+36 -25
View File
@@ -533,14 +533,8 @@ bool IsGameStreamEnabled()
printf("RegQueryValueExA() failed: %d" NL, error); printf("RegQueryValueExA() failed: %d" NL, error);
return false; return false;
} }
else if (!enabled) {
printf("GameStream is OFF!" NL); return enabled != 0;
return false;
}
else {
printf("GameStream is ON!" NL);
return true;
}
} }
void UpdatePortMappingsForTarget(bool enable, char* targetAddressIP4, char* internalAddressIP4, char* upstreamAddressIP4) void UpdatePortMappingsForTarget(bool enable, char* targetAddressIP4, char* internalAddressIP4, char* upstreamAddressIP4)
@@ -852,26 +846,33 @@ void ResetLogFile(bool standaloneExe)
DWORD WINAPI GameStreamStateChangeThread(PVOID Context) DWORD WINAPI GameStreamStateChangeThread(PVOID Context)
{ {
HKEY key; HKEY key;
DWORD err;
// We're watching this key that way we can still detect GameStream turning on do {
// if GFE wasn't even installed when our service started // We're watching this key that way we can still detect GameStream turning on
DWORD err = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\NVIDIA Corporation", 0, KEY_READ | KEY_WOW64_64KEY, &key); // if GFE wasn't even installed when our service started
if (err != ERROR_SUCCESS) { do {
printf("RegOpenKeyExA() failed: %d" NL, err); err = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\NVIDIA Corporation", 0, KEY_READ | KEY_WOW64_64KEY, &key);
return err; if (err != ERROR_SUCCESS) {
} // Wait 10 seconds and try again
Sleep(10000);
}
} while (err != ERROR_SUCCESS);
// Notify the main thread when the GameStream state changes // Notify the main thread when the GameStream state changes
bool lastGameStreamState = IsGameStreamEnabled(); bool lastGameStreamState = IsGameStreamEnabled();
while ((err = RegNotifyChangeKeyValue(key, true, REG_NOTIFY_CHANGE_LAST_SET, nullptr, false)) == ERROR_SUCCESS) { while ((err = RegNotifyChangeKeyValue(key, true, REG_NOTIFY_CHANGE_LAST_SET, nullptr, false)) == ERROR_SUCCESS) {
bool currentGameStreamState = IsGameStreamEnabled(); bool currentGameStreamState = IsGameStreamEnabled();
if (lastGameStreamState != currentGameStreamState) { if (lastGameStreamState != currentGameStreamState) {
SetEvent((HANDLE)Context); SetEvent((HANDLE)Context);
}
lastGameStreamState = currentGameStreamState;
} }
lastGameStreamState = currentGameStreamState;
}
printf("RegNotifyChangeKeyValue() failed: %d" NL, err); // If the key is deleted (by DDU or similar), we will hit this code path and poll until it comes back.
RegCloseKey(key);
} while (err == ERROR_KEY_DELETED);
return err; return err;
} }
@@ -904,7 +905,17 @@ int Run(bool standaloneExe)
for (;;) { for (;;) {
ResetEvent(gsChangeEvent); ResetEvent(gsChangeEvent);
ResetEvent(ifaceChangeEvent); ResetEvent(ifaceChangeEvent);
UpdatePortMappings(IsGameStreamEnabled());
bool gameStreamEnabled = IsGameStreamEnabled();
if (gameStreamEnabled) {
printf("GameStream is ON!" NL);
}
else {
printf("GameStream is OFF!" NL);
}
UpdatePortMappings(gameStreamEnabled);
// Refresh when half the duration is expired or if an IP interface // Refresh when half the duration is expired or if an IP interface
// change event occurs. // change event occurs.
+1 -1
View File
@@ -118,7 +118,7 @@ bool PCPMapPort(PSOCKADDR_STORAGE localAddr, int localAddrLen, PSOCKADDR_STORAGE
int bytesRead; int bytesRead;
union { union {
PCP_MAP_RESPONSE hdr; PCP_MAP_RESPONSE hdr;
char buf[1024]; char buf[1100];
} resp; } resp;
int lifetime; int lifetime;
+12 -6
View File
@@ -407,7 +407,7 @@ enum PortTestStatus {
PortTestError, PortTestError,
PortTestUnknown PortTestUnknown
}; };
PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withServer, bool isLoopbackRelay) PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withServer, bool isLoopbackRelay, bool mtuTest)
{ {
SOCKET clientSock = INVALID_SOCKET, serverSock = INVALID_SOCKET; SOCKET clientSock = INVALID_SOCKET, serverSock = INVALID_SOCKET;
int err; int err;
@@ -532,11 +532,14 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
return err == 1 ? PortTestOk : PortTestError; return err == 1 ? PortTestOk : PortTestError;
} }
else { else {
const char testMsg[] = "moonlight-test"; // Video packets are up to 1040 bytes.
const char testMsg[1040] = "moonlight-test";
// Send several test packets to ensure a random lost packet doesn't make the test fail // Send several test packets to ensure a random lost packet doesn't make the test fail
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
err = sendto(clientSock, testMsg, sizeof(testMsg), 0, (struct sockaddr*)&sin6, addrLen); // Send the full payload for MTU tests and the truncated payload for other tests.
err = sendto(clientSock, testMsg,
mtuTest ? sizeof(testMsg) : strlen(testMsg), 0, (struct sockaddr*)&sin6, addrLen);
if (err == SOCKET_ERROR) { if (err == SOCKET_ERROR) {
fprintf(LOG_OUT, "sendto() failed: %d\n", WSAGetLastError()); fprintf(LOG_OUT, "sendto() failed: %d\n", WSAGetLastError());
closesocket(clientSock); closesocket(clientSock);
@@ -698,7 +701,8 @@ bool TestAllPorts(PSOCKADDR_STORAGE addr, char* portMsg, int portMsgLen, bool is
fprintf(LOG_OUT, "Testing %s %d...", fprintf(LOG_OUT, "Testing %s %d...",
k_Ports[i].proto == IPPROTO_TCP ? "TCP" : "UDP", k_Ports[i].proto == IPPROTO_TCP ? "TCP" : "UDP",
k_Ports[i].port); k_Ports[i].port);
status = TestPort(addr, k_Ports[i].proto, k_Ports[i].port, k_Ports[i].withServer, isLoopbackRelay); status = TestPort(addr, k_Ports[i].proto, k_Ports[i].port,
k_Ports[i].withServer, isLoopbackRelay, k_Ports[i].port == 47998);
} }
if (status != PortTestOk) { if (status != PortTestOk) {
@@ -1464,8 +1468,10 @@ int main(int argc, char* argv[])
if (TestAllPorts((PSOCKADDR_STORAGE)current->ai_addr, portMsgBuf, sizeof(portMsgBuf), true, true, &allPortsFailedOnV4)) { if (TestAllPorts((PSOCKADDR_STORAGE)current->ai_addr, portMsgBuf, sizeof(portMsgBuf), true, true, &allPortsFailedOnV4)) {
freeaddrinfo(result); freeaddrinfo(result);
snprintf(msgBuf, sizeof(msgBuf), "This PC is ready to host over the Internet!\n\n" snprintf(msgBuf, sizeof(msgBuf), "This PC is ready to host over the Internet!\n\n"
"For the easiest setup, you should pair Moonlight to your gaming PC from your home network before trying to stream over the Internet.\n\n" "Do not uninstall the Moonlight Internet Hosting Tool, unless you no longer want to stream over the Internet. It needs to remain installed on your PC to maintain the port forwarding entries on your router.\n\n"
"If you can't, you can type the following address into Moonlight's Add PC dialog: %s", wanAddrStr); "For the easiest setup, you can simply pair Moonlight to your gaming PC while they are both on the same network and Internet streaming will work automatically.\n\n"
"If your client is not connected to the same network as your gaming PC, you can type the following address into Moonlight's Add PC dialog: %s",
wanAddrStr);
DisplayMessage(msgBuf, nullptr, MpInfo); DisplayMessage(msgBuf, nullptr, MpInfo);
return 0; return 0;
} }