mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #5923
5923: Only announce servers using Steam/Discord integration which are registered r=heinrich5991 a=def- <!-- What is the motivation for the changes of this pull request? --> <!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. --> ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
commit
9851a4b707
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue