mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-29 21:56:54 +02:00
Pass loaded game over network too
This commit is contained in:
parent
b888e640f3
commit
8a8716ce8a
@ -541,7 +541,7 @@ void CServerHandler::startGameplay(CGameState * gameState)
|
|||||||
client->newGame(gameState);
|
client->newGame(gameState);
|
||||||
break;
|
break;
|
||||||
case StartInfo::LOAD_GAME:
|
case StartInfo::LOAD_GAME:
|
||||||
client->loadGame();
|
client->loadGame(gameState);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("Invalid mode");
|
throw std::runtime_error("Invalid mode");
|
||||||
|
@ -197,54 +197,63 @@ void CClient::newGame(CGameState * gameState)
|
|||||||
initPlayerInterfaces();
|
initPlayerInterfaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClient::loadGame()
|
void CClient::loadGame(CGameState * gameState)
|
||||||
{
|
{
|
||||||
logNetwork->info("Loading procedure started!");
|
logNetwork->info("Loading procedure started!");
|
||||||
|
|
||||||
std::unique_ptr<CLoadFile> loader;
|
if(gameState)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
boost::filesystem::path clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(CSH->si->mapname, EResType::CLIENT_SAVEGAME));
|
logNetwork->info("Game state was transferred over network, loading.");
|
||||||
boost::filesystem::path controlServerSaveName;
|
gs = gameState;
|
||||||
|
|
||||||
if(CResourceHandler::get("local")->existsResource(ResourceID(CSH->si->mapname, EResType::SERVER_SAVEGAME)))
|
|
||||||
{
|
|
||||||
controlServerSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(CSH->si->mapname, EResType::SERVER_SAVEGAME));
|
|
||||||
}
|
|
||||||
else // create entry for server savegame. Triggered if save was made after launch and not yet present in res handler
|
|
||||||
{
|
|
||||||
controlServerSaveName = boost::filesystem::path(clientSaveName).replace_extension(".vsgm1");
|
|
||||||
CResourceHandler::get("local")->createResource(controlServerSaveName.string(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(clientSaveName.empty())
|
|
||||||
throw std::runtime_error("Cannot open client part of " + CSH->si->mapname);
|
|
||||||
if(controlServerSaveName.empty() || !boost::filesystem::exists(controlServerSaveName))
|
|
||||||
throw std::runtime_error("Cannot open server part of " + CSH->si->mapname);
|
|
||||||
|
|
||||||
{
|
|
||||||
CLoadIntegrityValidator checkingLoader(clientSaveName, controlServerSaveName, MINIMAL_SERIALIZATION_VERSION);
|
|
||||||
loadCommonState(checkingLoader);
|
|
||||||
loader = checkingLoader.decay();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(std::exception & e)
|
else
|
||||||
{
|
{
|
||||||
logGlobal->error("Cannot load game %s. Error: %s", CSH->si->mapname, e.what());
|
std::unique_ptr<CLoadFile> loader;
|
||||||
throw; //obviously we cannot continue here
|
try
|
||||||
|
{
|
||||||
|
boost::filesystem::path clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(CSH->si->mapname, EResType::CLIENT_SAVEGAME));
|
||||||
|
boost::filesystem::path controlServerSaveName;
|
||||||
|
|
||||||
|
if(CResourceHandler::get("local")->existsResource(ResourceID(CSH->si->mapname, EResType::SERVER_SAVEGAME)))
|
||||||
|
{
|
||||||
|
controlServerSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(CSH->si->mapname, EResType::SERVER_SAVEGAME));
|
||||||
|
}
|
||||||
|
else // create entry for server savegame. Triggered if save was made after launch and not yet present in res handler
|
||||||
|
{
|
||||||
|
controlServerSaveName = boost::filesystem::path(clientSaveName).replace_extension(".vsgm1");
|
||||||
|
CResourceHandler::get("local")->createResource(controlServerSaveName.string(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(clientSaveName.empty())
|
||||||
|
throw std::runtime_error("Cannot open client part of " + CSH->si->mapname);
|
||||||
|
if(controlServerSaveName.empty() || !boost::filesystem::exists(controlServerSaveName))
|
||||||
|
throw std::runtime_error("Cannot open server part of " + CSH->si->mapname);
|
||||||
|
|
||||||
|
{
|
||||||
|
CLoadIntegrityValidator checkingLoader(clientSaveName, controlServerSaveName, MINIMAL_SERIALIZATION_VERSION);
|
||||||
|
loadCommonState(checkingLoader);
|
||||||
|
loader = checkingLoader.decay();
|
||||||
|
}
|
||||||
|
|
||||||
|
serialize(loader->serializer, loader->serializer.fileVersion);
|
||||||
|
}
|
||||||
|
catch(std::exception & e)
|
||||||
|
{
|
||||||
|
logGlobal->error("Cannot load game %s. Error: %s", CSH->si->mapname, e.what());
|
||||||
|
throw; //obviously we cannot continue here
|
||||||
|
}
|
||||||
|
logNetwork->trace("Loaded common part of save %d ms", CSH->th->getDiff());
|
||||||
}
|
}
|
||||||
logNetwork->trace("Loaded common part of save %d ms", CSH->th->getDiff());
|
|
||||||
gs->preInit(VLC);
|
gs->preInit(VLC);
|
||||||
gs->updateOnLoad(CSH->si.get());
|
gs->updateOnLoad(CSH->si.get());
|
||||||
|
logNetwork->info("Game loaded, initialize interfaces.");
|
||||||
|
|
||||||
initMapHandler();
|
initMapHandler();
|
||||||
|
|
||||||
reinitScripting();
|
reinitScripting();
|
||||||
|
|
||||||
initPlayerEnvironments();
|
initPlayerEnvironments();
|
||||||
|
|
||||||
serialize(loader->serializer, loader->serializer.fileVersion);
|
|
||||||
|
|
||||||
initPlayerInterfaces();
|
initPlayerInterfaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ public:
|
|||||||
events::EventBus * eventBus() const override;
|
events::EventBus * eventBus() const override;
|
||||||
|
|
||||||
void newGame(CGameState * gameState);
|
void newGame(CGameState * gameState);
|
||||||
void loadGame();
|
void loadGame(CGameState * gameState);
|
||||||
void serialize(BinarySerializer & h, const int version);
|
void serialize(BinarySerializer & h, const int version);
|
||||||
void serialize(BinaryDeserializer & h, const int version);
|
void serialize(BinaryDeserializer & h, const int version);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user