2010-05-25 10:56:00 +00:00
|
|
|
//-------------------------------------------------------------------------
|
2006-04-13 20:47:06 +00:00
|
|
|
/*
|
2010-05-25 10:56:00 +00:00
|
|
|
Copyright (C) 2010 EDuke32 developers and contributors
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
This file is part of EDuke32.
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-25 10:56:00 +00:00
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2014-07-20 08:55:56 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-04-13 20:47:06 +00:00
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2012-11-24 09:13:29 +00:00
|
|
|
#ifdef _WIN32
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-12-21 12:53:11 +00:00
|
|
|
#include "compat.h"
|
2017-02-19 22:15:44 +00:00
|
|
|
|
|
|
|
#define NEED_SHELLAPI_H
|
|
|
|
#define NEED_WINSOCK2_H
|
|
|
|
#define NEED_WS2TCPIP_H
|
|
|
|
#include "windows_inc.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2012-11-25 04:26:37 +00:00
|
|
|
#include "renderlayer.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t G_GetVersionFromWebsite(char *buffer)
|
2008-11-24 09:22:07 +00:00
|
|
|
{
|
2018-10-10 19:14:41 +00:00
|
|
|
static int32_t wsainitialized = 0;
|
|
|
|
int32_t i=0, j=0, r=0;
|
2008-11-24 09:22:07 +00:00
|
|
|
struct sockaddr_in dest_addr;
|
|
|
|
struct hostent *h;
|
2016-01-11 05:06:10 +00:00
|
|
|
char const *host = "www.eduke32.com";
|
|
|
|
char const *req = "GET http://www.eduke32.com/VERSION HTTP/1.0\r\n\r\n\r\n";
|
2012-11-29 12:49:41 +00:00
|
|
|
char *tok;
|
2008-11-24 09:22:07 +00:00
|
|
|
char tempbuf[2048],otherbuf[16],ver[16];
|
|
|
|
SOCKET mysock;
|
2018-10-10 19:14:41 +00:00
|
|
|
WSADATA ws;
|
2008-11-24 09:22:07 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (wsainitialized == 0)
|
|
|
|
{
|
2018-10-10 19:14:41 +00:00
|
|
|
if (WSAStartup(0x101, &ws) == SOCKET_ERROR)
|
2016-06-21 00:34:41 +00:00
|
|
|
return 0;
|
2018-10-10 19:14:41 +00:00
|
|
|
|
2008-11-24 09:22:07 +00:00
|
|
|
wsainitialized = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-10 19:14:41 +00:00
|
|
|
if ((h = gethostbyname(host)) == NULL)
|
2008-11-24 09:22:07 +00:00
|
|
|
{
|
2018-10-10 19:14:41 +00:00
|
|
|
initprintf("Couldn't resolve %s!\n", host);
|
2016-06-21 00:34:41 +00:00
|
|
|
return 0;
|
2008-11-24 09:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dest_addr.sin_addr.s_addr = ((struct in_addr *)(h->h_addr))->s_addr;
|
|
|
|
dest_addr.sin_family = AF_INET;
|
|
|
|
dest_addr.sin_port = htons(80);
|
|
|
|
|
|
|
|
memset(&(dest_addr.sin_zero), '\0', 8);
|
|
|
|
|
|
|
|
mysock = socket(PF_INET, SOCK_STREAM, 0);
|
|
|
|
|
|
|
|
if (mysock == INVALID_SOCKET)
|
|
|
|
{
|
2018-10-10 19:14:41 +00:00
|
|
|
WSACleanup();
|
2016-06-21 00:34:41 +00:00
|
|
|
return 0;
|
2008-11-24 09:22:07 +00:00
|
|
|
}
|
2018-10-10 19:14:41 +00:00
|
|
|
|
2008-11-24 09:22:07 +00:00
|
|
|
initprintf("Connecting to http://%s\n",host);
|
2018-10-10 19:14:41 +00:00
|
|
|
|
2008-11-24 09:22:07 +00:00
|
|
|
if (connect(mysock, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR)
|
2018-10-10 19:14:41 +00:00
|
|
|
goto done;
|
2008-11-24 09:22:07 +00:00
|
|
|
|
2018-10-10 19:14:41 +00:00
|
|
|
i = send(mysock, req, strlen(req), 0);
|
|
|
|
|
|
|
|
if (i == SOCKET_ERROR)
|
|
|
|
goto done;
|
2008-11-24 09:22:07 +00:00
|
|
|
|
2012-11-29 12:49:41 +00:00
|
|
|
i = recv(mysock, (char *)&tempbuf, sizeof(tempbuf), 0);
|
2018-10-10 19:14:41 +00:00
|
|
|
|
2012-11-29 12:49:41 +00:00
|
|
|
if (i < 0)
|
2018-10-10 19:14:41 +00:00
|
|
|
goto done;
|
2012-11-29 12:49:41 +00:00
|
|
|
|
2018-10-10 19:14:41 +00:00
|
|
|
Bmemcpy(&otherbuf, &tempbuf, sizeof(otherbuf));
|
2008-11-24 09:22:07 +00:00
|
|
|
|
2018-10-10 19:14:41 +00:00
|
|
|
strtok(otherbuf, " ");
|
2008-11-24 09:22:07 +00:00
|
|
|
|
2018-10-10 19:14:41 +00:00
|
|
|
if ((tok = strtok(NULL, " ")) == NULL)
|
|
|
|
goto done;
|
2012-11-29 12:49:41 +00:00
|
|
|
|
|
|
|
if (Batol(tok) == 200)
|
2008-11-24 09:22:07 +00:00
|
|
|
{
|
2018-10-10 19:14:41 +00:00
|
|
|
for (i = 0; (unsigned)i < strlen(tempbuf); i++) // HACK: all of this needs to die a fiery death; we just skip to the content
|
2008-11-24 09:22:07 +00:00
|
|
|
{
|
|
|
|
// instead of actually parsing any of the http headers
|
|
|
|
if (i > 4)
|
|
|
|
if (tempbuf[i-1] == '\n' && tempbuf[i-2] == '\r' && tempbuf[i-3] == '\n' && tempbuf[i-4] == '\r')
|
|
|
|
{
|
|
|
|
while (j < 9)
|
|
|
|
{
|
|
|
|
ver[j] = tempbuf[i];
|
|
|
|
i++, j++;
|
|
|
|
}
|
|
|
|
ver[j] = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j)
|
|
|
|
{
|
2018-10-10 19:14:41 +00:00
|
|
|
strcpy(buffer, ver);
|
|
|
|
r = 1;
|
|
|
|
goto done;
|
2008-11-24 09:22:07 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-10 19:14:41 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
closesocket(mysock);
|
|
|
|
WSACleanup();
|
|
|
|
|
|
|
|
return r;
|
2008-11-24 09:22:07 +00:00
|
|
|
}
|
|
|
|
#endif
|