| 263 | |
| 264 | |
| 265 | void 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); |
nothing calls this directly
no test coverage detected