Merge branch 'random-port' into 'master'

Choose a random port as a client

See merge request STJr/SRB2!554
This commit is contained in:
James R 2019-12-20 17:33:12 -05:00
commit c50fe1874d
3 changed files with 26 additions and 13 deletions

View file

@ -70,7 +70,7 @@
boolean server = true; // true or false but !server == client boolean server = true; // true or false but !server == client
#define client (!server) #define client (!server)
boolean nodownload = false; boolean nodownload = false;
static boolean serverrunning = false; boolean serverrunning = false;
INT32 serverplayer = 0; INT32 serverplayer = 0;
char motd[254], server_context[8]; // Message of the Day, Unique Context (even without Mumble support) char motd[254], server_context[8]; // Message of the Day, Unique Context (even without Mumble support)

View file

@ -40,6 +40,8 @@ extern SINT8 nodetoplayer2[MAXNETNODES]; // Say the numplayer for this node if a
extern UINT8 playerpernode[MAXNETNODES]; // Used specially for splitscreen extern UINT8 playerpernode[MAXNETNODES]; // Used specially for splitscreen
extern boolean nodeingame[MAXNETNODES]; // Set false as nodes leave game extern boolean nodeingame[MAXNETNODES]; // Set false as nodes leave game
extern boolean serverrunning;
INT32 Net_GetFreeAcks(boolean urgent); INT32 Net_GetFreeAcks(boolean urgent);
void Net_AckTicker(void); void Net_AckTicker(void);

View file

@ -209,7 +209,8 @@ static size_t numbans = 0;
static boolean SOCK_bannednode[MAXNETNODES+1]; /// \note do we really need the +1? static boolean SOCK_bannednode[MAXNETNODES+1]; /// \note do we really need the +1?
static boolean init_tcp_driver = false; static boolean init_tcp_driver = false;
static char port_name[8] = DEFAULTPORT; static const char *serverport_name = DEFAULTPORT;
static const char *clientport_name;/* any port */
#ifndef NONET #ifndef NONET
@ -887,6 +888,7 @@ static boolean UDP_Socket(void)
#ifdef HAVE_IPV6 #ifdef HAVE_IPV6
const INT32 b_ipv6 = M_CheckParm("-ipv6"); const INT32 b_ipv6 = M_CheckParm("-ipv6");
#endif #endif
const char *serv;
for (s = 0; s < mysocketses; s++) for (s = 0; s < mysocketses; s++)
@ -902,11 +904,16 @@ static boolean UDP_Socket(void)
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP; hints.ai_protocol = IPPROTO_UDP;
if (serverrunning)
serv = serverport_name;
else
serv = clientport_name;
if (M_CheckParm("-bindaddr")) if (M_CheckParm("-bindaddr"))
{ {
while (M_IsNextParm()) while (M_IsNextParm())
{ {
gaie = I_getaddrinfo(M_GetNextParm(), port_name, &hints, &ai); gaie = I_getaddrinfo(M_GetNextParm(), serv, &hints, &ai);
if (gaie == 0) if (gaie == 0)
{ {
runp = ai; runp = ai;
@ -927,7 +934,7 @@ static boolean UDP_Socket(void)
} }
else else
{ {
gaie = I_getaddrinfo("0.0.0.0", port_name, &hints, &ai); gaie = I_getaddrinfo("0.0.0.0", serv, &hints, &ai);
if (gaie == 0) if (gaie == 0)
{ {
runp = ai; runp = ai;
@ -942,8 +949,8 @@ static boolean UDP_Socket(void)
#ifdef HAVE_MINIUPNPC #ifdef HAVE_MINIUPNPC
if (UPNP_support) if (UPNP_support)
{ {
I_UPnP_rem(port_name, "UDP"); I_UPnP_rem(serverport_name, "UDP");
I_UPnP_add(NULL, port_name, "UDP"); I_UPnP_add(NULL, serverport_name, "UDP");
} }
#endif #endif
} }
@ -960,7 +967,7 @@ static boolean UDP_Socket(void)
{ {
while (M_IsNextParm()) while (M_IsNextParm())
{ {
gaie = I_getaddrinfo(M_GetNextParm(), port_name, &hints, &ai); gaie = I_getaddrinfo(M_GetNextParm(), serv, &hints, &ai);
if (gaie == 0) if (gaie == 0)
{ {
runp = ai; runp = ai;
@ -981,7 +988,7 @@ static boolean UDP_Socket(void)
} }
else else
{ {
gaie = I_getaddrinfo("::", port_name, &hints, &ai); gaie = I_getaddrinfo("::", serv, &hints, &ai);
if (gaie == 0) if (gaie == 0)
{ {
runp = ai; runp = ai;
@ -1421,15 +1428,19 @@ boolean I_InitTcpNetwork(void)
if (!I_InitTcpDriver()) if (!I_InitTcpDriver())
return false; return false;
if (M_CheckParm("-port")) if (M_CheckParm("-port") || M_CheckParm("-serverport"))
// Combined -udpport and -clientport into -port // Combined -udpport and -clientport into -port
// As it was really redundant having two seperate parms that does the same thing // As it was really redundant having two seperate parms that does the same thing
/* Sorry Steel, I'm adding these back. But -udpport is a stupid name. */
{ {
if (M_IsNextParm()) /*
strcpy(port_name, M_GetNextParm()); If it's NULL, that's okay! Because then
else we'll get a random port from getaddrinfo.
strcpy(port_name, "0"); */
serverport_name = M_GetNextParm();
} }
if (M_CheckParm("-clientport"))
clientport_name = M_GetNextParm();
// parse network game options, // parse network game options,
if (M_CheckParm("-server") || dedicated) if (M_CheckParm("-server") || dedicated)