diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index f3a306109..479e90f62 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -646,8 +646,9 @@ void CClient::SetState(EClientState s) if(s == IClient::STATE_ONLINE) { - Discord()->SetGameInfo(ServerAddress(), m_aCurrentMap); - Steam()->SetGameInfo(ServerAddress(), m_aCurrentMap); + const bool AnnounceAddr = m_ServerBrowser.IsRegistered(ServerAddress()); + Discord()->SetGameInfo(ServerAddress(), m_aCurrentMap, AnnounceAddr); + Steam()->SetGameInfo(ServerAddress(), m_aCurrentMap, AnnounceAddr); } else if(Old == IClient::STATE_ONLINE) { diff --git a/src/engine/client/discord.cpp b/src/engine/client/discord.cpp index 0d2d94cfd..bd83eb41e 100644 --- a/src/engine/client/discord.cpp +++ b/src/engine/client/discord.cpp @@ -64,7 +64,7 @@ public: { m_pActivityManager->clear_activity(m_pActivityManager, 0, 0); } - void SetGameInfo(NETADDR ServerAddr, const char *pMapName) override + void SetGameInfo(const NETADDR &ServerAddr, const char *pMapName, bool AnnounceAddr) override { DiscordActivity Activity; mem_zero(&Activity, sizeof(DiscordActivity)); @@ -102,7 +102,7 @@ class CDiscordStub : public IDiscord { void Update() override {} void ClearGameInfo() override {} - void SetGameInfo(NETADDR ServerAddr, const char *pMapName) override {} + void SetGameInfo(const NETADDR &ServerAddr, const char *pMapName, bool AnnounceAddr) override {} }; IDiscord *CreateDiscord() diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 04bb6b304..f5046c293 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -1495,6 +1495,33 @@ void CServerBrowser::TypeFilterClean(int Network) str_copy(pExcludeTypes, aNewList, sizeof(g_Config.m_BrFilterExcludeTypes)); } +bool CServerBrowser::IsRegistered(const NETADDR &Addr) +{ + const int NumServers = m_pHttp->NumServers(); + for(int i = 0; i < NumServers; i++) + { + const CServerInfo Info = m_pHttp->Server(i); + for(int j = 0; j < Info.m_NumAddresses; j++) + { + if(net_addr_comp(&Info.m_aAddresses[j], &Addr) == 0) + { + return true; + } + } + } + + const int NumLegacyServers = m_pHttp->NumLegacyServers(); + for(int i = 0; i < NumLegacyServers; i++) + { + if(net_addr_comp(&m_pHttp->LegacyServer(i), &Addr) == 0) + { + return true; + } + } + + return false; +} + int CServerInfo::EstimateLatency(int Loc1, int Loc2) { if(Loc1 == LOC_UNKNOWN || Loc2 == LOC_UNKNOWN) diff --git a/src/engine/client/serverbrowser.h b/src/engine/client/serverbrowser.h index 249bced15..ac617c5f6 100644 --- a/src/engine/client/serverbrowser.h +++ b/src/engine/client/serverbrowser.h @@ -135,6 +135,7 @@ public: void QueueRequest(CServerEntry *pEntry); CServerEntry *Find(const NETADDR &Addr); int GetCurrentType() override { return m_ServerlistType; } + bool IsRegistered(const NETADDR &Addr); private: CNetClient *m_pNetClient = nullptr; diff --git a/src/engine/client/steam.cpp b/src/engine/client/steam.cpp index 148bf8d49..00f7e0727 100644 --- a/src/engine/client/steam.cpp +++ b/src/engine/client/steam.cpp @@ -112,16 +112,19 @@ public: { SteamAPI_ISteamFriends_ClearRichPresence(m_pSteamFriends); } - void SetGameInfo(NETADDR ServerAddr, const char *pMapName) override + void SetGameInfo(const NETADDR &ServerAddr, const char *pMapName, bool AnnounceAddr) override { - char aServerAddr[NETADDR_MAXSTRSIZE]; - net_addr_str(&ServerAddr, aServerAddr, sizeof(aServerAddr), true); + if(AnnounceAddr) + { + char aServerAddr[NETADDR_MAXSTRSIZE]; + net_addr_str(&ServerAddr, aServerAddr, sizeof(aServerAddr), true); + SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "connect", aServerAddr); + SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "steam_player_group", aServerAddr); + } - SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "connect", aServerAddr); SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "map", pMapName); SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "status", pMapName); SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "steam_display", "#Status"); - SteamAPI_ISteamFriends_SetRichPresence(m_pSteamFriends, "steam_player_group", aServerAddr); } }; @@ -132,7 +135,7 @@ class CSteamStub : public ISteam void ClearConnectAddress() override {} void Update() override {} void ClearGameInfo() override {} - void SetGameInfo(NETADDR ServerAddr, const char *pMapName) override {} + void SetGameInfo(const NETADDR &ServerAddr, const char *pMapName, bool AnnounceAddr) override {} }; ISteam *CreateSteam() diff --git a/src/engine/discord.h b/src/engine/discord.h index 62560de95..69fbcfe85 100644 --- a/src/engine/discord.h +++ b/src/engine/discord.h @@ -10,7 +10,7 @@ public: virtual void Update() = 0; virtual void ClearGameInfo() = 0; - virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0; + virtual void SetGameInfo(const NETADDR &ServerAddr, const char *pMapName, bool AnnounceAddr) = 0; }; IDiscord *CreateDiscord(); diff --git a/src/engine/steam.h b/src/engine/steam.h index 501d80e04..00eae8750 100644 --- a/src/engine/steam.h +++ b/src/engine/steam.h @@ -18,7 +18,7 @@ public: virtual void Update() = 0; virtual void ClearGameInfo() = 0; - virtual void SetGameInfo(NETADDR ServerAddr, const char *pMapName) = 0; + virtual void SetGameInfo(const NETADDR &ServerAddr, const char *pMapName, bool AnnounceAddr) = 0; }; ISteam *CreateSteam(); diff --git a/src/test/netaddr.cpp b/src/test/netaddr.cpp index 3c51ad5f6..b8c021559 100644 --- a/src/test/netaddr.cpp +++ b/src/test/netaddr.cpp @@ -87,3 +87,14 @@ TEST(NetAddr, FromStrInvalid) EXPECT_TRUE(net_addr_from_str(&Addr, "127.0.0.1:1a")); EXPECT_TRUE(net_addr_from_str(&Addr, "[::]:c")); } + +TEST(NetAddr, StrInvalid) +{ + NETADDR Addr = {0}; + char aBuf1[NETADDR_MAXSTRSIZE]; + char aBuf2[NETADDR_MAXSTRSIZE]; + net_addr_str(&Addr, aBuf1, sizeof(aBuf1), true); + EXPECT_STREQ(aBuf1, "unknown type 0"); + net_addr_str(&Addr, aBuf2, sizeof(aBuf2), false); + EXPECT_STREQ(aBuf2, "unknown type 0"); +}