Beispiel #1
0
/*
====================
NET_OpenIP
====================
*/
void NET_OpenIP (int flags)
{
	cvar_t	*ip;
	int		port;
	int		dedicated;

	net_total_in = net_packets_in = net_total_out = net_packets_out = 0;
	net_inittime = (unsigned int)time(NULL);

	ip = Cvar_Get ("ip", "localhost", CVAR_NOSET);

	dedicated = Cvar_IntValue ("dedicated");

	if (flags & NET_SERVER)
	{
		if (!ip_sockets[NS_SERVER])
		{
			port = Cvar_Get("ip_hostport", "0", CVAR_NOSET)->intvalue;
			if (!port)
			{
				port = Cvar_Get("hostport", "0", CVAR_NOSET)->intvalue;
				if (!port)
				{
					port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->intvalue;
				}
			}
			server_port = port;
			ip_sockets[NS_SERVER] = NET_IPSocket (ip->string, port);
			if (!ip_sockets[NS_SERVER] && dedicated)
				Com_Error (ERR_FATAL, "Couldn't allocate dedicated server IP port on %s:%d. Another application is probably using it.", ip->string, port);
		}
	}

	// dedicated servers don't need client ports
	if (dedicated)
		return;

	if (!ip_sockets[NS_CLIENT])
	{
		int newport = (int)(random() * 64000 + 1024);
		port = Cvar_Get("ip_clientport", va("%i", newport), CVAR_NOSET)->intvalue;
		if (!port)
		{
			
			port = Cvar_Get("clientport", va("%i", newport) , CVAR_NOSET)->intvalue;
			if (!port) {
				port = PORT_ANY;
				Cvar_Set ("clientport", va ("%d", newport));
			}
		}

		ip_sockets[NS_CLIENT] = NET_IPSocket (ip->string, newport);
		if (!ip_sockets[NS_CLIENT])
			ip_sockets[NS_CLIENT] = NET_IPSocket (ip->string, PORT_ANY);
	}

	if (!ip_sockets[NS_CLIENT])
		Com_Error (ERR_DROP, "Couldn't allocate client IP port.");
}
Beispiel #2
0
/*
====================
NET_OpenIP
====================
*/
void NET_OpenIP( void )
{
    cvar_t	*ip;
    int		port;
    int		i;

    ip = Cvar_Get( "net_ip", "localhost", CVAR_LATCH );
    port = Cvar_Get( "net_port", va( "%i", PORT_SERVER ), CVAR_LATCH )->integer;

    // automatically scan for a valid port, so multiple
    // dedicated servers can be started without requiring
    // a different net_port for each one
    for( i = 0 ; i < 10 ; i++ ) {
        ip_socket = NET_IPSocket( ip->string, port + i );
        if ( ip_socket ) {
            Cvar_SetValue( "net_port", port + i );
            if ( net_socksEnabled->integer ) {
                NET_OpenSocks( port + i );
            }
#ifdef _XBOX
            NET_GetLocalAddress( false );
#else
            NET_GetLocalAddress();
#endif
            return;
        }
    }
    Com_Printf( "WARNING: Couldn't allocate IP port\n");
}
Beispiel #3
0
/*
====================
NET_OpenIP
====================
*/
void NET_OpenIP( void ) {
	int		i;
	int		err;
	int		port;
	int		port6;

	port = net_port->integer;
	port6 = net_port6->integer;

	NET_GetLocalAddress();

	// automatically scan for a valid port, so multiple
	// dedicated servers can be started without requiring
	// a different net_port for each one

	if(net_enabled->integer & NET_ENABLEV6)
	{
		for( i = 0 ; i < 10 ; i++ )
		{
			ip6_socket = NET_IP6Socket(net_ip6->string, port6 + i, &boundto, &err);
			if (ip6_socket != INVALID_SOCKET)
			{
				Cvar_SetValue( "net_port6", port6 + i );
				break;
			}
			else
			{
				if(err == EAFNOSUPPORT)
					break;
			}
		}
		if(ip6_socket == INVALID_SOCKET)
			Com_Printf( "WARNING: Couldn't bind to a v6 ip address.\n");
	}

	if(net_enabled->integer & NET_ENABLEV4)
	{
		for( i = 0 ; i < 10 ; i++ ) {
			ip_socket = NET_IPSocket( net_ip->string, port + i, &err );
			if (ip_socket != INVALID_SOCKET) {
				Cvar_SetValue( "net_port", port + i );

				if (net_socksEnabled->integer)
					NET_OpenSocks( port + i );

				break;
			}
			else
			{
				if(err == EAFNOSUPPORT)
					break;
			}
		}
		
		if(ip_socket == INVALID_SOCKET)
			Com_Printf( "WARNING: Couldn't bind to a v4 ip address.\n");
	}
}
Beispiel #4
0
/*
====================
NET_OpenIP
====================
*/
void NET_OpenIP (void)
{
	cvar_t	*ip;
	int		port;
	int		dedicated;

	ip = Cvar_Get ("ip", "localhost", CVAR_NOSET);

	dedicated = Cvar_VariableValue ("dedicated");

	if (!ip_sockets[NS_SERVER])
	{
		port = Cvar_Get("ip_hostport", "0", CVAR_NOSET)->value;
		if (!port)
		{
			port = Cvar_Get("hostport", "0", CVAR_NOSET)->value;
			if (!port)
			{
				port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->value;
			}
		}
		ip_sockets[NS_SERVER] = NET_IPSocket (ip->string, port);
		if (!ip_sockets[NS_SERVER] && dedicated)
			Com_Error (ERR_FATAL, "Couldn't allocate dedicated server IP port");
	}


	// dedicated servers don't need client ports
	if (dedicated)
		return;

	if (!ip_sockets[NS_CLIENT])
	{
		port = Cvar_Get("ip_clientport", "0", CVAR_NOSET)->value;
		if (!port)
		{
			port = Cvar_Get("clientport", va("%i", PORT_CLIENT), CVAR_NOSET)->value;
			if (!port)
				port = PORT_ANY;
		}
		ip_sockets[NS_CLIENT] = NET_IPSocket (ip->string, port);
		if (!ip_sockets[NS_CLIENT])
			ip_sockets[NS_CLIENT] = NET_IPSocket (ip->string, PORT_ANY);
	}
}
Beispiel #5
0
/*
====================
NET_OpenIP
====================
*/
static void NET_OpenIP (int flag)
{
	cvar_t	*ip;
	int		port;
	int		dedicated;

	ip = Cvar_Get ("ip", "localhost", CVAR_NOSET);

	dedicated = Cvar_VariableIntValue ("dedicated");

	if (flag & NET_SERVER && ip_sockets[NS_SERVER] == INVALID_SOCKET)
	{
		port = Cvar_Get("ip_hostport", "0", CVAR_NOSET)->integer;
		if (!port)
		{
			port = Cvar_Get("hostport", "0", CVAR_NOSET)->integer;
			if (!port)
			{
				port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->integer;
			}
		}
		ip_sockets[NS_SERVER] = NET_IPSocket(ip->string, port);
		if (ip_sockets[NS_SERVER] == INVALID_SOCKET && dedicated)
			Com_Error (ERR_FATAL, "Couldn't allocate dedicated server IP port on %s:%d.", ip->string, port);
	}

	// dedicated servers don't need client ports
	if (dedicated)
		return;

	if (flag & NET_CLIENT && ip_sockets[NS_CLIENT] == INVALID_SOCKET)
	{
		ip_sockets[NS_CLIENT] = NET_IPSocket(ip->string, client_port->integer);

		if (ip_sockets[NS_CLIENT] == INVALID_SOCKET)
			ip_sockets[NS_CLIENT] = NET_IPSocket(ip->string, PORT_ANY);

		if (ip_sockets[NS_CLIENT] == INVALID_SOCKET)
			Com_Error (ERR_DROP, "Couldn't allocate client IP port.");
	}
}
Beispiel #6
0
/*
========================
idUDP::InitForPort
========================
*/
bool idUDP::InitForPort( int portNumber )
{
	netSocket = NET_IPSocket( net_ip.GetString(), portNumber, &bound_to );
	if( netSocket <= 0 )
	{
		netSocket = 0;
		memset( &bound_to, 0, sizeof( bound_to ) );
		return false;
	}
	
	return true;
}
/*
========================
idUDP::InitForPort
========================
*/
bool idUDP::InitForPort( int portNumber )
{
	// DG: don't specify an IP to bind for (and certainly not net_ip)
	// => it'll listen on all addresses (0.0.0.0 / INADDR_ANY)
	netSocket = NET_IPSocket( NULL, portNumber, &bound_to );
	// DG end
	if( netSocket <= 0 )
	{
		netSocket = 0;
		memset( &bound_to, 0, sizeof( bound_to ) );
		return false;
	}
	
	return true;
}
Beispiel #8
0
/*
==================
InitForPort
==================
*/
bool idPort::InitForPort( int portNumber ) {
	int len = sizeof( struct sockaddr_in );

	netSocket = NET_IPSocket( net_ip.GetString(), portNumber, &bound_to );
	if ( netSocket <= 0 ) {
		netSocket = 0;
		memset( &bound_to, 0, sizeof( bound_to ) );
		return false;
	}

#if 0
	if ( net_socksEnabled.GetBool() ) {
		NET_OpenSocks( portNumber );
	}
#endif

	udpPorts[ bound_to.port ] = new idUDPLag;

	return true;
}
Beispiel #9
0
/*
====================
NET_OpenIP
====================
*/
static void NET_OpenIP( void )
{
	int i;
	int err;
	int port = PORT_ANY;
	int port6 = PORT_ANY;

	struct sockaddr_in boundto4;

	if ( serverMode )
	{
		port = NET_EnsureValidPortNo( net_port->integer );
		port6 = NET_EnsureValidPortNo( net_port6->integer );
	}

	NET_GetLocalAddress();

	// automatically scan for a valid port, so multiple
	// dedicated servers can be started without requiring
	// a different net_port for each one

	if ( net_enabled->integer & NET_ENABLEV6 )
	{
		for ( i = ( port6 == PORT_ANY ? 1 : MAX_TRY_PORTS ); i; i++ )
		{
			ip6_socket = NET_IP6Socket( net_ip6->string, port6, &boundto, &err );

			if ( ip6_socket != INVALID_SOCKET )
			{
				port6 = ntohs( boundto.sin6_port );
				break;
			}
			else if ( err == EAFNOSUPPORT )
			{
				port6 = PORT_ANY;
				break;
			}

			port6 = ( port6 == PORT_ANY ) ? port6 : NET_EnsureValidPortNo( port6 + 1 );
		}

		if ( ip6_socket == INVALID_SOCKET || err == EAFNOSUPPORT )
		{
			Com_Printf( "WARNING: Couldn't bind to an IPv6 address.\n" );
			port6 = PORT_ANY;
		}
	}

	if ( net_enabled->integer & NET_ENABLEV4 )
	{
		for ( i = ( port6 == PORT_ANY ? 1 : MAX_TRY_PORTS ); i; i++ )
		{
			ip_socket = NET_IPSocket( net_ip->string, port, &boundto4, &err );

			if ( ip_socket != INVALID_SOCKET )
			{
				port = ntohs( boundto4.sin_port );
				break;
			}
			else if ( err == EAFNOSUPPORT )
			{
				port = PORT_ANY;
				break;
			}

			port = ( port == PORT_ANY ) ? port : NET_EnsureValidPortNo( port + 1 );
		}

		if ( ip_socket == INVALID_SOCKET )
		{
			Com_Printf( "WARNING: Couldn't bind to an IPv4 address.\n" );
			port = PORT_ANY;
		}
	}

	if ( port != PORT_ANY && net_socksEnabled->integer )
	{
		NET_OpenSocks( port );
	}

	Cvar_Set( "net_currentPort", va( "%i", port ) );
	Cvar_Set( "net_currentPort6", va( "%i", port6 ) );
}
Beispiel #10
0
/* <d470a> ../engine/net_ws.c:1842 */
void NET_OpenIP(void)
{
	//cvar_t *ip;//unused?
	int port;
	int dedicated;
	int sv_port = 0;
	int cl_port = 0;
	//int mc_port;//unused?
	static qboolean bFirst = TRUE;

	port = 0;
	dedicated = g_pcls.state == ca_dedicated;

	NET_ThreadLock();

	if (!ip_sockets[NS_SERVER])
	{
		port = (int)iphostport.value;

		if (!port)
		{
			port = (int)hostport.value;
			if (!port)
			{
				port = (int)defport.value;
				hostport.value = defport.value;
			}
		}
		ip_sockets[NS_SERVER] = NET_IPSocket(ipname.string, port, FALSE);

		if (!ip_sockets[NS_SERVER] && dedicated)
		{
			Sys_Error("Couldn't allocate dedicated server IP port %d.", port);
		}
		sv_port = port;
	}
	NET_ThreadUnlock();

	if (dedicated)
		return;

	NET_ThreadLock();
	if (!ip_sockets[NS_CLIENT])
	{
		port = (int)ip_clientport.value;

		if (!port)
		{
			port = (int)clientport.value;
			if (!port)
				port = -1;
		}
		ip_sockets[NS_CLIENT] = NET_IPSocket(ipname.string, port, FALSE);
		if (!ip_sockets[NS_CLIENT])
			ip_sockets[NS_CLIENT] = NET_IPSocket(ipname.string, -1, FALSE);
		cl_port = port;
	}
	if (!ip_sockets[NS_MULTICAST])
	{
		ip_sockets[NS_MULTICAST] = NET_IPSocket(ipname.string, multicastport.value, TRUE);
		if (!ip_sockets[NS_MULTICAST] && !dedicated)
			Con_Printf("Warning! Couldn't allocate multicast IP port.\n");
	}
	NET_ThreadUnlock();

	if (bFirst)
	{
		bFirst = FALSE;
		Con_Printf("NET Ports:  server %i, client %i\n", sv_port, cl_port);
	}
}