From 033a11a0286fef90c2cd429b7d5273db8932f36c Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Sun, 4 Mar 2018 23:51:26 -0500 Subject: [PATCH] - fix compile on clang - implement TCP connections in Linux - fix passing of request string to a thread - implement OS stats for ARM and PPC on Linux --- src/d_stats.cpp | 12 +++- src/posix/sdl/i_system.cpp | 128 +++++++++++++++++++++++++++---------- 2 files changed, 102 insertions(+), 38 deletions(-) diff --git a/src/d_stats.cpp b/src/d_stats.cpp index a2df44318..7150b9a9a 100644 --- a/src/d_stats.cpp +++ b/src/d_stats.cpp @@ -58,8 +58,12 @@ static int GetOSVersion() #else - // Todo: PPC + ARM - +// fall-through linux stuff here +#ifdef __arm__ + return 10; +#elif __ppc__ + return 9; +#else if (sizeof(void*) == 4) // 32 bit { return 11; @@ -68,6 +72,7 @@ static int GetOSVersion() { return 12; } +#endif #endif @@ -123,7 +128,8 @@ void D_DoAnonStats() if (currentrenderer == 0 && sentstats_swr) return; if (currentrenderer == 1 && sentstats_hwr) return; - FStringf requeststring("GET /stats.php?render=%i&cores=%i&os=%i HTTP/1.1\nHost: %s\nConnection: close\nUser-Agent: %s %s\n\n", + 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", GetRenderInfo(), GetCoreInfo(), GetOSVersion(), sys_statshost.GetHumanString(), GAMENAME, VERSIONSTR); DPrintf(DMSG_NOTIFY, "Sending %s", requeststring); std::thread t1(D_DoHTTPRequest, requeststring); diff --git a/src/posix/sdl/i_system.cpp b/src/posix/sdl/i_system.cpp index b3fa1eda7..f6d05f309 100644 --- a/src/posix/sdl/i_system.cpp +++ b/src/posix/sdl/i_system.cpp @@ -36,6 +36,11 @@ #include +#include +#include +#include +#include + #include "doomerrors.h" #include @@ -69,6 +74,8 @@ #include "g_level.h" EXTERN_CVAR (String, language) +EXTERN_CVAR(String, sys_statshost) +EXTERN_CVAR(Int, sys_statsport) extern "C" { @@ -94,7 +101,7 @@ void I_Tactile (int /*on*/, int /*off*/, int /*total*/) ticcmd_t emptycmd; ticcmd_t *I_BaseTiccmd(void) { - return &emptycmd; + return &emptycmd; } void I_BeginRead(void) @@ -129,7 +136,7 @@ void I_Init (void) DumpCPUInfo (&CPU); atterm (I_ShutdownSound); - I_InitSound (); + I_InitSound (); } // @@ -139,9 +146,9 @@ static int has_exited; void I_Quit (void) { - has_exited = 1; /* Prevent infinitely recursive exits -- killough */ + has_exited = 1; /* Prevent infinitely recursive exits -- killough */ - if (demorecording) + if (demorecording) G_CheckDemoStatus(); C_DeinitConsole(); @@ -191,11 +198,11 @@ void Linux_I_FatalError(const char* errortext) void I_FatalError (const char *error, ...) { - static bool alreadyThrown = false; - gameisdead = true; + static bool alreadyThrown = false; + gameisdead = true; - if (!alreadyThrown) // ignore all but the first message -- killough - { + if (!alreadyThrown) // ignore all but the first message -- killough + { alreadyThrown = true; char errortext[MAX_ERRORTEXT]; int index; @@ -221,25 +228,25 @@ void I_FatalError (const char *error, ...) // throw CFatalError (errortext); fprintf (stderr, "%s\n", errortext); exit (-1); - } + } - if (!has_exited) // If it hasn't exited yet, exit now -- killough - { + if (!has_exited) // If it hasn't exited yet, exit now -- killough + { has_exited = 1; // Prevent infinitely recursive exits -- killough exit(-1); - } + } } void I_Error (const char *error, ...) { - va_list argptr; - char errortext[MAX_ERRORTEXT]; + va_list argptr; + char errortext[MAX_ERRORTEXT]; - va_start (argptr, error); - vsprintf (errortext, error, argptr); - va_end (argptr); + va_start (argptr, error); + vsprintf (errortext, error, argptr); + va_end (argptr); - throw CRecoverableError (errortext); + throw CRecoverableError (errortext); } void I_SetIWADInfo () @@ -291,8 +298,8 @@ int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad) { FString cmd("kdialog --title \"" GAMESIG " "); cmd << GetVersionString() << ": Select an IWAD to use\"" - " --menu \"" GAMENAME " found more than one IWAD\n" - "Select from the list below to determine which one to use:\""; + " --menu \"" GAMENAME " found more than one IWAD\n" + "Select from the list below to determine which one to use:\""; for(i = 0; i < numwads; ++i) { @@ -380,7 +387,7 @@ static int matchfile (struct dirent *ent) static int matchfile (const struct dirent *ent) #endif { - return fnmatch (pattern, ent->d_name, FNM_NOESCAPE) == 0; + return fnmatch (pattern, ent->d_name, FNM_NOESCAPE) == 0; } void *I_FindFirst (const char *filespec, findstate_t *fileinfo) @@ -399,22 +406,22 @@ void *I_FindFirst (const char *filespec, findstate_t *fileinfo) dir = "."; } - fileinfo->current = 0; - fileinfo->count = scandir (dir.GetChars(), &fileinfo->namelist, + fileinfo->current = 0; + fileinfo->count = scandir (dir.GetChars(), &fileinfo->namelist, matchfile, alphasort); - if (fileinfo->count > 0) - { + if (fileinfo->count > 0) + { return fileinfo; - } - return (void*)-1; + } + return (void*)-1; } int I_FindNext (void *handle, findstate_t *fileinfo) { - findstate_t *state = (findstate_t *)handle; - if (state->current < fileinfo->count) - { - return ++state->current < fileinfo->count ? 0 : -1; + findstate_t *state = (findstate_t *)handle; + if (state->current < fileinfo->count) + { + return ++state->current < fileinfo->count ? 0 : -1; } return -1; } @@ -486,12 +493,63 @@ unsigned int I_MakeRNGSeed() TArray I_GetGogPaths() { - // GOG's Doom games are Windows only at the moment - return TArray(); + // GOG's Doom games are Windows only at the moment + return TArray(); } - bool I_HTTPRequest(const char* request) { - // todo + 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; } +