• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

Feature AutoSave in Sources

Status
Not open for further replies.

elf

Sing, sing blue silver
Senator
Joined
Dec 11, 2007
Messages
3,666
Solutions
1
Reaction score
125
Location
Warsaw, Poland
GitHub
tayandenga
Twitch
tayandenga
Okay, many people started searching this.
This is fully working feature, that doesn't cause lags like .lua ones.

1. game.cpp, around line 4200 above Game::saveServer, add:
Code:
void Game::autoSaveData(bool savePlayers)
{
	std::cout << ">> AutoSave ";
	saveData(savePlayers);
	Scheduler::getScheduler().addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::AUTOSAVE_FREQ), boost::bind(&Game::autoSaveData, this, savePlayers)));
}
// [END] Elf

2. game.cpp, in Game::saveData, add on begining:
Code:
std::cout << "> Saving data..." << std::endl; //Elf

3. game.h, under Game::prepareServerSave(), add:
Code:
void autoSaveData(bool savePlayers); //Elf

4. otserv.cpp, under:
Code:
IOLoginData::getInstance()->resetOnlineStatus();
add:
Code:
	// [START] Elf
	std::cout << ">> AutoSave:";
	if (g_config.getString(ConfigManager::AUTOSAVE_ENABLED) == "yes")
	{
		std::cout << " Enabled" << std::endl;
		Scheduler::getScheduler().addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::AUTOSAVE_FREQ), boost::bind(&Game::autoSaveData, &g_game, true)));
	}
	else
		std::cout << " Disabled" << std::endl;
	// [END] Elf

5. configmanager.cpp, under:
Code:
m_confString[GENERATE_ACCOUNT_NUMBER] = getGlobalString(L, "generateAccountNumber", "yes");
add:
Code:
	m_confString[AUTOSAVE_ENABLED] = getGlobalString(L, "autoSaveEnabled", "no");
	m_confInteger[AUTOSAVE_FREQ] = getGlobalNumber(L, "autoSaveFrequence", 30 * 60 * 1000);

6. configmanager.h, under:
Code:
GENERATE_ACCOUNT_NUMBER,
add:
Code:
AUTOSAVE_ENABLED,

7. configmanager.h, under:
Code:
STATUSQUERY_TIMEOUT,
add:
Code:
AUTOSAVE_FREQ,

Of course save the files and re-compile. Now add to config.lua values:
autoSaveEnabled = "yes"
autoSaveFrequence = 30 * 60 * 1000

Where 30 is a minutes value, change it to own use.




Code copied fastly in case of timeless Elf, specially for Ronaldino.
~yours.
 
Last edited:
Uhm.. I can't find THis "IOLoginData::getInstance()->resetOnlineStatus();" in Otserv.cpp?
 
Uhm... What make you think the Lua one cause lags? ^.-
 
I added it all in but when i start my server...
Code:
[07/04/2008  16:04:23] >> AutoSave:Warning: [ConfigManager::getString] 44
[07/04/2008  16:04:23]  Disabled

And heres my config file :

Code:
-- The Forgotten Server Config

	-- Account Manager
	accountManager = "yes"
	newPlayerChooseVoc = "no"
	newPlayerSpawnPosX = 322
	newPlayerSpawnPosY = 200
	newPlayerSpawnPosZ = 9
	newPlayerTownId = 1
	newPlayerLevel = 1
	newPlayerMagicLevel = 0
	generateAccountNumber = "no"

	-- Banishments
	broadcastBanishments = "yes"
	killsToBan = 6

	-- Battle
	worldType = "pvp"
	hotkeyAimbotEnabled = "yes"
	protectionLevel = 25
	killsToRedSkull = 3
	pzLocked = 60000
	deathLosePercent = 8
	criticalHitChance = 7
	removeAmmoWhenUsingDistanceWeapon = "yes"
	removeChargesFromRunes = "yes"
	timeToDecreaseFrags = 3600 * 1000 * 12
	-- Default white is 60 * 1000 * 15
	whiteSkullTime = 60 * 1000 * 2

	-- Commands
	displayGamemastersWithOnlineCommand = "no"

	-- Connection Config
	ip = "69.156.106.58"
	port = 7171
	loginTries = 500
	retryTimeout = 30 * 1000
	loginTimeout = 60 * 1000
	maxPlayers = "1000"
	motd = "Welcome to MythiaT RPG. Please report all bugs with !report and rule violations with ctrl+r"
	onePlayerOnlinePerAccount = "yes"
	allowClones = 0
	serverName = "Mythia RPG"
	loginMessage = "Welcome to Mythia RPG. Please report all bugs with !report and rule violations with ctrl+r"
	adminLogsEnabled = "yes"
	statusTimeout = 5 * 60 * 1000

	-- Deathlist
	deathListEnabled = "yes"
	maxDeathRecords = 10

	-- Guilds
	levelToFormGuild = 2
	guildNameMinLength = 4
	guildNameMaxLength = 20

	-- Highscores
	highscoreDisplayPlayers = 15
	updateHighscoresAfterMinutes = 60

	-- Houses
	housePriceEachSQM = 1000
	houseRentPeriod = "never"

	-- Idle
	kickIdlePlayerAfterMinutes = 15

	-- Item Usage
	timeBetweenActions = 200
	timeBetweenExActions = 1000

	-- Map
	mapName = "NTS2"
	mapAuthor = "SirNux"
	randomizeTiles = "yes"

	-- Messaging
	maxMessageBuffer = 4

	-- MySQL
	mysqlHost = "-------------"
	mysqlUser = "----------"
	mysqlPass = "-----"
	mysqlDatabase = "---"
	mysqlPort = ----

	-- Premium Account
	freePremium = "no"

	-- PVP Server
	displayOnOrOffAtCharlist = "no"
	allowChangeOutfit = "yes"
	noDamageToSameLookfeet = "no"
	experienceByKillingPlayers = "no"

	-- Rates
	rateExp = 10
	rate_rook_exp = 8
	rateSkill = 4
	rateLoot = 2
	rateMagic = 4
	rateSpawn = 1

	-- Server Save
	serverSaveEnabled = "yes"
	serverSaveHour = 1
	shutdownAtServerSave = "no"
	cleanMapAtServerSave = "yes"
	
	autoSaveEnabled = "yes"
	autoSaveFrequence = 2 * 60 * 1000
	

	-- Spawns
	deSpawnRange = 2
	deSpawnRadius = 50


	-- SQL
	sqlType = "mysql"
	passwordType = "plain"

	-- Startup
	defaultPriority = "realtime"

	-- Status
	ownerName = "Brandon"
	ownerEmail = "----"
	url = "http://mythiarpg.no-ip.org/"
	location = "Canada"

Any ideas?
 
Lol this is soo buggy, it kept messing everything up and preventing the server from savng and people from accessing their accounts
 
great one, works for me, thanks!
 
Great job, I'll use it. And yes the LUA one does cause a 3~ second freeze while saving.
 
Elf, I hope You will know how it make for newest release of TFS. I was searching for Game::saveData function and i doesn't find it. I hope it just another name of this function.

Regards~
 
Elf, I hope You will know how it make for newest release of TFS. I was searching for Game::saveData function and i doesn't find it. I hope it just another name of this function.

Regards~
Game::saveData has been deprecated, for save use:
g_game.setGameState(GAME_STATE_SAVE);
 
1. game.cpp, around line 4200 above Game::saveServer, add:
Code:
void Game::autoSaveData(bool savePlayers)
{
	std::cout << ">> AutoSave ";
	saveData(savePlayers);
	Scheduler::getScheduler().addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::AUTOSAVE_FREQ), boost::bind(&Game::autoSaveData, this, savePlayers)));
}
// [END] Elf
2. game.cpp, in Game::saveData, add on begining:
Code:
std::cout << "> Saving data..." << std::endl; //Elf

So it should look like that:
1. game.cpp, around line 4200 above Game::serverSave(), add:
Code:
void Game::autoSaveData(bool savePlayers)
{
	std::cout << ">> AutoSave ";
	setGameState(GAME_STATE_SAVE);
	Scheduler::getScheduler().addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::AUTOSAVE_FREQ), boost::bind(&Game::autoSaveData, this, savePlayers)));
}
// [END] Elf
2. game.cpp, in "case GAME_STATE_SAVE:" (around 170 line), add on begining:
Code:
std::cout << "> Saving data..." << std::endl; //Elf

I guess it will, cause that works fine.


I also want to say that some items like tapestry doesn't save and disappear after restart. I think that it is bigger problem but I'm not sure.
 
Last edited:
Elf, i'm got one problem on this line

Code:
	saveData(savePlayers);

Please Help...
'savedata' was not declared in this scope
 
Very simple, but very useful, it will help a lot of people, since .lua codes cause a lot of lag. I tried to make it a lot of ways using .lua, but when the server was being saved, it freezed. Using sources, it doesn't.

Good code >D!

Yours,
Rafael Hamdan;
 
Your lua scripts caused lags? ^.- Then either your distro must suck, or your code sucks. o_O
 
Rafael.. when I used this auto save in sources it cause same freezes like I got now when I use auto save in LUA. So as Empty said your distro or code must be sucks.
 
Status
Not open for further replies.
Back
Top