From f2f649bf77b8121fe31d538321022f8709f189c3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 4 Mar 2018 17:51:07 +0100 Subject: [PATCH] - put all stats related code into one file. --- src/d_stats.cpp | 122 ++++++++++++++++++++++++++++++++++--- src/posix/sdl/i_system.cpp | 63 ------------------- src/win32/hardware.cpp | 46 -------------- 3 files changed, 114 insertions(+), 117 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index 7150b9a9a..3cb089b4d 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -2,8 +2,13 @@ #define _WIN32_WINNT 0x0501 #define WIN32_LEAN_AND_MEAN #include +#include extern int sys_ostype; - +#else +#include +#include +#include +#include #endif #include @@ -18,13 +23,114 @@ CVAR(String, sys_statshost, "gzstats.drdteam.org", CVAR_ARCHIVE|CVAR_GLOBALCONFI CVAR(Int, sys_statsport, 80, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOSET) // Each machine will only send two reports, one when started with hardware rendering and one when started with software rendering. -CVAR(Bool, sentstats_swr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) -CVAR(Bool, sentstats_hwr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) +#define CHECKVERSION 330 +#define CHECKVERSIONSTR "330" +CVAR(Int, sentstats_swr_done, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) +CVAR(Int, sentstats_hwr_done, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOSET) std::pair gl_getInfo(); -bool I_HTTPRequest(const char* request); +#ifdef _WIN32 + +bool I_HTTPRequest(const char* request) +{ + if (sys_statshost.GetHumanString() == NULL) + return false; // no host, disable + + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) + { + DPrintf(DMSG_ERROR, "WSAStartup failed.\n"); + return false; + } + 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 false; + } + send(Socket, request, (int)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 true; +} +#else +bool I_HTTPRequest(const char* request) +{ + if (sys_statshost.GetHumanString() == NULL || sys_statshost.GetHumanString()[0] == 0) + return false; // no host, disable + + int sockfd, portno, n; + struct sockaddr_in serv_addr; + struct hostent *server; + + portno = sys_statsport; + sockfd = socket(AF_INET, SOCK_STREAM, 0); + + if (sockfd < 0) + { + DPrintf(DMSG_ERROR, "Error opening TCP socket.\n"); + return false; + } + + server = gethostbyname(sys_statshost.GetHumanString()); + if (server == NULL) + { + DPrintf(DMSG_ERROR, "Error looking up hostname.\n"); + return false; + } + bzero((char*) &serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + bcopy((char *)server->h_addr, + (char *)&serv_addr.sin_addr.s_addr, + server->h_length); + serv_addr.sin_port = htons(portno); + + DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); + if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) + { + DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); + return false; + } + + char buffer[1024]; + sprintf(buffer, "%s", request); + Printf("Buffer: %s", buffer); + n = write(sockfd, (char*)buffer, (int)strlen(request)); + if (n<0) + { + DPrintf(DMSG_ERROR, "Error writing to socket.\n"); + close(sockfd); + return false; + } + bzero(buffer, 1024); + + n = read(sockfd, buffer, 1023); + close(sockfd); + DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); + return true; +} +#endif + static int GetOSVersion() { #ifdef _WIN32 @@ -109,11 +215,11 @@ static void D_DoHTTPRequest(const char *request) { if (currentrenderer == 0) { - cvar_forceset("sentstats_swr", "1"); + cvar_forceset("sentstats_swr_done", CHECKVERSIONSTR); } else { - cvar_forceset("sentstats_hwr", "1"); + cvar_forceset("sentstats_hwr_done", CHECKVERSIONSTR); } } } @@ -125,8 +231,8 @@ void D_DoAnonStats() done = true; // Do not repeat if already sent. - if (currentrenderer == 0 && sentstats_swr) return; - if (currentrenderer == 1 && sentstats_hwr) return; + if (currentrenderer == 0 && sentstats_swr_done >= CHECKVERSION) return; + if (currentrenderer == 1 && sentstats_hwr_done >= CHECKVERSION) return; static char requeststring[1024]; sprintf(requeststring, "GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index f6d05f309..1f41788a0 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -36,11 +36,6 @@ #include -#include -#include -#include -#include - #include "doomerrors.h" #include @@ -74,8 +69,6 @@ #include "g_level.h" EXTERN_CVAR (String, language) -EXTERN_CVAR(String, sys_statshost) -EXTERN_CVAR(Int, sys_statsport) extern "C" { @@ -497,59 +490,3 @@ TArray I_GetGogPaths() return TArray(); } -bool I_HTTPRequest(const char* request) -{ - if (sys_statshost.GetHumanString() == NULL || sys_statshost.GetHumanString()[0] == 0) - return false; // no host, disable - - int sockfd, portno, n; - struct sockaddr_in serv_addr; - struct hostent *server; - - portno = sys_statsport; - sockfd = socket(AF_INET, SOCK_STREAM, 0); - - if (sockfd < 0) - { - DPrintf(DMSG_ERROR, "Error opening TCP socket.\n"); - return false; - } - - server = gethostbyname(sys_statshost.GetHumanString()); - if (server == NULL) - { - DPrintf(DMSG_ERROR, "Error looking up hostname.\n"); - return false; - } - bzero((char*) &serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - bcopy((char *)server->h_addr, - (char *)&serv_addr.sin_addr.s_addr, - server->h_length); - serv_addr.sin_port = htons(portno); - - DPrintf(DMSG_NOTIFY, "Connecting to host %s\n", sys_statshost.GetHumanString()); - if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) - { - DPrintf(DMSG_ERROR, "Connection to host %s failed!\n", sys_statshost.GetHumanString()); - return false; - } - - char buffer[1024]; - sprintf(buffer, "%s", request); - Printf("Buffer: %s", buffer); - n = write(sockfd, (char*)buffer, (int)strlen(request)); - if (n<0) - { - DPrintf(DMSG_ERROR, "Error writing to socket.\n"); - close(sockfd); - return false; - } - bzero(buffer, 1024); - - n = read(sockfd, buffer, 1023); - close(sockfd); - DPrintf(DMSG_NOTIFY, "Stats send successful.\n"); - return true; -} - diff --git a/src/win32/hardware.cpp b/src/win32/hardware.cpp index 17da1ff6d..a8ecfccae 100644 --- a/src/win32/hardware.cpp +++ b/src/win32/hardware.cpp @@ -509,49 +509,3 @@ CCMD (vid_currentmode) { Printf ("%dx%dx%d\n", DisplayWidth, DisplayHeight, DisplayBits); } - - -#include -EXTERN_CVAR(String, sys_statshost) -EXTERN_CVAR(Int, sys_statsport) - -bool I_HTTPRequest(const char* request) -{ - if (sys_statshost.GetHumanString() == NULL) - return false; // no host, disable - - WSADATA wsaData; - if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) - { - DPrintf(DMSG_ERROR, "WSAStartup failed.\n"); - return false; - } - 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 false; - } - send(Socket, request, (int)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 true; -}