git-svn-id: https://svn.eduke32.com/eduke32@1125 1a8010ca-5511-0410-912e-c29ae57300e0

This commit is contained in:
terminx 2008-11-11 13:45:12 +00:00
parent 54128e127c
commit 5be3b76e85
3 changed files with 122 additions and 104 deletions

View File

@ -914,96 +914,3 @@ int getexternaladdress(char *buffer, const char *host, int port)
Bmemcpy(buffer,&ipaddr,j);
return(1);
}
#ifdef _WIN32
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],otherbuf[16],ver[16];
#ifdef _WIN32
if (wsainitialized == 0)
{
WSADATA ws;
if (WSAStartup(0x101,&ws) == SOCKET_ERROR)
{
initprintf("update: Winsock error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
wsainitialized = 1;
}
#endif
if ((h=gethostbyname(host)) == NULL)
{
initprintf("update: gethostbyname() error in getversionfromwebsite() (%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("update: socket() error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
initprintf("Connecting to \"http://%s\"\n",host);
if (connect(mysock, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR)
{
initprintf("update: connect() error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
bytes_sent = send(mysock, req, strlen(req), 0);
if (bytes_sent == SOCKET_ERROR)
{
initprintf("update: send() error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
// initprintf("sent %d bytes\n",bytes_sent);
recv(mysock, (char *)&tempbuf, sizeof(tempbuf), 0);
closesocket(mysock);
memcpy(&otherbuf,&tempbuf,sizeof(otherbuf));
strtok(otherbuf," ");
if (atol(strtok(NULL," ")) == 200)
{
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;
}
}
if (j)
{
strcpy(buffer,ver);
return(1);
}
}
return(0);
}
#endif

View File

@ -15,6 +15,7 @@
#include "mmulti_unstable.h"
#include "enet/enet.h"
#include "compat.h"
#include "baselayer.h"
//STL
@ -169,6 +170,11 @@ void initmultiplayers(int argc, char **argv, char damultioption, char dacomrateo
{
long i;
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(damultioption);
UNREFERENCED_PARAMETER(dacomrateoption);
UNREFERENCED_PARAMETER(dapriority);
initcrc();
for(i=0;i<MAXPLAYERS;i++)
{
@ -331,6 +337,8 @@ void sendpacket(long other, char *bufptr, long messleng)
void setpackettimeout(long datimeoutcount, long daresendagaincount)
{
UNREFERENCED_PARAMETER(datimeoutcount);
UNREFERENCED_PARAMETER(daresendagaincount);
// Don't do this it keeps '/f4' from working
// Though /f4 feels weird on my mouse.... slugish is the word...
/*
@ -372,6 +380,7 @@ int getoutputcirclesize(void)
void setsocket(short newsocket)
{
UNREFERENCED_PARAMETER(newsocket);
}
@ -604,7 +613,6 @@ void deinit_network_transport(gcomtype *gcom)
#if PLATFORM_WIN32
# include <winsock.h>
# define EAGAIN WSAEWOULDBLOCK
# define EWOULDBLOCK WSAEWOULDBLOCK
# define ECONNREFUSED WSAECONNRESET
# define socklen_t size_t
@ -637,7 +645,6 @@ void deinit_network_transport(gcomtype *gcom)
#include <signal.h>
#include "cache1d.h" /* kopen4load for cfg file. */
#include "baselayer.h" /* getticks */
#define IPSEG1(ip) ((((unsigned int) ip) & 0xFF000000) >> 24)
#define IPSEG2(ip) ((((unsigned int) ip) & 0x00FF0000) >> 16)
@ -660,6 +667,7 @@ static struct {
volatile int ctrlc_pressed = 0;
static void siginthandler(int sigint)
{
UNREFERENCED_PARAMETER(sigint);
ctrlc_pressed = 1;
}
@ -766,7 +774,7 @@ static int get_udp_packet(int *ip, short *_port, void *pkt, size_t pktsize)
/* FIXME: Will this ever receive a partial packet? */
int rc = recvfrom(udpsocket, pkt, pktsize, 0,
(struct sockaddr *) &addr, (int *)&fromlen);
(struct sockaddr *) &addr, (unsigned int *)&fromlen);
if (rc == -1)
err = neterrno();
@ -887,7 +895,7 @@ static char *read_whole_file(const char *cfgfile)
if (cfgfile == NULL)
return(NULL);
handle = kopen4load(cfgfile, 0);
handle = kopen4load((char *)cfgfile, 0);
if (handle == -1)
{
initprintf("ERROR: Failed to open config file [%s].\n", cfgfile);
@ -951,7 +959,7 @@ static int set_socket_blockmode(int onOrOff)
rc = (ioctlsocket(udpsocket, FIONBIO, &flags) == 0);
#else
flags = fcntl(udpsocket, F_GETFL, 0);
if (flags != -1)
if ((signed)flags != -1)
{
if (onOrOff)
flags &= ~O_NONBLOCK;
@ -996,7 +1004,7 @@ static int open_udp_socket(int ip, int port)
initprintf("Stun is currently %s\n", (natfree) ? "Enabled":"Disabled");
udpsocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (udpsocket == -1)
if ((signed)udpsocket == -1)
{
initprintf("socket creation failed: %s\n", netstrerror());
return(0);
@ -1029,6 +1037,9 @@ static int open_udp_socket(int ip, int port)
/* server init. */
static int wait_for_other_players(gcomtype *gcom, int myip)
{
UNREFERENCED_PARAMETER(gcom);
UNREFERENCED_PARAMETER(myip);
initprintf("Server code NOT implemented!\n");
return(0);
}
@ -1036,6 +1047,9 @@ static int wait_for_other_players(gcomtype *gcom, int myip)
/* client init. */
static int connect_to_server(gcomtype *gcom, int myip)
{
UNREFERENCED_PARAMETER(gcom);
UNREFERENCED_PARAMETER(myip);
initprintf("Client code NOT implemented!\n");
return(0);
}
@ -1581,7 +1595,7 @@ void deinit_network_transport(gcomtype *gcom)
free(gcom);
}
if (udpsocket != -1)
if ((signed)udpsocket != -1)
{
initprintf(" ...closing socket...\n");
set_socket_blockmode(1); /* block while socket drains. */
@ -1601,7 +1615,7 @@ void callcommit(void)
int ip, i, rc;
short port;
if (udpsocket == -1)
if ((signed)udpsocket == -1)
return;
process_udp_send_queue();

View File

@ -48,12 +48,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#undef UNREFERENCED_PARAMETER
#ifndef ENET_NETWORKING
#include <windows.h>
#include <shellapi.h>
#include <winsock2.h>
#include <ws2tcpip.h>
extern int getversionfromwebsite(char *buffer);
#define UPDATEINTERVAL 604800 // 1w
#endif
#else
static int usecwd = 0;
#endif /* _WIN32 */
@ -74,7 +74,9 @@ static int g_NoSound = 0;
static int g_NoMusic = 0;
static char *CommandMap = NULL;
static char *CommandName = NULL;
#ifndef ENET_NETWORKING
static char *CommandNet = NULL;
#endif
static int g_KeepAddr = 0;
int CommandWeaponChoice = 0;
static struct strllist
@ -168,6 +170,101 @@ unsigned int g_FrameDelay = 0;
extern char forcegl;
#endif
#ifdef _WIN32
int getversionfromwebsite(char *buffer) // FIXME: this probably belongs in game land
{
int wsainitialized = 0;
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],otherbuf[16],ver[16];
SOCKET mysock;
#ifdef _WIN32
if (wsainitialized == 0)
{
WSADATA ws;
if (WSAStartup(0x101,&ws) == SOCKET_ERROR)
{
initprintf("update: Winsock error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
wsainitialized = 1;
}
#endif
if ((h=gethostbyname(host)) == NULL)
{
initprintf("update: gethostbyname() error in getversionfromwebsite() (%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("update: socket() error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
initprintf("Connecting to \"http://%s\"\n",host);
if (connect(mysock, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR)
{
initprintf("update: connect() error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
bytes_sent = send(mysock, req, strlen(req), 0);
if (bytes_sent == SOCKET_ERROR)
{
initprintf("update: send() error in getversionfromwebsite() (%d)\n",errno);
return(0);
}
// initprintf("sent %d bytes\n",bytes_sent);
recv(mysock, (char *)&tempbuf, sizeof(tempbuf), 0);
closesocket(mysock);
memcpy(&otherbuf,&tempbuf,sizeof(otherbuf));
strtok(otherbuf," ");
if (atol(strtok(NULL," ")) == 200)
{
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;
}
}
if (j)
{
strcpy(buffer,ver);
return(1);
}
}
return(0);
}
#endif
int kopen4loadfrommod(char *filename, char searchfirst)
{
static char fn[BMAX_PATH];
@ -8831,6 +8928,7 @@ static void comlinehelp(void)
#endif
}
#ifndef ENET_NETWORKING
static signed int rancid_players = 0;
static char rancid_ip_strings[MAXPLAYERS][32], rancid_local_port_string[8];
@ -8911,7 +9009,6 @@ static inline int stringsort(const char *p1, const char *p2)
return Bstrcmp(&p1[0],&p2[0]);
}
#ifndef ENET_NETWORKING
// Not supported with the enet network backend currently
static void setup_rancid_net(const char *fn)
{