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 ); } }
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; }