Skip to content

Commit af32894

Browse files
authored
Fix #1432: server names appearing blank (#1447)
1 parent 0ee554b commit af32894

File tree

3 files changed

+47
-40
lines changed

3 files changed

+47
-40
lines changed

Client/core/CQueryReceiver.cpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ bool CQueryReceiver::ReadString(std::string& strRead, const char* szBuffer, int&
8383
return false;
8484
}
8585

86-
SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
86+
SQueryInfo CQueryReceiver::GetServerResponse()
8787
{
8888
SQueryInfo info;
8989

@@ -120,8 +120,7 @@ SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
120120
// Game
121121
if (!ReadString(strTemp, szBuffer, i, len))
122122
return info;
123-
if ((restrictions & RESTRICTION_GAME_NAME) == false)
124-
info.gameName = strTemp;
123+
info.gameName = strTemp;
125124

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

136134
// Game type
137135
if (!ReadString(strTemp, szBuffer, i, len))
138136
return info;
139-
if ((restrictions & RESTRICTION_GAME_MODE) == false)
140-
info.gameType = strTemp;
137+
info.gameType = strTemp;
141138

142139
// Map name
143140
if (!ReadString(strMapTemp, szBuffer, i, len))
144141
return info;
145-
if ((restrictions & RESTRICTION_MAP_NAME) == false)
146-
info.mapName = strMapTemp;
142+
info.mapName = strMapTemp;
147143

148144
// Version
149145
if (!ReadString(strTemp, szBuffer, i, len))
150146
return info;
151-
if ((restrictions & RESTRICTION_SERVER_VERSION) == false)
152-
info.versionText = strTemp;
147+
info.versionText = strTemp;
153148

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

158-
if ((restrictions & RESTRICTION_PASSWORDED_FLAG) == false)
159-
info.isPassworded = (szBuffer[i++] == 1);
160-
161-
if ((restrictions & RESTRICTION_SERIALS_FLAG) == false)
162-
info.serials = (szBuffer[i++] == 1);
163-
164-
if ((restrictions & RESTRICTION_PLAYER_COUNT) == false)
165-
info.players = (unsigned char)szBuffer[i++];
166-
167-
if ((restrictions & RESTRICTION_MAX_PLAYER_COUNT) == false)
168-
info.playerSlot = (unsigned char)szBuffer[i++];
153+
info.isPassworded = (szBuffer[i++] == 1);
154+
info.serials = (szBuffer[i++] == 1);
155+
info.players = (unsigned char)szBuffer[i++];
156+
info.playerSlot = (unsigned char)szBuffer[i++];
169157

170158
// Recover large player count if present
171159
const SString strPlayerCount = strMapTemp.Right(strMapTemp.length() - strlen(strMapTemp) - 1);
@@ -174,10 +162,8 @@ SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
174162
SString strJoinedPlayers, strMaxPlayers;
175163
if (strPlayerCount.Split("/", &strJoinedPlayers, &strMaxPlayers))
176164
{
177-
if ((restrictions & RESTRICTION_PLAYER_COUNT) == false)
178-
info.players = atoi(strJoinedPlayers);
179-
if ((restrictions & RESTRICTION_MAX_PLAYER_COUNT) == false)
180-
info.playerSlot = atoi(strMaxPlayers);
165+
info.players = atoi(strJoinedPlayers);
166+
info.playerSlot = atoi(strMaxPlayers);
181167
}
182168
}
183169

@@ -218,8 +204,7 @@ SQueryInfo CQueryReceiver::GetServerResponse(uint restrictions)
218204
SString strResult = RemoveColorCodes(strPlayer.c_str());
219205
if (strResult.length() == 0)
220206
strResult = strPlayer;
221-
if ((restrictions & RESTRICTION_PLAYER_LIST) == false)
222-
info.playersPool.push_back(strResult);
207+
info.playersPool.push_back(strResult);
223208
}
224209
}
225210
catch (...)

Client/core/CQueryReceiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class CQueryReceiver
5757
void RequestQuery(const SString& address, ushort port);
5858
void InvalidateSocket();
5959

60-
SQueryInfo GetServerResponse(uint restrictions = 0);
60+
SQueryInfo GetServerResponse();
6161

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

Client/core/ServerBrowser/CServerList.cpp

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,27 +470,49 @@ void CServerListItem::Query()
470470

471471
bool CServerListItem::ParseQuery()
472472
{
473-
SQueryInfo info = queryReceiver.GetServerResponse(uiMasterServerSaysRestrictions);
473+
SQueryInfo info = queryReceiver.GetServerResponse();
474474
if (!info.containingInfo)
475475
return false;
476476

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

480480
nPing = info.pingTime;
481-
strGameName = info.gameName;
482-
strName = info.serverName;
483-
strGameMode = info.gameType;
484-
strMap = info.mapName;
485-
strVersion = info.versionText;
486-
bPassworded = info.isPassworded;
487-
bSerials = info.serials;
488-
nPlayers = info.players;
489-
nMaxPlayers = info.playerSlot;
481+
482+
// Only use info from server query if master list allows it
483+
if ((uiMasterServerSaysRestrictions & RESTRICTION_GAME_NAME) == false)
484+
strGameName = info.gameName;
485+
486+
if ((uiMasterServerSaysRestrictions & RESTRICTION_SERVER_NAME) == false)
487+
strName = info.serverName;
488+
489+
if ((uiMasterServerSaysRestrictions & RESTRICTION_GAME_MODE) == false)
490+
strGameMode = info.gameType;
491+
492+
if ((uiMasterServerSaysRestrictions & RESTRICTION_MAP_NAME) == false)
493+
strMap = info.mapName;
494+
495+
if ((uiMasterServerSaysRestrictions & RESTRICTION_SERVER_VERSION) == false)
496+
strVersion = info.versionText;
497+
498+
if ((uiMasterServerSaysRestrictions & RESTRICTION_PASSWORDED_FLAG) == false)
499+
bPassworded = info.isPassworded;
500+
501+
if ((uiMasterServerSaysRestrictions & RESTRICTION_SERIALS_FLAG) == false)
502+
bSerials = info.serials;
503+
504+
if ((uiMasterServerSaysRestrictions & RESTRICTION_PLAYER_COUNT) == false)
505+
nPlayers = info.players;
506+
507+
if ((uiMasterServerSaysRestrictions & RESTRICTION_MAX_PLAYER_COUNT) == false)
508+
nMaxPlayers = info.playerSlot;
509+
490510
m_iBuildType = info.buildType;
491511
m_iBuildNumber = info.buildNum;
492512
m_usHttpPort = info.httpPort;
493-
vecPlayers = info.playersPool;
513+
514+
if ((uiMasterServerSaysRestrictions & RESTRICTION_PLAYER_LIST) == false)
515+
vecPlayers = info.playersPool;
494516

495517
bScanned = true;
496518

0 commit comments

Comments
 (0)