Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions Client/core/CQueryReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool CQueryReceiver::ReadString(std::string& strRead, const char* szBuffer, int&
return false;
}

SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
SQueryInfo CQueryReceiver::GetServerResponse()
{
SQueryInfo info;

Expand Down Expand Up @@ -120,8 +120,7 @@ SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
// Game
if (!ReadString(strTemp, szBuffer, i, len))
return info;
if ((restrictions & RESTRICTION_GAME_NAME) == false)
info.gameName = strTemp;
info.gameName = strTemp;

// Port (Ignore result as we must already have the correct value)
if (!ReadString(strTemp, szBuffer, i, len))
Expand All @@ -130,42 +129,31 @@ SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
// Server name
if (!ReadString(strTemp, szBuffer, i, len))
return info;
if ((restrictions & RESTRICTION_SERVER_NAME) == false)
info.serverName = strTemp;
info.serverName = strTemp;

// Game type
if (!ReadString(strTemp, szBuffer, i, len))
return info;
if ((restrictions & RESTRICTION_GAME_MODE) == false)
info.gameType = strTemp;
info.gameType = strTemp;

// Map name
if (!ReadString(strMapTemp, szBuffer, i, len))
return info;
if ((restrictions & RESTRICTION_MAP_NAME) == false)
info.mapName = strMapTemp;
info.mapName = strMapTemp;

// Version
if (!ReadString(strTemp, szBuffer, i, len))
return info;
if ((restrictions & RESTRICTION_SERVER_VERSION) == false)
info.versionText = strTemp;
info.versionText = strTemp;

// Got space for password, serial verification, player count, players max?
if (i + 4 > len)
return info;

if ((restrictions & RESTRICTION_PASSWORDED_FLAG) == false)
info.isPassworded = (szBuffer[i++] == 1);

if ((restrictions & RESTRICTION_SERIALS_FLAG) == false)
info.serials = (szBuffer[i++] == 1);

if ((restrictions & RESTRICTION_PLAYER_COUNT) == false)
info.players = (unsigned char)szBuffer[i++];

if ((restrictions & RESTRICTION_MAX_PLAYER_COUNT) == false)
info.playerSlot = (unsigned char)szBuffer[i++];
info.isPassworded = (szBuffer[i++] == 1);
info.serials = (szBuffer[i++] == 1);
info.players = (unsigned char)szBuffer[i++];
info.playerSlot = (unsigned char)szBuffer[i++];

// Recover large player count if present
const SString strPlayerCount = strMapTemp.Right(strMapTemp.length() - strlen(strMapTemp) - 1);
Expand All @@ -174,10 +162,8 @@ SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
SString strJoinedPlayers, strMaxPlayers;
if (strPlayerCount.Split("/", &strJoinedPlayers, &strMaxPlayers))
{
if ((restrictions & RESTRICTION_PLAYER_COUNT) == false)
info.players = atoi(strJoinedPlayers);
if ((restrictions & RESTRICTION_MAX_PLAYER_COUNT) == false)
info.playerSlot = atoi(strMaxPlayers);
info.players = atoi(strJoinedPlayers);
info.playerSlot = atoi(strMaxPlayers);
}
}

Expand Down Expand Up @@ -218,8 +204,7 @@ SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
SString strResult = RemoveColorCodes(strPlayer.c_str());
if (strResult.length() == 0)
strResult = strPlayer;
if ((restrictions & RESTRICTION_PLAYER_LIST) == false)
info.playersPool.push_back(strResult);
info.playersPool.push_back(strResult);
}
}
catch (...)
Expand Down
2 changes: 1 addition & 1 deletion Client/core/CQueryReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CQueryReceiver
void RequestQuery(const SString& address, ushort port);
void InvalidateSocket();

SQueryInfo GetServerResponse(uint restrictions = 0);
SQueryInfo GetServerResponse();

uint GetElapsedTimeSinceLastQuery() { return static_cast<uint>(m_ElapsedTime.Get()); };

Expand Down
44 changes: 33 additions & 11 deletions Client/core/ServerBrowser/CServerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,27 +470,49 @@ void CServerListItem::Query()

bool CServerListItem::ParseQuery()
{
SQueryInfo info = queryReceiver.GetServerResponse(uiMasterServerSaysRestrictions);
SQueryInfo info = queryReceiver.GetServerResponse();
if (!info.containingInfo)
return false;

// Get IP as string
strHost = inet_ntoa(Address);

nPing = info.pingTime;
strGameName = info.gameName;
strName = info.serverName;
strGameMode = info.gameType;
strMap = info.mapName;
strVersion = info.versionText;
bPassworded = info.isPassworded;
bSerials = info.serials;
nPlayers = info.players;
nMaxPlayers = info.playerSlot;

// Only use info from server query if master list allows it
if ((uiMasterServerSaysRestrictions & RESTRICTION_GAME_NAME) == false)
strGameName = info.gameName;

if ((uiMasterServerSaysRestrictions & RESTRICTION_SERVER_NAME) == false)
strName = info.serverName;

if ((uiMasterServerSaysRestrictions & RESTRICTION_GAME_MODE) == false)
strGameMode = info.gameType;

if ((uiMasterServerSaysRestrictions & RESTRICTION_MAP_NAME) == false)
strMap = info.mapName;

if ((uiMasterServerSaysRestrictions & RESTRICTION_SERVER_VERSION) == false)
strVersion = info.versionText;

if ((uiMasterServerSaysRestrictions & RESTRICTION_PASSWORDED_FLAG) == false)
bPassworded = info.isPassworded;

if ((uiMasterServerSaysRestrictions & RESTRICTION_SERIALS_FLAG) == false)
bSerials = info.serials;

if ((uiMasterServerSaysRestrictions & RESTRICTION_PLAYER_COUNT) == false)
nPlayers = info.players;

if ((uiMasterServerSaysRestrictions & RESTRICTION_MAX_PLAYER_COUNT) == false)
nMaxPlayers = info.playerSlot;

m_iBuildType = info.buildType;
m_iBuildNumber = info.buildNum;
m_usHttpPort = info.httpPort;
vecPlayers = info.playersPool;

if ((uiMasterServerSaysRestrictions & RESTRICTION_PLAYER_LIST) == false)
vecPlayers = info.playersPool;

bScanned = true;

Expand Down