Пример #1
0
bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword )
{
    assert ( szHost );
    assert ( szNick );
    assert ( szPassword );

    // Are we already connecting?
    CNet* pNet = CCore::GetSingleton ().GetNetwork ();
    if ( m_bIsConnecting || pNet->IsConnected () )
    {
        CModManager::GetSingleton ().Unload ();
    }    

    // Is the nick valid?
    if ( !CheckNickProvided ( (char*) szNick ) )
    {
        SString strBuffer = "Connecting failed. Invalid nick provided!";
        CCore::GetSingleton ().ShowMessageBox ( "Error", strBuffer, MB_BUTTON_OK | MB_ICON_ERROR );
        return false;
    }

    // Save the nick too
    CVARS_SET ( "nick", std::string ( szNick ) );

    // Reset the network
    pNet->Reset ();
    assert ( pNet->GetServerBitStreamVersion () == 0 );

    // Set our packet handler
    pNet->RegisterPacketHandler ( CConnectManager::StaticProcessPacket, true );

    // Set our MTU size to the default
    pNet->SetMTUSize ( m_usMTUSize );

    // Try to start a network to connect
    if ( !pNet->StartNetwork ( szHost, usPort ) )
    {
        SString strBuffer ( "Connecting to %s at port %u failed!", szHost, usPort );
        CCore::GetSingleton ().ShowMessageBox ( "Error", strBuffer, MB_BUTTON_OK | MB_ICON_ERROR );
        return false;
    }

    m_strHost = szHost;
    m_strNick = szNick;
    m_strPassword = szPassword;

    // Store the port and that we're connecting
    m_usPort = usPort;
    m_bIsConnecting = true;
    m_tConnectStarted = time ( NULL );

    // Display the status box
    SString strBuffer ( "Connecting to %s:%u ...", m_strHost.c_str(), usPort );
    CCore::GetSingleton ().ShowMessageBox ( "CONNECTING", strBuffer, MB_BUTTON_CANCEL | MB_ICON_INFO, m_pOnCancelClick );

    return true;
}
Пример #2
0
bool CConnectManager::Abort ( void )
{
    // Stop the attempt
    CNet* pNet = CCore::GetSingleton ().GetNetwork ();
    pNet->StopNetwork ();
    pNet->Reset ();

    // Reset our variables
    m_strHost = "";
    m_strNick = "";
    m_strPassword = "";

    m_usPort = 0;
    m_bIsConnecting = false;
    m_tConnectStarted = 0;

    // Success
    return true;
}
Пример #3
0
bool CConnectManager::Abort ( void )
{
    // Stop the attempt
    CNet* pNet = CCore::GetSingleton ().GetNetwork ();
    pNet->StopNetwork ();
    pNet->Reset ();

    // Reset our variables
    m_strHost = "";
    m_strNick = "";
    m_strPassword = "";

    m_Address.s_addr = 0;
    m_usPort = 0;
    m_bIsConnecting = false;
    m_bIsDetectingVersion = false;
    m_tConnectStarted = 0;
    SAFE_DELETE ( m_pServerItem );

    // Success
    return true;
}
Пример #4
0
bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser, bool bForceInternalHTTPServer )
{
    assert ( szHost );
    assert ( szNick );
    assert ( szPassword );

    m_bNotifyServerBrowser = bNotifyServerBrowser;

    // Hide certain questions
    CCore::GetSingleton ().GetLocalGUI ()->GetMainMenu ()->GetQuestionWindow ()->OnConnect ();

    // Hide the server queue
    CServerInfo::GetSingletonPtr()->Hide( );

    // Save the browser state
    CServerBrowser::GetSingletonPtr()->SaveOptions( );

    // Are we already connecting?
    CNet* pNet = CCore::GetSingleton ().GetNetwork ();
    if ( m_bIsConnecting || pNet->IsConnected () )
    {
        CModManager::GetSingleton ().Unload ();
    }    

    // Is the nick valid?
    if ( !CheckNickProvided ( (char*) szNick ) )
    {
        SString strBuffer = _("Connecting failed. Invalid nick provided!");
        CCore::GetSingleton ().ShowMessageBox ( _("Error")+_E("CC20"), strBuffer, MB_BUTTON_OK | MB_ICON_ERROR ); // Invalid nick provided
        return false;
    }

    // Save the nick too
    CVARS_SET ( "nick", std::string ( szNick ) );

    // Reset the network
    pNet->Reset ();
    assert ( pNet->GetServerBitStreamVersion () == 0 );

    // Save input
    m_strHost = szHost;
    m_strNick = szNick;
    m_strPassword = szPassword;
    m_Address.s_addr = 0;
    m_usPort = usPort;
    m_bForceInternalHTTPServer = bForceInternalHTTPServer;
    m_bSave = true;

    m_strLastHost = m_strHost;
    m_usLastPort = m_usPort;
    m_strLastPassword = m_strPassword;

    // Parse host into a server item
    if ( !CServerListItem::Parse ( m_strHost.c_str(), m_Address ) )
    {
        SString strBuffer = _("Connecting failed. Invalid host provided!");
        CCore::GetSingleton ().ShowMessageBox ( _("Error")+_E("CC21"), strBuffer, MB_BUTTON_OK | MB_ICON_ERROR ); // Invalid host provided
        return false;
    }

    // No connect if disk space is low
    if ( !CCore::GetSingleton ().CheckDiskSpace () )
        return false;

    // Set our packet handler
    pNet->RegisterPacketHandler ( CConnectManager::StaticProcessPacket );

    // Try to start a network to connect
    SString strAddress = inet_ntoa ( m_Address );
    if ( m_usPort && !pNet->StartNetwork ( strAddress, m_usPort, CVARS_GET_VALUE < bool > ( "packet_tag" ) ) )
    {
        SString strBuffer ( _("Connecting to %s at port %u failed!"), m_strHost.c_str (), m_usPort );
        CCore::GetSingleton ().ShowMessageBox ( _("Error")+_E("CC22"), strBuffer, MB_BUTTON_OK | MB_ICON_ERROR ); // Failed to connect
        return false;
    }

    m_bIsConnecting = true;
    m_tConnectStarted = time ( NULL );

    // Load server password
    if ( m_strPassword.empty () )
        m_strPassword = CServerBrowser::GetSingletonPtr()->GetServerPassword ( m_strHost + ":" + SString ( "%u", m_usPort ) );

    // Start server version detection
    SAFE_DELETE ( m_pServerItem );
    m_pServerItem = new CServerListItem ( m_Address, m_usPort );
    m_pServerItem->m_iTimeoutLength = 2000;
    m_bIsDetectingVersion = true;

    // Display the status box
    SString strBuffer ( _("Connecting to %s:%u ..."), m_strHost.c_str(), m_usPort );
    CCore::GetSingleton ().ShowMessageBox ( _("CONNECTING"), strBuffer, MB_BUTTON_CANCEL | MB_ICON_INFO, m_pOnCancelClick );
    WriteDebugEvent( SString( "Connecting to %s:%u ...", m_strHost.c_str(), m_usPort ) );
    return true;
}