• 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.
Just don't talk about you don't know. I'm using newest revision of TFS (Trunk), without much changes, but every time the server is saved, it causes a freeze of about 2 seconds.

Using it on sources, the server freezes about 0.5 sec (almost nothing). My script (npc):

Code:
local SAVE_FREQUENCE = 20 * 60 * 2 * 2 -- seconds, x2 because onThink is executed every 500ms

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local saveTimer = SAVE_FREQUENCE

function onCreatureAppear(cid)			npcHandler:onCreatureAppear(cid)			end
function onCreatureDisappear(cid)		npcHandler:onCreatureDisappear(cid)			end
function onCreatureSay(cid, type, msg)	npcHandler:onCreatureSay(cid, type, msg)	end
function onThink()
	saveTimer = saveTimer - 2
	if saveTimer == 0 then
		doBroadcastMessage("Welcome to HellPiece OTServer.");
		saveServer()
		saveTimer = SAVE_FREQUENCE
	end

	npcHandler:onThink()
end

npcHandler:addModule(FocusModule:new())

Maybe my script was sux and I didn't know, anh?

My code on sources is almost the same, look:

Code:
void Game::autoSaveData()
{
	std::cout << ">> Server has been saved. " << std::endl;
        setGameState(GAME_STATE_SAVE);
	Scheduler::getScheduler().addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::AUTOSAVE_FREQ), boost::bind(&Game::autoSaveData, this)));
}

and at otserv.cpp

Code:
    std::cout << ">> Auto server save time: " << g_config.getNumber(ConfigManager::AUTOSAVE_FREQ) / 60000 << " minutes."<< std::endl;
    Scheduler::getScheduler().addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::AUTOSAVE_FREQ), boost::bind(&Game::autoSaveData, &g_game)));

Yours,
Rafael Hamdan;
 
Last edited:
I cannot find Game::saveServer in game.cpp, there is only serverSave. Is it?
Also i find 'savePlayers', it's now saveData? I must change it or it will be working?
 
Last edited:
gr8, gona try it out when ill be at home. But why isnt this future included in newest tfs's?
 
This has been implemented to tags and in trunk global events are used, please mind before adding it.

It would be nice if you updated this tutorial. From all 7 steps there was only 1 piece of code that was located at place where the tutorial says. Does someone know how to add autosave on newest tfs? Please post msg here/pm me/or contact me on msn. Im dieing cuz of this :D



huh ? so how are u saving ur server?

Im using .lua ones. It sucks, cuz when my server is saving game it freezes for ~8 seconds. Almost all real maps have that issue.
 
Last edited:
Is there any chance you could add this into the next release of your server and then make an option in the config where you can choose between which one you would like to use?
 
Status
Not open for further replies.
Back
Top