From 40f641b0a6e011bb101b8cb5824edb5bdb5f8bd3 Mon Sep 17 00:00:00 2001 From: furo Date: Mon, 11 Mar 2024 02:09:16 +0100 Subject: [PATCH] Add a `No login required` filter --- src/engine/client/serverbrowser.cpp | 3 +++ src/engine/server/server.cpp | 1 + src/engine/serverbrowser.h | 1 + src/engine/shared/config_variables.h | 1 + src/engine/shared/serverinfo.cpp | 9 +++++++++ src/engine/shared/serverinfo.h | 1 + src/game/client/components/menus_browser.cpp | 5 +++++ 7 files changed, 21 insertions(+) diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 25010a28f..2d4fc3d84 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -445,6 +445,8 @@ void CServerBrowser::Filter() Filtered = true; else if(g_Config.m_BrFilterUnfinishedMap && Info.m_HasRank == CServerInfo::RANK_RANKED) Filtered = true; + else if(g_Config.m_BrFilterLogin && Info.m_RequiresLogin) + Filtered = true; else { if(!Communities().empty()) @@ -597,6 +599,7 @@ int CServerBrowser::SortHash() const i |= g_Config.m_BrFilterUnfinishedMap << 13; i |= g_Config.m_BrFilterCountry << 14; i |= g_Config.m_BrFilterConnectingPlayers << 15; + i |= g_Config.m_BrFilterLogin << 16; return i; } diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 2e438ab69..f258dea50 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -2315,6 +2315,7 @@ void CServer::UpdateRegisterServerInfo() "}," "\"version\":\"%s\"," "\"client_score_kind\":\"time\"," + "\"requires_login\":false," "\"clients\":[", MaxClients, MaxPlayers, diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index 919ee10fb..1cb4a0899 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -117,6 +117,7 @@ public: char m_aAddress[MAX_SERVER_ADDRESSES * NETADDR_MAXSTRSIZE]; CClient m_aClients[SERVERINFO_MAX_CLIENTS]; int m_NumFilteredPlayers; + bool m_RequiresLogin; static int EstimateLatency(int Loc1, int Loc2); static bool ParseLocation(int *pResult, const char *pString); diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index 3eb78ced4..adaf48860 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -285,6 +285,7 @@ MACRO_CONFIG_INT(BrFilterGametypeStrict, br_filter_gametype_strict, 0, 0, 1, CFG MACRO_CONFIG_INT(BrFilterConnectingPlayers, br_filter_connecting_players, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Filter connecting players") MACRO_CONFIG_STR(BrFilterServerAddress, br_filter_serveraddress, 128, "", CFGFLAG_SAVE | CFGFLAG_CLIENT, "Server address to filter") MACRO_CONFIG_INT(BrFilterUnfinishedMap, br_filter_unfinished_map, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Show only servers with unfinished maps") +MACRO_CONFIG_INT(BrFilterLogin, br_filter_login, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Filter out servers that require login") MACRO_CONFIG_INT(BrIndicateFinished, br_indicate_finished, 1, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Show whether you have finished a DDNet map (transmits your player name to info.ddnet.org/info)") MACRO_CONFIG_STR(BrLocation, br_location, 16, "auto", CFGFLAG_SAVE | CFGFLAG_CLIENT, "Override location for ping estimation, available: auto, af, as, as:cn, eu, na, oc, sa (Automatic, Africa, Asia, China, Europe, North America, Oceania/Australia, South America") diff --git a/src/engine/shared/serverinfo.cpp b/src/engine/shared/serverinfo.cpp index ecccfa599..3e6ef8e57 100644 --- a/src/engine/shared/serverinfo.cpp +++ b/src/engine/shared/serverinfo.cpp @@ -71,6 +71,8 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson) const json_value &MapName = ServerInfo["map"]["name"]; const json_value &Version = ServerInfo["version"]; const json_value &Clients = ServerInfo["clients"]; + const json_value &RequiresLogin = ServerInfo["requires_login"]; + Error = false; Error = Error || MaxClients.type != json_integer; Error = Error || MaxPlayers.type != json_integer; @@ -96,6 +98,11 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson) { pOut->m_ClientScoreKind = CServerInfo::CLIENT_SCORE_KIND_TIME; } + pOut->m_RequiresLogin = false; + if(RequiresLogin.type == json_boolean) + { + pOut->m_RequiresLogin = RequiresLogin; + } pOut->m_Passworded = Passworded; str_copy(pOut->m_aGameType, GameType); str_copy(pOut->m_aName, Name); @@ -196,6 +203,7 @@ bool CServerInfo2::operator==(const CServerInfo2 &Other) const Unequal = Unequal || str_comp(m_aName, Other.m_aName) != 0; Unequal = Unequal || str_comp(m_aMapName, Other.m_aMapName) != 0; Unequal = Unequal || str_comp(m_aVersion, Other.m_aVersion) != 0; + Unequal = Unequal || m_RequiresLogin != Other.m_RequiresLogin; if(Unequal) { return false; @@ -225,6 +233,7 @@ CServerInfo2::operator CServerInfo() const Result.m_MaxPlayers = m_MaxPlayers; Result.m_NumPlayers = m_NumPlayers; Result.m_ClientScoreKind = m_ClientScoreKind; + Result.m_RequiresLogin = m_RequiresLogin; Result.m_Flags = m_Passworded ? SERVER_FLAG_PASSWORD : 0; str_copy(Result.m_aGameType, m_aGameType); str_copy(Result.m_aName, m_aName); diff --git a/src/engine/shared/serverinfo.h b/src/engine/shared/serverinfo.h index edb06a467..4e4c28902 100644 --- a/src/engine/shared/serverinfo.h +++ b/src/engine/shared/serverinfo.h @@ -38,6 +38,7 @@ public: char m_aName[64]; char m_aMapName[MAX_MAP_LENGTH]; char m_aVersion[32]; + bool m_RequiresLogin; bool operator==(const CServerInfo2 &Other) const; bool operator!=(const CServerInfo2 &Other) const { return !(*this == Other); } diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index bee9e311f..e2014d389 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -660,6 +660,10 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) if(DoButton_CheckBox(&g_Config.m_BrFilterPw, Localize("No password"), g_Config.m_BrFilterPw, &Button)) g_Config.m_BrFilterPw ^= 1; + View.HSplitTop(RowHeight, &Button, &View); + if(DoButton_CheckBox(&g_Config.m_BrFilterLogin, Localize("No login required"), g_Config.m_BrFilterLogin, &Button)) + g_Config.m_BrFilterLogin ^= 1; + View.HSplitTop(RowHeight, &Button, &View); if(DoButton_CheckBox(&g_Config.m_BrFilterGametypeStrict, Localize("Strict gametype filter"), g_Config.m_BrFilterGametypeStrict, &Button)) g_Config.m_BrFilterGametypeStrict ^= 1; @@ -798,6 +802,7 @@ void CMenus::ResetServerbrowserFilters() g_Config.m_BrFilterGametypeStrict = 0; g_Config.m_BrFilterConnectingPlayers = 1; g_Config.m_BrFilterServerAddress[0] = '\0'; + g_Config.m_BrFilterLogin = true; if(g_Config.m_UiPage != PAGE_LAN) {