EngineGP/system/library/cron/scan_servers_stop.php

57 lines
1.9 KiB
PHP
Raw Normal View History

2023-03-04 23:45:46 +00:00
<?php
2023-03-05 13:59:34 +00:00
if(!DEFINED('EGP'))
exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
class scan_servers_stop extends cron
{
function __construct()
{
global $cfg, $sql, $argv, $start_point;
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$servers = $argv;
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
unset($servers[0], $servers[1], $servers[2]);
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$sql->query('SELECT `address` FROM `units` WHERE `id`="'.$servers[4].'" LIMIT 1');
if(!$sql->num())
return NULL;
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$unit = $sql->get();
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$game = $servers[3];
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
unset($servers[3], $servers[4]);
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$sql->query('SELECT `unit` FROM `servers` WHERE `id`="'.$servers[5].'" LIMIT 1');
$server = $sql->get();
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$sql->query('SELECT `address`, `passwd` FROM `units` WHERE `id`="'.$server['unit'].'" LIMIT 1');
$unit = $sql->get();
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
include(LIB.'ssh.php');
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
// Проверка ssh соедниения пу с локацией
if(!$ssh->auth($unit['passwd'], $unit['address']))
return NULL;
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$autostop = $start_point-$cfg['autostop']*60;
$teststop = $start_point-$cfg['teststop']*60;
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$sqlq = '(`test`="1" AND `time_start`<"'.$teststop.'" OR `autostop`="1" AND `time_start`<"'.$autostop.'")';
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
foreach($servers as $id)
{
$sql->query('SELECT `id` FROM `servers` WHERE `id`="'.$id.'" AND `status`="working" AND `online`="0" AND '.$sqlq.' LIMIT 1');
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
if(!$sql->num())
continue;
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
exec('sh -c "cd /var/enginegp; php cron.php '.$cfg['cron_key'].' server_action stop '.$game.' '.$id.'"');
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
$sql->query('INSERT INTO `logs_sys` set `user`="0", `server`="'.$id.'", `text`="Выключение сервера: на сервере нет игроков", `time`="'.$start_point.'"');
}
2023-03-04 23:45:46 +00:00
2023-03-05 13:59:34 +00:00
return NULL;
}
}
2023-03-04 23:45:46 +00:00
?>