MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / addToList

Method addToList

src/game/ServerList.cpp:215–325  ·  view source on GitHub ↗

FIXME: the list gets jacked. maybe the stl::erase below are a bunch of other things, but needs to be tested/rewritten more.

Source from the content-addressed store, hash-verified

213// FIXME: the list gets jacked. maybe the stl::erase below are a
214// bunch of other things, but needs to be tested/rewritten more.
215void ServerList::addToList(ServerItem info, bool doCache) {
216 // update if we already have it
217 int i;
218
219 // search and delete entry for this item if it exists
220 std::map<std::string, ServerItem>::iterator serverIterator;
221
222 for (serverIterator = servers.begin(); serverIterator != servers.end(); serverIterator++) {
223 const ServerItem& server = (*serverIterator).second;
224 if ((server.ping.serverId.serverHost.s_addr == info.ping.serverId.serverHost.s_addr) &&
225 (server.ping.serverId.port == info.ping.serverId.port)) {
226 // retain age so it can stay sorted same agewise
227 info.setAge(server.getAgeMinutes(), server.getAgeSeconds());
228 servers.erase(serverIterator); // erase this item
229 break;
230 }
231 }
232
233 // sort before iterating through
234 sort();
235
236 // find point to insert new player at
237 int insertPoint = -1; // point to insert server into
238
239 i = 0;
240 // insert new item before the first serveritem with is deemed to be less
241 // in value than the item to be inserted -- cached items are less than
242 // non-cached, items that have more players are more, etc..
243 for (serverIterator = servers.begin(); serverIterator != servers.end(); serverIterator++) {
244 const ServerItem& server = (*serverIterator).second;
245 if (info < server) {
246 insertPoint = i;
247 break;
248 }
249 i++;
250 }
251
252 // mark server in current list if it is a favorite server
253 std::string serverAddress = info.getAddrName();
254 if (serverCache->isFavorite(serverAddress)) {
255 info.favorite = true;
256 }
257
258 if (serverCache->isRecent(serverAddress)) {
259 info.recent = true;
260 }
261
262 // Get the server's server key
263 const ServerItem& constInfo = info;
264 std::string serverKey = constInfo.name;
265 const unsigned int port = (int)ntohs((unsigned short)constInfo.port);
266 if (port != ServerPort) {
267 char portBuf[20];
268 sprintf(portBuf, "%d", port);
269 serverKey += ":";
270 serverKey += portBuf;
271 }
272

Callers

nothing calls this directly

Calls 14

setAgeMethod · 0.80
getAgeMinutesMethod · 0.80
getAgeSecondsMethod · 0.80
getAddrNameMethod · 0.80
isFavoriteMethod · 0.80
isRecentMethod · 0.80
resetAgeMethod · 0.80
sortFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected