• 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!

Feature [Release] /shutdown command in TFS

Decent60

My peanut
Joined
Feb 28, 2008
Messages
99
Reaction score
0
This has been tested and is running on my server right now with the lastest tags of TFS. If you find any errors let me know and I'll see what I can do lol.
This basically isn't my coding but working with those who originally made it. I guess the /shutdown was made by the OpenTibia team so creadits to them and the TFS team.
Probably many of you have this on your server, but here is one for those who don't can can't figure it out.

1) In the Commands.cpp

Search for /ghost and place this line below that:
Code:
{"/shutdown",&Commands::saveserver},

2) Search for "bool Commands::ghost" and place this above it:

Code:
bool Commands::saveserver(Creature* creature, const std::string &cmd, const std::string &param)
{
	Player* player = creature->getPlayer();
	if(player && !param.empty()){
		g_game.sheduleSaveserver(atoi(param.c_str()));
	}
		
	return true;
}


3) In Commands.h

Search for "bool ghost" and add this line below that:

Code:
bool saveserver(Creature* creature, const std::string &cmd, const std::string &param);

4) Now the easy part is done, head over to Game.cpp

Search for "void Game::saveData(bool savePlayers)"

and place this code above that:

Code:
void Game::sheduleSaveserver(int minutes)
{
	if (minutes > 0)
		checkSaveserver(minutes);
}

void Game::checkSaveserver(int minutes)
{
	if(minutes == 0){
		
		if(g_config.getString(ConfigManager::CLEAN_MAP_AT_SERVERSAVE) == "yes")
		map->clean();
		setGameState(GAME_STATE_SHUTDOWN);

		for(AutoList<Player>::listiterator it = Player::listPlayer.list.begin(); it != Player::listPlayer.list.end(); ++it)
	 	(*it).second->kickPlayer(true);
		saveData(true);
		std::cout << ":: Shutting down Server..." << std::endl;
		OTSYS_SLEEP(1000);
		exit(1);
	}
	else {
		std::stringstream msg;
		msg << "" << g_config.getString(ConfigManager::SERVER_NAME) << " is going down in " << minutes << (minutes > 1? " minutes!" : " minute!") << std::ends;

		AutoList<Player>::listiterator it = Player::listPlayer.list.begin();
		while(it != Player::listPlayer.list.end()){
			(*it).second->sendTextMessage(MSG_STATUS_CONSOLE_RED, msg.str().c_str());
			++it;
		}

		Scheduler::getScheduler().addEvent(createSchedulerTask(60000, boost::bind(&Game::checkSaveserver, this, minutes - 1)));
	}
}

5) In Game.h, search for this line: "void serverSave();" and add these lines below it:

Code:
void sheduleSaveserver(int minutes);
void checkSaveserver(int minutes);


After that, save all and then rebuild and there you go. For best results, use an autorestarter (works very well with the one I have). So far, I've had it going for 15 minutes for a shutdown running and its worked very well. Although it does clean the server when it shuts down and I haven't figured out how to change it (I've included a code that shouldn't make it clean up if you have "no" in the config.lua but it still does it anyways). Another note is that the player's screen doesn't show the kick immedantly, but rather a few seconds afterwards. If you have an autorestarter, their screen will show the kicked shortly before the server is fully loaded and players can login.
 
Probably, but every time I tried to adjust it to them it never worked (I couldn't even get it to compile xD), although, I am just starting to work with coding so, yeah there are probably many better ways to do it.
 
Why my server crash when i use /shutdown 5? When left one minutes and server is going close then i have crash. Why?
Sorry for my english.
 
Back
Top