- implemented anonymous stats collector

This commit is contained in:
Rachael Alexanderson 2018-03-04 23:49:01 -05:00 committed by Christoph Oelckers
parent 5d436cd3ed
commit c15e868b0f
4 changed files with 113 additions and 1 deletions

View File

@ -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());

52
src/d_stats.cpp Normal file
View File

@ -0,0 +1,52 @@
#if defined(_WIN32)
#include <thread>
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
}

View File

@ -510,3 +510,48 @@ CCMD (vid_currentmode)
Printf ("%dx%dx%d\n", DisplayWidth, DisplayHeight, DisplayBits);
}
#include <winsock2.h>
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;
}

View File

@ -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: