-
Notifications
You must be signed in to change notification settings - Fork 69
/
launch.py
134 lines (104 loc) · 4.22 KB
/
launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import os
import re
import shutil
import subprocess
from string import Template
import local
import workshop
def mod_param(name, mods):
return ' -{}="{}" '.format(name, ";".join(mods))
def env_defined(key):
return key in os.environ and len(os.environ[key]) > 0
CONFIG_FILE = os.environ["ARMA_CONFIG"]
KEYS = "/arma3/keys"
if not os.path.isdir(KEYS):
if os.path.exists(KEYS):
os.remove(KEYS)
os.makedirs(KEYS)
if os.environ["SKIP_INSTALL"] in ["", "false"]:
# Install Arma
steamcmd = ["/steamcmd/steamcmd.sh"]
steamcmd.extend(["+force_install_dir", "/arma3"])
steamcmd.extend(["+login", os.environ["STEAM_USER"], os.environ["STEAM_PASSWORD"]])
steamcmd.extend(["+app_update", "233780"])
if env_defined("STEAM_BRANCH"):
steamcmd.extend(["-beta", os.environ["STEAM_BRANCH"]])
if env_defined("STEAM_BRANCH_PASSWORD"):
steamcmd.extend(["-betapassword", os.environ["STEAM_BRANCH_PASSWORD"]])
steamcmd.extend(["validate"])
if env_defined("STEAM_ADDITIONAL_DEPOT"):
for depot in os.environ["STEAM_ADDITIONAL_DEPOT"].split("|"):
depot_parts = depot.split(",")
steamcmd.extend(
["+login", os.environ["STEAM_USER"], os.environ["STEAM_PASSWORD"]]
)
steamcmd.extend(
["+download_depot", "233780", depot_parts[0], depot_parts[1]]
)
steamcmd.extend(["+quit"])
subprocess.call(steamcmd)
if env_defined("STEAM_ADDITIONAL_DEPOT"):
for depot in os.environ["STEAM_ADDITIONAL_DEPOT"].split("|"):
depot_parts = depot.split(",")
depot_dir = (
f"/steamcmd/linux32/steamapps/content/app_233780/depot_{depot_parts[0]}/"
)
for file in os.listdir(depot_dir):
shutil.copytree(depot_dir + file, "/arma3/", dirs_exist_ok=True)
print(f"Moved {file} to /arma3")
# Mods
mods = []
if os.environ["MODS_PRESET"] != "":
mods.extend(workshop.preset(os.environ["MODS_PRESET"]))
if os.environ["MODS_LOCAL"] == "true" and os.path.exists("mods"):
mods.extend(local.mods("mods"))
launch = "{} -limitFPS={} -world={} {} {}".format(
os.environ["ARMA_BINARY"],
os.environ["ARMA_LIMITFPS"],
os.environ["ARMA_WORLD"],
os.environ["ARMA_PARAMS"],
mod_param("mod", mods),
)
if os.environ["ARMA_CDLC"] != "":
for cdlc in os.environ["ARMA_CDLC"].split(";"):
launch += " -mod={}".format(cdlc)
clients = int(os.environ["HEADLESS_CLIENTS"])
print("Headless Clients:", clients)
if clients != 0:
with open("/arma3/configs/{}".format(CONFIG_FILE)) as config:
data = config.read()
regex = r"(.+?)(?:\s+)?=(?:\s+)?(.+?)(?:$|\/|;)"
config_values = {}
matches = re.finditer(regex, data, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
config_values[match.group(1).lower()] = match.group(2)
if "headlessclients[]" not in config_values:
data += '\nheadlessclients[] = {"127.0.0.1"};\n'
if "localclient[]" not in config_values:
data += '\nlocalclient[] = {"127.0.0.1"};\n'
with open("/tmp/arma3.cfg", "w") as tmp_config:
tmp_config.write(data)
launch += ' -config="/tmp/arma3.cfg"'
client_launch = launch
client_launch += " -client -connect=127.0.0.1 -port={}".format(os.environ["PORT"])
if "password" in config_values:
client_launch += " -password={}".format(config_values["password"])
for i in range(0, clients):
hc_template = Template(
os.environ["HEADLESS_CLIENTS_PROFILE"]
) # eg. '$profile-hc-$i'
hc_name = hc_template.substitute(
profile=os.environ["ARMA_PROFILE"], i=i, ii=i + 1
)
hc_launch = client_launch + ' -name="{}"'.format(hc_name)
print("LAUNCHING ARMA CLIENT {} WITH".format(i), hc_launch)
subprocess.Popen(hc_launch, shell=True)
else:
launch += ' -config="/arma3/configs/{}"'.format(CONFIG_FILE)
launch += ' -port={} -name="{}" -profiles="/arma3/configs/profiles"'.format(
os.environ["PORT"], os.environ["ARMA_PROFILE"]
)
if os.path.exists("servermods"):
launch += mod_param("serverMod", local.mods("servermods"))
print("LAUNCHING ARMA SERVER WITH", launch, flush=True)
os.system(launch)