/*
================
rvDebuggerServer::Initialize

Initialize the debugger server.  This function should be called before the
debugger server is used.
================
*/
bool rvDebuggerServer::Initialize ( void )
{
	// Initialize the network connection
	if ( !mPort.InitForPort ( 27980 ) )
	{
		return false;
	}

	// Get a copy of the game thread handle so we can suspend the thread on a break
	DuplicateHandle ( GetCurrentProcess(), GetCurrentThread ( ), GetCurrentProcess(), &mGameThread, 0, FALSE, DUPLICATE_SAME_ACCESS );

	// Create a critical section to ensure that the shared thread
	// variables are protected
	InitializeCriticalSection ( &mCriticalSection );

	// Server must be running on the local host on port 28980
	Sys_StringToNetAdr ( "localhost", &mClientAdr, true );
	mClientAdr.port = 27981;
	
	// Attempt to let the server know we are here.  The server may not be running so this
	// message will just get ignored.
	SendMessage ( DBMSG_CONNECT );
	
	return true;
}	
/*
========================
idLobbyBackendDirect::GetConnectInfo
========================
*/
lobbyConnectInfo_t idLobbyBackendDirect::GetConnectInfo()
{
	lobbyConnectInfo_t connectInfo;
	
	// If we aren't the host, this lobby should have been joined through JoinFromConnectInfo
	if( IsHost() )
	{
		// If we are the host, give them our ip address
		// DG: always using the first IP doesn't work, because on linux that's 127.0.0.1
		// and even if not, this causes trouble with NAT.
		// So either use net_ip or, if it's not set ("localhost"), use 0.0.0.0 which is
		// a special case the client will treat as "just use the IP I used for the lobby"
		// (which is the right behavior for the Direct backend, I guess).
		// the client special case is in idLobby::HandleReliableMsg
		const char* ip = net_ip.GetString();
		if( ip == NULL || idStr::Length( ip ) == 0 || idStr::Icmp( ip, "localhost" ) == 0 )
			ip = "0.0.0.0";
		// DG end
		Sys_StringToNetAdr( ip, &address, false );
		address.port = net_port.GetInteger();
	}
	
	connectInfo.netAddr = address;
	
	return connectInfo;
}
示例#3
0
/*
==================
idTCP::Init
==================
*/
bool idTCP::Init( const char *host, short port )
{
    struct sockaddr_in sadr;
    if ( !Sys_StringToNetAdr( host, &address, true ) )
    {
        common->Printf( "Couldn't resolve server name \"%s\"\n", host );
        return false;
    }
    address.type = NA_IP;
    if (!address.port)
    {
        address.port = port;
    }
    common->Printf( "\"%s\" resolved to %i.%i.%i.%i:%i\n", host,
                    address.ip[0], address.ip[1], address.ip[2], address.ip[3],  address.port );
    NetadrToSockadr(&address, &sadr);

    if (fd)
    {
        common->Warning("idTCP::Init: already initialized?\n");
    }

    if ((fd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
    {
        fd = 0;
        common->Printf("ERROR: idTCP::Init: socket: %s\n", strerror(errno));
        return false;
    }

    if ( connect( fd, (const sockaddr *)&sadr, sizeof( sadr ) ) == -1 )
    {
        common->Printf( "ERROR: idTCP::Init: connect: %s\n", strerror( errno ) );
        close( fd );
        fd = 0;
        return false;
    }

    int status;
    if ((status = fcntl(fd, F_GETFL, 0)) != -1)
    {
        status |= O_NONBLOCK; /* POSIX */
        status = fcntl(fd, F_SETFL, status);
    }
    if (status == -1)
    {
        common->Printf("ERROR: idTCP::Init: fcntl / O_NONBLOCK: %s\n", strerror(errno));
        close(fd);
        fd = 0;
        return false;
    }

    common->DPrintf("Opened TCP connection\n");
    return true;
}
/*
========================
idLobbyBackendDirect::JoinFromConnectInfo
========================
*/
void idLobbyBackendDirect::JoinFromConnectInfo( const lobbyConnectInfo_t & connectInfo ) {
	if ( lobbyToSessionCB->CanJoinLocalHost() ) {
		Sys_StringToNetAdr( "localhost", &address, true );
		address.port = net_port.GetInteger();
	} else {
		address = connectInfo.netAddr;
	}

	state		= STATE_READY;
	isLocal		= false;
	isHost		= false;
}
示例#5
0
/*
==================
idTCP::Init
==================
*/
bool idTCP::Init( const char *host, short port )
{
    unsigned long	_true = 1;
    struct sockaddr sadr;

    if ( !Sys_StringToNetAdr( host, &address, true ) )
    {
        common->Printf( "Couldn't resolve server name \"%s\"\n", host );
        return false;
    }
    address.type = NA_IP;
    if ( !address.port )
    {
        address.port = port;
    }
    common->Printf( "\"%s\" resolved to %i.%i.%i.%i:%i\n", host,
                    address.ip[0], address.ip[1], address.ip[2], address.ip[3], address.port );
    Net_NetadrToSockadr( &address, &sadr );

    if ( fd )
    {
        common->Warning( "idTCP::Init: already initialized?" );
    }

    if ( ( fd = socket( AF_INET, SOCK_STREAM, 0 ) ) == INVALID_SOCKET )
    {
        fd = 0;
        common->Printf( "ERROR: idTCP::Init: socket: %s\n", NET_ErrorString() );
        return false;
    }

    if ( connect( fd, &sadr, sizeof(sadr)) == SOCKET_ERROR )
    {
        common->Printf( "ERROR: idTCP::Init: connect: %s\n", NET_ErrorString() );
        closesocket( fd );
        fd = 0;
        return false;
    }

    // make it non-blocking
    if( ioctlsocket( fd, FIONBIO, &_true ) == SOCKET_ERROR )
    {
        common->Printf( "ERROR: idTCP::Init: ioctl FIONBIO: %s\n", NET_ErrorString() );
        closesocket( fd );
        fd = 0;
        return false;
    }

    common->DPrintf( "Opened TCP connection\n" );
    return true;
}
/*
================
idServerScan::AddServer
================
*/
void idServerScan::AddServer( int id, const char *srv ) {
	inServer_t s;
	incoming_net = true;
	incoming_lastTime = Sys_Milliseconds() + INCOMING_TIMEOUT;
	s.id = id;
	// using IPs, not hosts
	if( !Sys_StringToNetAdr( srv, &s.adr, false ) ) {
		common->DPrintf( "idServerScan::AddServer: failed to parse server %s\n", srv );
		return;
	}
	if( !s.adr.port ) {
		s.adr.port = PORT_SERVER;
	}
	net_servers.Append( s );
}
/*
========================
idLobbyBackendDirect::GetConnectInfo
========================
*/
lobbyConnectInfo_t idLobbyBackendDirect::GetConnectInfo() {
	lobbyConnectInfo_t connectInfo;

	// If we aren't the host, this lobby should have been joined through JoinFromConnectInfo
	if ( IsHost() ) {
		// If we are the host, give them our ip address
		const char * ip = Sys_GetLocalIP( 0 );
		Sys_StringToNetAdr( ip, &address, false );
		address.port = net_port.GetInteger();
	}

	connectInfo.netAddr = address;

	return connectInfo;
}
/*
========================
idLobbyBackendDirect::JoinFromConnectInfo
========================
*/
void idLobbyBackendDirect::JoinFromConnectInfo( const lobbyConnectInfo_t& connectInfo )
{
	if( lobbyToSessionCB->CanJoinLocalHost() )
	{
		// TODO: "CanJoinLocalHost" == *must* join LocalHost ?!
		Sys_StringToNetAdr( "localhost", &address, true );
		address.port = net_port.GetInteger();
		NET_VERBOSE_PRINT( "NET: idLobbyBackendDirect::JoinFromConnectInfo(): canJoinLocalHost\n" );
	}
	else
	{
		address = connectInfo.netAddr;
		NET_VERBOSE_PRINT( "NET: idLobbyBackendDirect::JoinFromConnectInfo(): %s\n", Sys_NetAdrToString( address ) );
	}
	
	state		= STATE_READY;
	isLocal		= false;
	isHost		= false;
}
/*
================
rvDebuggerClient::Initialize

Initialize the debugger client
================
*/
bool rvDebuggerClient::Initialize(void)
{
	// Nothing else can run with the debugger
	com_editors = EDITOR_DEBUGGER;

	// Initialize the network connection
	if (!mPort.InitForPort(27981)) {
		return false;
	}

	// Server must be running on the local host on port 28980
	Sys_StringToNetAdr("localhost", &mServerAdrt, true);
	mServerAdr.port = 27980;

	// Attempt to let the server know we are here.  The server may not be running so this
	// message will just get ignored.
	SendMessage(DBMSG_CONNECT);

	return true;
}
/*
========================
idSessionLocalWin::Connect_f
========================
*/
void idSessionLocalWin::Connect_f( const idCmdArgs& args )
{
	if( args.Argc() < 2 )
	{
		idLib::Printf( "Usage: Connect to IP.  Use with net_port. \n" );
		return;
	}
	
	Cancel();
	
	if( signInManager->GetMasterLocalUser() == NULL )
	{
		signInManager->RegisterLocalUser( 0 );
	}
	
	lobbyConnectInfo_t connectInfo;
	
	Sys_StringToNetAdr( args.Argv( 1 ), &connectInfo.netAddr, true );
	connectInfo.netAddr.port = net_port.GetInteger();
	
	ConnectAndMoveToLobby( GetPartyLobby(), connectInfo, false );
}