- put all stats related code into one file.

This commit is contained in:
Christoph Oelckers 2018-03-04 17:51:07 +01:00
commit f2f649bf77
3 changed files with 114 additions and 117 deletions

View file

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