zakius
Enter the Ninja!
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
in your index.php add
after
in your adminpanel.php add
before
in phpmyadmin execute
and in globalevents create file restarter.lua
in globalevents.xml add
hope its all
small screenie
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
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.';
}
?>
Code:
case "restarter":
$topic = "Restarter";
$subtopic = "restarter";
include("restarter.php");
break;
Code:
case "latestnews":
$topic = "Latest News";
$subtopic = "latestnews";
include("latestnews.php");
break;
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>
Code:
</table>
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);
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
Code:
<globalevent name="safe_shutdown" interval="5" event="script" value="restarter.lua"/>
hope its all
small screenie
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