From dc0dea7c09fa584ae5982012a0bf8090edc98fa6 Mon Sep 17 00:00:00 2001 From: terminx Date: Thu, 14 Dec 2006 03:34:55 +0000 Subject: [PATCH] Update checking for win32... git-svn-id: https://svn.eduke32.com/eduke32@416 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/mmulti.c | 122 +++++++++++++++++++++++++------ polymer/eduke32/source/astub.c | 8 +- polymer/eduke32/source/config.c | 12 +++ polymer/eduke32/source/config.h | 4 + polymer/eduke32/source/funct.h | 2 +- polymer/eduke32/source/game.c | 90 +++++++++++++++++++---- polymer/eduke32/source/osdcmds.c | 36 ++++----- polymer/eduke32/source/sector.c | 4 +- 8 files changed, 219 insertions(+), 59 deletions(-) diff --git a/polymer/build/src/mmulti.c b/polymer/build/src/mmulti.c index 6e831ea92..64927f0ae 100644 --- a/polymer/build/src/mmulti.c +++ b/polymer/build/src/mmulti.c @@ -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,7 +128,8 @@ void netuninit () { if (mysock != (SOCKET)INVALID_HANDLE_VALUE) closesocket(mysock); #ifdef _WIN32 - WSACleanup(); + if (wsainitialized) + WSACleanup(); #endif } @@ -165,9 +170,13 @@ long netinit (long portnum) long i; #ifdef _WIN32 - WSADATA ws; + if (wsainitialized == 0) + { + WSADATA ws; - if (WSAStartup(0x101,&ws) == SOCKET_ERROR) return(0); + 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)ih_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 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); } diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 7637c7ae4..e7724cfc9 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -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; } diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index 0b676eacf..5d9e0516d 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -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 1) - { allowtimetocorrecterrorswhenquitting(); - uninitmultiplayers(); - } + + 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,15 +8358,17 @@ 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 (tempbuf[0]) + if (getexternaladdress(tempbuf)) { - for (i=0;i 1) initprintf("Multiplayer initialized.\n"); +#ifdef _WIN32 + else if (checkforupdates == 1) + { + i = time(NULL); + + if (i > lastupdatecheck+86400) + { +#include + 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) { diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 39b771c2b..46cc930f6 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -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) { diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 2f6e13490..b7f355b0f 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -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;