Update checking for win32...

git-svn-id: https://svn.eduke32.com/eduke32@416 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2006-12-14 03:34:55 +00:00
parent 991d785e73
commit dc0dea7c09
8 changed files with 219 additions and 59 deletions

View file

@ -79,6 +79,10 @@ static SOCKET mysock;
static long myip, myport = NETPORT, otherip[MAXPLAYERS], otherport[MAXPLAYERS];
static long snatchip = 0, snatchport = 0, danetmode = 255, netready = 0;
#ifdef _WIN32
int wsainitialized = 0;
#endif
/*Addfaz NatFree Start*/
int natfree; //NatFree mode flag
int nfCurrentPlayer = 0; //Current NatFree player counter. Will only talk with one player at a time
@ -124,6 +128,7 @@ void netuninit ()
{
if (mysock != (SOCKET)INVALID_HANDLE_VALUE) closesocket(mysock);
#ifdef _WIN32
if (wsainitialized)
WSACleanup();
#endif
}
@ -165,9 +170,13 @@ long netinit (long portnum)
long i;
#ifdef _WIN32
if (wsainitialized == 0)
{
WSADATA ws;
if (WSAStartup(0x101,&ws) == SOCKET_ERROR) return(0);
wsainitialized = 1;
}
#endif
mysock = socket(AF_INET,SOCK_DGRAM,0); if (mysock == INVALID_SOCKET) return(0);
@ -804,20 +813,17 @@ long getpacket (long *retother, char *bufptr)
return(0);
}
char tempbuf[512],ipaddr[32];
const char *getexternaladdress(void)
int getexternaladdress(char *buffer)
{
int sockfd, bytes_sent, i=0, j=0;
int bytes_sent, i=0, j=0;
struct sockaddr_in dest_addr;
struct hostent *h;
char *host = "checkip.dyndns.org";
char *req = "GET / HTTP/1.0\r\n\r\n";
if (ipaddr[0])
return(ipaddr);
char tempbuf[512], ipaddr[32];
#ifdef _WIN32
if (wsainitialized == 0)
{
WSADATA ws;
@ -825,6 +831,7 @@ const char *getexternaladdress(void)
initprintf("mmulti: Winsock error in getexternaladdress() (%d)\n",errno);
return(0);
}
wsainitialized = 1;
}
#endif
@ -839,30 +846,28 @@ const char *getexternaladdress(void)
memset(&(dest_addr.sin_zero), '\0', 8);
sockfd = socket(PF_INET, SOCK_STREAM, 0);
if (sockfd == SOCKET_ERROR) {
mysock = socket(PF_INET, SOCK_STREAM, 0);
if (mysock == INVALID_SOCKET) {
initprintf("mmulti: socket() error in getexternaladdress() (%d)\n",errno);
return(0);
}
if (connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR) {
if (connect(mysock, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR) {
initprintf("mmulti: connect() error in getexternaladdress() (%d)\n",errno);
return(0);
}
bytes_sent = send(sockfd, req, strlen(req), 0);
bytes_sent = send(mysock, req, strlen(req), 0);
if (bytes_sent == SOCKET_ERROR) {
initprintf("mmulti: send() error in getexternaladdress() (%d)\n",errno);
return(0);
}
// initprintf("sent %d bytes\n",bytes_sent);
recv(sockfd, (char *)&tempbuf, sizeof(tempbuf), 0);
closesocket(sockfd);
#ifdef _WIN32
WSACleanup();
#endif
recv(mysock, (char *)&tempbuf, sizeof(tempbuf), 0);
closesocket(mysock);
for (i=0;(unsigned)i<strlen(tempbuf);i++)
{
@ -877,5 +882,80 @@ const char *getexternaladdress(void)
break;
}
}
return(ipaddr);
memcpy(buffer,&ipaddr,j);
return(1);
}
int getversionfromwebsite(char *buffer) // FIXME: this probably belongs in game land
{
int bytes_sent, i=0, j=0;
struct sockaddr_in dest_addr;
struct hostent *h;
char *host = "eduke32.sourceforge.net";
char *req = "GET http://eduke32.sourceforge.net/VERSION HTTP/1.0\r\n\r\n";
char tempbuf[2048],ver[16];
#ifdef _WIN32
if (wsainitialized == 0)
{
WSADATA ws;
if (WSAStartup(0x101,&ws) == SOCKET_ERROR) {
initprintf("mmulti: Winsock error in getexternaladdress() (%d)\n",errno);
return(0);
}
wsainitialized = 1;
}
#endif
if ((h=gethostbyname(host)) == NULL) {
initprintf("mmulti: gethostbyname() error in getexternaladdress() (%d)\n",h_errno);
return(0);
}
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) {
initprintf("mmulti: socket() error in getexternaladdress() (%d)\n",errno);
return(0);
}
if (connect(mysock, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR) {
initprintf("mmulti: connect() error in getexternaladdress() (%d)\n",errno);
return(0);
}
bytes_sent = send(mysock, req, strlen(req), 0);
if (bytes_sent == SOCKET_ERROR) {
initprintf("mmulti: send() error in getexternaladdress() (%d)\n",errno);
return(0);
}
// initprintf("sent %d bytes\n",bytes_sent);
recv(mysock, (char *)&tempbuf, sizeof(tempbuf), 0);
closesocket(mysock);
for (i=0;(unsigned)i<strlen(tempbuf);i++) // HACK: all of this needs to die a fiery death; we just skip to the content
{ // 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;
}
}
strcpy(buffer,ver);
return(1);
}

View file

@ -4463,15 +4463,17 @@ int ExtInit(void)
if (glusetexcache == -1 || glusetexcachecompression == -1)
{
int i;
#if 1
i=wm_ynbox("Texture caching",
"Would you like to enable the on-disk texture cache? "
"This feature may use up to 200 megabytes of disk "
"space if you have a great deal of high resolution "
"textures and skins, but textures will load dramatically "
"faster after the first time they are loaded.");
if (i) i = 'y';
if (i == 'y' || i == 'Y')
#else
i = 1;
#endif
if (i)
glusetexcompr = glusetexcache = glusetexcachecompression = 1;
else glusetexcache = glusetexcachecompression = 0;
}

View file

@ -100,6 +100,8 @@ int32 ForceSetup = 1;
int32 scripthandle = -1;
static int32 setupread=0;
int32 checkforupdates = 0, lastupdatecheck = 0;
/*
===================
=
@ -714,6 +716,11 @@ int32 CONFIG_ReadSetup(void)
ps[0].auto_aim = AutoAim;
SCRIPT_GetNumber(scripthandle, "Controls","WeaponSwitchMode",&ud.weaponswitch);
ps[0].weaponswitch = ud.weaponswitch;
#ifdef _WIN32
SCRIPT_GetNumber(scripthandle, "Updates", "CheckForUpdates", &checkforupdates);
SCRIPT_GetNumber(scripthandle, "Updates", "LastUpdateCheck", &lastupdatecheck);
#endif
}
CONFIG_ReadKeys();
@ -814,6 +821,11 @@ void CONFIG_WriteSetup(void)
SCRIPT_PutNumber(scripthandle, "Sound Setup", "SoundToggle",SoundToggle,false,false);
SCRIPT_PutNumber(scripthandle, "Sound Setup", "VoiceToggle",VoiceToggle,false,false);
#ifdef _WIN32
SCRIPT_PutNumber(scripthandle, "Updates", "CheckForUpdates", checkforupdates, false, false);
SCRIPT_PutNumber(scripthandle, "Updates", "LastUpdateCheck", lastupdatecheck, false, false);
#endif
// JBF 20031211
for (dummy=0;dummy<NUMGAMEFUNCTIONS;dummy++)
{

View file

@ -66,6 +66,10 @@ extern int32 JoystickAnalogueScale[MAXJOYAXES];
extern int32 JoystickAnalogueDead[MAXJOYAXES];
extern int32 JoystickAnalogueSaturate[MAXJOYAXES];
#ifdef _WIN32
extern int32 checkforupdates, lastupdatecheck;
#endif
int32 CONFIG_ReadSetup( void );
void CONFIG_GetSetupFilename( void );
void CONFIG_WriteSetup( void );

View file

@ -74,7 +74,7 @@ extern void checkplayerhurt(struct player_struct *p,short j);
extern char checkhitceiling(short sn);
extern void checkhitsprite(short i,short sn);
extern void allignwarpelevators(void);
extern void cheatkeys(short snum);
extern void sharedkeys(short snum);
extern void checksectors(short snum);
extern int32 RTS_AddFile(char *filename);
extern void RTS_Init(char *filename);

View file

@ -50,6 +50,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define TIMERUPDATESIZ 32
#define BUILDDATE 20061213
long cameradist = 0, cameraclock = 0;
char playerswhenstarted;
char qe,cp,usecwd = 0;
@ -2568,10 +2570,9 @@ void gameexit(char *t)
if (*t != 0) ps[myconnectindex].palette = (char *) &palette[0];
if (numplayers > 1)
{
allowtimetocorrecterrorswhenquitting();
uninitmultiplayers();
}
if (ud.recstat == 1) closedemowrite();
else if (ud.recstat == 2)
@ -8221,7 +8222,7 @@ static void comlinehelp(void)
signed int rancid_players = 0;
char rancid_ip_strings[MAXPLAYERS][32], rancid_local_port_string[8];
extern const char *getexternaladdress(void);
extern int getexternaladdress(char *buffer);
int load_rancid_net(char *fn)
{
@ -8357,7 +8358,8 @@ void setup_rancid_net(char *fn)
Bstrcpy(tmp,strtok(tempbuf,"."));
if (i == rancid_players && ((Bstrcmp(tmp,"192") == 0) || (Bstrcmp(tmp,"172") == 0) || (Bstrcmp(tmp,"169") == 0) || (Bstrcmp(tmp,"10") == 0)))
{
Bsprintf(tempbuf, getexternaladdress());
if (getexternaladdress(tempbuf))
{
if (tempbuf[0])
{
for (i=0;i<rancid_players;i++)
@ -8371,6 +8373,7 @@ void setup_rancid_net(char *fn)
}
}
}
}
qsort((char *)rancid_ip_strings, rancid_players, sizeof(rancid_ip_strings[0]), (int(*)(const void*,const void*))stringsort);
networkmode = 1;
@ -9407,8 +9410,49 @@ static void Startup(long argc, char **argv)
netparam = NULL;
netparamcount = 0;
initprintf("%ld\n",time(NULL));
if (numplayers > 1)
initprintf("Multiplayer initialized.\n");
#ifdef _WIN32
else if (checkforupdates == 1)
{
i = time(NULL);
if (i > lastupdatecheck+86400)
{
#include <shellapi.h>
extern int getversionfromwebsite(char *buffer);
if (getversionfromwebsite(tempbuf))
{
lastupdatecheck = i;
if (atol(tempbuf) > BUILDDATE)
{
if (wm_ynbox("EDuke32","A new version of EDuke32 is available. "
"Would you like to download it now?"))
{
SHELLEXECUTEINFOA sinfo;
char *p = "http://www.eduke32.com/";
Bmemset(&sinfo, 0, sizeof(sinfo));
sinfo.cbSize = sizeof(sinfo);
sinfo.fMask = SEE_MASK_CLASSNAME;
sinfo.lpVerb = "open";
sinfo.lpFile = p;
sinfo.nShow = SW_SHOWNORMAL;
sinfo.lpClass = "http";
if(!ShellExecuteExA(&sinfo))
initprintf("Error launching browser!\n");
gameexit(" ");
}
}
}
}
}
#endif
screenpeek = myconnectindex;
ps[myconnectindex].palette = (char *) &palette[0];
@ -9723,10 +9767,16 @@ void app_main(int argc,char **argv)
#if defined(POLYMOST) && defined(USE_OPENGL)
glusetexcache = glusetexcachecompression = -1;
#endif
#ifdef _WIN32
checkforupdates = -1;
#endif
i = CONFIG_ReadSetup();
if (getenv("DUKE3DGRP")) duke3dgrp = getenv("DUKE3DGRP");
#if defined(POLYMOST) && defined(USE_OPENGL)
if (glusetexcache == -1 || glusetexcachecompression == -1)
{
i=wm_ynbox("Texture caching",
@ -9735,13 +9785,25 @@ void app_main(int argc,char **argv)
"space if you have a great deal of high resolution "
"textures and skins, but textures will load dramatically "
"faster after the first time they are loaded.");
if (i) i = 'y';
if (i == 'y' || i == 'Y')
useprecache = glusetexcompr = glusetexcache = glusetexcachecompression = 1;
if (i) useprecache = glusetexcompr = glusetexcache = glusetexcachecompression = 1;
else glusetexcache = glusetexcachecompression = 0;
}
#endif
#ifdef _WIN32
if (checkforupdates == -1)
{
i=wm_ynbox("Automatic update notification",
"Would you like EDuke32 to automatically check for updates? "
"This feature will contact the EDuke32 site at game startup "
"once every 24 hours in order to determine if a new "
"version is available. If so, you will be prompted to "
"download it.");
if (i) checkforupdates = 1;
else checkforupdates = 0;
}
#endif
if (preinitengine())
{
wm_msgbox("Build Engine Initialisation Error",
@ -11328,7 +11390,7 @@ static char domovethings(void)
if (sprite[ps[i].i].pal != 1)
sprite[ps[i].i].pal = ud.pcolor[i];
cheatkeys(i);
sharedkeys(i);
if (ud.pause_on == 0)
{

View file

@ -28,13 +28,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern int gotvote[MAXPLAYERS], votes[MAXPLAYERS], voting;
struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat;
int osdcmd_quit(const osdfuncparm_t *parm)
static inline int osdcmd_quit(const osdfuncparm_t *parm)
{
sendquit();
return OSDCMD_OK;
}
int osdcmd_echo(const osdfuncparm_t *parm)
static int osdcmd_echo(const osdfuncparm_t *parm)
{
int i;
for (i = 0; i < parm->numparms; i++)
@ -47,7 +47,7 @@ int osdcmd_echo(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_changelevel(const osdfuncparm_t *parm)
static int osdcmd_changelevel(const osdfuncparm_t *parm)
{
int volume=0,level;
char *p;
@ -165,7 +165,7 @@ int osdcmd_changelevel(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_map(const osdfuncparm_t *parm)
static int osdcmd_map(const osdfuncparm_t *parm)
{
int i;
char filename[256];
@ -268,7 +268,7 @@ int osdcmd_map(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_god(const osdfuncparm_t *parm)
static int osdcmd_god(const osdfuncparm_t *parm)
{
if (numplayers == 1 && ps[myconnectindex].gm & MODE_GAME)
{
@ -282,7 +282,7 @@ int osdcmd_god(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_noclip(const osdfuncparm_t *parm)
static int osdcmd_noclip(const osdfuncparm_t *parm)
{
if (numplayers == 1 && ps[myconnectindex].gm & MODE_GAME)
{
@ -296,7 +296,7 @@ int osdcmd_noclip(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_fileinfo(const osdfuncparm_t *parm)
static int osdcmd_fileinfo(const osdfuncparm_t *parm)
{
unsigned long crc, length;
int i,j;
@ -497,7 +497,7 @@ static int osdcmd_spawn(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_setvar(const osdfuncparm_t *parm)
static int osdcmd_setvar(const osdfuncparm_t *parm)
{
int i, varval;
char varname[256];
@ -520,7 +520,7 @@ int osdcmd_setvar(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_addpath(const osdfuncparm_t *parm)
static int osdcmd_addpath(const osdfuncparm_t *parm)
{
char pathname[BMAX_PATH];
@ -531,7 +531,7 @@ int osdcmd_addpath(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_initgroupfile(const osdfuncparm_t *parm)
static int osdcmd_initgroupfile(const osdfuncparm_t *parm)
{
char file[BMAX_PATH];
@ -542,7 +542,7 @@ int osdcmd_initgroupfile(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_cmenu(const osdfuncparm_t *parm)
static int osdcmd_cmenu(const osdfuncparm_t *parm)
{
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
if (numplayers > 1)
@ -558,7 +558,7 @@ int osdcmd_cmenu(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_exec(const osdfuncparm_t *parm)
static int osdcmd_exec(const osdfuncparm_t *parm)
{
char fn[BMAX_PATH];
extern int load_script(char *szStartupScript);
@ -627,7 +627,7 @@ cvar[] =
{ "r_precache", "r_precache: enable/disable the pre-level caching routine", (void*)&useprecache, CVAR_BOOL, 0, 0, 1 }
};
int osdcmd_cvar_set(const osdfuncparm_t *parm)
static int osdcmd_cvar_set(const osdfuncparm_t *parm)
{
int showval = (parm->numparms == 0);
unsigned int i;
@ -694,7 +694,7 @@ int osdcmd_cvar_set(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_sensitivity(const osdfuncparm_t *parm)
static int osdcmd_sensitivity(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
{
@ -706,7 +706,7 @@ int osdcmd_sensitivity(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_gamma(const osdfuncparm_t *parm)
static int osdcmd_gamma(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
{
@ -719,7 +719,7 @@ int osdcmd_gamma(const osdfuncparm_t *parm)
return OSDCMD_OK;
}
int osdcmd_give(const osdfuncparm_t *parm)
static int osdcmd_give(const osdfuncparm_t *parm)
{
int i;
@ -806,7 +806,7 @@ void onvideomodechange(int newmode)
restorepalette = 1;
}
int osdcmd_usemousejoy(const osdfuncparm_t *parm)
static int osdcmd_usemousejoy(const osdfuncparm_t *parm)
{
int showval = (parm->numparms < 1);
if (!Bstrcasecmp(parm->name, "usemouse"))
@ -838,7 +838,7 @@ int osdcmd_usemousejoy(const osdfuncparm_t *parm)
return OSDCMD_SHOWHELP;
}
int osdcmd_name(const osdfuncparm_t *parm)
static int osdcmd_name(const osdfuncparm_t *parm)
{
if (parm->numparms != 1)
{

View file

@ -1617,7 +1617,7 @@ void activatebysector(short sect,short j)
operatesectors(sect,j);
}
void breakwall(short newpn,short spr,short dawallnum)
static void breakwall(short newpn,short spr,short dawallnum)
{
wall[dawallnum].picnum = newpn;
spritesound(VENT_BUST,spr);
@ -2524,7 +2524,7 @@ void allignwarpelevators(void)
}
}
void cheatkeys(short snum)
void sharedkeys(short snum)
{
short i, k;
char dainv;