diff --git a/hlna.py b/hlna.py index ffb6310..a715836 100755 --- a/hlna.py +++ b/hlna.py @@ -14,7 +14,7 @@ from rcon.source import Client home_dir = Path.home() dir_server = f"{home_dir}/ARK_Servers/" -dir_config = f"{home_dir}/.config/hlna/" +dir_config = f"{home_dir}/.config/hlna/maps/" mods_id = "" listen_server = True @@ -51,7 +51,8 @@ def create_dir(directory): """Проверка и создание директории""" if not os.path.exists(directory): os.mkdir(directory) - os.chdir("..") + if not os.path.exists(f"{home_dir}/.config/hlna/maps"): + os.chdir(f"{home_dir}/.config/hlna/") os.mkdir("maps") @@ -214,7 +215,7 @@ def config(list_config=list_config): if query_port == 0: query_port = 27015 - print("Порт Сервера=",port_server) + print("Порт Сервера=", port_server) print("Query Port=", query_port) rcon_enabled = True @@ -373,18 +374,21 @@ def start(m, name_server=list_config): print("Запускаем все активные карты") names_serverstart = choose_map(names_serverstart) - server_dir = dir_server + "/ShooterGame/Binaries/Linux/" + server_dir = dir_server + "ShooterGame/Binaries/Linux/" print_line("Валидация файлов сервера") - x = os.system(f"steamcmd +force_install_dir {server_dir} +login anonymous +app_update 376030 +quit") + x = os.system(f"steamcmd +force_install_dir {dir_server} +login anonymous +app_update 376030 +quit") os.chdir(server_dir) for i in names_serverstart: data = read_yaml(i) starting_map = dict_mapname[i] + print_line(data['Cluster']) + if not data['Cluster']: + ntff = "" + else: + ntff = "-NoTransferFromFiltering" def starting(i): - os.system( - f"./ShooterGameServer {i}?SessionName={data['SessionName']}?Port={data['Port']}?QueryPort={data['QueryPort']}?RCONEnabled={data['RCONEnabled']}?RCONPort={data['RCONPort']}?ServerAdminPassword={data['ServerAdminPassword']}?multihome=127.0.0.1?MaxPlayers={data['MaxPlayers']}?GameModIds={data['ModsId']}?listen={data['Listen']} -clusterid={data['clusterid']} -ClusterDirOverride={data['clusterdir']} -NoTransferFromFiltering") - + os.system(f"{server_dir}ShooterGameServer {i}?SessionName={data['SessionName']}?Port={data['Port']}?QueryPort={data['QueryPort']}?RCONEnabled={data['RCONEnabled']}?RCONPort={data['RCONPort']}?ServerAdminPassword={data['ServerAdminPassword']}?MaxPlayers={data['MaxPlayers']}?GameModIds={data['ModsId']}?listen={data['Listen']} -clusterid={data['clusterid']} -ClusterDirOverride={data['clusterdir']} {ntff}") if x == 0: print_line("Запускаем карту" + i) threads = threading.Thread(target=starting, args=(starting_map,)) @@ -413,7 +417,7 @@ def delete(m, list_config=list_config): def read_yaml(name_server, flag=True): # Читаем конфиги активных или неактивных карт в зависимости от флага if flag == True: - dirs = f"{home_dir}/.config/hlna/{name_server}" + dirs = f"{home_dir}/.config/hlna/maps/{name_server}" else: dirs = f"{home_dir}/.config/hlna/deactivated/{name_server}" with open(dirs, "r") as yamlfile: diff --git a/hlna_bot.py b/hlna_bot.py index 7c840ef..81cd1b4 100755 --- a/hlna_bot.py +++ b/hlna_bot.py @@ -10,12 +10,12 @@ import colorama import hlna list_config = hlna.list_config - +hlna.print_line(list_config) def start(): - if not os.path.exists(f"{hlna.dir_config}bot/hlna_bot"): + if not os.path.exists(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot"): key_api = input("Укажите ключ бота\n") - os.chdir(hlna.dir_config) + os.chdir(f"{hlna.home_dir}/.config/hlna/") try: os.mkdir("bot") except OSError as e: @@ -31,12 +31,12 @@ def start(): elif x == "y": read_config() elif x == "n": - os.remove(f"{hlna.dir_config}bot/hlna_bot") + os.remove(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot") start() def read_config(): - with open(f"{hlna.dir_config}bot/hlna_bot", "r") as yamlfile: + with open(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot", "r") as yamlfile: data = yaml.load(yamlfile, Loader=yaml.FullLoader) return data[0] @@ -48,7 +48,7 @@ def create_config(key_api): 'key_api': k_api, } ] - with open(f"{hlna.dir_config}bot/hlna_bot", 'w') as yamlfile: + with open(f"{hlna.home_dir}/.config/hlna/bot/hlna_bot", 'w') as yamlfile: yaml.dump(config_hlna_bot, yamlfile) print(colorama.Fore.GREEN + "Конфиг бота создан" + colorama.Style.RESET_ALL) return k_api @@ -93,18 +93,33 @@ def m_chose(m): reply_markup=menu_install) hlna_bot.register_next_step_handler(m, m_install) else: - hlna.read_yaml(list_config, flag=True) + hlna.read_yaml(list_config[-1], flag=True) menu_start = types.ReplyKeyboardMarkup(resize_keyboard=True) for i in list_config: - k_mapname = types.KeyboardButton(f"{i}") + k_mapname = types.KeyboardButton(i) menu_start.add(k_mapname) k_back = types.KeyboardButton("Назад") menu_start.add(k_back) hlna_bot.send_message(m.chat.id, text="{0.first_name}, выбери карту".format(m.from_user), reply_markup=menu_start) + elif (m.text.strip() == '🧾 Статус'): + for i in list_config: + data = hlna.read_yaml(i) + x = os.system(f"lsof -w -i :{data['Port']}") + n_srv = data['SessionName'] + if x != 0: + hlna_bot.send_message(m.chat.id, text=f"Сервер {n_srv} не работает 🛑") + while x != 0: + time.sleep(5) + x = os.system("lsof -w -i :7778") + hlna_bot.send_message(m.chat.id, text="Сервер запустился 🟢".format( + m.from_user)) + # elif x == 0: + # time.sleep(30) + # pass elif m.text.strip() == 'Назад': m_start(m) - # elif m.text.strip() == 'TheIsland': - # hlna.start() + elif m.text.strip() == 'TheIsland': + hlna.start() def m_install(m): @@ -125,14 +140,7 @@ hlna_bot.polling(none_stop=True, interval=0, timeout=999) # subprocess.run(["arkmanager","restart", "--alwaysrestart", "--warn", "@all"]) # elif (m.text.strip() == '🔸 Обновить'): # subprocess.run(["arkmanager", "update", "--update-mods", "@all"]) -# elif (m.text.strip() == '🧾 Статус'): -# x = os.system("lsof -w -i :7777") -# if x!=0: -# bot.send_message(m.chat.id, text="Сервер не работает 🛑".format( -# m.from_user)) -# else: -# bot.send_message(m.chat.id, text="Сервер работает 🟢".format( -# m.from_user)) +# # # elif (m.text.strip() == '⏬ Установка модов'): # bot.send_message(m.from_user.id, "Введите id модификации")