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

Method loadCached

src/clientbase/WorldDownLoader.cpp:265–353  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263
264
265void WorldDownLoader::loadCached() {
266 // can't get a cache from nothing
267 if (worldCachePath.size() == 0) {
268 joiningGame = false;
269 return;
270 }
271
272 // lookup the cached world
273 std::istream* cachedWorld = FILEMGR.createDataInStream(worldCachePath, true);
274 if (!cachedWorld) {
275 showError("World cache files disappeared. Join canceled", true);
276 remove(worldCachePath.c_str());
277 joiningGame = false;
278 return;
279 }
280
281 // status update
282 showError("Loading world into memory...", true);
283
284 // get the world size
285 cachedWorld->seekg(0, std::ios::end);
286 std::streampos size = cachedWorld->tellg();
287 unsigned long charSize = std::streamoff(size);
288
289 // load the cached world
290 cachedWorld->seekg(0);
291 char* localWorldDatabase = new char[charSize];
292 if (!localWorldDatabase) {
293 showError("Error loading cached world. Join canceled", true);
294 remove(worldCachePath.c_str());
295 joiningGame = false;
296 return;
297 }
298 cachedWorld->read(localWorldDatabase, charSize);
299 delete cachedWorld;
300 cachedWorld = NULL;
301
302 // verify
303 showError("Verifying world integrity...", true);
304 MD5 md5;
305 md5.update((unsigned char*)localWorldDatabase, charSize);
306 md5.finalize();
307 std::string digest = md5.hexdigest();
308 if (digest != md5Digest) {
309 if (worldBuilder) {
310 delete worldBuilder;
311 worldBuilder = NULL;
312 }
313 delete[] localWorldDatabase;
314 localWorldDatabase = NULL;
315 showError("Error on md5. Removing offending file.");
316 remove(worldCachePath.c_str());
317 joiningGame = false;
318 return;
319 }
320
321 // make world
322 showError("Preparing world...", true);

Callers

nothing calls this directly

Calls 13

createDataInStreamMethod · 0.80
c_strMethod · 0.80
hexdigestMethod · 0.80
setMapHashMethod · 0.80
isTrueMethod · 0.80
startDownloadsMethod · 0.80
showErrorFunction · 0.50
sizeMethod · 0.45
readMethod · 0.45
updateMethod · 0.45
finalizeMethod · 0.45
unpackMethod · 0.45

Tested by

no test coverage detected