Added support for running game servers behind NAT
This commit is contained in:
parent
2671f4ae01
commit
efb01cd7ce
|
@ -38,6 +38,7 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
|
@ -102,7 +103,7 @@ class action extends actions
|
|||
$fps = $server['fps'] + $cfg['fpsplus'];
|
||||
|
||||
// Параметры запуска
|
||||
$bash = './hlds_run -debug -game cstrike -norestart -condebug -sys_ticrate ' . $fps . ' +servercfgfile server.cfg +sys_ticrate ' . $fps . ' +map \'' . $server['map_start'] . '\' +maxplayers ' . $server['slots_start'] . ' +ip ' . $ip . ' +port ' . $port . ' +sv_lan 0 ' . $vac . ' ' . $pingboost;
|
||||
$bash = './hlds_run -debug -game cstrike -norestart -condebug -sys_ticrate ' . $fps . ' +servercfgfile server.cfg +sys_ticrate ' . $fps . ' +map \'' . $server['map_start'] . '\' +maxplayers ' . $server['slots_start'] . ' +ip ' . $internalIp . ' +port ' . $port . ' +sv_lan 0 ' . $vac . ' ' . $pingboost;
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp($bash);
|
||||
|
|
|
@ -38,6 +38,7 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
|
@ -117,7 +118,7 @@ class action extends actions
|
|||
$mod = !$server['pingboost'] ? $mods[2] : $mods[$server['pingboost']];
|
||||
|
||||
// Параметры запуска
|
||||
$bash = './game/bin/linuxsteamrt64/cs2 -dedicated -debug -norestart -condebug console.log -usercon -ip ' . $ip . ' -port ' . $port . ' -maxplayers ' . $server['slots_start'] . ' -tickrate ' . $server['tickrate'] . ' ' . $mod . ' +servercfgfile server.cfg ' . $map . ' ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
$bash = './game/bin/linuxsteamrt64/cs2 -dedicated -debug -norestart -condebug console.log -usercon -ip ' . $internalIp . ' -port ' . $port . ' -maxplayers ' . $server['slots_start'] . ' -tickrate ' . $server['tickrate'] . ' ' . $mod . ' +servercfgfile server.cfg ' . $map . ' ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp($bash);
|
||||
|
|
|
@ -38,6 +38,7 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
|
@ -104,7 +105,7 @@ class action extends actions
|
|||
$mod = !$server['pingboost'] ? $mods[2] : $mods[$server['pingboost']];
|
||||
|
||||
// Параметры запуска
|
||||
$bash = './srcds_run -debug -game csgo -norestart -condebug console.log -usercon -tickrate ' . $server['tickrate'] . ' ' . $mod . ' +servercfgfile server.cfg ' . $map . ' -maxplayers_override ' . $server['slots_start'] . ' +ip ' . $ip . ' +net_public_adr ' . $ip . ' +port ' . $port . ' -sv_lan 0 ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
$bash = './srcds_run -debug -game csgo -norestart -condebug console.log -usercon -tickrate ' . $server['tickrate'] . ' ' . $mod . ' +servercfgfile server.cfg ' . $map . ' -maxplayers_override ' . $server['slots_start'] . ' +ip ' . $internalIp . ' +net_public_adr ' . $internalIp . ' +port ' . $port . ' -sv_lan 0 ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp($bash);
|
||||
|
|
|
@ -38,6 +38,7 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
|
@ -86,7 +87,7 @@ class action extends actions
|
|||
$tv = isset($server['tv']) ? '+tv_enable 1 +tv_maxclients 30 +tv_port ' . ($port + 10000) : '-nohltv';
|
||||
|
||||
// Параметры запуска
|
||||
$bash = './srcds_run -debug -game cstrike -norestart -condebug console.log -tickrate ' . $server['tickrate'] . ' +servercfgfile server.cfg +map \'' . $server['map_start'] . '\' +maxplayers ' . $server['slots_start'] . ' +ip ' . $ip . ' +port ' . $port . ' -sv_lan 0 ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
$bash = './srcds_run -debug -game cstrike -norestart -condebug console.log -tickrate ' . $server['tickrate'] . ' +servercfgfile server.cfg +map \'' . $server['map_start'] . '\' +maxplayers ' . $server['slots_start'] . ' +ip ' . $internalIp . ' +port ' . $port . ' -sv_lan 0 ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp($bash);
|
||||
|
|
|
@ -38,6 +38,7 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
|
@ -89,7 +90,7 @@ class action extends actions
|
|||
$fps = $server['fps'] + $cfg['fpsplus'];
|
||||
|
||||
// Параметры запуска
|
||||
$bash = './srcds_run -debug -game cstrike -norestart -condebug console.log -tickrate ' . $server['tickrate'] . ' +fps_max ' . $fps . ' +servercfgfile server.cfg +map \'' . $server['map_start'] . '\' -maxplayers ' . $server['slots_start'] . ' -ip ' . $ip . ' -port ' . $port . ' +sv_lan 0 -nomaster -localcser ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
$bash = './srcds_run -debug -game cstrike -norestart -condebug console.log -tickrate ' . $server['tickrate'] . ' +fps_max ' . $fps . ' +servercfgfile server.cfg +map \'' . $server['map_start'] . '\' -maxplayers ' . $server['slots_start'] . ' -ip ' . $internalIp . ' -port ' . $port . ' +sv_lan 0 -nomaster -localcser ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp($bash);
|
||||
|
|
|
@ -38,13 +38,14 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
. 'lsof -i@' . $server['address'] . ' | awk ' . "'{print $2}'" . ' | grep -v PID | xargs`; sudo -u server' . $server['uid'] . ' screen -wipe;');
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp(action::config($ip, $port, $server['slots_start'], $ssh->get('cat ' . $tarif['install'] . '/' . $server['uid'] . '/server.properties')));
|
||||
$temp = sys::temp(action::config($internalIp, $port, $server['slots_start'], $ssh->get('cat ' . $tarif['install'] . '/' . $server['uid'] . '/server.properties')));
|
||||
|
||||
// Обновление файла server.cfg
|
||||
$ssh->setfile($temp, $tarif['install'] . $server['uid'] . '/server.properties', 0644);
|
||||
|
|
|
@ -38,13 +38,14 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
. 'lsof -i@' . $server['address'] . ' | awk ' . "'{print $2}'" . ' | grep -v PID | xargs`; sudo -u server' . $server['uid'] . ' screen -wipe;');
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp(action::config($ip, $port, $server['slots_start'], $ssh->get('cat ' . $tarif['install'] . '/' . $server['uid'] . '/mods/deathmatch/mtaserver.conf')));
|
||||
$temp = sys::temp(action::config($internalIp, $port, $server['slots_start'], $ssh->get('cat ' . $tarif['install'] . '/' . $server['uid'] . '/mods/deathmatch/mtaserver.conf')));
|
||||
|
||||
// Обновление файла server.cfg
|
||||
$ssh->setfile($temp, $tarif['install'] . $server['uid'] . '/mods/deathmatch/mtaserver.conf', 0644);
|
||||
|
|
|
@ -38,6 +38,7 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
|
@ -104,7 +105,7 @@ class action extends actions
|
|||
$mod = !$server['pingboost'] ? $mods[2] : $mods[$server['pingboost']];
|
||||
|
||||
// Параметры запуска
|
||||
$bash = './RustDedicated -dedicated -debug -norestart -condebug console.log -usercon -ip ' . $ip . ' -port ' . $port . ' -maxplayers ' . $server['slots_start'] . ' -tickrate ' . $server['tickrate'] . ' ' . $mod . ' +servercfgfile server.cfg ' . $map . ' ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
$bash = './RustDedicated -dedicated -debug -norestart -condebug console.log -usercon -ip ' . $internalIp . ' -port ' . $port . ' -maxplayers ' . $server['slots_start'] . ' -tickrate ' . $server['tickrate'] . ' ' . $mod . ' +servercfgfile server.cfg ' . $map . ' ' . $vac . ' ' . $bots . ' ' . $tv;
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp($bash);
|
||||
|
|
|
@ -38,13 +38,14 @@ class action extends actions
|
|||
return array('e' => sys::text('error', 'ssh'));
|
||||
|
||||
list($ip, $port) = explode(':', $server['address']);
|
||||
$internalIp = $ssh->getInternalIp();
|
||||
|
||||
// Убить процессы
|
||||
$ssh->set('kill -9 `ps aux | grep s_' . $server['uid'] . ' | grep -v grep | awk ' . "'{print $2}'" . ' | xargs;'
|
||||
. 'lsof -i@' . $server['address'] . ' | awk ' . "'{print $2}'" . ' | grep -v PID | xargs`; sudo -u server' . $server['uid'] . ' screen -wipe;');
|
||||
|
||||
// Временный файл
|
||||
$temp = sys::temp(action::config($ip, $port, $server['slots_start'], $ssh->get('cat ' . $tarif['install'] . '/' . $server['uid'] . '/server.cfg')));
|
||||
$temp = sys::temp(action::config($internalIp, $port, $server['slots_start'], $ssh->get('cat ' . $tarif['install'] . '/' . $server['uid'] . '/server.cfg')));
|
||||
|
||||
// Обновление файла server.cfg
|
||||
$ssh->setfile($temp, $tarif['install'] . $server['uid'] . '/server.cfg', 0644);
|
||||
|
|
|
@ -18,6 +18,7 @@ class ssh
|
|||
{
|
||||
var $conn;
|
||||
var $stream;
|
||||
private $alternativeInterfaces = ['enp3s0', 'enp0s3', 'ens3', 'eth0'];
|
||||
|
||||
public function auth($passwd, $address)
|
||||
{
|
||||
|
@ -105,6 +106,17 @@ class ssh
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function getInternalIp()
|
||||
{
|
||||
foreach ($this->alternativeInterfaces as $interface) {
|
||||
$command = "ip addr show $interface | grep 'inet ' | awk '{print $2}' | cut -d/ -f1";
|
||||
$internal_ip = $this->get($command);
|
||||
if (!empty(trim($internal_ip))) {
|
||||
return trim($internal_ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ssh = new ssh;
|
||||
|
|
Loading…
Reference in a new issue