Compare commits

..
9 Commits
5 changed files with 169 additions and 34 deletions
+14 -5
View File
@@ -97,7 +97,8 @@ bool UPnPMapPort(struct UPNPUrls* urls, struct IGDdatas* data, int proto, const
printf("NOT FOUND" NL);
}
else if (err == UPNPCOMMAND_SUCCESS) {
if (!strcmp(intClient, myAddr) && !strcmp(desc, myDesc)) {
// Some routers change the description, so we can't check that here
if (!strcmp(intClient, myAddr)) {
if (atoi(leaseDuration) == 0) {
printf("OK (Permanent)" NL);
}
@@ -746,21 +747,29 @@ void ResetLogFile()
{
char oldLogFilePath[MAX_PATH + 1];
char currentLogFilePath[MAX_PATH + 1];
char timeString[MAX_PATH + 1] = {};
SYSTEMTIME time;
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", oldLogFilePath, sizeof(oldLogFilePath));
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", currentLogFilePath, sizeof(currentLogFilePath));
// Delete the old log file
DeleteFileA(oldLogFilePath);
// Close the existing stdout handle. This is important because otherwise
// it may still be open as stdout when we try to MoveFileEx below.
fclose(stdout);
// Rotate the current to the old log file
MoveFileA(currentLogFilePath, oldLogFilePath);
// Rotate the current to the old log file
MoveFileExA(currentLogFilePath, oldLogFilePath, MOVEFILE_REPLACE_EXISTING);
// Redirect stdout to this new file
freopen(currentLogFilePath, "w", stdout);
// Print a log header
printf("Moonlight Internet Streaming Service v" VER_VERSION_STR NL);
// Print the current time
GetSystemTime(&time);
GetTimeFormatA(LOCALE_SYSTEM_DEFAULT, 0, &time, "hh':'mm':'ss tt", timeString, ARRAYSIZE(timeString));
printf("The current UTC time is: %s" NL, timeString);
}
DWORD WINAPI GameStreamStateChangeThread(PVOID Context)
+3
View File
@@ -3,6 +3,7 @@
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_VERSION
PRODUCTVERSION VER_VERSION
BEGIN
BLOCK "StringFileInfo"
BEGIN
@@ -11,6 +12,8 @@ BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", "Moonlight Internet Streaming Service"
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "FileVersion", VER_VERSION_STR
VALUE "ProductVersion", VER_VERSION_STR
END
END
+147 -27
View File
@@ -11,6 +11,7 @@
#include <assert.h>
#include <shellapi.h>
#include <objbase.h>
#include <WinInet.h>
#include "..\version.h"
@@ -18,6 +19,7 @@
#pragma comment(lib, "libnatpmp.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "wininet.lib")
#define MINIUPNP_STATICLIB
#include <miniupnpc/miniupnpc.h>
@@ -40,8 +42,13 @@ static struct port_entry {
{IPPROTO_UDP, 47998, true},
{IPPROTO_UDP, 47999, true},
{IPPROTO_UDP, 48000, true},
#if 0
// These are not currently used, so let's
// avoid testing them for now.
{IPPROTO_UDP, 48002, true},
{IPPROTO_UDP, 48010, true}
#endif
};
char logFilePath[MAX_PATH + 1];
@@ -70,11 +77,13 @@ void DisplayMessage(const char* message, const char* helpUrl = nullptr, MessageP
printf("%s\n", message);
if (terminal) {
printf("--------------- MISS LOG -------------------\n");
char missPath[MAX_PATH + 1];
FILE* f;
printf("--------------- CURRENT MISS LOG -------------------\n");
char missPath[MAX_PATH + 1];
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-current.log", missPath, sizeof(missPath));
FILE* f = fopen(missPath, "r");
f = fopen(missPath, "r");
if (f != nullptr) {
char buffer[1024];
while (!feof(f)) {
@@ -84,9 +93,25 @@ void DisplayMessage(const char* message, const char* helpUrl = nullptr, MessageP
fclose(f);
}
else {
printf("Failed to find MISS log\n");
printf("Failed to find current MISS log\n");
}
printf("\n----------------- OLD MISS LOG ---------------------\n");
ExpandEnvironmentStringsA("%ProgramData%\\MISS\\miss-old.log", missPath, sizeof(missPath));
f = fopen(missPath, "r");
if (f != nullptr) {
char buffer[1024];
while (!feof(f)) {
int bytesRead = fread(buffer, 1, ARRAYSIZE(buffer), f);
fwrite(buffer, 1, bytesRead, stdout);
}
fclose(f);
}
else {
printf("Failed to find old MISS log\n");
}
fflush(stdout);
}
@@ -254,12 +279,23 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
fd_set fds;
FD_ZERO(&fds);
FD_SET(clientSock, &fds);
if (serverSock != INVALID_SOCKET) {
FD_SET(serverSock, &fds);
}
else {
FD_SET(clientSock, &fds);
}
// If we have a server socket, listen for the accept() instead of the
// connect() so we can be compatible with the loopback relay.
timeout.tv_sec = 3;
err = select(0, nullptr, &fds, nullptr, &timeout);
err = select(0,
serverSock != INVALID_SOCKET ? &fds : nullptr,
serverSock == INVALID_SOCKET ? &fds : nullptr,
nullptr, &timeout);
if (err == 1) {
// Our FD was signalled for connect() completion
// Our FD was signalled for connect() or accept() completion
printf("Success\n");
}
else if (err == 0) {
@@ -315,6 +351,58 @@ PortTestStatus TestPort(PSOCKADDR_STORAGE addr, int proto, int port, bool withSe
}
}
PortTestStatus TestHttpPort(PSOCKADDR_STORAGE addr, int port)
{
HINTERNET hInternet;
HINTERNET hRequest;
char url[1024];
hInternet = InternetOpenA("MIST", 0, nullptr, nullptr, 0);
if (hInternet == nullptr) {
printf("InternetOpen() failed: %d\n", GetLastError());
return PortTestError;
}
char addrStr[64];
inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, addrStr, sizeof(addrStr));
sprintf(url, "%s://%s:%d/",
port == 47989 ? "http" : "https",
addrStr,
port);
hRequest = InternetOpenUrlA(hInternet, url, nullptr, 0,
INTERNET_FLAG_IGNORE_CERT_DATE_INVALID | INTERNET_FLAG_NO_UI | INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_RELOAD,
NULL);
if (hRequest == nullptr) {
if (GetLastError() == ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED) {
// This is expected for our HTTPS connection
printf("Success\n");
}
else {
// CANNOT_CONNECT is the "expected" error
if (GetLastError() == ERROR_INTERNET_CANNOT_CONNECT) {
printf("Failed\n");
}
else {
printf("Failed: %d\n", GetLastError());
}
InternetCloseHandle(hInternet);
return PortTestError;
}
}
else {
printf("Success\n");
InternetCloseHandle(hRequest);
}
InternetCloseHandle(hInternet);
return PortTestOk;
}
bool TestAllPorts(PSOCKADDR_STORAGE addr, char* portMsg, int portMsgLen)
{
bool ret = true;
@@ -323,7 +411,19 @@ bool TestAllPorts(PSOCKADDR_STORAGE addr, char* portMsg, int portMsgLen)
printf("Testing %s %d...",
k_Ports[i].proto == IPPROTO_TCP ? "TCP" : "UDP",
k_Ports[i].port);
PortTestStatus status = TestPort(addr, k_Ports[i].proto, k_Ports[i].port, k_Ports[i].withServer);
PortTestStatus status;
status = TestPort(addr, k_Ports[i].proto, k_Ports[i].port, k_Ports[i].withServer);
if (status != PortTestError && !k_Ports[i].withServer) {
// Test using a real HTTP client if the port wasn't totally dead.
// This is required to confirm functionality with the loopback relay.
// TestHttpPort() can take significantly longer to timeout than TestPort(),
// so we only do this test if we believe we're likely to get a response.
printf("Testing TCP %d with HTTP traffic...", k_Ports[i].port);
status = TestHttpPort(addr, k_Ports[i].port);
}
if (status != PortTestOk) {
// If we got an unknown result, assume it matches with whatever
// we've gotten so far.
@@ -510,7 +610,7 @@ bool CheckWANAccess(PSOCKADDR_IN wanAddr, PSOCKADDR_IN reportedWanAddr, bool* fo
case CONFLICTED:
snprintf(conflictMessage, sizeof(conflictMessage),
"Detected a port forwarding conflict with another PC on your network: %s\n\n"
"Remove that PC from your network or uninstall the Moonlight Internet Streaming Service from it, then restart your router.",
"Remove that PC from your network or uninstall the Moonlight Internet Streaming Helper from it, then restart your router.",
conflictEntry);
DisplayMessage(conflictMessage);
return false;
@@ -617,6 +717,8 @@ bool IsDoubleNAT(PSOCKADDR_IN wanAddr)
int main(int argc, char* argv[])
{
WSADATA wsaData;
SYSTEMTIME time;
char timeString[MAX_PATH + 1] = {};
char tempPath[MAX_PATH + 1];
GetTempPathA(sizeof(tempPath), tempPath);
@@ -627,6 +729,11 @@ int main(int argc, char* argv[])
// Print a log header
printf("Moonlight Internet Streaming Tester v" VER_VERSION_STR "\n");
// Print the current time
GetSystemTime(&time);
GetTimeFormatA(LOCALE_SYSTEM_DEFAULT, 0, &time, "hh':'mm':'ss tt", timeString, ARRAYSIZE(timeString));
printf("The current UTC time is: %s\n", timeString);
// Print a console header
fprintf(stderr, "Moonlight Internet Streaming Tester v" VER_VERSION_STR "\n\n");
@@ -651,7 +758,7 @@ int main(int argc, char* argv[])
char msgBuf[2048];
char portMsgBuf[512];
fprintf(stderr, "Testing local GameStream connectivity...\n");
fprintf(stderr, "Testing GameStream connectivity on this PC...\n");
// Try to connect via IPv4 loopback
ss = {};
@@ -660,8 +767,7 @@ int main(int argc, char* argv[])
printf("Testing GameStream ports via loopback\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf))) {
snprintf(msgBuf, sizeof(msgBuf),
"Local GameStream connectivity check failed. Please try reinstalling GeForce Experience.\n\nThe following ports were not working:\n%s",
portMsgBuf);
"Local GameStream connectivity check failed.\n\nFirst, try reinstalling GeForce Experience. If that doesn't resolve the problem, try temporarily disabling your antivirus and firewall.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting");
return -1;
}
@@ -671,14 +777,13 @@ int main(int argc, char* argv[])
return -1;
}
fprintf(stderr, "Testing network GameStream connectivity...\n");
fprintf(stderr, "Testing GameStream connectivity on your local network...\n");
// Try to connect via LAN IPv4 address
printf("Testing GameStream ports via local network\n");
if (!TestAllPorts(&ss, portMsgBuf, sizeof(portMsgBuf))) {
snprintf(msgBuf, sizeof(msgBuf),
"Local network GameStream connectivity check failed. Try temporarily disabling your firewall software or adding firewall exceptions for the following ports:\n%s",
portMsgBuf);
"Local network GameStream connectivity check failed. This is almost always caused by a firewall on your computer blocking the connection.\n\nTry temporarily disabling your antivirus and firewall.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting");
return -1;
}
@@ -702,7 +807,7 @@ int main(int argc, char* argv[])
printf("Detected inconsistency between UPnP/NAT-PMP and STUN reported WAN addresses!\n");
}
fprintf(stderr, "Testing Internet GameStream connectivity...\n");
fprintf(stderr, "Testing GameStream connectivity over the Internet...\n");
char wanAddrStr[64];
inet_ntop(AF_INET, &sin.sin_addr, wanAddrStr, sizeof(wanAddrStr));
@@ -720,20 +825,35 @@ int main(int argc, char* argv[])
snprintf(msgBuf, sizeof(msgBuf), "Your ISP is running a Carrier-Grade NAT that is preventing you from hosting services like Moonlight on the Internet. Click the Help button for guidance on fixing this issue.");
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#carrier-grade-nat-error");
}
else if (rulesFound) {
snprintf(msgBuf, sizeof(msgBuf), "Manual Internet streaming test required!\n\n"
"Connect your client device to a different network or cellular data (it MUST NOT on be the same network as this PC for testing!). If Moonlight doesn't automatically connect, you can type the following address into Moonlight's Add PC dialog: %s\n\n"
"If that doesn't work, click the Help button for guidance on fixing this issue.", wanAddrStr);
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#manual-internet-streaming-test-fails", MpWarn);
}
else {
snprintf(msgBuf, sizeof(msgBuf), "Internet GameStream connectivity check failed. Click the Help button for guidance on fixing this issue.\n\nThe following ports were not forwarded properly:\n%s", portMsgBuf);
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#internet-gamestream-connectivity-check-error");
}
else {
struct hostent* host;
// We can get here if the router doesn't support NAT reflection.
// We'll need to call out to our loopback server to get a second opinion.
printf("Testing GameStream ports via loopback server\n");
host = gethostbyname("loopback.moonlight-stream.org");
if (host != nullptr) {
sin.sin_addr = *(struct in_addr*)host->h_addr;
if (TestAllPorts((PSOCKADDR_STORAGE)&sin, portMsgBuf, sizeof(portMsgBuf))) {
goto AllTestsPassed;
}
}
else {
printf("gethostbyname() failed: %d\n", WSAGetLastError());
}
}
snprintf(msgBuf, sizeof(msgBuf), "Internet GameStream connectivity check failed. Click the Help button for guidance on fixing this issue.\n\nThe following ports were not forwarded properly:\n%s", portMsgBuf);
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#internet-gamestream-connectivity-check-error");
return -1;
}
snprintf(msgBuf, sizeof(msgBuf), "All tests passed! If Moonlight doesn't automatically connect outside your network, you can type the following address into Moonlight's Add PC dialog: %s", wanAddrStr);
AllTestsPassed:
snprintf(msgBuf, sizeof(msgBuf), "This PC is ready to stream over the Internet!\n\n"
"For the easiest setup, you should pair Moonlight to your PC from your home network before trying to stream over the Internet.\n\n"
"If you can't, you can type the following address into Moonlight's Add PC dialog: %s", wanAddrStr);
DisplayMessage(msgBuf, nullptr, MpInfo);
return 0;
+3
View File
@@ -3,6 +3,7 @@
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_VERSION
PRODUCTVERSION VER_VERSION
BEGIN
BLOCK "StringFileInfo"
BEGIN
@@ -11,6 +12,8 @@ BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "FileDescription", "Moonlight Internet Streaming Tester"
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "FileVersion", VER_VERSION_STR
VALUE "ProductVersion", VER_VERSION_STR
END
END
+2 -2
View File
@@ -1,7 +1,7 @@
#pragma once
#define VER_VERSION 2,3,0,0
#define VER_VERSION_STR "2.3.0.0"
#define VER_VERSION 3,0,0,0
#define VER_VERSION_STR "3.0.0.0"
#define VER_COMPANYNAME_STR "Moonlight Game Streaming Project"
#define VER_PRODUCTNAME_STR "Moonlight Internet Streaming Helper"