@@ -333,84 +333,168 @@ void CServerInfo::Show(eWindowType WindowType, const char* szHost, unsigned shor
333333
334334void CServerInfo::SetServerInformation (const char * szHost, unsigned short usPort, const char * szPassword, CServerListItem* pInitialServerListItem)
335335{
336- // Store the parameters in our class instance for later use
337336 m_usPort = usPort;
337+ m_strPassword = szPassword ? szPassword : " " ;
338+ m_strHost = szHost ? szHost : " " ;
338339
339- m_strPassword = szPassword;
340- m_strHost = szHost;
341-
342- // Create a winsock address endpoint and parse the IP into it
343340 in_addr Address;
344- CServerListItem::Parse (szHost, Address);
345-
346- // Set our server query's address, query port and game port
341+ memset (&Address, 0 , sizeof (Address));
342+ if (!CServerListItem::Parse (szHost, Address))
343+ Address.S_un .S_addr = 0 ;
344+
345+ m_Server.CancelPendingQuery ();
346+
347+ // Clear stale address data before applying the new endpoint
348+ m_Server.Address .S_un .S_addr = 0 ;
349+ m_Server.AddressCopy .S_un .S_addr = 0 ;
350+ m_Server.usGamePort = 0 ;
351+ m_Server.usGamePortCopy = 0 ;
352+ m_Server.strHost = " " ;
353+ m_Server.strEndpoint = " " ;
354+ m_Server.strEndpointSortKey = " " ;
355+ m_Server.bScanned = false ;
356+ m_Server.bSkipped = false ;
357+
358+ // Assign the new address details
347359 m_Server.ChangeAddress (Address, usPort);
348360
349- if (pInitialServerListItem) // If we have a pointer to an already scanned server, we initially set text to this
350- ResetServerGUI (pInitialServerListItem);
351- else // Otherwise, reset it to blank text
361+ if (m_Server.Address .S_un .S_addr != Address.S_un .S_addr || m_Server.usGamePort != usPort)
362+ {
363+ m_Server.Address = Address;
364+ m_Server.usGamePort = usPort;
365+ }
366+
367+ m_Server.AddressCopy = m_Server.Address ;
368+ m_Server.usGamePortCopy = m_Server.usGamePort ;
369+
370+ const uchar* addressBytes = reinterpret_cast <const uchar*>(&m_Server.Address .S_un .S_addr );
371+ SString strAddressHost = inet_ntoa (m_Server.Address );
372+ if (strAddressHost.empty ())
373+ strAddressHost = szHost;
374+ m_Server.strHost = strAddressHost;
375+ m_Server.strEndpoint = SString (" %s:%u" , *strAddressHost, m_Server.usGamePort );
376+ m_Server.strEndpointSortKey =
377+ SString (" %02x%02x%02x%02x-%04x" , addressBytes[0 ], addressBytes[1 ], addressBytes[2 ], addressBytes[3 ], m_Server.usGamePort );
378+
379+ if (pInitialServerListItem && CServerListItem::StaticIsValid (pInitialServerListItem))
380+ {
381+ m_Server.strName = pInitialServerListItem->strName ;
382+ m_Server.strSearchableName = pInitialServerListItem->strSearchableName ;
383+ m_Server.strHostName = pInitialServerListItem->strHostName ;
384+ m_Server.strGameName = pInitialServerListItem->strGameName ;
385+ m_Server.strGameMode = pInitialServerListItem->strGameMode ;
386+ m_Server.strMap = pInitialServerListItem->strMap ;
387+ m_Server.strVersion = pInitialServerListItem->strVersion ;
388+ m_Server.nPlayers = pInitialServerListItem->nPlayers ;
389+ m_Server.nMaxPlayers = pInitialServerListItem->nMaxPlayers ;
390+ m_Server.nPing = pInitialServerListItem->nPing ;
391+ m_Server.bPassworded = pInitialServerListItem->bPassworded ;
392+ m_Server.bSerials = pInitialServerListItem->bSerials ;
393+ m_Server.isStatusVerified = pInitialServerListItem->isStatusVerified ;
394+ m_Server.bMaybeOffline = pInitialServerListItem->bMaybeOffline ;
395+ m_Server.bMasterServerSaysNoResponse = pInitialServerListItem->bMasterServerSaysNoResponse ;
396+ m_Server.uiMasterServerSaysRestrictions = pInitialServerListItem->uiMasterServerSaysRestrictions ;
397+ m_Server.vecPlayers = pInitialServerListItem->vecPlayers ;
398+ m_Server.uiTieBreakPosition = pInitialServerListItem->uiTieBreakPosition ;
399+ m_Server.strTieBreakSortKey = pInitialServerListItem->strTieBreakSortKey ;
400+ m_Server.strNameSortKey = pInitialServerListItem->strNameSortKey ;
401+ m_Server.strVersionSortKey = pInitialServerListItem->strVersionSortKey ;
402+ m_Server.m_iBuildType = pInitialServerListItem->m_iBuildType ;
403+ m_Server.m_iBuildNumber = pInitialServerListItem->m_iBuildNumber ;
404+ m_Server.m_usHttpPort = pInitialServerListItem->m_usHttpPort ;
405+ m_Server.m_ucSpecialFlags = pInitialServerListItem->m_ucSpecialFlags ;
406+ m_Server.SetDataQuality (pInitialServerListItem->GetDataQuality ());
407+ m_Server.bScanned = true ;
408+ m_Server.bSkipped = false ;
409+
410+ if (!pInitialServerListItem->strHost .empty ())
411+ m_Server.strHost = pInitialServerListItem->strHost ;
412+ if (!pInitialServerListItem->strEndpoint .empty ())
413+ m_Server.strEndpoint = pInitialServerListItem->strEndpoint ;
414+ if (!pInitialServerListItem->strEndpointSortKey .empty ())
415+ m_Server.strEndpointSortKey = pInitialServerListItem->strEndpointSortKey ;
416+
417+ ResetServerGUI (&m_Server);
418+ }
419+ else
420+ {
352421 Reset ();
422+ }
353423
354- m_pServerAddressLabel->SetText (SString (" %s:%u" , szHost, usPort));
424+ const SString strDisplayedEndpoint = !m_Server.strEndpoint .empty () ? m_Server.strEndpoint : SString (" %s:%u" , szHost, usPort);
425+ m_pServerAddressLabel->SetText (strDisplayedEndpoint);
355426
356- // Lets query the server now, as the previous data is out of date
427+ // Start a fresh query so we get the latest data for this server
357428 Refresh ();
358429}
359430
360431void CServerInfo::DoPulse ()
361432{
362- // Are we visible?
363- if (IsVisible ())
433+ if (!IsVisible ())
364434 {
365- // Pulse the server query
366- m_Server.Pulse (true );
367-
368- // Do we need a refresh?
369- if ((m_Server.bScanned && (CClientTime::GetTime () - m_ulLastUpdateTime) >= SERVER_UPDATE_INTERVAL))
435+ if (m_bWaitingToActivatePassword)
370436 {
371- // Are we queing, and is auto join enabled?
372- if (m_pCurrentWindowType == eWindowTypes::SERVER_INFO_QUEUE && m_pCheckboxAutojoin->GetSelected ())
373- {
374- // Is a slot available?
375- if (m_Server.nPlayers < m_Server.nMaxPlayers )
376- {
377- // Lets attempt to connect
378- Connect ();
379- return ;
380- }
381- }
437+ m_bWaitingToActivatePassword = false ;
438+ m_pWindow->Activate ();
439+ m_pEnterPasswordEdit->Activate ();
440+ }
441+ return ;
442+ }
382443
383- ResetServerGUI (&m_Server);
444+ const unsigned long ulNow = CClientTime::GetTime ();
445+ bool bRefreshed = false ;
384446
385- m_ulLastUpdateTime = CClientTime::GetTime ( );
447+ m_Server. Pulse ( true );
386448
387- // Query the server
388- Refresh ();
389- }
390- else if (m_Server.bSkipped ) // Server query timed out
391- {
392- // Should we try to query again?
393- if (CClientTime::GetTime () - m_ulLastUpdateTime >= SERVER_UPDATE_INTERVAL)
394- {
395- // Query the server
396- Refresh ();
397- }
449+ in_addr expectedAddress;
450+ memset (&expectedAddress, 0 , sizeof (expectedAddress));
451+ const bool bHasExpectedAddress = !m_strHost.empty () && CServerListItem::Parse (m_strHost.c_str (), expectedAddress);
452+ const bool bAddressMatches = !bHasExpectedAddress || (expectedAddress.S_un .S_addr == m_Server.Address .S_un .S_addr && m_usPort == m_Server.usGamePort );
398453
454+ if (m_Server.bScanned )
455+ {
456+ if (bAddressMatches)
457+ {
399458 ResetServerGUI (&m_Server);
400459
401- // The server has timed out
402- m_pLatencyLabel->SetText (_ (" Timed Out" ));
460+ if (m_pCurrentWindowType == eWindowTypes::SERVER_INFO_QUEUE && m_pCheckboxAutojoin->GetSelected () &&
461+ m_Server.nPlayers < m_Server.nMaxPlayers )
462+ {
463+ Connect ();
464+ return ;
465+ }
403466
404- m_ulLastUpdateTime = CClientTime::GetTime () ;
467+ m_ulLastUpdateTime = ulNow ;
405468 }
406-
407- if (m_bWaitingToActivatePassword)
469+ else
408470 {
409- m_bWaitingToActivatePassword = false ;
410- m_pWindow-> Activate () ;
411- m_pEnterPasswordEdit-> Activate () ;
471+ Refresh () ;
472+ bRefreshed = true ;
473+ m_ulLastUpdateTime = ulNow ;
412474 }
413475 }
476+ else if (m_Server.bSkipped )
477+ {
478+ ResetServerGUI (&m_Server);
479+ m_pLatencyLabel->SetText (_ (" Timed Out" ));
480+ m_ulLastUpdateTime = ulNow;
481+
482+ Refresh ();
483+ bRefreshed = true ;
484+ }
485+
486+ if (!bRefreshed && (ulNow - m_ulLastUpdateTime) >= SERVER_UPDATE_INTERVAL)
487+ {
488+ Refresh ();
489+ m_ulLastUpdateTime = ulNow;
490+ }
491+
492+ if (m_bWaitingToActivatePassword)
493+ {
494+ m_bWaitingToActivatePassword = false ;
495+ m_pWindow->Activate ();
496+ m_pEnterPasswordEdit->Activate ();
497+ }
414498}
415499
416500void CServerInfo::Refresh ()
0 commit comments