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

Start, kill and shutdown server from website(tfs0.63.6 windows tested)

zakius

Enter the Ninja!
Joined
Apr 30, 2009
Messages
2,635
Reaction score
65
Location
with Taiga
DAMN, my pc restarted before I posted it -.-

Ok, last version was for total dumbs, but I wont write it again so try to understand all bu yourself

so lets start
first, in your htdocs create restarter.php
Code:
<?PHP
$path = $config['site']['server_path'];
$exename = "theforgottenserver.exe";
if($group_id_of_acc_logged >= $config['site']['access_admin_panel']) 
{
	if($action == "")
	{
		$main_content .= '<table style=\'clear:both\' border=0 cellpadding=0 cellspacing=0 width=\'100%\'>
		<tr bgcolor='.$config['site']['darkborder'].'><td width="150"><font color="red"><b>Option</b></font></td><td><font color="red"><b>Description</b></font></td></tr>
		<tr bgcolor='.$config['site']['lightborder'].'><td width="150"><b><a href="?subtopic=restarter&action=restart">Restart</a></b></td><td><b>Kills server process and starts new one.</b></td></tr>
		<tr bgcolor='.$config['site']['darkborder'].'><td width="150"><b><a href="?subtopic=restarter&action=kill">Kill process</a></b></td><td><b>Kills server process.</b></td></tr>
		<tr bgcolor='.$config['site']['lightborder'].'><td width="150"><b><a href="?subtopic=restarter&action=start">Start server</a></b></td><td><b>Starts server.</b></td></tr>
		<tr bgcolor='.$config['site']['darkborder'].'><td width="150"><b><a href="?subtopic=restarter&action=shutdown">Shutdown server instantly</a></b></td><td><b>Allows you to safe shutdown server(using servers own shutdown function).</b></td></tr>
		<tr bgcolor='.$config['site']['lightborder'].'><td width="150"><b><a href="?subtopic=restarter&action=shutdownlong">Player-friendly shutdown</a></b></td><td><b>Performs safe shutdown after broadcast warning and 5 minutes delay.</b></td></tr>
		<tr bgcolor='.$config['site']['darkborder'].'><td width="150"><b><a href="?subtopic=adminpanel">Back to admin panel</a></b></td><td><b>Go back to admin panel.</b></td></tr>
		</table>';
	}
	getcwd();  
	chdir($path);
	if($action == "restart")
	{
		exec('TASKKILL /F /IM ".$exename."');
		$command = 'START/HIGH '.$exename;
		$tmpnam = "temp.bat";
		$fp = fopen ($tmpnam, "w");
		fwrite($fp, $command);
		fclose ($fp);
		$foo = @popen($tmpnam, 'r');
		$main_content .='<center>Server restarted.<br><b><a href="?subtopic=restarter">Back</a></center>';
	}
	if($action == "kill"){exec('TASKKILL /F /IM "'.$exename.'"'); $main_content .='<center>Server closed.<br><b><a href="?subtopic=restarter">Back</a></center>';}
	if($action == "start")
	{
		$command = 'START/HIGH '.$exename;
		$tmpnam = "temp.bat";
		$fp = fopen ($tmpnam, "w");
		fwrite($fp, $command);
		fclose ($fp);
		$foo = @popen($tmpnam, 'r');
		$main_content .='<center>Server started. <br><b><a href="?subtopic=restarter">Back</a></center>';
	}
	if($action == "shutdown")
	{  
		$SQL->query('UPDATE '.$SQL->tableName('z_shut').' SET `shutdown`="1", `long`="0" WHERE id = "1";');
		$main_content .='<center>Server will shut down soon. <br><b><a href="?subtopic=restarter">Back</a></center>';
	}
	if($action == "shutdownlong")
	{  
		$SQL->query('UPDATE '.$SQL->tableName('z_shut').' SET `shutdown`="1", `long`="1" WHERE `id` = "1";');
		$main_content .='<center>Server will shut down soon. <br><b><a href="?subtopic=restarter">Back</a></center>';
	}
}
else
{
	$title = $GLOBALS['config']['server']["serverName"]." - OTS";
	$main_content .= 'Invalid subtopic. Can\'t load page.';
}
?>
in your index.php add
Code:
case "restarter":
		$topic = "Restarter";
		$subtopic = "restarter";
		include("restarter.php");
	break;
after
Code:
case "latestnews":
		$topic = "Latest News";
		$subtopic = "latestnews";
		include("latestnews.php");
	break;
in your adminpanel.php add
Code:
<tr bgcolor='.$config['site']['lightborder'].'><td width="150"><b><a href="?subtopic=restarter">Restarter</a></b></td><td><b>Here you start, stop and restart server!</b></td></tr>
before
Code:
</table>
in phpmyadmin execute
Code:
CREATE TABLE IF NOT EXISTS `z_shut` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `shutdown` int(11) NOT NULL DEFAULT '1',
  `long` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`),
  KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


INSERT INTO `z_shut` (`id`, `shutdown`, `long`) VALUES
(1, 0, 1);
and in globalevents create file restarter.lua
Code:
local message = 
{
	"Server will shut down in 5 minutes. Dont ask me why, I'm only script", 
	"Server will shutdown in 2 minutes, please log off", 
	"Server is going down..."
}
local class = 21
function shutDown()
	doBroadcastMessage(message[3], class)
	doSetGameState(GAMESTATE_SHUTDOWN)
	return TRUE
end
function broadcast()
	doBroadcastMessage(message[2], class)
	return TRUE
end

function onThink(interval, lastExecution)
    local result_plr = db.getResult("SELECT * FROM z_shut WHERE `id` = 1;")
    if(result_plr:getID() ~= -1) then 
		while(true) do
			if(tonumber(result_plr:getDataInt("shutdown"))==1) then
				db.executeQuery("UPDATE z_shut SET shutdown = '0' WHERE id = '1';")
				if(tonumber(result_plr:getDataInt("long"))==0) then
					doBroadcastMessage(message[3], class)
					doSetGameState(GAMESTATE_SHUTDOWN)
				else
					doBroadcastMessage(message[1], class)
					addEvent(broadcast, 3*60*1000, {})
					addEvent(shutDown, 5*60*1000, {})
				end
			end
			if not(result_plr:next()) then break end
		end
	end
	result_plr:free()
return TRUE
end
in globalevents.xml add
Code:
	<globalevent name="safe_shutdown" interval="5" event="script" value="restarter.lua"/>

hope its all

small screenie
20100125184903.png


and its tested with tfs 0.3.6 on windows xp pro sp3
probably in xp home taskkill is repleaced by another function but in serv2003 and serv2008 its probably like in xp pro
also I dont know commands for linux

globalevent may not work on older releases, but it can be rewritten to work with all 0.3 and 0.4 I guess

If you like it you can rep++ me
 
for linux somewhere here is scrptt made I guess by elf, maby I will add linux functions too, but I don't have space on hdd to install any distro to test it
 
when you start - restart the server.. it's opened as a system process.. you can see the console at all..

how do i fix this?
 
it starts on system user, so window wont appear(but serv is running, sometimes start may take long when otland is offline so dont worry, just wait few minutes).
Dunno if theres any way to start as current user
 
I have a problem on Windows 7, if I want to reset start stop etc. my server there it`s not responding....

Please help me
 
how big map you have etc?
start it normally and check how much time it takes, if using restarter it will take 2x more you have some kind of problem(no idea what, for me works(on acc with admin rights))
kill process kills ALL running $exename, so even if you have launched it n times and many windows with warning about running serv appeared on system acc it will KILL all these processes so new one can easy strart after that
 
Back
Top