scan_servers_stop.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. if(!DEFINED('EGP'))
  3. exit(header('Refresh: 0; URL=http://'.$_SERVER['SERVER_NAME'].'/404'));
  4. class scan_servers_stop extends cron
  5. {
  6. function __construct()
  7. {
  8. global $cfg, $sql, $argv, $start_point;
  9. $servers = $argv;
  10. unset($servers[0], $servers[1], $servers[2]);
  11. $sql->query('SELECT `address` FROM `units` WHERE `id`="'.$servers[4].'" LIMIT 1');
  12. if(!$sql->num())
  13. return NULL;
  14. $unit = $sql->get();
  15. $game = $servers[3];
  16. unset($servers[3], $servers[4]);
  17. $sql->query('SELECT `unit` FROM `servers` WHERE `id`="'.$servers[5].'" LIMIT 1');
  18. $server = $sql->get();
  19. $sql->query('SELECT `address`, `passwd` FROM `units` WHERE `id`="'.$server['unit'].'" LIMIT 1');
  20. $unit = $sql->get();
  21. include(LIB.'ssh.php');
  22. // Проверка ssh соедниения пу с локацией
  23. if(!$ssh->auth($unit['passwd'], $unit['address']))
  24. return NULL;
  25. $autostop = $start_point-$cfg['autostop']*60;
  26. $teststop = $start_point-$cfg['teststop']*60;
  27. $sqlq = '(`test`="1" AND `time_start`<"'.$teststop.'" OR `autostop`="1" AND `time_start`<"'.$autostop.'")';
  28. foreach($servers as $id)
  29. {
  30. $sql->query('SELECT `id` FROM `servers` WHERE `id`="'.$id.'" AND `status`="working" AND `online`="0" AND '.$sqlq.' LIMIT 1');
  31. if(!$sql->num())
  32. continue;
  33. exec('sh -c "cd /var/enginegp; php cron.php '.$cfg['cron_key'].' server_action stop '.$game.' '.$id.'"');
  34. $sql->query('INSERT INTO `logs_sys` set `user`="0", `server`="'.$id.'", `text`="Выключение сервера: на сервере нет игроков", `time`="'.$start_point.'"');
  35. }
  36. return NULL;
  37. }
  38. }
  39. ?>