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

Method saveCache

src/game/ServerListCache.cpp:85–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void ServerListCache::saveCache() {
86 std::string fileName = getCacheFilename();
87 if (fileName == "") { return; }
88
89 std::ostream* outFile = FILEMGR.createDataOutStream(fileName, true, true);
90 int lenCpy = max_string;
91
92 if (outFile != NULL) {
93 char buffer[max_string + 1];
94 for (SRV_STR_MAP::iterator iter = serverCache.begin(); iter != serverCache.end(); iter++) {
95
96 // skip items that are more than 30 days old, but always save favorites
97 if (!iter->second.favorite && iter->second.getAgeMinutes() > 60 * 24 * 30) {
98 continue;
99 }
100
101 // write out the index of the map
102 memset(buffer, 0, sizeof(buffer));
103 lenCpy = int((iter->first).size() < max_string ? (iter->first).size() : max_string);
104 strncpy(buffer, (iter->first.c_str()), lenCpy);
105 outFile->write(buffer, sizeof(buffer));
106
107 ServerItem x = iter->second;
108 // write out the serverinfo -- which is mapped by index
109 iter->second.writeToFile(*outFile);
110 }
111 delete outFile;
112 }
113}
114
115
116void ServerListCache::loadCache() {

Callers

nothing calls this directly

Calls 8

createDataOutStreamMethod · 0.80
getAgeMinutesMethod · 0.80
c_strMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
writeMethod · 0.45
writeToFileMethod · 0.45

Tested by

no test coverage detected