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

Method loadCache

src/game/ServerListCache.cpp:116–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115
116void ServerListCache::loadCache() {
117 std::string fileName = getCacheFilename();
118 if (fileName == "") { return; }
119 std::ifstream inFile(fileName.c_str(), std::ios::in | std::ios::binary);
120
121 if (inFile) {
122 char buffer[max_string + 1];
123 while (inFile) {
124 std::string serverIndex;
125 ServerItem info;
126
127 inFile.read(buffer, sizeof(buffer)); //read the index of the map
128 if ((size_t)inFile.gcount() < sizeof(buffer)) { break; } // failed to read entire string
129 serverIndex = buffer;
130
131 bool infoWorked = info.readFromFile(inFile);
132 // after a while it is doubtful that player counts are accurate
133 if (info.getAgeMinutes() > (time_t)30) { info.ping.zeroPlayerCounts(); }
134 if (!infoWorked) { break; }
135
136 serverCache.insert(SRV_STR_MAP::value_type(serverIndex, info));
137 }
138 inFile.close();
139 }
140}
141
142
143bool ServerListCache::clearCache() {

Callers

nothing calls this directly

Calls 7

c_strMethod · 0.80
getAgeMinutesMethod · 0.80
zeroPlayerCountsMethod · 0.80
readMethod · 0.45
readFromFileMethod · 0.45
insertMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected