Advertisement
InnovativeStudios

launch.py

Jun 11th, 2023
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.28 KB | None | 0 0
  1. import os
  2. import re
  3. import subprocess
  4. import local
  5. import workshop
  6.  
  7.  
  8. def mod_param(name, mods):
  9.     return ' -{}="{}" '.format(name, ";".join(mods))
  10.  
  11.  
  12. def env_defined(key):
  13.     return key in os.environ and len(os.environ[key]) > 0
  14.  
  15.  
  16. CONFIG_FILE = os.environ["ARMA_CONFIG"]
  17. KEYS = "/arma3/keys"
  18.  
  19. if not os.path.isdir(KEYS):
  20.     if os.path.exists(KEYS):
  21.         os.remove(KEYS)
  22.     os.makedirs(KEYS)
  23.  
  24. if os.environ["SKIP_INSTALL"] in ["", "false"]:
  25.     steamcmd = ["/steamcmd/steamcmd.sh"]
  26.     steamcmd.extend(
  27.         [
  28.             "+force_install_dir",
  29.             "/arma3",
  30.             "+login",
  31.             os.environ["STEAM_USERNAME"],
  32.             os.environ["STEAM_PASSWORD"],
  33.             "+app_update",
  34.             "233780",
  35.         ]
  36.     )
  37.     if env_defined("STEAM_BRANCH"):
  38.         steamcmd.extend(["-beta", os.environ["STEAM_BRANCH"]])
  39.     if env_defined("STEAM_BRANCH_PASSWORD"):
  40.         steamcmd.extend(["-betapassword", os.environ["STEAM_BRANCH_PASSWORD"]])
  41.     steamcmd.extend(["validate", "+quit"])
  42.     subprocess.call(steamcmd)
  43.  
  44. mods = []
  45.  
  46. if os.environ["MODS_PRESET"] != "":
  47.     mods.extend(workshop.preset(os.environ["MODS_PRESET"]))
  48.  
  49. if os.environ["MODS_LOCAL"] == "true" and os.path.exists("mods"):
  50.     mods.extend(local.mods("mods"))
  51.  
  52. launch = "{} -limitFPS={} -world={} {} {}".format(
  53.     os.environ["ARMA_BINARY"],
  54.     os.environ["ARMA_LIMITFPS"],
  55.     os.environ["ARMA_WORLD"],
  56.     os.environ["ARMA_PARAMS"],
  57.     mod_param("mod", mods),
  58. )
  59.  
  60. if os.environ["ARMA_CDLC"] != "":
  61.     for cdlc in os.environ["ARMA_CDLC"].split(";"):
  62.         launch += " -mod={}".format(cdlc)
  63.  
  64. clients = int(os.environ["HEADLESS_CLIENTS"])
  65. print("Headless Clients:", clients)
  66.  
  67. if clients != 0:
  68.     with open("arma3/configs/{}".format(CONFIG_FILE)) as config:
  69.         data = config.read()
  70.         regex = r"(.+?)(?:\s+)?=(?:\s+)?(.+?)(?:$|\/|;)"
  71.  
  72.         config_values = {}
  73.  
  74.         matches = re.finditer(regex, data, re.MULTILINE)
  75.         for matchNum, match in enumerate(matches, start=1):
  76.             config_values[match.group(1).lower()] = match.group(2)
  77.  
  78.         if "headlessclients[]" not in config_values:
  79.             data += '\nheadlessclients[] = {"127.0.0.1"};\n'
  80.         if "localclient[]" not in config_values:
  81.             data += '\nlocalclient[] = {"127.0.0.1"};\n'
  82.  
  83.         with open("/tmp/arma3.cfg", "w") as tmp_config:
  84.             tmp_config.write(data)
  85.         launch += ' -config="/tmp/arma3.cfg"'
  86.  
  87.     client_launch = launch
  88.     client_launch += " -client -connect=127.0.0.1"
  89.     if "password" in config_values:
  90.         client_launch += " -password={}".format(config_values["password"])
  91.  
  92.     for i in range(0, clients):
  93.         hc_launch = client_launch + ' -name="{}-hc-{}"'.format(
  94.             os.environ["ARMA_PROFILE"], i
  95.         )
  96.         print("LAUNCHING ARMA CLIENT {} WITH".format(i), hc_launch)
  97.         subprocess.Popen(hc_launch, shell=True)
  98.  
  99. else:
  100.     launch += ' -config="/arma3/configs/{}"'.format(CONFIG_FILE)
  101.  
  102. launch += ' -port={} -name="{}" -profiles="/arma3/configs/profiles"'.format(
  103.     os.environ["PORT"], os.environ["ARMA_PROFILE"]
  104. )
  105.  
  106. if os.path.exists("servermods"):
  107.     launch += mod_param("serverMod", local.mods("servermods"))
  108.  
  109. print("Launching Arma Server With", launch, flush=True)
  110. os.system(launch)
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement