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

This commit is contained in:
terminx 2008-11-14 19:55:48 +00:00
parent 4f029a0097
commit a0b49f13e4
3 changed files with 155 additions and 150 deletions

View file

@ -1773,32 +1773,32 @@ static void deinitialize_sockets(void)
#endif #endif
} }
int isvalidipaddress(char *st) int isvalidipaddress(char *st)
{ {
int i, bcnt, num; int i, bcnt, num;
bcnt = 0; num = 0; bcnt = 0; num = 0;
for (i=0;st[i];i++) for (i=0;st[i];i++)
{ {
if (st[i] == '.') { bcnt++; num = 0; continue; } if (st[i] == '.') { bcnt++; num = 0; continue; }
if (st[i] == ':') if (st[i] == ':')
{ {
if (bcnt != 3) return(0); if (bcnt != 3) return(0);
num = 0; num = 0;
for (i++;st[i];i++) for (i++;st[i];i++)
{ {
if ((st[i] >= '0') && (st[i] <= '9')) if ((st[i] >= '0') && (st[i] <= '9'))
{ num = num*10+st[i]-'0'; if (num >= 65536) return(0); } { num = num*10+st[i]-'0'; if (num >= 65536) return(0); }
else return(0); else return(0);
} }
return(1); return(1);
} }
if ((st[i] >= '0') && (st[i] <= '9')) if ((st[i] >= '0') && (st[i] <= '9'))
{ num = num*10+st[i]-'0'; if (num >= 256) return(0); } { num = num*10+st[i]-'0'; if (num >= 256) return(0); }
} }
return(bcnt == 3); return(bcnt == 3);
} }
static int parse_udp_config(int argc, char **argv, gcomtype *gcom) static int parse_udp_config(int argc, char **argv, gcomtype *gcom)
{ {
@ -1812,106 +1812,106 @@ static int parse_udp_config(int argc, char **argv, gcomtype *gcom)
if (buf == NULL) if (buf == NULL)
{ {
// do JF-style argv parsing here // do JF-style argv parsing here
int i, j, daindex; int i, j, daindex;
int danetmode = 255; int danetmode = 255;
char *st; char *st;
daindex = 0; daindex = 0;
// if (!argv) return 0; // if (!argv) return 0;
// go looking for the port, if specified // go looking for the port, if specified
for (i=0;i<argc;i++) for (i=0;i<argc;i++)
{ {
if (argv[i][0] != '-' && argv[i][0] != '/') continue; if (argv[i][0] != '-' && argv[i][0] != '/') continue;
if ((argv[i][1] == 'p' || argv[i][1] == 'P') && argv[i][2]) if ((argv[i][1] == 'p' || argv[i][1] == 'P') && argv[i][2])
{ {
char *p; char *p;
j = strtol(argv[i]+2, &p, 10); j = strtol(argv[i]+2, &p, 10);
if (!(*p) && j > 1024 && j<65535) udpport = j; if (!(*p) && j > 1024 && j<65535) udpport = j;
initprintf("mmulti_unstable: Using port %d\n", udpport); initprintf("mmulti_unstable: Using port %d\n", udpport);
} }
} }
for (i=0;i<argc;i++) for (i=0;i<argc;i++)
{ {
//if (((argv[i][0] == '/') || (argv[i][0] == '-')) && //if (((argv[i][0] == '/') || (argv[i][0] == '-')) &&
// ((argv[i][1] == 'N') || (argv[i][1] == 'n')) && // ((argv[i][1] == 'N') || (argv[i][1] == 'n')) &&
// ((argv[i][2] == 'E') || (argv[i][2] == 'e')) && // ((argv[i][2] == 'E') || (argv[i][2] == 'e')) &&
// ((argv[i][3] == 'T') || (argv[i][3] == 't')) && // ((argv[i][3] == 'T') || (argv[i][3] == 't')) &&
// (!argv[i][4])) // (!argv[i][4]))
// { foundnet = 1; continue; } // { foundnet = 1; continue; }
//if (!foundnet) continue; //if (!foundnet) continue;
if ((argv[i][0] == '-') || (argv[i][0] == '/')) if ((argv[i][0] == '-') || (argv[i][0] == '/'))
{ {
if ((argv[i][1] == 'N') || (argv[i][1] == 'n') || (argv[i][1] == 'I') || (argv[i][1] == 'i')) if ((argv[i][1] == 'N') || (argv[i][1] == 'n') || (argv[i][1] == 'I') || (argv[i][1] == 'i'))
{ {
gcom->numplayers = 1; gcom->numplayers = 1;
if (argv[i][2] == '0') if (argv[i][2] == '0')
{ {
danetmode = 0; danetmode = 0;
udpmode = udpmode_client; udpmode = udpmode_client;
if ((argv[i][3] == ':') && (argv[i][4] >= '0') && (argv[i][4] <= '9')) if ((argv[i][3] == ':') && (argv[i][4] >= '0') && (argv[i][4] <= '9'))
{ {
udpmode = udpmode_server; udpmode = udpmode_server;
gcom->numplayers = (argv[i][4]-'0'); gcom->numplayers = (argv[i][4]-'0');
if ((argv[i][5] >= '0') && (argv[i][5] <= '9')) gcom->numplayers = gcom->numplayers*10+(argv[i][5]-'0'); if ((argv[i][5] >= '0') && (argv[i][5] <= '9')) gcom->numplayers = gcom->numplayers*10+(argv[i][5]-'0');
initprintf("mmulti_unstable: %d-player game server\n", gcom->numplayers--); initprintf("mmulti_unstable: %d-player game server\n", gcom->numplayers--);
} }
initprintf("mmulti_unstable: Master-slave mode\n"); initprintf("mmulti_unstable: Master-slave mode\n");
} }
else if (argv[i][2] == '1') else if (argv[i][2] == '1')
{ {
danetmode = 1; danetmode = 1;
udpmode = udpmode_peer; udpmode = udpmode_peer;
myconnectindex = daindex; myconnectindex = daindex;
// daindex++; // daindex++;
initprintf("mmulti_unstable: Peer-to-peer mode\n"); initprintf("mmulti_unstable: Peer-to-peer mode\n");
} }
continue; continue;
} }
else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue; else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue;
} }
st = strdup(argv[i]); if (!st) break; st = strdup(argv[i]); if (!st) break;
if (isvalidipaddress(st)) if (isvalidipaddress(st))
{ {
// if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; // if ((danetmode == 1) && (daindex == myconnectindex)) daindex++;
/* for (j=0;st[j];j++) /* for (j=0;st[j];j++)
{ {
if (st[j] == ':') if (st[j] == ':')
{ allowed_addresses[daindex].port = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; } { allowed_addresses[daindex].port = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; }
} }
allowed_addresses[daindex].host = inet_addr(st); */ allowed_addresses[daindex].host = inet_addr(st); */
parse_interface(st, &allowed_addresses[daindex].host, &allowed_addresses[daindex].port); parse_interface(st, &allowed_addresses[daindex].host, &allowed_addresses[daindex].port);
initprintf("mmulti_unstable: Player %d at %s:%d\n",daindex,st,allowed_addresses[daindex].port); initprintf("mmulti_unstable: Player %d at %s:%d\n",daindex,st,allowed_addresses[daindex].port);
daindex++; daindex++;
} }
/* else else
{ {
struct hostent * lph; struct hostent * lph;
unsigned short pt = BUILD_DEFAULT_UDP_PORT; unsigned short pt = BUILD_DEFAULT_UDP_PORT;
for (j=0;st[j];j++) for (j=0;st[j];j++)
if (st[j] == ':') if (st[j] == ':')
{ pt = (unsigned short)atol(&st[j+1]); st[j] = 0; break; } { pt = (unsigned short)atol(&st[j+1]); st[j] = 0; break; }
if ((lph = gethostbyname(st))) if ((lph = gethostbyname(st)))
{ {
if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; // if ((danetmode == 1) && (daindex == myconnectindex)) daindex++;
allowed_addresses[daindex].host = *(int *)lph->h_addr; allowed_addresses[daindex].host = ntohl(*(int *)lph->h_addr);
allowed_addresses[daindex].port = pt; allowed_addresses[daindex].port = pt;
initprintf("mmulti: Player %d at %s:%d (%s)\n",daindex, initprintf("mmulti_unstable: Player %d at %s:%d (%s)\n",daindex,
inet_ntoa(*(struct in_addr *)lph->h_addr),ntohs(pt),argv[i]); inet_ntoa(*(struct in_addr *)lph->h_addr),pt,argv[i]);
daindex++; daindex++;
} }
else initprintf("mmulti: Failed resolving %s\n",argv[i]); else initprintf("mmulti_unstable: Failed resolving %s\n",argv[i]);
} */ }
free(st); free(st);
} }
if ((danetmode == 255) && (daindex)) { gcom->numplayers = 2; udpmode = udpmode_client; } //an IP w/o /n# defaults to /n0 if ((danetmode == 255) && (daindex)) { gcom->numplayers = 2; udpmode = udpmode_client; } //an IP w/o /n# defaults to /n0
// if ((numplayers >= 2) && (daindex) && (!danetmode)) myconnectindex = 1; // if ((numplayers >= 2) && (daindex) && (!danetmode)) myconnectindex = 1;
if (daindex > gcom->numplayers) gcom->numplayers = daindex; if (daindex > gcom->numplayers) gcom->numplayers = daindex;
} }
else else
{ {
@ -1925,12 +1925,12 @@ static int parse_udp_config(int argc, char **argv, gcomtype *gcom)
if (Bstrcasecmp(tok, "interface") == 0) if (Bstrcasecmp(tok, "interface") == 0)
{ {
if ((tok = get_token(&ptr)) && if ((tok = get_token(&ptr)) &&
(parse_interface(tok, &ip, &udpport))) (parse_interface(tok, &ip, &udpport)))
{ {
bogus = 0; bogus = 0;
} }
initprintf("mmulti_unstable: Using interface %s:%d\n", initprintf("mmulti_unstable: Using interface %s:%d\n",
static_ipstring(ip), (int) udpport); static_ipstring(ip), (int) udpport);
} }
else if (Bstrcasecmp(tok, "mode") == 0) else if (Bstrcasecmp(tok, "mode") == 0)
@ -2003,7 +2003,7 @@ static int parse_udp_config(int argc, char **argv, gcomtype *gcom)
} }
free(buf); free(buf);
} }
if (open_udp_socket(ip, udpport)) if (open_udp_socket(ip, udpport))
{ {

View file

@ -101,7 +101,7 @@ int recfilep,totalreccnt;
int debug_on = 0,actor_tog = 0; int debug_on = 0,actor_tog = 0;
static char *rtsptr; static char *rtsptr;
//extern char syncstate; //extern char syncstate;
extern int numlumps; extern int numlumps;
static FILE *frecfilep = (FILE *)NULL; static FILE *frecfilep = (FILE *)NULL;
@ -652,7 +652,7 @@ void getpackets(void)
int i, j, k, l; int i, j, k, l;
int other; int other;
int packbufleng; int packbufleng;
input_t *osyn, *nsyn; input_t *osyn, *nsyn;
sampletimer(); sampletimer();
@ -1539,13 +1539,13 @@ static void checksync(void)
printext256(4L,130L,31,0,"Out Of Sync - Please restart game",0); printext256(4L,130L,31,0,"Out Of Sync - Please restart game",0);
printext256(4L,138L,31,0,"RUN DN3DHELP.EXE for information.",0); printext256(4L,138L,31,0,"RUN DN3DHELP.EXE for information.",0);
} }
#if 0 #if 0
if (syncstate) if (syncstate)
{ {
printext256(4L,160L,31,0,"Missed Network packet!",0); printext256(4L,160L,31,0,"Missed Network packet!",0);
printext256(4L,138L,31,0,"RUN DN3DHELP.EXE for information.",0); printext256(4L,138L,31,0,"RUN DN3DHELP.EXE for information.",0);
} }
#endif #endif
} }
void check_fta_sounds(int i) void check_fta_sounds(int i)
@ -4036,12 +4036,12 @@ void displayrest(int smoothratio)
else if (ud.screen_size > 2) else if (ud.screen_size > 2)
{ {
i = scale(tilesizy[BOTTOMSTATUSBAR]+1,ud.statusbarscale,100); i = scale(tilesizy[BOTTOMSTATUSBAR]+1,ud.statusbarscale,100);
// j = scale(2,ud.config.ScreenWidth,320); // j = scale(2,ud.config.ScreenWidth,320);
} }
else else
{ {
i = 2; i = 2;
// j = scale(2,ud.config.ScreenWidth,320); // j = scale(2,ud.config.ScreenWidth,320);
} }
j = scale(2,ud.config.ScreenWidth,320); j = scale(2,ud.config.ScreenWidth,320);
@ -9624,9 +9624,9 @@ static void checkcommandline(int argc, const char **argv)
#endif #endif
if (!Bstrcasecmp(c+1,"net") if (!Bstrcasecmp(c+1,"net")
#ifdef RANCID_NETWORKING #ifdef RANCID_NETWORKING
|| !Bstrcasecmp(c+1,"rmnet") || !Bstrcasecmp(c+1,"rmnet")
#endif #endif
) )
{ {
g_NoSetup = TRUE; g_NoSetup = TRUE;
firstnet = i; firstnet = i;
@ -10523,7 +10523,7 @@ static void Startup(void)
for (i=0;i<MAXPLAYERS;i++) for (i=0;i<MAXPLAYERS;i++)
g_player[i].playerreadyflag = 0; g_player[i].playerreadyflag = 0;
#ifndef RANCID_NETWORKING #ifndef RANCID_NETWORKING
// enet regression // enet regression
if (CommandNet) if (CommandNet)
{ {
@ -10535,9 +10535,9 @@ static void Startup(void)
} }
CommandNet = NULL; CommandNet = NULL;
} }
#endif #endif
#ifdef RANCID_NETWORKING #ifdef RANCID_NETWORKING
// TODO: split this up in the same fine-grained manner as eduke32 network backend, to // TODO: split this up in the same fine-grained manner as eduke32 network backend, to
// allow for event handling // allow for event handling
initmultiplayers(netparamcount,netparam); initmultiplayers(netparamcount,netparam);
@ -10548,7 +10548,7 @@ static void Startup(void)
return; return;
} }
#else #else
if (initmultiplayersparms(netparamcount,netparam)) if (initmultiplayersparms(netparamcount,netparam))
{ {
initprintf("Waiting for players...\n"); initprintf("Waiting for players...\n");
@ -10562,7 +10562,7 @@ static void Startup(void)
} }
} }
} }
#endif #endif
if (netparam) Bfree(netparam); if (netparam) Bfree(netparam);
netparam = NULL; netparam = NULL;
@ -13180,10 +13180,15 @@ FRAGBONUS:
fadepal(0,0,0, 63,0,-7); fadepal(0,0,0, 63,0,-7);
KB_FlushKeyboardQueue(); KB_FlushKeyboardQueue();
while (KB_KeyWaiting()==0)
{ {
handleevents(); int tc = totalclock;
getpackets(); while (KB_KeyWaiting()==0)
{
if (totalclock > tc + 600) break;
handleevents();
getpackets();
}
} }
if (bonusonly || ud.multimode > 1) return; if (bonusonly || ud.multimode > 1) return;

View file

@ -1538,11 +1538,11 @@ void waitforeverybody()
while (1) while (1)
{ {
idle(); idle();
/* /*
sampletimer(); sampletimer();
handleevents(); handleevents();
AudioUpdate(); AudioUpdate();
*/ */
if (quitevent || keystatus[1]) gameexit(""); if (quitevent || keystatus[1]) gameexit("");