forked from BrettMayson/Arma3Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.py
103 lines (75 loc) · 3 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
import os
import re
import subprocess
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)
# Install Arma
steamcmd = ["/steamcmd/steamcmd.sh"]
steamcmd.extend(["+login", os.environ["STEAM_USER"], os.environ["STEAM_PASSWORD"]])
steamcmd.extend(["+force_install_dir", "/arma3"])
steamcmd.extend(["+app_update", "233780"])
if env_defined("STEAM_BRANCH_PASSWORD"):
steamcmd.extend(["-beta", os.environ["STEAM_BRANCH"]])
if env_defined("STEAM_BRANCH_PASSWORD"):
steamcmd.extend(["-betapassword", os.environ["STEAM_BRANCH_PASSWORD"]])
steamcmd.extend(["validate", "+quit"])
subprocess.call(steamcmd)
# 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"))
if os.environ["ARMA_CDLC"] != "":
mods.extend(os.environ["ARMA_CDLC"].replace(" ", "").split(";"))
launch = "{} -limitFPS={} -world={} {} {}".format(
os.environ["ARMA_BINARY"],
os.environ["ARMA_LIMITFPS"],
os.environ["ARMA_WORLD"],
os.environ["ARMA_PARAMS"],
mod_param("mod", mods),
)
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"
if "password" in config_values:
client_launch += " -password={}".format(config_values["password"])
for i in range(0, clients):
hc_launch = client_launch + ' -name="{}-hc-{}"'.format(os.environ["ARMA_PROFILE"], i)
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)