Skip to content

Commit cc95877

Browse files
committed
Improve serverinfo (This still doesn't fix stale (i) button data)
1 parent c5fd124 commit cc95877

File tree

5 files changed

+159
-54
lines changed

5 files changed

+159
-54
lines changed

Client/core/ServerBrowser/CServerBrowser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ void CServerBrowser::CreateTab(ServerBrowserType type, const char* szName)
578578
m_pServerList[type]->SetSize(CVector2D(fWidth, fHeight), false);
579579
m_pServerList[type]->SetIgnoreTextSpacer(true);
580580
m_pServerList[type]->SetClickHandler(GUI_CALLBACK(&CServerBrowser::OnClick, this));
581+
m_pServerList[type]->SetSelectionHandler(GUI_CALLBACK(&CServerBrowser::OnClick, this));
581582
m_pServerListRevision[type] = 0;
582583

583584
// Server List Columns
@@ -617,7 +618,7 @@ void CServerBrowser::CreateTab(ServerBrowserType type, const char* szName)
617618
// Filters
618619
float fLineHeight = SB_BACK_BUTTON_SIZE_Y / 2;
619620
fX = SB_SMALL_SPACER;
620-
fY = m_WidgetSize.fY - SB_SMALL_SPACER / 2 - SB_BACK_BUTTON_SIZE_Y - TAB_SIZE_Y;
621+
fY = m_WidgetSize.fY - (SB_SMALL_SPACER * 0.5f) - SB_BACK_BUTTON_SIZE_Y - TAB_SIZE_Y;
621622

622623
// Include label
623624
m_pLabelInclude[type] = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pTab[type], _("Include:")));
@@ -917,6 +918,7 @@ void CServerBrowser::DeleteTab(ServerBrowserType type)
917918
m_pServerList[type]->SetEnterKeyHandler(GUI_CALLBACK());
918919
m_pServerList[type]->SetDoubleClickHandler(GUI_CALLBACK());
919920
m_pServerList[type]->SetKeyDownHandler(GUI_CALLBACK_KEY());
921+
m_pServerList[type]->SetSelectionHandler(GUI_CALLBACK());
920922
delete m_pServerList[type];
921923
m_pServerList[type] = nullptr;
922924
}
@@ -1718,7 +1720,7 @@ bool CServerBrowser::OnInfoClick(CGUIElement* pElement)
17181720

17191721
if (CServerInfo* pServerInfo = CServerInfo::GetSingletonPtr())
17201722
{
1721-
pServerInfo->Show(eWindowTypes::SERVER_INFO_RAW, strHost.c_str(), usPort, strPassword.c_str());
1723+
pServerInfo->Show(eWindowTypes::SERVER_INFO_RAW, strHost.c_str(), usPort, strPassword.c_str(), nullptr);
17221724
}
17231725
return true;
17241726
}

Client/core/ServerBrowser/CServerInfo.cpp

Lines changed: 136 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -333,84 +333,168 @@ void CServerInfo::Show(eWindowType WindowType, const char* szHost, unsigned shor
333333

334334
void 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

360431
void 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

416500
void CServerInfo::Refresh()

Client/gui/CGUIGridList_Impl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ CGUIGridList_Impl::CGUIGridList_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, bool
2525
m_hUniqueHandle = 0;
2626
m_iIndex = 0;
2727
m_bIgnoreTextSpacer = false;
28+
m_OnSortColumn = NULL;
29+
m_OnSelectionChanged = NULL;
2830

2931
// Get an unique identifier for CEGUI (gah, there's gotta be an another way)
3032
char szUnique[CGUI_CHAR_SIZE];
@@ -49,6 +51,7 @@ CGUIGridList_Impl::CGUIGridList_Impl(CGUI_Impl* pGUI, CGUIElement* pParent, bool
4951

5052
// Register our events
5153
m_pWindow->subscribeEvent(CEGUI::MultiColumnList::EventSortColumnChanged, CEGUI::Event::Subscriber(&CGUIGridList_Impl::Event_OnSortColumn, this));
54+
m_pWindow->subscribeEvent(CEGUI::MultiColumnList::EventSelectionChanged, CEGUI::Event::Subscriber(&CGUIGridList_Impl::Event_OnSelectionChanged, this));
5255
AddEvents();
5356

5457
// If a parent is specified, add it to it's children list, if not, add it as a child to the pManager
@@ -787,13 +790,25 @@ void CGUIGridList_Impl::SetSortColumnHandler(GUI_CALLBACK Callback)
787790
m_OnSortColumn = Callback;
788791
}
789792

793+
void CGUIGridList_Impl::SetSelectionHandler(GUI_CALLBACK Callback)
794+
{
795+
m_OnSelectionChanged = Callback;
796+
}
797+
790798
bool CGUIGridList_Impl::Event_OnSortColumn(const CEGUI::EventArgs& e)
791799
{
792800
if (m_OnSortColumn)
793801
m_OnSortColumn(reinterpret_cast<CGUIElement*>(this));
794802
return true;
795803
}
796804

805+
bool CGUIGridList_Impl::Event_OnSelectionChanged(const CEGUI::EventArgs& e)
806+
{
807+
if (m_OnSelectionChanged)
808+
m_OnSelectionChanged(reinterpret_cast<CGUIElement*>(this));
809+
return true;
810+
}
811+
797812
unsigned int CGUIGridList_Impl::GetUniqueHandle()
798813
{
799814
return ++m_hUniqueHandle;

Client/gui/CGUIGridList_Impl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CGUIGridList_Impl : public CGUIGridList, public CGUIElement_Impl
8080
void SetSelectedItem(int iRow, int hColumn, bool bReset);
8181

8282
void SetSortColumnHandler(GUI_CALLBACK Callback);
83+
void SetSelectionHandler(GUI_CALLBACK Callback);
8384

8485
void SetIgnoreTextSpacer(bool bIgnoreTextSpacer) { m_bIgnoreTextSpacer = bIgnoreTextSpacer; };
8586
eCGUIType GetType() { return CGUI_GRIDLIST; };
@@ -88,6 +89,7 @@ class CGUIGridList_Impl : public CGUIGridList, public CGUIElement_Impl
8889

8990
private:
9091
bool Event_OnSortColumn(const CEGUI::EventArgs& e);
92+
bool Event_OnSelectionChanged(const CEGUI::EventArgs& e);
9193

9294
int m_iIndex;
9395

@@ -98,6 +100,7 @@ class CGUIGridList_Impl : public CGUIGridList, public CGUIElement_Impl
98100
CFastHashMap<CEGUI::ListboxItem*, CGUIListItem_Impl*> m_Items;
99101

100102
GUI_CALLBACK m_OnSortColumn;
103+
GUI_CALLBACK m_OnSelectionChanged;
101104

102105
bool m_bIgnoreTextSpacer;
103106
};

Client/sdk/gui/CGUIGridList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class CGUIGridList : public CGUIElement
110110
virtual void SetSelectedItem(int iRow, int hColumn, bool bReset) = 0;
111111

112112
virtual void SetSortColumnHandler(GUI_CALLBACK Callback) = 0;
113+
virtual void SetSelectionHandler(GUI_CALLBACK Callback) = 0;
113114

114115
virtual void SetIgnoreTextSpacer(bool bIgnoreTextSpacer) = 0;
115116
};

0 commit comments

Comments
 (0)