.
This commit is contained in:
parent
3343480e11
commit
3de8242305
153
hlna.py
153
hlna.py
@ -1,98 +1,47 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"Модуль для создания и управления серверами Арк"
|
|
||||||
import os
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
import threading
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import colorama
|
import colorama
|
||||||
import datetime
|
|
||||||
|
|
||||||
home_dir = Path.home()
|
home_dir = Path.home()
|
||||||
dir_server = f"{home_dir}/ARK_Servers/"
|
dir_server = f"{home_dir}/ARK_Servers/"
|
||||||
config_hlna = f"{home_dir}/.config/hlna/"
|
config_hlna = f"{home_dir}/.config/hlna/"
|
||||||
mods_id = ""
|
mods_id = ""
|
||||||
listen_server = True
|
listen_server = True
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
def hlna():
|
def hlna():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
list_config = next(os.walk(config_hlna), (None, None, []))[2] # [] if no file
|
list_config = next(os.walk(config_hlna), (None, None, []))[2] # [] if no file
|
||||||
x = list_config.count('.directory')
|
x = list_config.count('.directory')
|
||||||
if x > 0:
|
if x>0:
|
||||||
list_config.remove('.directory')
|
list_config.remove('.directory')
|
||||||
|
|
||||||
|
|
||||||
def logging(l):
|
|
||||||
"Записываем логи в файл"
|
|
||||||
with open(dir_server + "logs", "a") as filelog:
|
|
||||||
now1 = datetime.datetime.today()
|
|
||||||
now1 = now1.strftime("%d-%m %H:%M | ")
|
|
||||||
filelog.write(now1 + l)
|
|
||||||
|
|
||||||
|
|
||||||
def print_line(text):
|
def print_line(text):
|
||||||
"Добавление тире вокруг текста, покраска"
|
"Добавление тире вокруг текста, покраска"
|
||||||
print(colorama.Fore.YELLOW + "-"*30)
|
print(colorama.Fore.YELLOW + "-"*30)
|
||||||
print(colorama.Fore.GREEN + text)
|
print(colorama.Fore.GREEN + text)
|
||||||
print(colorama.Fore.YELLOW + "-"*30 + colorama.Style.RESET_ALL)
|
print(colorama.Fore.YELLOW + "-"*30 + colorama.Style.RESET_ALL)
|
||||||
|
|
||||||
|
|
||||||
def create_dir(directory):
|
def create_dir(directory):
|
||||||
"Проверка и создание директории"
|
"Проверка и создание директории"
|
||||||
try:
|
if not os.path.exists(directory):
|
||||||
if not os.path.exists(directory):
|
os.mkdir(directory)
|
||||||
os.mkdir(directory)
|
|
||||||
except:
|
|
||||||
logging(traceback.format_exc())
|
|
||||||
logging(f"Не удалось создать директорию - {directory}")
|
|
||||||
|
|
||||||
|
|
||||||
def check_int(number=""):
|
def check_int(number=""):
|
||||||
"Проверка на ввод числа"
|
"Проверка на ввод числа"
|
||||||
x=""
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
x = input(number)
|
x = input(number)
|
||||||
if bool(x) == True:
|
if x == "":
|
||||||
x = x.replace(' ', '')
|
|
||||||
x = x.replace(',', '')
|
|
||||||
x = int(x)
|
|
||||||
return x
|
|
||||||
else:
|
|
||||||
return 0
|
return 0
|
||||||
|
x = x.replace(' ', '')
|
||||||
|
x = x.replace(',', '')
|
||||||
|
x = int(x)
|
||||||
|
return x
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logging(traceback.format_exc())
|
|
||||||
logging(f"Не прошла проверка на ввод числа, func(check_int) ввод пользователя {x}")
|
|
||||||
print("Введите число")
|
print("Введите число")
|
||||||
|
|
||||||
|
|
||||||
create_dir(dir_server)
|
create_dir(dir_server)
|
||||||
create_dir(config_hlna)
|
create_dir(config_hlna)
|
||||||
|
|
||||||
|
|
||||||
<<<<<<< HEAD:dodo.py
|
|
||||||
@dodo.command(help='Установка модов, укажите через запятую id модов')
|
|
||||||
@click.option('--id', default="", help='id модификаций из мастерской steam')
|
|
||||||
def modinstall(id, map_server=list_config):
|
|
||||||
print(id)
|
|
||||||
print(type(id))
|
|
||||||
print("Выберите карты, которым добавить моды")
|
|
||||||
map_server=choose_map(map_server)
|
|
||||||
print("map_server=",map_server)
|
|
||||||
print("Перезагрузите сервера для установки модов")
|
|
||||||
|
|
||||||
|
|
||||||
@dodo.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
|
|
||||||
def config(map_server=list_config):
|
|
||||||
=======
|
|
||||||
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
|
@hlna.command(help='Для конфигурирования параметров запускаемого сервера или кластера серверов')
|
||||||
def config(map_server=list_config):
|
def config(map_server=list_config):
|
||||||
query_p = []
|
query_p = []
|
||||||
@ -103,8 +52,6 @@ def config(map_server=list_config):
|
|||||||
data = data[0]
|
data = data[0]
|
||||||
port_s.append(data['Port'])
|
port_s.append(data['Port'])
|
||||||
query_p.append(data['QueryPort'])
|
query_p.append(data['QueryPort'])
|
||||||
|
|
||||||
>>>>>>> master:hlna.py
|
|
||||||
cluster_dir_override = ""
|
cluster_dir_override = ""
|
||||||
cluster_id = ""
|
cluster_id = ""
|
||||||
count_cluster = check_int("""Укажите требуется ли кластер?
|
count_cluster = check_int("""Укажите требуется ли кластер?
|
||||||
@ -120,12 +67,10 @@ def config(map_server=list_config):
|
|||||||
cluster_dir_override = (dir_server + cluster_id)
|
cluster_dir_override = (dir_server + cluster_id)
|
||||||
else:
|
else:
|
||||||
cluster_server = False
|
cluster_server = False
|
||||||
|
|
||||||
if map_server != []:
|
if map_server != []:
|
||||||
print("Уже установленные карты: ")
|
print("Уже установленные карты: ")
|
||||||
for i in map_server:
|
for i in map_server:
|
||||||
print(i)
|
print(i)
|
||||||
|
|
||||||
count_maps = check_int("Укажите количество карт: \n")
|
count_maps = check_int("Укажите количество карт: \n")
|
||||||
if count_maps == 0: # 0 возрвращает check_int когда, ничего не было введено
|
if count_maps == 0: # 0 возрвращает check_int когда, ничего не было введено
|
||||||
count_maps = 1
|
count_maps = 1
|
||||||
@ -176,28 +121,15 @@ def config(map_server=list_config):
|
|||||||
map_server.append("LostIsland")
|
map_server.append("LostIsland")
|
||||||
case 12:
|
case 12:
|
||||||
map_server.append("Fjordur")
|
map_server.append("Fjordur")
|
||||||
|
|
||||||
name_server = input("Укажите название Сервера: \n")
|
name_server = input("Укажите название Сервера: \n")
|
||||||
if name_server == "":
|
if name_server == "":
|
||||||
name_server = map_server[-1]
|
name_server = map_server[-1]
|
||||||
query_p = []
|
|
||||||
port_s = []
|
|
||||||
for i in map_server:
|
|
||||||
try:
|
|
||||||
with open(f"{home_dir}/.config/dodo/{i}", "r") as yamlfile:
|
|
||||||
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
|
||||||
data = data[0]
|
|
||||||
port_s.append(data['Port'])
|
|
||||||
query_p.append(data['QueryPort'])
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
while True:
|
while True:
|
||||||
port_server = check_int("Укажите порт Сервера <7777>: \n")
|
port_server = check_int("Укажите порт Сервера <7777>: \n")
|
||||||
if port_server == 0:
|
if port_server == 0:
|
||||||
if port_s == []:
|
if port_s == []:
|
||||||
port_server = 7777
|
port_server = 7777
|
||||||
else:
|
else:
|
||||||
print()
|
|
||||||
port_server = max(port_s) + 2
|
port_server = max(port_s) + 2
|
||||||
if port_server is port_s: # если веденный порт есть в списке портов
|
if port_server is port_s: # если веденный порт есть в списке портов
|
||||||
print("Этот порт уже занят")
|
print("Этот порт уже занят")
|
||||||
@ -218,12 +150,9 @@ def config(map_server=list_config):
|
|||||||
break
|
break
|
||||||
password_server = input("Укажите пароль Сервера: \n")
|
password_server = input("Укажите пароль Сервера: \n")
|
||||||
max_players = check_int("Укажите максимальное количество игроков: \n")
|
max_players = check_int("Укажите максимальное количество игроков: \n")
|
||||||
if max_players == 0:
|
if max_players == "":
|
||||||
max_players = 70
|
max_players = 70
|
||||||
|
|
||||||
yaml_create(cluster_server, map_server, name_server, port_server, query_port, password_server, max_players, cluster_id, cluster_dir_override)
|
yaml_create(cluster_server, map_server, name_server, port_server, query_port, password_server, max_players, cluster_id, cluster_dir_override)
|
||||||
|
|
||||||
|
|
||||||
def yaml_create(cluster_server, map_server, name_server, port_server, query_port, password_server, max_players, cluster_id, cluster_dir_override):
|
def yaml_create(cluster_server, map_server, name_server, port_server, query_port, password_server, max_players, cluster_id, cluster_dir_override):
|
||||||
settings_hlna = [
|
settings_hlna = [
|
||||||
{
|
{
|
||||||
@ -238,24 +167,16 @@ def yaml_create(cluster_server, map_server, name_server, port_server, query_port
|
|||||||
'ServerPath' : dir_server
|
'ServerPath' : dir_server
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
print(cluster_id)
|
||||||
if cluster_id != None:
|
if cluster_id != None:
|
||||||
settings_hlna[0]['clusterid'] = cluster_id
|
settings_hlna[0]['clusterid'] = cluster_id
|
||||||
settings_hlna[0]['clusterdir'] = cluster_dir_override
|
settings_hlna[0]['clusterdir'] = cluster_dir_override
|
||||||
with open(config_hlna + f"{map_server[-1]}", 'w') as yamlfile:
|
with open(config_hlna + f"{map_server[-1]}", 'w') as yamlfile:
|
||||||
data = yaml.dump(settings_hlna, yamlfile)
|
data = yaml.dump(settings_hlna, yamlfile)
|
||||||
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
|
print(colorama.Fore.GREEN + "Конфиг создан" + colorama.Style.RESET_ALL)
|
||||||
|
|
||||||
|
|
||||||
<<<<<<< HEAD:dodo.py
|
|
||||||
@dodo.command()
|
|
||||||
def servers(map_servers=list_config):
|
|
||||||
if map_servers==[]:
|
|
||||||
=======
|
|
||||||
@hlna.command()
|
@hlna.command()
|
||||||
def servers(map_server=list_config):
|
def servers(map_server=list_config):
|
||||||
if map_server==[]:
|
if map_server==[]:
|
||||||
>>>>>>> master:hlna.py
|
|
||||||
print("Сервера не установлены")
|
print("Сервера не установлены")
|
||||||
else:
|
else:
|
||||||
for i in map_server:
|
for i in map_server:
|
||||||
@ -271,79 +192,41 @@ def servers(map_server=list_config):
|
|||||||
Моды: {mods_id}
|
Моды: {mods_id}
|
||||||
Кластер id: {cluster_id}""")
|
Кластер id: {cluster_id}""")
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
|
|
||||||
@hlna.command(help='Для запуска, сконфигурированного сервера или кластера')
|
@hlna.command(help='Для запуска, сконфигурированного сервера или кластера')
|
||||||
def start(map_server=list_config):
|
def start(map_server=list_config):
|
||||||
if map_server == []:
|
|
||||||
return print("Нет карт для запуска")
|
|
||||||
print("Выберите карты для запуска")
|
|
||||||
map_server = choose_map(map_server)
|
|
||||||
|
|
||||||
for i in map_server:
|
|
||||||
cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride = read_yaml(i)
|
|
||||||
create_dir(dir_server + i)
|
|
||||||
print_line("Качаем карту: " + i)
|
|
||||||
os.system(f"steamcmd +force_install_dir {dir_server + i} +login anonymous +app_update 376030 +quit")
|
|
||||||
print_line("Карта скачана: " + i)
|
|
||||||
def start(i):
|
|
||||||
os.chdir(dir_server + i + "/ShooterGame/Binaries/Linux/")
|
|
||||||
os.system(f"./ShooterGameServer {i}?SessionName={name_server}?Port={port_server}?QueryPort={query_port}?MaxPlayers={max_players}?GameModIds={mods_id}?listen={listen_server} -clusterid={cluster_id} -ClusterDirOverride={cluster_dir_ovverride}")
|
|
||||||
if os.path.exists(dir_server + i + "/ShooterGame/Binaries/Linux/"):
|
|
||||||
threads = threading.Thread(target=start, args=(i,))
|
|
||||||
threads.start()
|
|
||||||
else:
|
|
||||||
print("Сервер не установлен, проверьте, достаточно ли места на диске для установки карты")
|
|
||||||
|
|
||||||
|
|
||||||
def choose_map(map_server):
|
|
||||||
map_choise = []
|
map_choise = []
|
||||||
while True:
|
while True:
|
||||||
"Проверка на выбор имеющихся карт"
|
"Проверка на выбор имеющихся карт"
|
||||||
check = True
|
check = True
|
||||||
for i in range(len(map_server)):
|
for i in range(len(map_server)):
|
||||||
print(f"{i + 1}) {map_server[i]}")
|
print(f"{i+1}) {map_server[i]}")
|
||||||
|
map_list = input("Выбери карты для запуска в формате 1 2 3 или 1,2,3")
|
||||||
map_list = input("Выбери карты в формате 1 2 3 или 1,2,3\n")
|
|
||||||
map_list = map_list.replace(',', ' ')
|
map_list = map_list.replace(',', ' ')
|
||||||
map_list = list(set(map_list.split()))
|
map_list = list(set(map_list.split()))
|
||||||
try:
|
try:
|
||||||
for s in map_list:
|
for s in map_list:
|
||||||
if int(s) > len(map_server):
|
if int(s) > len(map_server):
|
||||||
check = False
|
check = False
|
||||||
if len(map_list) <= len(map_server) and check == True:
|
if len(map_list) <= len(map_server) and check == True:
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
logging(traceback.format_exc())
|
|
||||||
logging(f"Ошибка при выборе карт для запуска, пользователь ввел - {map_list}")
|
|
||||||
print("Неправильный ввод")
|
print("Неправильный ввод")
|
||||||
<<<<<<< HEAD:dodo.py
|
|
||||||
for j in str(map_list):
|
|
||||||
map_choise.append(map_server[int(j) - 1])
|
|
||||||
map_server = map_choise
|
|
||||||
return map_server
|
|
||||||
=======
|
|
||||||
print_line(map_list)
|
print_line(map_list)
|
||||||
for j in map_list:
|
for j in map_list:
|
||||||
print_line(j)
|
print_line(j)
|
||||||
map_choise.append(map_server[int(j) - 1])
|
map_choise.append(map_server[int(j) - 1])
|
||||||
map_server = map_choise
|
map_server = map_choise
|
||||||
|
|
||||||
for i in map_server:
|
for i in map_server:
|
||||||
cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride = read_yaml(i)
|
cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride = read_yaml(i)
|
||||||
create_dir(dir_server + i)
|
create_dir(dir_server + i)
|
||||||
print_line("Качаем карту: " + i)
|
print_line("Качаем карту: " + i)
|
||||||
os.system(f"steamcmd +force_install_dir {dir_server + i} +login anonymous +app_update 376030 +quit")
|
os.system(f"steamcmd +force_install_dir {dir_server + i} +login anonymous +app_update 376030 +quit")
|
||||||
print_line("Карта скачана: " + i)
|
print_line("Карта скачана: " + i)
|
||||||
|
|
||||||
def start(i):
|
def start(i):
|
||||||
os.chdir(dir_server + i + "/ShooterGame/Binaries/Linux/")
|
os.chdir(dir_server + i + "/ShooterGame/Binaries/Linux/")
|
||||||
os.system(f"./ShooterGameServer {i}?SessionName={name_server}?Port={port_server}?QueryPort={query_port}?MaxPlayers={max_players}?GameModIds={mods_id}?listen={listen_server} -clusterid={cluster_id} -ClusterDirOverride={cluster_dir_ovverride}")
|
os.system(f"./ShooterGameServer {i}?SessionName={name_server}?Port={port_server}?QueryPort={query_port}?MaxPlayers={max_players}?GameModIds={mods_id}?listen={listen_server} -clusterid={cluster_id} -ClusterDirOverride={cluster_dir_ovverride}")
|
||||||
threads = threading.Thread(target=start, args=(i,))
|
threads = threading.Thread(target=start, args=(i,))
|
||||||
threads.start()
|
threads.start()
|
||||||
>>>>>>> master:hlna.py
|
|
||||||
|
|
||||||
|
|
||||||
def read_yaml(map_server):
|
def read_yaml(map_server):
|
||||||
with open(f"{home_dir}/.config/hlna/{map_server}", "r") as yamlfile:
|
with open(f"{home_dir}/.config/hlna/{map_server}", "r") as yamlfile:
|
||||||
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
||||||
@ -359,8 +242,8 @@ def read_yaml(map_server):
|
|||||||
cluster_server = data['Cluster']
|
cluster_server = data['Cluster']
|
||||||
cluster_id = data['clusterid']
|
cluster_id = data['clusterid']
|
||||||
cluster_dir_ovverride = data['clusterdir']
|
cluster_dir_ovverride = data['clusterdir']
|
||||||
|
print(cluster_id)
|
||||||
|
print(cluster_dir_ovverride)
|
||||||
return cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride
|
return cluster_server, name_server, port_server, query_port, password_server, max_players, dir_server, mods_id, listen_server, cluster_id, cluster_dir_ovverride
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
hlna()
|
hlna()
|
Loading…
Reference in New Issue
Block a user