Ejemplo n.º 1
0
CServerList* CScriptXmlInit::InitServerList(LPCSTR path, CUIWindow* parent){
	CServerList* pWnd = xr_new<CServerList>();
	pWnd->InitFromXml(m_xml, path);	
	pWnd->SetAutoDelete(true);
	_attach_child(pWnd, parent);
//.	if(parent) parent->AttachChild(pWnd);
	return pWnd;	
}
Ejemplo n.º 2
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;
}
	bool OnLS2C_GameServerList_Ret(LS2C_GameServerList_Ret* value)
	{
		if ( value->gameServers.size() > 0 )
		{
			CServerList* pServerList = (CServerList*)(CLoginScene::gLoginLayer->OpenUI(login_ui_serverlist));
			pServerList->Show(value->regionCnt,value->gameServers);
		}
		return true;
	}
Ejemplo n.º 4
0
void CServerBrowser::Event_MasterListQueryHandler( const std::vector<String>& servers )
{
	// Get the current server list
	CServerList * pList = pCore->GetGUI()->GetServerBrowser()->GetServerList( pCore->GetGUI()->GetServerBrowser()->GetCurrentServerBrowserType() );

	// Loop over all servers in the vector
	for ( auto server : servers )
	{
		// Add the new server to the list
		if ( server.GetLength() > 1 )
			pList->Add( server );
	}
}
Ejemplo n.º 5
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.º 6
0
void CServerBrowser::Update ( void )
{
    CServerList *pList = GetServerList ( GetCurrentServerBrowserType () );

    // Update the current server list class
    pList->Pulse ();

    // If an update is needed, the serverbrowser is visible and it has gone some time since last update
    if ( ( pList->IsUpdated () || m_PrevServerBrowserType != GetCurrentServerBrowserType () ) && m_ulLastUpdateTime < CClientTime::GetTime () - SERVER_BROWSER_UPDATE_INTERVAL )
    {
        // Update the GUI
        UpdateServerList ( GetCurrentServerBrowserType () );

        // Set the status string
        m_pServerListStatus->SetText ( pList->GetStatus ().c_str () );

        // Update last time updated
        m_ulLastUpdateTime = CClientTime::GetTime ();

        // Update last viewed tab
        m_PrevServerBrowserType = GetCurrentServerBrowserType ();
    }
}
Ejemplo n.º 7
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.º 8
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;
}
Ejemplo n.º 9
0
bool CConnectManager::StaticProcessPacket ( unsigned char ucPacketID, NetBitStreamInterface& BitStream )
{
    // We're working on connecting?
    if ( g_pConnectManager->m_bIsConnecting )
    {
        // The packet we're expecting?
        if ( ucPacketID == PACKET_ID_MOD_NAME )
        {
            // Read out the mod to load
            char* szModName = new char [ BitStream.GetNumberOfBytesUsed () + 1 ];
            memset ( szModName, 0, BitStream.GetNumberOfBytesUsed () + 1 );
            if ( BitStream.Read ( szModName, BitStream.GetNumberOfBytesUsed () ) )
            {
                // Backward compatibly examine the bytes following the mod name
                BitStream.ResetReadPointer ();
                BitStream.Read ( szModName, strlen ( szModName ) );
                char cPad;
                BitStream.Read ( cPad );
                unsigned short usServerBitStreamVersion = 0x01;
                BitStream.Read ( usServerBitStreamVersion );    // This will silently fail for < 1.0.2 and leave the bitstream version at 0x01
                CCore::GetSingleton ().GetNetwork ()->SetServerBitStreamVersion ( usServerBitStreamVersion );

                // Populate the arguments to pass it (-c host port nick)
                SString strArguments ( "%s %s", g_pConnectManager->m_strNick.c_str(), g_pConnectManager->m_strPassword.c_str() );

                // Hide the messagebox we're currently showing
                CCore::GetSingleton ().RemoveMessageBox ();

                // If we connected from quick-connect, get rid of it
                CQuickConnect * pQuickConnect = CCore::GetSingleton ().GetLocalGUI ()->GetMainMenu ()->GetQuickConnectWindow ();
                if ( pQuickConnect->IsVisible () )
                    pQuickConnect->SetVisible ( false );

                // Save the connection details into the config
                CVARS_SET ( "host",     g_pConnectManager->m_strHost );
                CVARS_SET ( "port",     g_pConnectManager->m_usPort );
                CVARS_SET ( "password", g_pConnectManager->m_strPassword );


                // Save the connection details into the recently played servers list
                in_addr Address;
                if ( CServerListItem::Parse ( g_pConnectManager->m_strHost.c_str (), Address ) )
                {
                    CServerBrowser* pServerBrowser = CCore::GetSingleton ().GetLocalGUI ()->GetMainMenu ()->GetServerBrowser ();
                    CServerList* pRecentList = pServerBrowser->GetRecentList ();
                    CServerListItem RecentServer ( Address, g_pConnectManager->m_usPort + SERVER_LIST_QUERY_PORT_OFFSET );
                    if ( !pRecentList->Exists ( RecentServer ) )
                    {
                        pRecentList->Add ( RecentServer );
                    }

                    // Set as our current server for xfire
                    if ( XfireIsLoaded () )
                    {
                        const char *szKey[2], *szValue[2];
                        szKey[0] = "Gamemode";
                        szValue[0] = RecentServer.strType.c_str();

                        szKey[1] = "Map";
                        szValue[1] = RecentServer.strMap.c_str();

                        XfireSetCustomGameData ( 2, szKey, szValue ); 
                    }
                }

                // Kevuwk: Forced the config to save here so that the IP/Port isn't lost on crash
                CCore::GetSingleton ().SaveConfig ();

                // Reset our variables
                g_pConnectManager->m_strNick = "";
                g_pConnectManager->m_strHost = "";
                g_pConnectManager->m_strPassword = "";

                g_pConnectManager->m_usPort = 0;
                g_pConnectManager->m_bIsConnecting = false;
                g_pConnectManager->m_tConnectStarted = 0;

                // Load the mod
                if ( !CModManager::GetSingleton ().Load ( szModName, strArguments ) )
                {
                    // Failed loading the mod
                    strArguments.Format ( "No such mod installed (%s)", szModName );
                    CCore::GetSingleton ().ShowMessageBox ( "Error", strArguments, MB_BUTTON_OK | MB_ICON_ERROR );
					g_pConnectManager->Abort ();
                }
            }
            else
            {
                // Show failed message and abort the attempt
                CCore::GetSingleton ().ShowMessageBox ( "Error", "Bad server response (2)", MB_BUTTON_OK | MB_ICON_ERROR );
                g_pConnectManager->Abort ();
            }

            delete [] szModName;
        }
        else
        {
            // Not the player joined packet?
            if ( ucPacketID != PACKET_ID_SERVER_JOIN && ucPacketID != PACKET_ID_SERVER_JOIN_DATA )
            {
                // Show failed message and abort the attempt
                CCore::GetSingleton ().ShowMessageBox ( "Error", "Bad server response (1)", MB_BUTTON_OK | MB_ICON_ERROR );
                g_pConnectManager->Abort ();
            }
        }

        return true;
    }

    return false;
}