добавлен 7DaystoDie
This commit is contained in:
parent
71cef7bc70
commit
32f73457c7
95
hlna.py
95
hlna.py
@ -10,14 +10,21 @@ from pathlib import Path
|
||||
from rcon.source import Client
|
||||
|
||||
home_dir = Path.home()
|
||||
dir_server = f"{home_dir}/Servers/"
|
||||
dir_server_ark = f"{dir_server}/ARK/"
|
||||
server_dir = f"{dir_server_ark}ShooterGame/Binaries/Linux/"
|
||||
dir_unit = f"{home_dir}/.config/systemd/user/"
|
||||
dir_config = f"{home_dir}/.config/hlna/"
|
||||
dir_unit = f"{home_dir}/.config/systemd/user/"
|
||||
dir_server = f"{home_dir}/Servers/"
|
||||
dir_logs = f"{dir_config}logs/"
|
||||
dir_maps = f"{dir_config}maps/"
|
||||
dir_deactivated = f"{dir_maps}deactivated/"
|
||||
|
||||
dir_server_ark = f"{dir_server}/ARK/"
|
||||
dir_server_ark = f"{dir_server_ark}ShooterGame/Binaries/Linux/"
|
||||
|
||||
|
||||
dir_maps_ark = f"{dir_config}/ARK"
|
||||
dir_deactivated = f"{dir_maps_ark}deactivated/"
|
||||
|
||||
dir_server_7days = f"{dir_server}/7Days/"
|
||||
|
||||
|
||||
|
||||
mods_id = ""
|
||||
now = datetime.datetime.now()
|
||||
@ -37,11 +44,11 @@ def create_dir(directory):
|
||||
|
||||
|
||||
create_dir(dir_server)
|
||||
create_dir(dir_server_ark)
|
||||
create_dir(dir_unit)
|
||||
create_dir(dir_config)
|
||||
create_dir(dir_logs)
|
||||
create_dir(dir_maps)
|
||||
|
||||
|
||||
|
||||
|
||||
def find_file(path):
|
||||
@ -56,7 +63,7 @@ def find_file(path):
|
||||
return arr
|
||||
|
||||
|
||||
list_config = find_file(dir_maps)
|
||||
list_config = find_file(dir_maps_ark)
|
||||
delist_config = find_file(dir_deactivated)
|
||||
|
||||
|
||||
@ -83,17 +90,23 @@ def check_int(number=""):
|
||||
@hlna.command(help='Сбор настроек для сервера или кластера')
|
||||
def config():
|
||||
while True:
|
||||
count_server = check_int("""Выберите игру для конфигурирования
|
||||
count_game = check_int("""Выберите игру для конфигурирования
|
||||
1. ARK Survival Evolved
|
||||
2. 7 Days to Die
|
||||
: """)
|
||||
if count_server == 1:
|
||||
if count_game == 1:
|
||||
config_ark()
|
||||
break
|
||||
elif count_game == 2:
|
||||
config_7daystodie()
|
||||
break
|
||||
else:
|
||||
print_line("Пока есть только ARK xD")
|
||||
print_line("Пока есть только ARK и 7Days xD")
|
||||
|
||||
|
||||
def config_ark(list_config=list_config):
|
||||
create_dir(dir_server_ark)
|
||||
create_dir(dir_maps_ark)
|
||||
"""Сбор данных для конфига"""
|
||||
data = {}
|
||||
port_s = []
|
||||
@ -254,11 +267,30 @@ def config_ark(list_config=list_config):
|
||||
else:
|
||||
listen_server = True
|
||||
|
||||
yaml_create(cluster_server, map_s, list_config[-1], port_server, query_port, rcon_enabled, rcon_port,
|
||||
yaml_create(game:="ARK", cluster_server, map_s, list_config[-1], port_server, query_port, rcon_enabled, rcon_port,
|
||||
adminpassword_server, password_server, max_players, cluster_id, cluster_dir_override, listen_server)
|
||||
|
||||
|
||||
def yaml_create(cluster_server, map_s, name_server, port_server, query_port, rcon_enabled, rcon_port,
|
||||
def config_7daystodie():
|
||||
list_simvols = "$@-.%{}+/".split()
|
||||
create_dir(dir_server_7days)
|
||||
print("Введите имя конфига (serverconfig):\n")
|
||||
config_7days = input()
|
||||
if config_7days == "":
|
||||
config_7days = "serverconfig"
|
||||
elif config_7days == "serverconfig":
|
||||
config_7days = "serverconfig"
|
||||
elif config_7days in list_simvols:
|
||||
print_line("Запрещённые символы")
|
||||
else:
|
||||
xml_parser()
|
||||
systemd_unit_create(game:="7Days", config_7days)
|
||||
|
||||
|
||||
def xml_parser():
|
||||
print("Я не умею парсить))")
|
||||
|
||||
def yaml_create(game, cluster_server, map_s, name_server, port_server, query_port, rcon_enabled, rcon_port,
|
||||
adminpassword_server, password_server, max_players, cluster_id, cluster_dir_override, listen_server):
|
||||
settings_hlna = [
|
||||
{
|
||||
@ -279,26 +311,35 @@ def yaml_create(cluster_server, map_s, name_server, port_server, query_port, rco
|
||||
'clusterdir': cluster_dir_override
|
||||
}
|
||||
]
|
||||
with open(dir_maps + f"{name_server}", 'w') as yamlfile:
|
||||
with open(dir_maps_ark + f"{name_server}", 'w') as yamlfile:
|
||||
yaml.dump(settings_hlna, yamlfile)
|
||||
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
|
||||
systemd_unit_create()
|
||||
systemd_unit_create(game)
|
||||
|
||||
|
||||
def systemd_unit_create(name_server=list_config):
|
||||
def systemd_unit_create(game, config_7days="", name_server=list_config):
|
||||
if game == "ARK":
|
||||
id_game = "376030"
|
||||
for i in name_server:
|
||||
data = read_yaml(i)
|
||||
ntff = "" if not data['Cluster'] else "-NoTransferFromFiltering"
|
||||
systemd_unit_exec = f"{dir_server_ark}ShooterGameServer {data['map']}?listen={data['Listen']}?SessionName={data['SessionName']}?Port={data['Port']}?QueryPort={data['QueryPort']}?RCONEnabled={data['RCONEnabled']}?RCONPort={data['RCONPort']}?ServerAdminPassword={data['ServerAdminPassword']}?MaxPlayers={data['MaxPlayers']} -clusterid={data['clusterid']} -ClusterDirOverride={data['clusterdir']} {ntff}"
|
||||
unit_file = f"{dir_unit}ARK_{data['SessionName']}.service"
|
||||
elif game == "7Days":
|
||||
id_game = "294420"
|
||||
#сюда дописать обращение к xml для получения уникального имени сервера
|
||||
systemd_unit_exec = f"{dir_server_7days}startserver.sh -configfile={config_7days}.xml"
|
||||
unit_file = f"{dir_unit}7Days.service"
|
||||
|
||||
unit_text = f'''[Unit]
|
||||
Description=ARK: Survival Evolved dedicated server - {data['map']}
|
||||
Description={game}: Server
|
||||
Wants=network-online.target
|
||||
After=syslog.target network.target nss-lookup.target network-online.target
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/usr/bin/steamcmd +force_install_dir {dir_server} +login anonymous +app_update 376030 +quit
|
||||
TimeoutStartSec=1200
|
||||
ExecStart={dir_server_ark}ShooterGameServer {data['map']}?listen={data['Listen']}?SessionName={data['SessionName']}?Port={data['Port']}?QueryPort={data['QueryPort']}?RCONEnabled={data['RCONEnabled']}?RCONPort={data['RCONPort']}?ServerAdminPassword={data['ServerAdminPassword']}?MaxPlayers={data['MaxPlayers']} -clusterid={data['clusterid']} -ClusterDirOverride={data['clusterdir']} {ntff}
|
||||
ExecStartPre=/usr/bin/steamcmd +force_install_dir {dir_server} +login anonymous +app_update {id_game} +quit
|
||||
TimeoutStartSec=99999
|
||||
ExecStart={systemd_unit_exec}
|
||||
LimitNOFILE=100000
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
ExecStop=/bin/kill -s INT $MAINPID
|
||||
@ -308,8 +349,8 @@ WantedBy=default.target
|
||||
'''
|
||||
with open(unit_file, 'w') as systemd_unit:
|
||||
systemd_unit.write(unit_text)
|
||||
os.system(f"systemctl --user unmask ARK_{data['SessionName']}.service")
|
||||
os.system(f"systemctl --user enable ARK_{data['SessionName']}.service")
|
||||
os.system(f"systemctl --user unmask {unit_file}")
|
||||
os.system(f"systemctl --user enable {unit_file}")
|
||||
os.system('systemctl --user daemon-reload')
|
||||
|
||||
|
||||
@ -354,9 +395,9 @@ def enablemap(m, e):
|
||||
if data['QueryPort'] in query_p:
|
||||
print("Заменить query port?")
|
||||
continue
|
||||
x = os.system(f"mv {dir_deactivated}{i} {dir_maps} >> {dir_logs}{date} 2>&1") # Добавить текущее время
|
||||
x = os.system(f"mv {dir_deactivated}{i} {dir_maps_ark} >> {dir_logs}{date} 2>&1") # Добавить текущее время
|
||||
with open(f"{dir_logs}{date}.log", "a") as f:
|
||||
f.write(f"[{time}] File {i} has been moved to {dir_maps}\n")
|
||||
f.write(f"[{time}] File {i} has been moved to {dir_maps_ark}\n")
|
||||
if x == 0:
|
||||
print(f"Карта активирована - {i}")
|
||||
else:
|
||||
@ -373,7 +414,7 @@ def enablemap(m, e):
|
||||
print(f"Карта {i} уже есть в деактивированных")
|
||||
continue
|
||||
x = os.system(
|
||||
f"mv {dir_maps}{i} {dir_deactivated} >> {dir_logs}{date} 2>&1") # Добавить текущее время
|
||||
f"mv {dir_maps_ark}{i} {dir_deactivated} >> {dir_logs}{date} 2>&1") # Добавить текущее время
|
||||
with open(f"{dir_logs}{date}.log", "a") as f:
|
||||
f.write(f"[{time}] File {i} has been moved to {dir_deactivated}\n")
|
||||
if x == 0:
|
||||
@ -466,7 +507,7 @@ def start(m, b, name_server=list_config):
|
||||
|
||||
def read_yaml(list_config, flag=True):
|
||||
# Читаем конфиги активных или неактивных карт в зависимости от флага
|
||||
dirs = f"{dir_maps}{list_config}" if flag else f"{dir_deactivated}{list_config}"
|
||||
dirs = f"{dir_maps_ark}{list_config}" if flag else f"{dir_deactivated}{list_config}"
|
||||
with open(dirs, "r") as yamlfile:
|
||||
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
||||
return data[0] # возвращаем словарь со всеми значениями
|
||||
|
Loading…
Reference in New Issue
Block a user