Добавлено обновление модов ARK

This commit is contained in:
2023-05-23 22:52:31 +03:00
parent b9c31d22af
commit 61f59cac0c
3 changed files with 154 additions and 130 deletions

192
hlna.py
View File

@ -508,39 +508,39 @@ WantedBy=default.target
@click.argument('id_mods_ark', nargs=-1)
def mod(g, m, i, id_mods_ark):
if g == "ark":
id_game_workshop = "346110"
if not os.path.isdir(dir_mods_ark):
create_dir(dir_mods_ark)
id_mods_ark = id_mods_ark[0].split(',')
for id_mod in id_mods_ark:
dir_ark_mods = f"{dir_mods_ark}/{id_mod}"
if not os.path.isfile(f"{dir_ark_mods}.mod"):
dir_mod_ark = f"{dir_mods_ark}/{id_mod}"
if not os.path.isfile(f"{dir_mod_ark}.mod"):
print_line(f"{dir_mod_ark}.mod")
if i:
moddownload(id_mod, id_game_workshop, dir_ark_mods)
moddownload(id_mod,dir_mod_ark)
else:
os.system(f"rm -rf {dir_ark_mods}")
print_line(f"{dir_ark_mods} удалён")
os.system(f"rm -rf {dir_mod_ark}")
print_line(f"{dir_mod_ark} удалён")
os.system(f"rm {dir_mods_ark}/{id_mod}.mod")
print_line(f"{dir_mods_ark}/{id_mod}.mod удалён")
os.system(f"mv {dir_workshop_ark}/appworkshop_{id_game_workshop}.acf {dir_ark_mods}/appworkshop_{id_game_workshop}.acf")
else:
modupdate(g, m, id_mod, dir_ark_mods)
modupdate(g, m, id_mod, dir_mod_ark)
else:
print_line("Не поддерживаемая игра")
def modupdate(g, m, id_mod, dir_ark_mods):
def modupdate(g, m, id_mod, dir_mod_ark):
if g == "ark":
if not os.path.isfile(os.path.join(dir_ark_mods, f"appworkshop_{id_mod}.acf")):
return
with open(os.path.join(dir_ark_mods, f"appworkshop_{id_mod}.acf"), "r") as f:
# if not os.path.isfile(os.path.join(dir_ark_mods, f"appworkshop_{id_mod}.acf")):
# return
with open(os.path.join(dir_mod_ark, f"appworkshop_346110.acf"), "r") as f:
content = f.readlines()
content = "".join(content)
locale_date = ""
for line in content.split("\n"):
for line in content.splitlines():
if '\t"WorkshopItemsInstalled"' in line:
for line in content.split("\n"):
if f'\t\t"{id_mod}"' in line:
locale_date = line.split('"')[5]
for line in content.splitlines():
if f'\t\t"timeupdated"' in line:
locale_date = line.split('"')[3]
if '}' in line:
break
break
@ -553,82 +553,92 @@ def modupdate(g, m, id_mod, dir_ark_mods):
json_zapros = zapros.json()
steam_date = json_zapros['response']['publishedfiledetails'][0]['time_updated']
if steam_date and locale_date == steam_date:
return
if int(steam_date) != int(locale_date):
moddownload(g, m, id_mod, dir_mod_ark)
else:
print_line(f"Мод {id_mod} обновлен")
if steam_date and locale_date != steam_date:
print_line("хз")
def modupdateall():
def modupdateall(g, m):
print_line("Вход в обновление всех")
for file in os.listdir(dir_mods_ark):
if os.path.isfile(os.path.join(dir_mods_ark, file)):
if file.endswith('.mod'):
print(file)
id_mod = file.split(".")[0]
if id_mod == "111111111":
continue
dir_mod_ark = f"{dir_mods_ark}/{id_mod}"
modupdate(g, m, id_mod, dir_mod_ark)
def moddownload(id_mod, id_game_workshop, dir_ark_mods):
def moddownload(g, m, id_mod, dir_mod_ark):
"""Распаковывает файлы мода и создаёт .mod файл для него"""
dir_steam_workshop = f"{dir_workshop_ark}/content/{id_game_workshop}/{id_mod}/WindowsNoEditor"
dir_extract = dir_ark_mods
if id_mod == "111111111":
return
os.system(f"steamcmd +login anonymous +workshop_download_item {id_game_workshop} {id_mod} +quit")
try:
for curdir, subdirs, files in os.walk(os.path.join(dir_steam_workshop)):
for file in files:
name, ext = os.path.splitext(file)
if ext == ".z":
src = os.path.join(curdir, file)
dst = os.path.join(curdir, name)
uncompressed = os.path.join(curdir, file + ".uncompressed_size")
unpack(src, dst)
print("[+] Extracted " + file)
os.remove(src)
if os.path.isfile(uncompressed):
os.remove(uncompressed)
except Exception as e:
print(e)
print("[x] Unpacking .z files failed, aborting mod install")
return False
if g == "ark":
id_game_workshop = "346110"
dir_steam_workshop = f"{dir_workshop_ark}/content/{id_game_workshop}/{id_mod}/WindowsNoEditor"
dir_extract = dir_mod_ark
if id_mod == "111111111":
return
if os.path.isfile(f"{dir_workshop_ark}/appworkshop_{id_game_workshop}.acf"):
os.system(f"rm {dir_workshop_ark}/appworkshop_{id_game_workshop}.acf")
os.system(f"steamcmd +login anonymous +workshop_download_item {id_game_workshop} {id_mod} +quit")
try:
for curdir, subdirs, files in os.walk(os.path.join(dir_steam_workshop)):
for file in files:
name, ext = os.path.splitext(file)
if ext == ".z":
src = os.path.join(curdir, file)
dst = os.path.join(curdir, name)
uncompressed = os.path.join(curdir, file + ".uncompressed_size")
unpack(src, dst)
print("[+] Extracted " + file)
os.remove(src)
if os.path.isfile(uncompressed):
os.remove(uncompressed)
except Exception as e:
print(e)
print("[x] Unpacking .z files failed, aborting mod install")
return False
os.system(f"rm -rf {dir_ark_mods}")
os.system(f"mv -f {dir_steam_workshop} {dir_ark_mods}")
os.system(f"rm -rf {dir_mod_ark}")
os.system(f"mv -f {dir_steam_workshop} {dir_mod_ark}")
modname = subprocess.check_output(
['curl', '-s', f'https://steamcommunity.com/sharedfiles/filedetails/?id={id_mod}']).decode('utf-8')
modname = re.search(r'<div class="workshopItemTitle">(.+)</div>', modname)
modname = modname and modname.group(1)
modname = subprocess.check_output(
['curl', '-s', f'https://steamcommunity.com/sharedfiles/filedetails/?id={id_mod}']).decode('utf-8')
modname = re.search(r'<div class="workshopItemTitle">(.+)</div>', modname)
modname = modname and modname.group(1)
if os.path.isfile(f"{dir_ark_mods}.mod"):
os.remove(f"{dir_ark_mods}.mod")
if os.path.isfile(f"{dir_mod_ark}.mod"):
os.remove(f"{dir_mod_ark}.mod")
with open(f"{dir_extract}/mod.info", "rb") as modinfo:
data = modinfo.read()
mapnamelen = struct.unpack_from("<L", data, 0)[0]
mapname = data[4:mapnamelen + 3]
nummaps = struct.unpack_from("<L", data, mapnamelen + 4)[0]
pos = mapnamelen + 8
modname = (modname.encode() or mapname.decode()) + b'\x00'
modnamelen = len(modname)
modpath = b"../../../" + dir_shooter.encode() + b"/Content/Mods/" + id_mod.encode() + b'\x00'
modpathlen = len(modpath)
with open(f"{dir_ark_mods}.mod", "wb") as mod:
mod.write(struct.pack(f'<LLL{modnamelen}sL{modpathlen}sL', int(id_mod), 0, modnamelen, modname,
modpathlen, modpath, nummaps))
for mapnum in range(nummaps):
mapfilelen = struct.unpack_from("<L", data, pos)[0]
mapfile = data[mapnamelen + 12:mapnamelen + 12 + mapfilelen]
mod.write(struct.pack("<L%ds" % mapfilelen, mapfilelen, mapfile))
pos = pos + 4 + mapfilelen
mod.write(b"\x33\xFF\x22\xFF\x02\x00\x00\x00\x01")
with open(f"{dir_extract}/mod.info", "rb") as modinfo:
data = modinfo.read()
mapnamelen = struct.unpack_from("<L", data, 0)[0]
mapname = data[4:mapnamelen + 3]
nummaps = struct.unpack_from("<L", data, mapnamelen + 4)[0]
pos = mapnamelen + 8
modname = (modname.encode() or mapname.decode()) + b'\x00'
modnamelen = len(modname)
modpath = b"../../../" + dir_shooter.encode() + b"/Content/Mods/" + id_mod.encode() + b'\x00'
modpathlen = len(modpath)
with open(f"{dir_mod_ark}.mod", "wb") as mod:
mod.write(struct.pack(f'<LLL{modnamelen}sL{modpathlen}sL', int(id_mod), 0, modnamelen, modname,
modpathlen, modpath, nummaps))
for mapnum in range(nummaps):
mapfilelen = struct.unpack_from("<L", data, pos)[0]
mapfile = data[mapnamelen + 12:mapnamelen + 12 + mapfilelen]
mod.write(struct.pack("<L%ds" % mapfilelen, mapfilelen, mapfile))
pos = pos + 4 + mapfilelen
mod.write(b"\x33\xFF\x22\xFF\x02\x00\x00\x00\x01")
if os.path.isfile(os.path.join(dir_extract, "modmeta.info")):
with open(os.path.join(dir_extract, "modmeta.info"), "rb") as f:
with open(f"{dir_extract}.mod", "ab") as f_out:
f_out.write(f.read())
else:
with open(f"{dir_mods_ark}.mod", "wb") as f_out:
f_out.write(b'\x01\x00\x00\x00\x08\x00\x00\x00ModType\x00\x02\x00\x00\x001\x00')
if os.path.isfile(os.path.join(dir_extract, "modmeta.info")):
with open(os.path.join(dir_extract, "modmeta.info"), "rb") as f:
with open(f"{dir_extract}.mod", "ab") as f_out:
f_out.write(f.read())
else:
with open(f"{dir_mods_ark}.mod", "wb") as f_out:
f_out.write(b'\x01\x00\x00\x00\x08\x00\x00\x00ModType\x00\x02\x00\x00\x001\x00')
x = os.system(f"mv {dir_workshop_ark}/appworkshop_{id_game_workshop}.acf {dir_mod_ark}/appworkshop_{id_game_workshop}.acf")
@hlna.command(help='Выключение/включение серверов (без удаления) <hlna switch -m all -d')
@ -734,6 +744,7 @@ def start(g, m):
"""Запускает сервер выбранной игры"""
# добавить проверку на ввод аргумента ark/7day если else: давать подсказку
# если нет конфигов, то выводим что серверов нет
modupdateall(g, m)
start_stop("start", g, m)
@ -748,6 +759,7 @@ def stop(g, m):
@click.option('-g', required=True, help="Название игры для запуска. (ark, 7days")
@click.option('-m', default='all', help="Название карты для запуска или all для запуска все карт")
def restart(g, m):
modupdateall(g, m)
start_stop("restart", g, m)
@ -785,9 +797,8 @@ def start_stop(action, g, m, list_config=list_config):
names_serverstart = choose_map(names_serverstart)
for i in names_serverstart:
data = read_yaml(i, game="ARK")
if stop or restart:
y = os.system(
f"~/git/hln-a/hlna.py rcon SaveWorld -m {i}") if action == "restart" or action == "stop" else ""
if action == "stop" or action == "restart":
rcon_local(i, "SaveWorld")
x = os.system(f"systemctl --user {action} ark_{data['SessionName'].lower()}.service")
if x == 0:
@ -839,6 +850,10 @@ def choose_map(arr):
@click.argument('c', nargs=1)
@click.option('-m', required=True, help="Название карты для применения rcon команды")
def rcon(m, c):
rcon_local(m, c)
def rcon_local(m, c):
try:
dict_mapname = {}
dict_adminpwd = {}
@ -864,7 +879,7 @@ def rcon(m, c):
else:
pass
except:
print(f"Ошибка отправки команды в {m}", flag=False)
print_line(f"Ошибка отправки команды {c} в {m}", flag=False)
def zero(x=""):
@ -900,10 +915,17 @@ create_dir(dir_unit)
create_dir(dir_logs)
class HlnaApp(QtWidgets.QMainWindow, hlnaui.Ui_MainWindow):
class HlnaApp(QtWidgets.QMainWindow, hlnaui.Ui_mainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.lineEdit_ARK.returnPressed.connect(self.printable)
def printable(self):
namesession = self.lineEdit_ARK.text()
print_line(namesession)
def hlnag():
if len(sys.argv) > 1: