From d79f544c221f35a128805103886a49789dc4ab82 Mon Sep 17 00:00:00 2001 From: terminx Date: Fri, 14 Nov 2008 08:22:57 +0000 Subject: [PATCH] Support for JFDuke style network play setup with the duke3d_w32 networking code git-svn-id: https://svn.eduke32.com/eduke32@1132 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/mmulti_unstable.c | 295 ++++++++++++++------ polymer/eduke32/source/astub.c | 2 +- polymer/eduke32/source/game.c | 2 +- polymer/eduke32/source/global.c | 2 +- polymer/eduke32/source/player.c | 8 +- 5 files changed, 222 insertions(+), 87 deletions(-) diff --git a/polymer/eduke32/build/src/mmulti_unstable.c b/polymer/eduke32/build/src/mmulti_unstable.c index 35d576b8f..9db4a240a 100644 --- a/polymer/eduke32/build/src/mmulti_unstable.c +++ b/polymer/eduke32/build/src/mmulti_unstable.c @@ -132,7 +132,7 @@ enum ECommitCMDs //PacketQueue outgoingPacketQueue; //outgoingPacketQueue.reserve(128); -gcomtype *init_network_transport(char **ARGV, int argpos); +gcomtype *init_network_transport(int argc, char **argv); void deinit_network_transport(gcomtype *gcom); //void callcommit(void); void dosendpackets(int other); @@ -205,11 +205,13 @@ void initmultiplayers(int argc, char **argv) return; } - gcom = init_network_transport(argv, 0); + gcom = init_network_transport(argc, argv); if (gcom == NULL) { initprintf("Network transport initialization failed. Aborting...\n"); - exit(1); + numplayers = 1; myconnectindex = 0; + connecthead = 0; connectpoint2[0] = -1; + return; } numplayers = gcom->numplayers; @@ -855,7 +857,7 @@ static char *read_whole_file(const char *cfgfile) handle = kopen4load((char *)cfgfile, 0); if (handle == -1) { - initprintf("ERROR: Failed to open config file [%s].\n", cfgfile); +// initprintf("ERROR: Failed to open config file [%s].\n", cfgfile); return(NULL); } @@ -1771,7 +1773,34 @@ static void deinitialize_sockets(void) #endif } -static int parse_udp_config(const char *cfgfile, gcomtype *gcom) +int isvalidipaddress(char *st) +{ + int i, bcnt, num; + + bcnt = 0; num = 0; + for (i=0;st[i];i++) + { + if (st[i] == '.') { bcnt++; num = 0; continue; } + if (st[i] == ':') + { + if (bcnt != 3) return(0); + num = 0; + for (i++;st[i];i++) + { + if ((st[i] >= '0') && (st[i] <= '9')) + { num = num*10+st[i]-'0'; if (num >= 65536) return(0); } + else return(0); + } + return(1); + } + if ((st[i] >= '0') && (st[i] <= '9')) + { num = num*10+st[i]-'0'; if (num >= 256) return(0); } + + } + return(bcnt == 3); +} + +static int parse_udp_config(int argc, char **argv, gcomtype *gcom) { char *buf; char *tok; @@ -1779,96 +1808,203 @@ static int parse_udp_config(const char *cfgfile, gcomtype *gcom) int ip = 0; /* interface */ int bcast = 0; - buf = read_whole_file(cfgfile); /* we must free this. */ + buf = read_whole_file(argv[0]); /* we must free this. */ if (buf == NULL) - return(0); - - ptr = buf; - while ((tok = get_token(&ptr)) != NULL) { - int bogus = 1; + // do JF-style argv parsing here + int i, j, daindex; + int danetmode = 255; + char *st; + + daindex = 0; + + // if (!argv) return 0; + // go looking for the port, if specified + for (i=0;i 1024 && j<65535) udpport = j; + + initprintf("mmulti_unstable: Using port %d\n", udpport); + } + } + + for (i=0;inumplayers = 1; + if (argv[i][2] == '0') + { + danetmode = 0; + udpmode = udpmode_client; + if ((argv[i][3] == ':') && (argv[i][4] >= '0') && (argv[i][4] <= '9')) + { + udpmode = udpmode_server; + gcom->numplayers = (argv[i][4]-'0'); + if ((argv[i][5] >= '0') && (argv[i][5] <= '9')) gcom->numplayers = gcom->numplayers*10+(argv[i][5]-'0'); + gcom->numplayers--; + initprintf("mmulti_unstable: %d-player game server\n", gcom->numplayers); + } + initprintf("mmulti_unstable: Master-slave mode\n"); + } + else if (argv[i][2] == '1') + { + danetmode = 1; + udpmode = udpmode_peer; + myconnectindex = daindex; +// daindex++; + initprintf("mmulti_unstable: Peer-to-peer mode\n"); + } + continue; + } + else if ((argv[i][1] == 'P') || (argv[i][1] == 'p')) continue; + } + + st = strdup(argv[i]); if (!st) break; + if (isvalidipaddress(st)) + { +// if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; +/* for (j=0;st[j];j++) + { + if (st[j] == ':') + { allowed_addresses[daindex].port = htons((unsigned short)atol(&st[j+1])); st[j] = 0; break; } + } + allowed_addresses[daindex].host = inet_addr(st); */ + 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); + daindex++; + } +/* else + { + struct hostent * lph; + unsigned short pt = BUILD_DEFAULT_UDP_PORT; + + for (j=0;st[j];j++) + if (st[j] == ':') + { pt = (unsigned short)atol(&st[j+1]); st[j] = 0; break; } + if ((lph = gethostbyname(st))) + { + if ((danetmode == 1) && (daindex == myconnectindex)) daindex++; + allowed_addresses[daindex].host = *(int *)lph->h_addr; + allowed_addresses[daindex].port = pt; + initprintf("mmulti: Player %d at %s:%d (%s)\n",daindex, + inet_ntoa(*(struct in_addr *)lph->h_addr),ntohs(pt),argv[i]); + daindex++; + } + else initprintf("mmulti: Failed resolving %s\n",argv[i]); + } */ + free(st); + } + 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 (daindex > gcom->numplayers) gcom->numplayers = daindex; + } + else + { + initprintf("mmulti_unstable: Using '%s' as configuration file\n", argv[0]); - if (Bstrcasecmp(tok, "interface") == 0) + ptr = buf; + while ((tok = get_token(&ptr)) != NULL) { - if ((tok = get_token(&ptr)) && + int bogus = 1; + + if (Bstrcasecmp(tok, "interface") == 0) + { + if ((tok = get_token(&ptr)) && (parse_interface(tok, &ip, &udpport))) - { - bogus = 0; - } - initprintf("mmulti_unstable: Using interface %s:%d\n", - static_ipstring(ip), (int) udpport); - } - - else if (Bstrcasecmp(tok, "mode") == 0) - { - if ((tok = get_token(&ptr)) != NULL) - { - bogus = 0; - if (Bstrcasecmp(tok, "server") == 0) - udpmode = udpmode_server; - else if (Bstrcasecmp(tok, "client") == 0) - udpmode = udpmode_client; - else if (Bstrcasecmp(tok, "peer") == 0) - udpmode = udpmode_peer; - else - bogus = 1; - - if (!bogus) - initprintf("You want to be in [%s] mode\n", tok); - } - } - - else if (Bstrcasecmp(tok, "broadcast") == 0) - { - if ((tok = get_token(&ptr)) != NULL) - { - bcast = atoi(tok); - if (bcast > MAX_PLAYERS - 1) { - initprintf("WARNING: Too many broadcast players.\n"); - bcast = MAX_PLAYERS - 1; + bogus = 0; } - - bogus = 0; + initprintf("mmulti_unstable: Using interface %s:%d\n", + static_ipstring(ip), (int) udpport); } - } - else if (Bstrcasecmp(tok, "allow") == 0) - { - int host; - short port=BUILD_DEFAULT_UDP_PORT; - if ((tok = get_token(&ptr)) != NULL) + else if (Bstrcasecmp(tok, "mode") == 0) { - if (gcom->numplayers >= MAX_PLAYERS - 1) - initprintf("WARNING: Too many allowed IP addresses.\n"); - - else if (parse_interface(tok, &host, &port)) + if ((tok = get_token(&ptr)) != NULL) { - allowed_addresses[gcom->numplayers].host = host; - allowed_addresses[gcom->numplayers].port = port; - gcom->numplayers++; + bogus = 0; + if (Bstrcasecmp(tok, "server") == 0) + udpmode = udpmode_server; + else if (Bstrcasecmp(tok, "client") == 0) + udpmode = udpmode_client; + else if (Bstrcasecmp(tok, "peer") == 0) + udpmode = udpmode_peer; + else + bogus = 1; + + if (!bogus) + initprintf("You want to be in [%s] mode\n", tok); + } + } + + else if (Bstrcasecmp(tok, "broadcast") == 0) + { + if ((tok = get_token(&ptr)) != NULL) + { + bcast = atoi(tok); + if (bcast > MAX_PLAYERS - 1) + { + initprintf("WARNING: Too many broadcast players.\n"); + bcast = MAX_PLAYERS - 1; + } + bogus = 0; } } - } - else if (Bstrcasecmp(tok, "players") == 0) - { - if ((tok = get_token(&ptr)) != NULL) + else if (Bstrcasecmp(tok, "allow") == 0) { - bogus = 0; - if (udpmode == udpmode_server) - gcom->numplayers = atoi(tok)-1; - else - bogus = 1; + int host; + short port=BUILD_DEFAULT_UDP_PORT; + if ((tok = get_token(&ptr)) != NULL) + { + if (gcom->numplayers >= MAX_PLAYERS - 1) + initprintf("WARNING: Too many allowed IP addresses.\n"); + + else if (parse_interface(tok, &host, &port)) + { + allowed_addresses[gcom->numplayers].host = host; + allowed_addresses[gcom->numplayers].port = port; + gcom->numplayers++; + bogus = 0; + } + } } + + else if (Bstrcasecmp(tok, "players") == 0) + { + if ((tok = get_token(&ptr)) != NULL) + { + bogus = 0; + if (udpmode == udpmode_server) + gcom->numplayers = atoi(tok)-1; + else + bogus = 1; + } + } + + if (bogus) + initprintf("bogus token! [%s]\n", tok); } - if (bogus) - initprintf("bogus token! [%s]\n", tok); - } - - free(buf); + free(buf); + } if (open_udp_socket(ip, udpport)) { @@ -1888,7 +2024,7 @@ static int parse_udp_config(const char *cfgfile, gcomtype *gcom) } -gcomtype *init_network_transport(char **ARGV, int argpos) +gcomtype *init_network_transport(int argc, char **argv) { gcomtype *retval; @@ -1903,7 +2039,7 @@ gcomtype *init_network_transport(char **ARGV, int argpos) if (retval != NULL) { int rc; - char *cfgfile = ARGV[argpos]; +// char *cfgfile = ARGV[argpos]; memset(retval, '\0', sizeof(gcomtype)); memset(allowed_addresses, '\0', sizeof(allowed_addresses)); @@ -1911,8 +2047,7 @@ gcomtype *init_network_transport(char **ARGV, int argpos) udpport = BUILD_DEFAULT_UDP_PORT; udpmode = udpmode_peer; - initprintf("mmulti_unstable: Using '%s' as configuration file\n", cfgfile); - rc = parse_udp_config(cfgfile, retval); + rc = parse_udp_config(argc, argv, retval); if (!rc) { diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 9dc4aa3d7..abf91def3 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -44,7 +44,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #endif -#define BUILDDATE " 20081111" +#define BUILDDATE " 20081114" #define VERSION " 1.2.0devel" static int floor_over_floor; diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index cf1cbad84..c35837627 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -12652,7 +12652,7 @@ static int domovethings(void) g_player[myconnectindex].ps->ftq = 116, g_player[myconnectindex].ps->fta = 180; if (j < 0 && networkmode == 0) - gameexit("The server/master player just quit the game; disconnected."); + gameexit("Server terminated"); } if ((numplayers >= 2) && ((movefifoplc&7) == 7)) diff --git a/polymer/eduke32/source/global.c b/polymer/eduke32/source/global.c index 509df87df..d7e040422 100644 --- a/polymer/eduke32/source/global.c +++ b/polymer/eduke32/source/global.c @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //------------------------------------------------------------------------- #include "duke3d.h" -char *s_builddate = "20081111"; +char *s_builddate = "20081114"; char *MusicPtr = NULL; int Musicsize; diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index 5a1344095..0b7ca85f0 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -3043,13 +3043,13 @@ void getinput(int snum) loc.extbits = 0; if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_MOVEFORWARD]) - loc.extbits |= BUTTON(gamefunc_Move_Forward); + loc.extbits |= BUTTON(gamefunc_Move_Forward) || (vel > 0); if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_MOVEBACKWARD]) - loc.extbits |= BUTTON(gamefunc_Move_Backward)<<1; + loc.extbits |= (BUTTON(gamefunc_Move_Backward) || (vel < 0))<<1; if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_STRAFELEFT]) - loc.extbits |= BUTTON(gamefunc_Strafe_Left)<<2; + loc.extbits |= (BUTTON(gamefunc_Strafe_Left) || (svel > 0))<<2; if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_STRAFERIGHT]) - loc.extbits |= BUTTON(gamefunc_Strafe_Right)<<3; + loc.extbits |= (BUTTON(gamefunc_Strafe_Right) || (svel < 0))<<3; if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_TURNLEFT]) loc.extbits |= BUTTON(gamefunc_Turn_Left)<<4; if (apScriptGameEvent[EVENT_PROCESSINPUT] || apScriptGameEvent[EVENT_TURNRIGHT])