запуск с одной директории
This commit is contained in:
parent
03da3ffa1c
commit
1e25eac454
75
hlna.py
75
hlna.py
@ -61,8 +61,6 @@ def check_int(number=""):
|
||||
x = input(number)
|
||||
if x == "":
|
||||
return 0
|
||||
x = x.replace(' ', '')
|
||||
x = x.replace(',', '')
|
||||
x = int(x)
|
||||
return x
|
||||
except ValueError:
|
||||
@ -189,7 +187,6 @@ def config(list_config=list_config):
|
||||
if map_s in list_config:
|
||||
count = 1
|
||||
new_name = map_s
|
||||
print(list_config)
|
||||
while new_name in list_config:
|
||||
new_name = f"{map_s}({str(count)})"
|
||||
count += 1
|
||||
@ -214,33 +211,10 @@ def config(list_config=list_config):
|
||||
port_server = 7777
|
||||
if query_port == 0:
|
||||
query_port = 27015
|
||||
|
||||
print("Порт Сервера=",port_server)
|
||||
print("Query Port=", query_port)
|
||||
'''
|
||||
while True:
|
||||
port_server = check_int("Укажите порт Сервера <7777>: \n")
|
||||
if port_server == 0:
|
||||
if port_s == []:
|
||||
port_server = 7777
|
||||
else:
|
||||
port_server = max(port_s) + 2
|
||||
if port_server is port_s: # если веденный порт есть в списке портов
|
||||
print("Этот порт уже занят")
|
||||
else:
|
||||
break
|
||||
|
||||
while True:
|
||||
query_port = check_int("Укажите Query-порт Сервера <27015>: \n")
|
||||
if query_port == 0:
|
||||
if query_p == []:
|
||||
query_port = 27015
|
||||
else:
|
||||
query_port = max(query_p) + 1
|
||||
if query_port is query_p: # если веденный порт есть в списке портов
|
||||
print("Этот порт уже занят")
|
||||
else:
|
||||
break
|
||||
'''
|
||||
rcon_enabled = True
|
||||
if rcon_p == []:
|
||||
rcon_port = 27020
|
||||
@ -255,7 +229,6 @@ def config(list_config=list_config):
|
||||
|
||||
yaml_create(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)
|
||||
|
||||
|
||||
def yaml_create(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):
|
||||
settings_hlna = [
|
||||
{
|
||||
@ -395,28 +368,25 @@ def start(m, name_server=list_config):
|
||||
if name_server != []:
|
||||
if m == "all":
|
||||
print("Запускаем все активные карты")
|
||||
|
||||
|
||||
names_serverstart = choose_map(names_serverstart)
|
||||
server_dir = dir_server + "Server" + "/ShooterGame/Binaries/Linux/"
|
||||
print_line("Качаем сервер")
|
||||
x = os.system(f"steamcmd +force_install_dir {server_dir} +login anonymous +app_update 376030 +quit")
|
||||
for i in names_serverstart:
|
||||
data = read_yaml(i)
|
||||
create_dir(data['ServerPath'] + i)
|
||||
print_line("Качаем карту: " + i)
|
||||
starting_map = dict_mapname[i]
|
||||
x = os.system(
|
||||
f"steamcmd +force_install_dir {data['ServerPath'] + i} +login anonymous +app_update 376030 +quit")
|
||||
|
||||
|
||||
def starting(i):
|
||||
# os.chdir(data['ServerPath'] + i + "/ShooterGame/Binaries/Linux/")
|
||||
os.chdir(dir_server + "Server" + "/ShooterGame/Binaries/Linux/")
|
||||
os.chdir(server_dir)
|
||||
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']}")
|
||||
|
||||
if x == 0:
|
||||
print_line("Карта скачана: " + i)
|
||||
print_line("Запускаем карту" + i)
|
||||
threads = threading.Thread(target=starting, args=(starting_map,))
|
||||
threads.start()
|
||||
else:
|
||||
print(f"Карта {i} не установлена")
|
||||
print(f"Карта не запущена, сервер не установлен")
|
||||
|
||||
else:
|
||||
print("Ни одной карты не установлено")
|
||||
@ -446,12 +416,33 @@ def read_yaml(name_server, flag=True):
|
||||
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
|
||||
return data[0] # возвращаем словарь со всеми значениями
|
||||
|
||||
|
||||
def choose_map(arr):
|
||||
new_arr = []
|
||||
arr = sorted(arr)
|
||||
print('Найдены сервера с этой картой')
|
||||
for i,map in enumerate(arr):
|
||||
print(f"{i+1}) {map}")
|
||||
while True:
|
||||
try:
|
||||
x = input("Выберите сервер из списка, либо несколько через запятую: ").split(',')
|
||||
x = [int (i) for i in x]
|
||||
break
|
||||
except:
|
||||
print("Неправильный ввод")
|
||||
|
||||
for i in x:
|
||||
new_arr.append(arr[i-1])
|
||||
print('Выбранные сервера:', new_arr)
|
||||
|
||||
return new_arr
|
||||
|
||||
@hlna.command()
|
||||
@click.argument('c', nargs=1)
|
||||
@click.option('-m', required=True, help="Название карты для применения rcon команды")
|
||||
def rcon(m,c):
|
||||
print_line(c)
|
||||
print_line(m)
|
||||
print_line("Команда: ", c)
|
||||
print_line("Карты: ", m)
|
||||
dict_mapname = {}
|
||||
dict_adminpwd = {}
|
||||
for i in list_config:
|
||||
@ -460,7 +451,7 @@ def rcon(m,c):
|
||||
dict_adminpwd[data['RCONPort']] = data['ServerAdminPassword']
|
||||
rcon_ports = []
|
||||
for ns, v in dict_mapname.items():
|
||||
print_line(f"переменные v и m {v} & {m}")
|
||||
print_line(f"переменные v и m {v} & {m}") # обьединить с таким же блоком в start()
|
||||
if v in m:
|
||||
rcon_ports.append(ns)
|
||||
print_line(f"Карта которая запускается {ns}")
|
||||
|
39
pytest.py
39
pytest.py
@ -1,55 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
from colorama import Fore, Style
|
||||
import os
|
||||
import unittest
|
||||
|
||||
import time
|
||||
from threading import Thread
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
||||
def zero(x=""):
|
||||
return 0
|
||||
input = zero
|
||||
import hlna
|
||||
home_dir = Path.home()
|
||||
config_hlna = f"{home_dir}/.config/hlna/"
|
||||
|
||||
"---------------import подменяем через unittest.mock -----------------------"
|
||||
|
||||
"---------------------------------------------------------------------------"
|
||||
|
||||
def config():
|
||||
hlna.config()
|
||||
def servers():
|
||||
x = input()
|
||||
print('x=',x)
|
||||
x = os.system("./hlna.py servers")
|
||||
x = os.system("./hlna.py servers >> /dev/null")
|
||||
if x == 0:
|
||||
print("Servers - "+Fore.GREEN + "OK" + Style.RESET_ALL)
|
||||
else:
|
||||
print(Fore.RED + "Servers Fail" + Style.RESET_ALL)
|
||||
def delete():
|
||||
print("Delete - " + Fore.RED + "False" + Style.RESET_ALL)
|
||||
class TestHlna(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.p1
|
||||
def test_config(self):
|
||||
pass
|
||||
# self.assert _input(hlna.config(input(1), 11))
|
||||
def test_servers(self):
|
||||
pass
|
||||
def test_enablemap(self):
|
||||
passs
|
||||
def test_start(self):
|
||||
pass
|
||||
def test_delete(self):
|
||||
pass
|
||||
def test_rcon(self):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
#unittest.main()
|
||||
#servers()
|
||||
config()
|
||||
|
||||
servers()
|
||||
delete()
|
||||
config()
|
||||
|
||||
|
||||
|
||||
#print(f"{Fore.GREEN} + {text}")
|
||||
|
Loading…
Reference in New Issue
Block a user