1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

Merged server savegame and (broken and unused) client savegame files

This commit is contained in:
Ivan Savenko 2023-07-09 15:30:47 +03:00
parent fa4a0004b2
commit 8750aa2c5b
12 changed files with 11 additions and 65 deletions

View File

@ -761,7 +761,7 @@ void CServerHandler::debugStartTest(std::string filename, bool save)
if(save)
{
resetStateForLobby(StartInfo::LOAD_GAME);
mapInfo->saveInit(ResourceID(filename, EResType::CLIENT_SAVEGAME));
mapInfo->saveInit(ResourceID(filename, EResType::SAVEGAME));
screenType = ESelectionScreen::loadGame;
}
else

View File

@ -94,7 +94,6 @@ public:
void visitSystemMessage(SystemMessage & pack) override;
void visitPlayerBlocked(PlayerBlocked & pack) override;
void visitYourTurn(YourTurn & pack) override;
void visitSaveGameClient(SaveGameClient & pack) override;
void visitPlayerMessageClient(PlayerMessageClient & pack) override;
void visitAdvmapSpellCast(AdvmapSpellCast & pack) override;
void visitShowWorldViewEx(ShowWorldViewEx & pack) override;

View File

@ -856,26 +856,6 @@ void ApplyClientNetPackVisitor::visitYourTurn(YourTurn & pack)
callOnlyThatInterface(cl, pack.player, &CGameInterface::yourTurn);
}
void ApplyClientNetPackVisitor::visitSaveGameClient(SaveGameClient & pack)
{
const auto stem = FileInfo::GetPathStem(pack.fname);
if(!CResourceHandler::get("local")->createResource(stem.to_string() + ".vcgm1"))
{
logNetwork->error("Failed to create resource %s", stem.to_string() + ".vcgm1");
return;
}
try
{
CSaveFile save(*CResourceHandler::get()->getResourceName(ResourceID(stem.to_string(), EResType::CLIENT_SAVEGAME)));
save << cl;
}
catch(std::exception &e)
{
logNetwork->error("Failed to save game:%s", e.what());
}
}
void ApplyClientNetPackVisitor::visitPlayerMessageClient(PlayerMessageClient & pack)
{
logNetwork->debug("pack.player %s sends a message: %s", pack.player.getStr(), pack.text);

View File

@ -79,7 +79,7 @@ void CSavingScreen::saveGame()
close();
};
if(CResourceHandler::get("local")->existsResource(ResourceID(path, EResType::CLIENT_SAVEGAME)))
if(CResourceHandler::get("local")->existsResource(ResourceID(path, EResType::SAVEGAME)))
{
std::string hlp = CGI->generaltexth->allTexts[493]; //%s exists. Overwrite?
boost::algorithm::replace_first(hlp, "%s", tabSel->inputName->getText());

View File

@ -232,11 +232,11 @@ void SelectionTab::toggleMode()
case ESelectionScreen::loadGame:
inputName->disable();
parseSaves(getFiles("Saves/", EResType::SERVER_SAVEGAME));
parseSaves(getFiles("Saves/", EResType::SAVEGAME));
break;
case ESelectionScreen::saveGame:
parseSaves(getFiles("Saves/", EResType::SERVER_SAVEGAME));
parseSaves(getFiles("Saves/", EResType::SAVEGAME));
inputName->enable();
restoreLastSelection();
break;
@ -416,7 +416,7 @@ void SelectionTab::select(int position)
if(inputName && inputName->isActive())
{
auto filename = *CResourceHandler::get("local")->getResourceName(ResourceID(curItems[py]->fileURI, EResType::CLIENT_SAVEGAME));
auto filename = *CResourceHandler::get("local")->getResourceName(ResourceID(curItems[py]->fileURI, EResType::SAVEGAME));
inputName->setText(filename.stem().string());
}
updateListItems();

View File

@ -138,7 +138,6 @@ public:
virtual void visitDigWithHero(DigWithHero & pack) {}
virtual void visitCastAdvSpell(CastAdvSpell & pack) {}
virtual void visitSaveGame(SaveGame & pack) {}
virtual void visitSaveGameClient(SaveGameClient & pack) {}
virtual void visitPlayerMessage(PlayerMessage & pack) {}
virtual void visitPlayerMessageClient(PlayerMessageClient & pack) {}
virtual void visitCenterView(CenterView & pack) {}
@ -162,4 +161,4 @@ public:
virtual void visitLobbyShowMessage(LobbyShowMessage & pack) {}
};
VCMI_LIB_NAMESPACE_END
VCMI_LIB_NAMESPACE_END

View File

@ -2571,23 +2571,6 @@ struct DLL_LINKAGE SaveGame : public CPackForServer
}
};
// TODO: Eventually we should re-merge both SaveGame and PlayerMessage
struct DLL_LINKAGE SaveGameClient : public CPackForClient
{
SaveGameClient() = default;
SaveGameClient(std::string Fname)
: fname(std::move(Fname))
{
}
std::string fname;
virtual void visitTyped(ICPackVisitor & visitor) override;
template <typename Handler> void serialize(Handler & h, const int version)
{
h & fname;
}
};
struct DLL_LINKAGE PlayerMessage : public CPackForServer
{
PlayerMessage() = default;

View File

@ -656,11 +656,6 @@ void SaveGame::visitTyped(ICPackVisitor & visitor)
visitor.visitSaveGame(*this);
}
void SaveGameClient::visitTyped(ICPackVisitor & visitor)
{
visitor.visitSaveGameClient(*this);
}
void PlayerMessage::visitTyped(ICPackVisitor & visitor)
{
visitor.visitPlayerMessage(*this);

View File

@ -153,8 +153,7 @@ EResType::Type EResTypeHelper::getTypeFromExtension(std::string extension)
{".VID", EResType::ARCHIVE_VID},
{".SND", EResType::ARCHIVE_SND},
{".PAL", EResType::PALETTE},
{".VCGM1", EResType::CLIENT_SAVEGAME},
{".VSGM1", EResType::SERVER_SAVEGAME},
{".VSGM1", EResType::SAVEGAME},
{".ERM", EResType::ERM},
{".ERT", EResType::ERT},
{".ERS", EResType::ERS},
@ -191,8 +190,7 @@ std::string EResTypeHelper::getEResTypeAsString(EResType::Type type)
MAP_ENUM(ARCHIVE_SND)
MAP_ENUM(ARCHIVE_VID)
MAP_ENUM(PALETTE)
MAP_ENUM(CLIENT_SAVEGAME)
MAP_ENUM(SERVER_SAVEGAME)
MAP_ENUM(SAVEGAME)
MAP_ENUM(DIRECTORY)
MAP_ENUM(ERM)
MAP_ENUM(ERT)

View File

@ -50,8 +50,7 @@ namespace EResType
ARCHIVE_SND,
ARCHIVE_LOD,
PALETTE,
CLIENT_SAVEGAME,
SERVER_SAVEGAME,
SAVEGAME,
DIRECTORY,
ERM,
ERT,

View File

@ -326,7 +326,6 @@ void registerTypesClientPacks2(Serializer &s)
s.template registerType<CArtifactOperationPack, DisassembledArtifact>();
s.template registerType<CArtifactOperationPack, BulkMoveArtifacts>();
s.template registerType<CPackForClient, SaveGameClient>();
s.template registerType<CPackForClient, PlayerMessageClient>();
s.template registerType<CGarrisonOperationPack, BulkRebalanceStacks>();
s.template registerType<CGarrisonOperationPack, BulkSmartRebalanceStacks>();

View File

@ -2977,16 +2977,10 @@ void CGameHandler::save(const std::string & filename)
const auto savefname = stem.to_string() + ".vsgm1";
CResourceHandler::get("local")->createResource(savefname);
{
logGlobal->info("Ordering clients to serialize...");
SaveGameClient sg(savefname);
sendToAllClients(&sg);
}
try
{
{
CSaveFile save(*CResourceHandler::get("local")->getResourceName(ResourceID(stem.to_string(), EResType::SERVER_SAVEGAME)));
CSaveFile save(*CResourceHandler::get("local")->getResourceName(ResourceID(stem.to_string(), EResType::SAVEGAME)));
saveCommonState(save);
logGlobal->info("Saving server state");
save << *this;
@ -3009,7 +3003,7 @@ bool CGameHandler::load(const std::string & filename)
try
{
{
CLoadFile lf(*CResourceHandler::get("local")->getResourceName(ResourceID(stem.to_string(), EResType::SERVER_SAVEGAME)), MINIMAL_SERIALIZATION_VERSION);
CLoadFile lf(*CResourceHandler::get("local")->getResourceName(ResourceID(stem.to_string(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION);
loadCommonState(lf);
logGlobal->info("Loading server state");
lf >> *this;