mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Remove unused parts of the new serverinfo
This commit is contained in:
parent
bfef7c9ba3
commit
f5e91ba192
|
@ -55,11 +55,6 @@ bool CServerInfo2::Validate() const
|
|||
|
||||
bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson)
|
||||
{
|
||||
/*
|
||||
TODO: What to do if we have more players than we can store?
|
||||
TODO: What to do on incomplete infos?
|
||||
*/
|
||||
|
||||
mem_zero(pOut, sizeof(*pOut));
|
||||
bool Error;
|
||||
|
||||
|
@ -70,8 +65,6 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson)
|
|||
const json_value &GameType = ServerInfo["game_type"];
|
||||
const json_value &Name = ServerInfo["name"];
|
||||
const json_value &MapName = ServerInfo["map"]["name"];
|
||||
//const json_value &MapCrc = ServerInfo["map"]["crc"];
|
||||
//const json_value &MapSize = ServerInfo["map"]["size"];
|
||||
const json_value &Version = ServerInfo["version"];
|
||||
const json_value &Clients = ServerInfo["clients"];
|
||||
Error = false;
|
||||
|
@ -81,8 +74,6 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson)
|
|||
Error = Error || GameType.type != json_string;
|
||||
Error = Error || Name.type != json_string;
|
||||
Error = Error || MapName.type != json_string;
|
||||
//Error = Error || MapCrc.type != json_string;
|
||||
//Error = Error || MapSize.type != json_integer;
|
||||
Error = Error || Version.type != json_string;
|
||||
Error = Error || Clients.type != json_array;
|
||||
if(Error)
|
||||
|
@ -95,8 +86,6 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson)
|
|||
str_copy(pOut->m_aGameType, GameType, sizeof(pOut->m_aGameType));
|
||||
str_copy(pOut->m_aName, Name, sizeof(pOut->m_aName));
|
||||
str_copy(pOut->m_aMapName, MapName, sizeof(pOut->m_aMapName));
|
||||
//if(ParseCrc(&pOut->m_MapCrc, MapCrc)) { return true; }
|
||||
//pOut->m_MapSize = MapSize;
|
||||
str_copy(pOut->m_aVersion, Version, sizeof(pOut->m_aVersion));
|
||||
|
||||
pOut->m_NumClients = 0;
|
||||
|
@ -108,14 +97,12 @@ bool CServerInfo2::FromJsonRaw(CServerInfo2 *pOut, const json_value *pJson)
|
|||
const json_value &Clan = Client["clan"];
|
||||
const json_value &Country = Client["country"];
|
||||
const json_value &Score = Client["score"];
|
||||
//const json_value &Team = Client["team"];
|
||||
const json_value &IsPlayer = Client["is_player"];
|
||||
Error = false;
|
||||
Error = Error || Name.type != json_string;
|
||||
Error = Error || Clan.type != json_string;
|
||||
Error = Error || Country.type != json_integer;
|
||||
Error = Error || Score.type != json_integer;
|
||||
//Error = Error || Team.type != json_integer;
|
||||
Error = Error || IsPlayer.type != json_boolean;
|
||||
if(Error)
|
||||
{
|
||||
|
@ -152,8 +139,6 @@ bool CServerInfo2::operator==(const CServerInfo2 &Other) const
|
|||
Unequal = Unequal || str_comp(m_aGameType, Other.m_aGameType) != 0;
|
||||
Unequal = Unequal || str_comp(m_aName, Other.m_aName) != 0;
|
||||
Unequal = Unequal || str_comp(m_aMapName, Other.m_aMapName) != 0;
|
||||
//Unequal = Unequal || m_MapCrc != Other.m_MapCrc;
|
||||
//Unequal = Unequal || m_MapSize != Other.m_MapSize;
|
||||
Unequal = Unequal || str_comp(m_aVersion, Other.m_aVersion) != 0;
|
||||
if(Unequal)
|
||||
{
|
||||
|
@ -166,7 +151,6 @@ bool CServerInfo2::operator==(const CServerInfo2 &Other) const
|
|||
Unequal = Unequal || str_comp(m_aClients[i].m_aClan, Other.m_aClients[i].m_aClan) != 0;
|
||||
Unequal = Unequal || m_aClients[i].m_Country != Other.m_aClients[i].m_Country;
|
||||
Unequal = Unequal || m_aClients[i].m_Score != Other.m_aClients[i].m_Score;
|
||||
//Unequal = Unequal || m_aClients[i].m_Team != Other.m_aClients[i].m_Team;
|
||||
Unequal = Unequal || m_aClients[i].m_IsPlayer != Other.m_aClients[i].m_IsPlayer;
|
||||
if(Unequal)
|
||||
{
|
||||
|
@ -176,54 +160,6 @@ bool CServerInfo2::operator==(const CServerInfo2 &Other) const
|
|||
return true;
|
||||
}
|
||||
|
||||
void CServerInfo2::ToJson(char *pBuffer, int BufferSize) const
|
||||
{
|
||||
dbg_assert(BufferSize > 0, "empty buffer");
|
||||
/*
|
||||
char aGameType[32];
|
||||
char aName[128];
|
||||
char aMapName[64];
|
||||
char aVersion[64];
|
||||
str_format(pBuffer, BufferSize, "{\"max_clients\":%d,\"max_players\":%d,\"passworded\":%s,\"game_type\":\"%s\",\"name\":\"%s\",\"map\":{\"name\":\"%s\",\"crc\":\"%08x\",\"size\":%d},\"version\":\"%s\",\"clients\":[",
|
||||
m_MaxClients,
|
||||
m_MaxPlayers,
|
||||
JsonBool(m_Passworded),
|
||||
EscapeJson(aGameType, sizeof(aGameType), m_aGameType),
|
||||
EscapeJson(aName, sizeof(aName), m_aName),
|
||||
EscapeJson(aMapName, sizeof(aMapName), m_aMapName),
|
||||
m_MapCrc,
|
||||
m_MapSize,
|
||||
EscapeJson(aVersion, sizeof(aVersion), m_aVersion));
|
||||
|
||||
{
|
||||
int Length = str_length(pBuffer);
|
||||
pBuffer += Length;
|
||||
BufferSize -= Length;
|
||||
}
|
||||
|
||||
for(int i = 0; i < m_NumClients; i++)
|
||||
{
|
||||
char aName[MAX_NAME_LENGTH * 2];
|
||||
char aClan[MAX_NAME_LENGTH * 2];
|
||||
str_format(pBuffer, BufferSize, "%s{\"name\":\"%s\",\"clan\":\"%s\",\"country\":%d,\"score\":%d,\"team\":%d}",
|
||||
i != 0 ? "," : "",
|
||||
EscapeJson(aName, sizeof(aName), m_aClients[i].m_aName),
|
||||
EscapeJson(aClan, sizeof(aClan), m_aClients[i].m_aClan),
|
||||
m_aClients[i].m_Country,
|
||||
m_aClients[i].m_Score,
|
||||
m_aClients[i].m_Team);
|
||||
|
||||
{
|
||||
int Length = str_length(pBuffer);
|
||||
pBuffer += Length;
|
||||
BufferSize -= Length;
|
||||
}
|
||||
}
|
||||
|
||||
str_format(pBuffer, BufferSize, "]}");
|
||||
*/
|
||||
}
|
||||
|
||||
CServerInfo2::operator CServerInfo() const
|
||||
{
|
||||
CServerInfo Result = {0};
|
||||
|
@ -235,8 +171,6 @@ CServerInfo2::operator CServerInfo() const
|
|||
str_copy(Result.m_aGameType, m_aGameType, sizeof(Result.m_aGameType));
|
||||
str_copy(Result.m_aName, m_aName, sizeof(Result.m_aName));
|
||||
str_copy(Result.m_aMap, m_aMapName, sizeof(Result.m_aMap));
|
||||
//Result.m_MapCrc = m_MapCrc;
|
||||
//Result.m_MapSize = m_MapSize;
|
||||
str_copy(Result.m_aVersion, m_aVersion, sizeof(Result.m_aVersion));
|
||||
|
||||
for(int i = 0; i < std::min(m_NumClients, (int)MAX_CLIENTS); i++)
|
||||
|
@ -245,7 +179,6 @@ CServerInfo2::operator CServerInfo() const
|
|||
str_copy(Result.m_aClients[i].m_aClan, m_aClients[i].m_aClan, sizeof(Result.m_aClients[i].m_aClan));
|
||||
Result.m_aClients[i].m_Country = m_aClients[i].m_Country;
|
||||
Result.m_aClients[i].m_Score = m_aClients[i].m_Score;
|
||||
//Result.m_aClients[i].m_Team = m_aClients[i].m_Team;
|
||||
Result.m_aClients[i].m_Player = m_aClients[i].m_IsPlayer;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ public:
|
|||
char m_aClan[MAX_CLAN_LENGTH];
|
||||
int m_Country;
|
||||
int m_Score;
|
||||
//int m_Team;
|
||||
bool m_IsPlayer;
|
||||
};
|
||||
|
||||
|
@ -29,8 +28,6 @@ public:
|
|||
char m_aGameType[16];
|
||||
char m_aName[64];
|
||||
char m_aMapName[32];
|
||||
//unsigned int m_MapCrc;
|
||||
//int m_MapSize;
|
||||
char m_aVersion[32];
|
||||
|
||||
bool operator==(const CServerInfo2 &Other) const;
|
||||
|
|
|
@ -27,100 +27,6 @@ TEST(ServerInfo, ParseLocation)
|
|||
EXPECT_EQ(Result, CServerInfo::LOC_AUSTRALIA);
|
||||
}
|
||||
|
||||
/*
|
||||
static CServerInfo2 Parse(const char *pJson)
|
||||
{
|
||||
CServerInfo2 Out = {0};
|
||||
json_value *pParsed = json_parse(pJson, str_length(pJson));
|
||||
EXPECT_TRUE(pParsed);
|
||||
if(pParsed)
|
||||
{
|
||||
EXPECT_FALSE(CServerInfo2::FromJson(&Out, pParsed));
|
||||
}
|
||||
return Out;
|
||||
}
|
||||
|
||||
TEST(ServerInfo, Empty)
|
||||
{
|
||||
static const char EMPTY[] = "{\"max_clients\":0,\"max_players\":0,\"passworded\":false,\"game_type\":\"\",\"name\":\"\",\"map\":{\"name\":\"\",\"crc\":\"00000000\",\"size\":0},\"version\":\"\",\"clients\":[]}";
|
||||
|
||||
CServerInfo2 Empty = {0};
|
||||
EXPECT_EQ(Parse(EMPTY), Empty);
|
||||
char aBuf[1024];
|
||||
Empty.ToJson(aBuf, sizeof(aBuf));
|
||||
EXPECT_STREQ(aBuf, EMPTY);
|
||||
}
|
||||
|
||||
CServerInfo2 SomethingImpl()
|
||||
{
|
||||
CServerInfo2 Something = {0};
|
||||
|
||||
str_copy(Something.m_aClients[0].m_aName, "Learath2", sizeof(Something.m_aClients[0].m_aName));
|
||||
Something.m_aClients[0].m_Country = -1;
|
||||
Something.m_aClients[0].m_Score = -1;
|
||||
Something.m_aClients[0].m_Team = 1;
|
||||
|
||||
str_copy(Something.m_aClients[1].m_aName, "deen", sizeof(Something.m_aClients[1].m_aName));
|
||||
str_copy(Something.m_aClients[1].m_aClan, "DDNet", sizeof(Something.m_aClients[1].m_aClan));
|
||||
Something.m_aClients[1].m_Country = 276;
|
||||
Something.m_aClients[1].m_Score = 0;
|
||||
Something.m_aClients[1].m_Team = 0;
|
||||
|
||||
Something.m_MaxClients = 16;
|
||||
Something.m_NumClients = 2;
|
||||
Something.m_MaxPlayers = 8;
|
||||
Something.m_NumPlayers = 1;
|
||||
Something.m_Passworded = true;
|
||||
str_copy(Something.m_aGameType, "DM", sizeof(Something.m_aGameType));
|
||||
str_copy(Something.m_aName, "unnamed server", sizeof(Something.m_aName));
|
||||
str_copy(Something.m_aMapName, "dm1", sizeof(Something.m_aMapName));
|
||||
Something.m_MapCrc = 0xf2159e6e;
|
||||
Something.m_MapSize = 5805;
|
||||
str_copy(Something.m_aVersion, "0.6.4", sizeof(Something.m_aVersion));
|
||||
|
||||
return Something;
|
||||
}
|
||||
|
||||
static const CServerInfo2 s_Something = SomethingImpl();
|
||||
|
||||
TEST(ServerInfo, Something)
|
||||
{
|
||||
static const char SOMETHING[] = "{\"max_clients\":16,\"max_players\":8,\"passworded\":true,\"game_type\":\"DM\",\"name\":\"unnamed server\",\"map\":{\"name\":\"dm1\",\"crc\":\"f2159e6e\",\"size\":5805},\"version\":\"0.6.4\",\"clients\":[{\"name\":\"Learath2\",\"clan\":\"\",\"country\":-1,\"score\":-1,\"team\":1},{\"name\":\"deen\",\"clan\":\"DDNet\",\"country\":276,\"score\":0,\"team\":0}]}";
|
||||
|
||||
EXPECT_EQ(Parse(SOMETHING), s_Something);
|
||||
|
||||
char aBuf[1024];
|
||||
s_Something.ToJson(aBuf, sizeof(aBuf));
|
||||
EXPECT_EQ(Parse(aBuf), s_Something);
|
||||
}
|
||||
|
||||
TEST(ServerInfo, ToServerBrowserServerInfo)
|
||||
{
|
||||
CServerInfo Sbsi = s_Something;
|
||||
|
||||
EXPECT_EQ(Sbsi.m_MaxClients, s_Something.m_MaxClients);
|
||||
EXPECT_EQ(Sbsi.m_NumClients, s_Something.m_NumClients);
|
||||
EXPECT_EQ(Sbsi.m_MaxPlayers, s_Something.m_MaxPlayers);
|
||||
EXPECT_EQ(Sbsi.m_NumPlayers, s_Something.m_NumPlayers);
|
||||
EXPECT_EQ((Sbsi.m_Flags&SERVER_FLAG_PASSWORD) != 0, s_Something.m_Passworded);
|
||||
EXPECT_STREQ(Sbsi.m_aGameType, s_Something.m_aGameType);
|
||||
EXPECT_STREQ(Sbsi.m_aName, s_Something.m_aName);
|
||||
EXPECT_STREQ(Sbsi.m_aMap, s_Something.m_aMapName);
|
||||
EXPECT_EQ(Sbsi.m_MapCrc, s_Something.m_MapCrc);
|
||||
EXPECT_EQ(Sbsi.m_MapSize, s_Something.m_MapSize);
|
||||
EXPECT_STREQ(Sbsi.m_aVersion, s_Something.m_aVersion);
|
||||
|
||||
for(int i = 0; i < Sbsi.m_NumClients; i++)
|
||||
{
|
||||
EXPECT_STREQ(Sbsi.m_aClients[i].m_aName, s_Something.m_aClients[i].m_aName);
|
||||
EXPECT_STREQ(Sbsi.m_aClients[i].m_aClan, s_Something.m_aClients[i].m_aClan);
|
||||
EXPECT_EQ(Sbsi.m_aClients[i].m_Country, s_Something.m_aClients[i].m_Country);
|
||||
EXPECT_EQ(Sbsi.m_aClients[i].m_Score, s_Something.m_aClients[i].m_Score);
|
||||
EXPECT_EQ(Sbsi.m_aClients[i].m_Player, s_Something.m_aClients[i].m_Team != 0);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
static unsigned int ParseCrcOrDeadbeef(const char *pString)
|
||||
{
|
||||
unsigned int Result;
|
||||
|
|
Loading…
Reference in a new issue