ещё что-то сделал)
This commit is contained in:
parent
a355809e5f
commit
6faedaba52
44
hlna.py
44
hlna.py
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
|
import datetime
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import click
|
import click
|
||||||
@ -10,15 +11,18 @@ from rcon.source import Client
|
|||||||
|
|
||||||
home_dir = Path.home()
|
home_dir = Path.home()
|
||||||
dir_server = f"{home_dir}/Servers/"
|
dir_server = f"{home_dir}/Servers/"
|
||||||
dir_server_ark = f"{dir_server}/ARK"
|
dir_server_ark = f"{dir_server}/ARK/"
|
||||||
server_dir = dir_server + "ShooterGame/Binaries/Linux/"
|
server_dir = f"{dir_server_ark}ShooterGame/Binaries/Linux/"
|
||||||
dir_unit = f"{home_dir}/.config/systemd/user/"
|
dir_unit = f"{home_dir}/.config/systemd/user/"
|
||||||
dir_config = f"{home_dir}/.config/hlna/"
|
dir_config = f"{home_dir}/.config/hlna/"
|
||||||
dir_logs = f"{dir_config}logs"
|
dir_logs = f"{dir_config}logs/"
|
||||||
dir_maps = f"{dir_config}maps/"
|
dir_maps = f"{dir_config}maps/"
|
||||||
dir_deactivated = f"{dir_maps}deactivated/"
|
dir_deactivated = f"{dir_maps}deactivated/"
|
||||||
|
|
||||||
mods_id = ""
|
mods_id = ""
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
date = now.strftime("%Y-%m-%d")
|
||||||
|
time = now.strftime("%H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@ -38,7 +42,6 @@ create_dir(dir_unit)
|
|||||||
create_dir(dir_config)
|
create_dir(dir_config)
|
||||||
create_dir(dir_logs)
|
create_dir(dir_logs)
|
||||||
create_dir(dir_maps)
|
create_dir(dir_maps)
|
||||||
create_dir(dir_deactivated)
|
|
||||||
|
|
||||||
|
|
||||||
def find_file(path):
|
def find_file(path):
|
||||||
@ -298,7 +301,7 @@ After=syslog.target network.target nss-lookup.target network-online.target
|
|||||||
[Service]
|
[Service]
|
||||||
ExecStartPre=/usr/bin/steamcmd +force_install_dir {dir_server} +login anonymous +app_update 376030 +quit
|
ExecStartPre=/usr/bin/steamcmd +force_install_dir {dir_server} +login anonymous +app_update 376030 +quit
|
||||||
TimeoutStartSec=1200
|
TimeoutStartSec=1200
|
||||||
ExecStart={server_dir}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}
|
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}
|
||||||
LimitNOFILE=100000
|
LimitNOFILE=100000
|
||||||
ExecReload=/bin/kill -s HUP $MAINPID
|
ExecReload=/bin/kill -s HUP $MAINPID
|
||||||
ExecStop=/bin/kill -s INT $MAINPID
|
ExecStop=/bin/kill -s INT $MAINPID
|
||||||
@ -331,10 +334,11 @@ test_mod_install()
|
|||||||
@click.option("-m", required=True, help="Название Сервера")
|
@click.option("-m", required=True, help="Название Сервера")
|
||||||
@click.option("-e/-d", default=True, help="-e активировать карты, -d деактивировать")
|
@click.option("-e/-d", default=True, help="-e активировать карты, -d деактивировать")
|
||||||
def enablemap(m, e):
|
def enablemap(m, e):
|
||||||
"""Тут переписать надо"""
|
"""Включение/выключение карт"""
|
||||||
|
|
||||||
m = m.split(",")
|
m = m.split(",")
|
||||||
# m = check_name_map(m, False)
|
if not os.path.isdir(dir_deactivated):
|
||||||
create_dir(dir_config + "deactivated")
|
create_dir(dir_deactivated)
|
||||||
if e == True:
|
if e == True:
|
||||||
port_s = []
|
port_s = []
|
||||||
query_p = []
|
query_p = []
|
||||||
@ -350,26 +354,32 @@ def enablemap(m, e):
|
|||||||
data = read_yaml(i)
|
data = read_yaml(i)
|
||||||
if data['Port'] in port_s:
|
if data['Port'] in port_s:
|
||||||
print("Предлагаем заменить")
|
print("Предлагаем заменить")
|
||||||
|
continue
|
||||||
if data['QueryPort'] in query_p:
|
if data['QueryPort'] in query_p:
|
||||||
print("Заменить query port?")
|
print("Заменить query port?")
|
||||||
x = os.system(
|
continue
|
||||||
f"mv {dir_config}deactivated/{i} {dir_config + i} 2>> {dir_config}logs") # Добавить текущее время
|
x = os.system(f"mv {dir_deactivated}{i} {dir_maps} >> {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")
|
||||||
if x == 0:
|
if x == 0:
|
||||||
print(f"Карта активирована - {i}")
|
print(f"Карта активирована - {i}")
|
||||||
else:
|
else:
|
||||||
print(f"{i} либо уже активирована, либо такой карты нет")
|
print(f"{i} либо уже активирована, либо такой карты нет")
|
||||||
except:
|
finally:
|
||||||
print("ошибка")
|
|
||||||
pass
|
pass
|
||||||
|
# except:
|
||||||
|
# print("ошибка при активации карты")
|
||||||
|
# pass
|
||||||
else:
|
else:
|
||||||
|
|
||||||
for i in m:
|
for i in m:
|
||||||
try:
|
try:
|
||||||
if i in delist_config:
|
if i in delist_config:
|
||||||
print(f"Карта {i} уже есть в деактивированных")
|
print(f"Карта {i} уже есть в деактивированных")
|
||||||
continue
|
continue
|
||||||
x = os.system(
|
x = os.system(
|
||||||
f"mv {dir_config + i} {dir_config}deactivated/{i} 2>> {dir_config}logs") # Добавить текущее время
|
f"mv {dir_maps}{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:
|
if x == 0:
|
||||||
print(f"Карта деактивирована - {i}")
|
print(f"Карта деактивирована - {i}")
|
||||||
else:
|
else:
|
||||||
@ -458,12 +468,12 @@ def start(m, b, name_server=list_config):
|
|||||||
print("Ни одной карты не установлено")
|
print("Ни одной карты не установлено")
|
||||||
|
|
||||||
|
|
||||||
def read_yaml(name_server, flag=True):
|
def read_yaml(list_config, flag=True):
|
||||||
# Читаем конфиги активных или неактивных карт в зависимости от флага
|
# Читаем конфиги активных или неактивных карт в зависимости от флага
|
||||||
if flag:
|
if flag:
|
||||||
dirs = f"{dir_maps}{name_server}"
|
dirs = f"{dir_maps}{list_config}"
|
||||||
else:
|
else:
|
||||||
dirs = f"{home_dir}/.config/hlna/deactivated/{name_server}"
|
dirs = f"{dir_deactivated}{list_config}"
|
||||||
with open(dirs, "r") as yamlfile:
|
with open(dirs, "r") as yamlfile:
|
||||||
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
||||||
return data[0] # возвращаем словарь со всеми значениями
|
return data[0] # возвращаем словарь со всеми значениями
|
||||||
|
Loading…
Reference in New Issue
Block a user