Ejemplo n.º 1
0
bool CServerBrowser::OnClick ( CGUIElement* pElement )
{
    ServerBrowserType Type = GetCurrentServerBrowserType ();

    m_pServerPlayerList [ Type ]->Clear ();

    char buf[32];
 
    // If there is one item selected
    if ( m_pServerList [ Type ]->GetSelectedCount () >= 1 )
    {
        // Get the selected row
        int iSelectedIndex = m_pServerList [ Type ]->GetSelectedItemRow ();

        // Walk the server list looking for this server
        CServerList * pList = GetServerList ( Type );
        CServerListIterator i, i_b = pList->IteratorBegin (), i_e = pList->IteratorEnd ();
        std::string strSelectedEndpoint = m_pServerList [ Type ]->GetItemText ( iSelectedIndex, m_hHost [ Type ] );
        for ( i = i_b; i != i_e; i++ ) 
        {
            CServerListItem * pServer = *i;
            std::string strEndpoint = pServer->strHost + ":" + itoa ( pServer->usGamePort, buf, 10 );
            if ( strSelectedEndpoint.compare ( strEndpoint ) == 0 ) 
            {
                // We found the server, add all the players
                for ( unsigned int j = 0; j < pServer->vecPlayers.size (); j++ ) 
                {
                    int k = m_pServerPlayerList [ Type ]->AddRow ();
                    m_pServerPlayerList [ Type ]->SetItemText ( k, m_hPlayerName [ Type ], pServer->vecPlayers[j].c_str () );
                }

                // It's not the same server as was selected before, so we update the password
                if ( iSelectedIndex != m_iSelectedServer[ Type ] )
                {
                    bool bSavedPasswords;
                    CVARS_GET ( "save_server_passwords", bSavedPasswords );
                    if ( pServer->bPassworded && bSavedPasswords )
                    {
                        m_pEditPassword [ Type ]->SetText ( GetServerPassword(strEndpoint).c_str() );
                    }
                    else
                    {
                        m_pEditPassword [ Type ]->SetText ( "" );
                    }
                }
            }
        }

        // save the selected server
        m_iSelectedServer [ Type ] = iSelectedIndex;
    }
    else
    {
        m_pEditPassword [ Type ]->SetText ( "" );
    }
    return true;
}
Ejemplo n.º 2
0
void CServerBrowser::OnClick( CGUIElement_Impl * pElement )
{
	// Get the current serverbrowser type
	ServerBrowserType type = GetCurrentServerBrowserType();

	// Clear the current playerlist
	m_pPlayersGridList->Clear();

	// Have we selected any server?
	if( m_pServerGridList[ type ]->GetSelectedCount() > 0 )
	{
		// Enable the connection button in the main menu
		pCore->GetGUI()->GetMainMenu()->SetConnectButtonVisible( true );

		// Get the selected row index
		int iSelectedIndex = m_pServerGridList[ type ]->GetSelectedItemRow();

		// Find this server from the serverlist
		CServerList * pServerList = GetServerList( type );
		CServerListIterator iter, begin = pServerList->IteratorBegin(), end = pServerList->IteratorEnd();

		// Loop over all servers in the list
		for( iter = begin; iter != end; iter++ )
		{
			// Get the current server
			CServerListItem * pCurrentServer = *iter;

			// Is the current server valid and the one we're looking for?
			if( pCurrentServer && pCurrentServer->iRow == iSelectedIndex )
			{
				// Loop over the players
				for( std::map< std::string, unsigned short >::iterator iter2 = pCurrentServer->m_players.begin(); iter2 != pCurrentServer->m_players.end(); iter2++ )
				{
					// Add a new row in the players grid
					int iRow =  m_pPlayersGridList->AddRow();
					iRow = m_pPlayersGridList->SetItemText ( iRow, 1, (*iter2).first.c_str () );
					iRow = m_pPlayersGridList->SetItemText ( iRow, 2, String ( "%u", (*iter2).second ), true );
				}
			}
		}

		// Store the current selected server
		m_iSelectedServer[ type ] = iSelectedIndex;
	}
	else
	{
		// Disable the connection button
		pCore->GetGUI()->GetMainMenu()->SetConnectButtonVisible( false );
	}
}
Ejemplo n.º 3
0
void CServerBrowser::UpdateServerList ( ServerBrowserType Type, bool bClearServerList )
{

    // Get the appropriate server list
    CServerList* pList = GetServerList ( Type );

    if ( pList->GetRevision () != m_pServerListRevision [ Type ] || bClearServerList )
    {
        m_pServerListRevision [ Type ] = pList->GetRevision ();

        // Clear current list
        m_pServerList [ Type ]->Clear ();

        // Clear the player lists
        m_pServerPlayerList [ Type ]->Clear ();
    }

    // Loop the server list
    CServerListIterator i, i_b = pList->IteratorBegin (), i_e = pList->IteratorEnd ();
    int j = 0;
    int k = pList->GetServerCount ();
    if ( k > 0 )
    {
        for ( CServerListIterator i = i_b; i != i_e; i++ )
        {
            CServerListItem * pServer = *i;

            // Add the item to the list
            if ( ( pServer->bScanned || (pServer->bSkipped && m_pIncludeOffline [ Type ] && m_pIncludeOffline [ Type ]->GetSelected ()) ) &&
                 ( !pServer->bAddedToList[ Type ] || bClearServerList ) )
                AddServerToList ( pServer, Type );
            j++;
        }
    }

    /*
    SString strTitle = SString::Printf ( "Server Browser - %d servers - %d/%d players", iNumServers, iNumPlayers, iNumPlayerSlots );
    m_pWindow->SetText ( strTitle );
    */
    m_pServerList [ Type ]->ForceUpdate ();
    pList->SetUpdated ( false );
}
Ejemplo n.º 4
0
bool CServerBrowser::ConnectToSelectedServer ( void )
{
    ServerBrowserType Type = GetCurrentServerBrowserType ();
    m_pServerPlayerList [ Type ]->Clear ();

    char buf[32];
 
    // If there is one item selected
    if ( m_pServerList [ Type ]->GetSelectedCount () >= 1 )
    {
        // Get the selected row
        int iSelectedIndex = m_pServerList [ Type ]->GetSelectedItemRow ();

        // Walk the server list looking for this server
        CServerList * pList = GetServerList ( Type );
        CServerListIterator i, i_b = pList->IteratorBegin (), i_e = pList->IteratorEnd ();
        std::string strSelectedEndpoint = m_pServerList [ Type ]->GetItemText ( iSelectedIndex, m_hHost [ Type ] );
        for ( i = i_b; i != i_e; i++ ) {
            CServerListItem * pServer = *i;
            std::string strEndpoint = pServer->strHost + ":" + itoa ( pServer->usGamePort, buf, 10 );
            if ( strSelectedEndpoint.compare ( strEndpoint ) == 0 )
            {
                if ( ( pServer->bSerials ) && ( !g_pCore->GetCommunity()->IsLoggedIn() ) )
                {
                    m_pCommunityLogin.SetVisible ( true );
                    return true;
                }
                // Get the nick from the config
                std::string strNick;
                CVARS_GET ( "nick", strNick );

                // Valid nick?
                if ( !CCore::GetSingleton ().IsValidNick ( strNick.c_str () ) )
                {
                    CCore::GetSingleton ().ShowMessageBox ( "Error", "Invalid nickname! Please go to Settings and set a new!", MB_BUTTON_OK | MB_ICON_INFO );
                    return true;
                }

                // Password buffer
                char szPassword [48];
                szPassword [47] = 0;
                strncpy ( szPassword, m_pEditPassword [ Type ]->GetText ().c_str (), 47 );
                
                bool bSavedPasswords;
                CVARS_GET ( "save_server_passwords", bSavedPasswords );
                if ( pServer->bPassworded && bSavedPasswords )
                {
                    SetServerPassword ( strEndpoint, ( std::string )szPassword );
                }
                

                // Start the connect
                CCore::GetSingleton ().GetConnectManager ()->Connect ( pServer->strHost.c_str (), pServer->usGamePort, strNick.c_str (), szPassword );
            }
        }
    }
    else
    {
        CCore::GetSingleton ().ShowMessageBox ( "Information", "You have to select a server to connect to.", MB_BUTTON_OK | MB_ICON_INFO );
    }
    return false;
}