| 1149 | } |
| 1150 | |
| 1151 | void CServerBrowser::UpdateFromHttp() |
| 1152 | { |
| 1153 | int OwnLocation; |
| 1154 | if(str_comp(g_Config.m_BrLocation, "auto") == 0) |
| 1155 | { |
| 1156 | OwnLocation = m_OwnLocation; |
| 1157 | } |
| 1158 | else |
| 1159 | { |
| 1160 | if(CServerInfo::ParseLocation(&OwnLocation, g_Config.m_BrLocation)) |
| 1161 | { |
| 1162 | char aBuf[64]; |
| 1163 | str_format(aBuf, sizeof(aBuf), "cannot parse br_location: '%s'", g_Config.m_BrLocation); |
| 1164 | m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "serverbrowser", aBuf); |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | int NumServers = m_pHttp->NumServers(); |
| 1169 | m_vpServerlist.reserve(NumServers); |
| 1170 | std::function<bool(const NETADDR *, int)> Want = [](const NETADDR *pAddrs, int NumAddrs) { return true; }; |
| 1171 | if(m_ServerlistType == IServerBrowser::TYPE_FAVORITES) |
| 1172 | { |
| 1173 | Want = [this](const NETADDR *pAddrs, int NumAddrs) -> bool { |
| 1174 | return m_pFavorites->IsFavorite(pAddrs, NumAddrs) != TRISTATE::NONE; |
| 1175 | }; |
| 1176 | } |
| 1177 | else if(m_ServerlistType >= IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 && m_ServerlistType <= IServerBrowser::TYPE_FAVORITE_COMMUNITY_5) |
| 1178 | { |
| 1179 | const size_t CommunityIndex = m_ServerlistType - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1; |
| 1180 | std::vector<const CCommunity *> vpFavoriteCommunities = FavoriteCommunities(); |
| 1181 | dbg_assert(CommunityIndex < vpFavoriteCommunities.size(), "Invalid community index"); |
| 1182 | const CCommunity *pWantedCommunity = vpFavoriteCommunities[CommunityIndex]; |
| 1183 | const bool IsNoneCommunity = str_comp(pWantedCommunity->Id(), COMMUNITY_NONE) == 0; |
| 1184 | Want = [this, pWantedCommunity, IsNoneCommunity](const NETADDR *pAddrs, int NumAddrs) -> bool { |
| 1185 | for(int AddressIndex = 0; AddressIndex < NumAddrs; AddressIndex++) |
| 1186 | { |
| 1187 | const auto CommunityServer = m_CommunityServersByAddr.find(CommunityAddressKey(pAddrs[AddressIndex])); |
| 1188 | if(CommunityServer != m_CommunityServersByAddr.end()) |
| 1189 | { |
| 1190 | if(IsNoneCommunity) |
| 1191 | { |
| 1192 | // Servers with community "none" are not present in m_CommunityServersByAddr, so we ignore |
| 1193 | // any server that is found in this map to determine only the servers without community. |
| 1194 | return false; |
| 1195 | } |
| 1196 | else if(str_comp(CommunityServer->second.CommunityId(), pWantedCommunity->Id()) == 0) |
| 1197 | { |
| 1198 | return true; |
| 1199 | } |
| 1200 | } |
| 1201 | } |
| 1202 | return IsNoneCommunity; |
| 1203 | }; |
| 1204 | } |
| 1205 | |
| 1206 | for(int i = 0; i < NumServers; i++) |
| 1207 | { |
| 1208 | CServerInfo Info = m_pHttp->Server(i); |
nothing calls this directly
no test coverage detected