sv_tcpport -> sv_port_tcp, added sv_port/sv_port_ipx/sv_port_ipv6 defaulting to 27500, use 0 to disable and shutdown protocol, -port/-svport redirect to these cvars

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2256 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2006-05-09 00:02:05 +00:00
parent 6cbf2b2f32
commit c32061184e
2 changed files with 161 additions and 49 deletions

View file

@ -67,11 +67,22 @@ void (*pfreeaddrinfo) (struct addrinfo*);
void NET_GetLocalAddress (int socket, netadr_t *out);
int TCP_OpenListenSocket (int port);
extern cvar_t sv_port;
#ifdef IPPROTO_IPV6
int UDP6_OpenSocket (int port, qboolean bcast);
extern cvar_t sv_port_ipv6;
#endif
#ifdef USEIPX
void IPX_CloseSocket (int socket);
extern cvar_t sv_port_ipx;
#endif
#ifdef TCPCONNECT
extern cvar_t sv_port_tcp;
#endif
extern cvar_t sv_public, sv_listen;
extern cvar_t sv_tcpport;
static qboolean allowconnects = false;
#define MAX_LOOPBACK 4
typedef struct
@ -655,18 +666,103 @@ void NET_SendLoopPacket (netsrc_t sock, int length, void *data, netadr_t to)
void SV_Tcpport_Callback(struct cvar_s *var, char *oldvalue)
{
#ifdef TCPCONNECT
if (svs.sockettcp == INVALID_SOCKET && sv_tcpport.value)
if (!allowconnects)
return;
if (var->value)
{
svs.sockettcp = TCP_OpenListenSocket(sv_tcpport.value);
if (svs.sockettcp != INVALID_SOCKET)
NET_GetLocalAddress (svs.sockettcp, &net_local_sv_tcpipadr);
else
Con_Printf("Failed to open TCP port %i\n", (int)sv_tcpport.value);
if (svs.sockettcp == INVALID_SOCKET)
{
svs.sockettcp = TCP_OpenListenSocket(var->value);
if (svs.sockettcp != INVALID_SOCKET)
NET_GetLocalAddress (svs.sockettcp, &net_local_sv_tcpipadr);
else
Con_Printf("Failed to open TCP port %i\n", (int)var->value);
}
}
else
{
UDP_CloseSocket(svs.sockettcp);
svs.sockettcp = INVALID_SOCKET;
if (svs.sockettcp != INVALID_SOCKET)
{
closesocket(svs.sockettcp);
svs.sockettcp = INVALID_SOCKET;
}
}
#endif
}
void SV_Port_Callback(struct cvar_s *var, char *oldvalue)
{
if (!allowconnects)
return;
if (var->value)
{
if (svs.socketip == INVALID_SOCKET)
{
svs.socketip = UDP_OpenSocket (var->value, false);
if (svs.socketip != INVALID_SOCKET)
NET_GetLocalAddress (svs.socketip, &net_local_sv_ipadr);
}
}
else
{
if (svs.socketip != INVALID_SOCKET)
{
UDP_CloseSocket(svs.socketip);
svs.socketip = INVALID_SOCKET;
}
}
}
void SV_PortIPv6_Callback(struct cvar_s *var, char *oldvalue)
{
#ifdef IPPROTO_IPV6
if (!allowconnects)
return;
if (var->value)
{
if (svs.socketip6 == INVALID_SOCKET)
{
svs.socketip6 = UDP6_OpenSocket (var->value, false);
if (svs.socketip6 != INVALID_SOCKET)
NET_GetLocalAddress (svs.socketip6, &net_local_sv_ip6adr);
}
}
else
{
if (svs.socketip6 != INVALID_SOCKET)
{
UDP_CloseSocket(svs.socketip6);
svs.socketip6 = INVALID_SOCKET;
}
}
#endif
}
void SV_PortIPX_Callback(struct cvar_s *var, char *oldvalue)
{
#ifdef USEIPX
if (!allowconnects)
return;
if (var->value)
{
if (svs.socketipx == INVALID_SOCKET)
{
svs.socketipx = IPX_OpenSocket (var->value, false);
if (svs.socketipx != INVALID_SOCKET)
NET_GetLocalAddress (svs.socketipx, &net_local_sv_ipxadr);
}
}
else
{
if (svs.socketipx != INVALID_SOCKET)
{
IPX_CloseSocket(svs.socketipx);
svs.socketipx = INVALID_SOCKET;
}
}
#endif
}
@ -1560,6 +1656,8 @@ void NET_InitClient(void)
void NET_CloseServer(void)
{
allowconnects = false;
if (svs.socketip != INVALID_SOCKET)
{
UDP_CloseSocket(svs.socketip);
@ -1582,7 +1680,7 @@ void NET_CloseServer(void)
#ifdef TCPCONNECT
if (svs.sockettcp != INVALID_SOCKET)
{
UDP_CloseSocket(svs.sockettcp);
closesocket(svs.sockettcp);
svs.sockettcp = INVALID_SOCKET;
}
#endif
@ -1595,51 +1693,22 @@ void NET_CloseServer(void)
void NET_InitServer(void)
{
int port;
int p;
port = PORT_SERVER;
if (sv_listen.value)
{
p = COM_CheckParm ("-port");
if (p && p < com_argc)
{
port = atoi(com_argv[p+1]);
}
p = COM_CheckParm ("-svport");
if (p && p < com_argc)
{
port = atoi(com_argv[p+1]);
}
allowconnects = true;
//
// open the single socket to be used for all communications
//
if (svs.socketip == INVALID_SOCKET)
{
svs.socketip = UDP_OpenSocket (port, false);
if (svs.socketip != INVALID_SOCKET)
NET_GetLocalAddress (svs.socketip, &net_local_sv_ipadr);
}
Cvar_ForceCallback(&sv_port);
#ifdef TCPCONNECT
Cvar_ForceCallback(&sv_port_tcp);
#endif
#ifdef IPPROTO_IPV6
if (svs.socketip6 == INVALID_SOCKET)
{
svs.socketip6 = UDP6_OpenSocket (port, false);
if (svs.socketip6 != INVALID_SOCKET)
NET_GetLocalAddress (svs.socketip6, &net_local_sv_ip6adr);
}
Cvar_ForceCallback(&sv_port_ipv6);
#endif
#ifdef USEIPX
if (svs.socketipx == INVALID_SOCKET)
{
svs.socketipx = IPX_OpenSocket (port, false);
if (svs.socketipx != INVALID_SOCKET)
NET_GetLocalAddress (svs.socketipx, &net_local_sv_ipxadr);
}
Cvar_ForceCallback(&sv_port_ipx);
#endif
#ifdef TCPCONNECT
Cvar_ForceCallback(&sv_tcpport);
#endif
}
else
NET_CloseServer();

View file

@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "qwsvdef.h"
#include "netinc.h"
#include <sys/types.h>
#ifndef CLIENTONLY
#define Q2EDICT_NUM(i) (q2edict_t*)((char *)ge->edicts+i*ge->edict_size)
@ -46,6 +47,9 @@ int host_hunklevel;
// callbacks
void SV_Masterlist_Callback(struct cvar_s *var, char *oldvalue);
void SV_Tcpport_Callback(struct cvar_s *var, char *oldvalue);
void SV_Port_Callback(struct cvar_s *var, char *oldvalue);
void SV_PortIPv6_Callback(struct cvar_s *var, char *oldvalue);
void SV_PortIPX_Callback(struct cvar_s *var, char *oldvalue);
typedef struct {
qboolean isdp;
@ -128,7 +132,16 @@ cvar_t sv_masterport = SCVAR("sv_masterport", "0");
cvar_t sv_voicechat = SCVAR("sv_voicechat", "0"); //still development.
cvar_t sv_gamespeed = SCVAR("sv_gamespeed", "1");
cvar_t sv_csqcdebug = SCVAR("sv_csqcdebug", "0");
cvar_t sv_tcpport = SCVARC("sv_tcpport", "0", SV_Tcpport_Callback);
#ifdef TCPCONNECT
cvar_t sv_port_tcp = SCVARC("sv_port_tcp", "0", SV_Tcpport_Callback);
#endif
cvar_t sv_port = SCVARC("sv_port", "27500", SV_Port_Callback);
#ifdef IPPROTO_IPV6
cvar_t sv_port_ipv6 = SCVARC("sv_port_ipv6", "27500", SV_PortIPv6_Callback);
#endif
#ifdef USEIPX
cvar_t sv_port_ipx = SCVARC("sv_port_ipx", "27500", SV_PortIPX_Callback);
#endif
cvar_t pausable = SCVAR("pausable", "1");
@ -3182,7 +3195,17 @@ void SV_InitLocal (void)
Cvar_Register (&sv_public, cvargroup_servercontrol);
Cvar_Register (&sv_listen, cvargroup_servercontrol);
Cvar_Register (&sv_tcpport, cvargroup_servercontrol);
#ifdef TCPCONNECT
Cvar_Register (&sv_port_tcp, cvargroup_servercontrol);
#endif
#ifdef IPPROTO_IPV6
Cvar_Register (&sv_port_ipv6, cvargroup_servercontrol);
#endif
#ifdef USEIPX
Cvar_Register (&sv_port_ipx, cvargroup_servercontrol);
#endif
Cvar_Register (&sv_port, cvargroup_servercontrol);
Cvar_Register (&sv_reportheartbeats, cvargroup_servercontrol);
#ifndef SERVERONLY
@ -3811,6 +3834,8 @@ SV_Init
void SV_Demo_Init(void);
void SV_Init (quakeparms_t *parms)
{
int p;
#ifndef SERVERONLY
if (isDedicated)
#endif
@ -3837,6 +3862,24 @@ void SV_Init (quakeparms_t *parms)
COM_Init ();
Mod_Init ();
}
p = COM_CheckParm ("-port");
if (!p)
p = COM_CheckParm ("-svport");
if (p && p < com_argc)
{
int port = atoi(com_argv[p+1]);
if (!port)
port = PORT_SERVER;
Cvar_SetValue(&sv_port, port);
#ifdef IPPROTO_IPV6
Cvar_SetValue(&sv_port_ipv6, port);
#endif
#ifdef USEIPX
Cvar_SetValue(&sv_port_ipx, port);
#endif
}
PR_Init ();
SV_InitNet ();