Explorar o código

save successful

Laserlicht hai 3 semanas
pai
achega
7e7ced8ec1

+ 3 - 3
client/CPlayerInterface.cpp

@@ -282,7 +282,7 @@ void CPlayerInterface::performAutosave()
 		int autosaveCountLimit = settings["general"]["autosaveCountLimit"].Integer();
 		if(autosaveCountLimit > 0)
 		{
-			cb->save("Saves/Autosave/" + prefix + std::to_string(autosaveCount));
+			cb->save("Saves/Autosave/" + prefix + std::to_string(autosaveCount), false);
 			autosaveCount %= autosaveCountLimit;
 		}
 		else
@@ -291,7 +291,7 @@ void CPlayerInterface::performAutosave()
 					+ std::to_string(cb->getDate(Date::WEEK))
 					+ std::to_string(cb->getDate(Date::DAY_OF_WEEK));
 
-			cb->save("Saves/Autosave/" + prefix + stringifiedDate);
+			cb->save("Saves/Autosave/" + prefix + stringifiedDate, false);
 		}
 	}
 }
@@ -1802,7 +1802,7 @@ void CPlayerInterface::quickSaveGame()
 	txt.appendTextID("vcmi.adventureMap.savingQuickSave");
 	txt.replaceRawString(QUICKSAVE_PATH);
 	GAME->server().getGameChat().sendMessageGameplay(txt.toString());
-	GAME->interface()->cb->save(QUICKSAVE_PATH);
+	GAME->interface()->cb->save(QUICKSAVE_PATH, false);
 	hasQuickSave = true;
 	if(adventureInt)
 		adventureInt->updateActiveState();

+ 1 - 1
client/ClientCommandManager.cpp

@@ -62,7 +62,7 @@ void ClientCommandManager::handleSaveCommand(std::istringstream & singleWordBuff
 
 	std::string saveFilename;
 	singleWordBuffer >> saveFilename;
-	GAME->interface()->cb->save(saveFilename);
+	GAME->interface()->cb->save(saveFilename, false);
 	printCommandMessage("Game saved as: " + saveFilename);
 }
 

+ 1 - 1
client/GameInstance.cpp

@@ -142,5 +142,5 @@ void GameInstance::pauseAutoSave()
 		return;
 	}
 
-	GAME->interface()->cb->save(autoSaveName);
+	GAME->interface()->cb->save(autoSaveName, false);
 }

+ 1 - 1
client/lobby/CSavingScreen.cpp

@@ -85,7 +85,7 @@ void CSavingScreen::saveGame()
 	{
 		Settings lastSave = settings.write["general"]["lastSave"];
 		lastSave->String() = path;
-		GAME->interface()->cb->save(path);
+		GAME->interface()->cb->save(path, true);
 		close();
 	};
 

+ 2 - 2
lib/callback/CCallback.cpp

@@ -311,9 +311,9 @@ void CCallback::saveLocalState(const JsonNode & data)
 	sendRequest(state);
 }
 
-void CCallback::save( const std::string &fname )
+void CCallback::save( const std::string &fname, bool notifySuccess )
 {
-	SaveGame save_game(fname);
+	SaveGame save_game(fname, notifySuccess);
 	sendRequest(save_game);
 }
 

+ 1 - 1
lib/callback/CCallback.h

@@ -78,7 +78,7 @@ public:
 	void setFormation(const CGHeroInstance * hero, EArmyFormation mode) override;
 	void setTownName(const CGTownInstance * town, std::string & name) override;
 	void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero, const HeroTypeID & nextHero=HeroTypeID::NONE) override;
-	void save(const std::string &fname) override;
+	void save(const std::string &fname, bool notifySuccess) override;
 	void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) override;
 	void gamePause(bool pause) override;
 	void buildBoat(const IShipyard *obj) override;

+ 1 - 1
lib/callback/IGameActionCallback.h

@@ -72,7 +72,7 @@ public:
 	virtual void setFormation(const CGHeroInstance * hero, EArmyFormation mode)=0;
 	virtual void setTownName(const CGTownInstance * town, std::string & name)=0;
 
-	virtual void save(const std::string &fname) = 0;
+	virtual void save(const std::string &fname, bool notifySuccess) = 0;
 	virtual void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) = 0;
 	virtual void gamePause(bool pause) = 0;
 	virtual void buildBoat(const IShipyard *obj) = 0;

+ 4 - 1
lib/networkPacks/PacksForServer.h

@@ -756,17 +756,20 @@ struct DLL_LINKAGE RequestStatistic : public CPackForServer
 struct DLL_LINKAGE SaveGame : public CPackForServer
 {
 	SaveGame() = default;
-	SaveGame(std::string Fname)
+	SaveGame(std::string Fname, bool NotifySuccess)
 		: fname(std::move(Fname))
+		, notifySuccess(NotifySuccess)
 	{
 	}
 	std::string fname;
+	bool notifySuccess = false;
 
 	void visitTyped(ICPackVisitor & visitor) override;
 
 	template <typename Handler> void serialize(Handler & h)
 	{
 		h & static_cast<CPackForServer &>(*this);
+		h & notifySuccess;
 		h & fname;
 	}
 };

+ 25 - 3
server/CGameHandler.cpp

@@ -1002,7 +1002,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, EMovementMode moveme
 		gameInfo().getPlayerState(h->getOwner())->human &&
 	   (guardian || objectToVisit) &&
 	   movementMode == EMovementMode::STANDARD)
-		save("Saves/BeforeVisitSave");
+		save("Saves/BeforeVisitSave", PlayerColor::CANNOT_DETERMINE);
 
 	if (!transit && embarking)
 	{
@@ -1611,7 +1611,7 @@ bool CGameHandler::responseStatistic(PlayerColor player)
 	return true;
 }
 
-void CGameHandler::save(const std::string & filename)
+void CGameHandler::save(const std::string & filename, PlayerColor playerToNotifyOnSuccess)
 {
 	logGlobal->info("Saving to %s", filename);
 	const auto stem	= FileInfo::GetPathStem(filename);
@@ -1619,6 +1619,15 @@ void CGameHandler::save(const std::string & filename)
 	ResourcePath savePath(stem.to_string(), EResType::SAVEGAME);
 	CResourceHandler::get("local")->createResource(savefname);
 
+	std::string filenameWithoutPath;
+	auto pos = filename.find_last_of("/\\");
+	if (pos != std::string::npos)
+		filenameWithoutPath = filename.substr(pos + 1);
+	else
+		filenameWithoutPath = filename;
+	InfoWindow iw;
+	iw.player = playerToNotifyOnSuccess;
+
 	try
 	{
 		CSaveFile save;
@@ -1626,12 +1635,25 @@ void CGameHandler::save(const std::string & filename)
 		logGlobal->info("Saving server state");
 		save.save(*this);
 		save.write(*CResourceHandler::get("local")->getResourceName(savePath));
+
+		if(playerToNotifyOnSuccess.isValidPlayer())
+		{
+			iw.text = MetaString::createFromTextID("core.genrltxt.350");
+			iw.text.replaceRawString(filenameWithoutPath);
+			sendAndApply(iw);
+		}
+		logGlobal->info("Game has been successfully saved!");
 	}
 	catch(std::exception &e)
 	{
+		if(playerToNotifyOnSuccess.isValidPlayer())
+		{
+			iw.text = MetaString::createFromTextID("core.genrltxt.9");
+			iw.text.replaceRawString(filenameWithoutPath);
+			sendAndApply(iw);
+		}
 		logGlobal->error("Failed to save game: %s", e.what());
 	}
-	logGlobal->info("Game has been successfully saved!");
 }
 
 void CGameHandler::load(const StartInfo &info)

+ 1 - 1
server/CGameHandler.h

@@ -238,7 +238,7 @@ public:
 	bool bulkMergeStacks(SlotID slotSrc, ObjectInstanceID srcOwner);
 	bool bulkSplitAndRebalanceStack(SlotID slotSrc, ObjectInstanceID srcOwner);
 	bool responseStatistic(PlayerColor player);
-	void save(const std::string &fname);
+	void save(const std::string &fname, PlayerColor playerToNotifyOnSuccess);
 	void load(const StartInfo &info);
 
 	void onPlayerTurnStarted(PlayerColor which);

+ 1 - 1
server/NetPacksServer.cpp

@@ -29,7 +29,7 @@
 
 void ApplyGhNetPackVisitor::visitSaveGame(SaveGame & pack)
 {
-	gh.save(pack.fname);
+	gh.save(pack.fname, pack.notifySuccess ? pack.player : PlayerColor::CANNOT_DETERMINE);
 	logGlobal->info("Game has been saved as %s", pack.fname);
 	result = true;
 }

+ 1 - 1
server/processors/PlayerMessageProcessor.cpp

@@ -121,7 +121,7 @@ void PlayerMessageProcessor::commandSave(PlayerColor player, const std::vector<s
 
 	if(words.size() == 2)
 	{
-		gameHandler->save("Saves/" + words[1]);
+		gameHandler->save("Saves/" + words[1], PlayerColor::CANNOT_DETERMINE);
 		MetaString str;
 		str.appendTextID("vcmi.broadcast.gameSavedAs");
 		str.appendRawString(" ");