From c15e868b0fed901edb52f3c9f052a6854b55fd35 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 4 Mar 2018 23:49:01 -0500 Subject: [PATCH] - implemented anonymous stats collector --- src/d_main.cpp | 3 +++ src/d_stats.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ src/win32/hardware.cpp | 45 ++++++++++++++++++++++++++++++++++++ src/win32/i_system.cpp | 14 +++++++++++- 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/d_stats.cpp diff --git a/src/d_main.cpp b/src/d_main.cpp index 73450cc0a5..15fcaada34 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -118,6 +118,7 @@ #include "vm.h" #include "types.h" #include "r_data/r_vanillatrans.h" +#include "d_stats.cpp" EXTERN_CVAR(Bool, hud_althud) void DrawHUD(); @@ -2744,6 +2745,8 @@ void D_DoomMain (void) setmodeneeded = false; // This may be set to true here, but isn't needed for a restart } + D_DoAnonStats(); + if (I_FriendlyWindowTitle) I_SetWindowTitle(DoomStartupInfo.Name.GetChars()); diff --git a/src/d_stats.cpp b/src/d_stats.cpp new file mode 100644 index 0000000000..797cd3ccc4 --- /dev/null +++ b/src/d_stats.cpp @@ -0,0 +1,52 @@ +#if defined(_WIN32) +#include + +EXTERN_CVAR(Bool, gl_legacy_mode) +EXTERN_CVAR(Bool, vid_glswfb) +extern int currentrenderer, sys_ostype, restart; +CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +void D_DoHTTPRequest(char* request); + +#endif + +void D_DoAnonStats() +{ +#if defined(_WIN32) + uint8_t astat_render, astat_sysbits; + static char* requeststring = new char[512]; + // astat_render: + // 0: Unaccelerated (Software) + // 1: Direct3D (Software) + // 2: OpenGL (Software) + // 3: Legacy OpenGL mode + // 4: Modern OpenGL (>3.3) path + + // sys_ostype: + // 0: unknown/outdated + // 1: legacy (XP/Vista) + // 2: supported (7/8/8.1) + // 3: modern (10+) + + // astat_sysbits: + // 0: 32-bit + // 1: 64-bit + + if (!restart) + { + astat_render = (currentrenderer == 1) ? + (gl_legacy_mode ? 3 : 4) : // opengl + (!(screen->Accel2D)) ? 0 : (vid_glswfb ? 2 : 1); // software +#ifdef _WIN64 + astat_sysbits = 1; +#else + astat_sysbits = 0; +#endif + sprintf(requeststring, "GET /stats.php?render=%i&bits=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + astat_render, astat_sysbits, sys_ostype, sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); + //Printf("%s", requeststring); + std::thread t1(D_DoHTTPRequest, requeststring); + t1.detach(); + } +#endif +} diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 58a611d3e7..df0bb3cdb8 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -510,3 +510,48 @@ CCMD (vid_currentmode) Printf ("%dx%dx%d\n", DisplayWidth, DisplayHeight, DisplayBits); } + +#include +EXTERN_CVAR(String, sys_statshost) +EXTERN_CVAR(Int, sys_statsport) + +void D_DoHTTPRequest(char* request) +{ + if (sys_statshost.GetHumanString() == NULL) + return; // no host, disable + + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) + { + DPrintf(DMSG_ERROR, "WSAStartup failed.\n"); + return; + } + SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + struct hostent *host; + host = gethostbyname(sys_statshost.GetHumanString()); + SOCKADDR_IN SockAddr; + SockAddr.sin_port = htons(sys_statsport); + SockAddr.sin_family = AF_INET; + SockAddr.sin_addr.s_addr = *((uint32_t*)host->h_addr); + DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); + if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) + { + DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); + return; + } + send(Socket, request, strlen(request), 0); + char buffer[1024]; + int nDataLength; + while ((nDataLength = recv(Socket, buffer, 1024, 0)) > 0) + { + int i = 0; + while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') + { + i++; + } + } + closesocket(Socket); + WSACleanup(); + DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); + return; +} diff --git a/src/win32/i_system.cpp b/src/win32/i_system.cpp index a537329e40..ba829d959c 100644 --- a/src/win32/i_system.cpp +++ b/src/win32/i_system.cpp @@ -154,6 +154,7 @@ uint32_t LanguageIDs[4]; UINT TimerPeriod; bool gameisdead; +int sys_ostype = 0; // PRIVATE DATA DEFINITIONS ------------------------------------------------ @@ -229,10 +230,12 @@ void I_DetectOS(void) if (info.dwMinorVersion == 1) { osname = "XP"; + sys_ostype = 1; // legacy OS } else if (info.dwMinorVersion == 2) { osname = "Server 2003"; + sys_ostype = 1; // legacy OS } } else if (info.dwMajorVersion == 6) @@ -240,10 +243,12 @@ void I_DetectOS(void) if (info.dwMinorVersion == 0) { osname = (info.wProductType == VER_NT_WORKSTATION) ? "Vista" : "Server 2008"; + sys_ostype = 1; // legacy OS } else if (info.dwMinorVersion == 1) { osname = (info.wProductType == VER_NT_WORKSTATION) ? "7" : "Server 2008 R2"; + sys_ostype = 2; // supported OS } else if (info.dwMinorVersion == 2) { @@ -251,16 +256,23 @@ void I_DetectOS(void) // the highest version of Windows you support, which will also be the // highest version of Windows this function returns. osname = (info.wProductType == VER_NT_WORKSTATION) ? "8" : "Server 2012"; + sys_ostype = 2; // supported OS } else if (info.dwMinorVersion == 3) { osname = (info.wProductType == VER_NT_WORKSTATION) ? "8.1" : "Server 2012 R2"; + sys_ostype = 2; // supported OS } else if (info.dwMinorVersion == 4) { - osname = (info.wProductType == VER_NT_WORKSTATION) ? "10 (or higher)" : "Server 10 (or higher)"; + osname = (info.wProductType == VER_NT_WORKSTATION) ? "10 (beta)" : "Server 10 (beta)"; } } + else if (info.dwMajorVersion == 10) + { + osname = (info.wProductType == VER_NT_WORKSTATION) ? "10 (or higher)" : "Server 10 (or higher)"; + sys_ostype = 3; // modern OS + } break; default: