def __init__(self, astroPath, launcherINI="Launcher.ini", disable_auto_update=None): AstroLogging.setup_logging() # check if path specified if astroPath is not None: if os.path.exists(os.path.join(astroPath, "AstroServer.exe")): self.astroPath = astroPath else: AstroLogging.logPrint( "Specified path does not contain the server executable! (AstroServer.exe)", "critical") time.sleep(5) return # check if executable in current directory elif os.path.exists(os.path.join(os.getcwd(), "AstroServer.exe")): self.astroPath = os.getcwd() # fallback to automatic detection (experimental, do NOT rely on it) else: try: autoPath = AstroAPI.getInstallPath() if os.path.exists(os.path.join(autoPath, "AstroServer.exe")): self.astroPath = autoPath except: AstroLogging.logPrint( "Unable to find server executable anywhere! (AstroServer.exe)", "critical") time.sleep(5) return # AstroRequests.checkProxies() self.launcherINI = launcherINI self.launcherConfig = self.LauncherConfig() self.launcherPath = os.getcwd() self.refresh_launcher_config() AstroLogging.discordWebhookURL = self.launcherConfig.DiscordWebHookURL dwhl = self.launcherConfig.DiscordWebHookLevel.lower() dwhl = dwhl if dwhl in ("all", "cmd", "chat") else "cmd" AstroLogging.discordWebhookLevel = dwhl self.start_WebHookLoop() AstroLogging.setup_loggingPath( astroPath=self.astroPath, logRetention=int(self.launcherConfig.LogRetentionDays)) if disable_auto_update is not None: self.launcherConfig.DisableAutoUpdate = disable_auto_update self.version = "v1.7.6" colsize = os.get_terminal_size().columns if colsize >= 77: vText = "Version " + self.version[1:] # pylint: disable=anomalous-backslash-in-string print( " __________________________________________________________________________\n" + "| _ _ _ _ |\n" + "| /_\\ ___| |_ _ _ ___ | | __ _ _ _ _ _ __ | |_ ___ _ _ |\n" + "| / _ \\ (_-<| _|| '_|/ _ \\ | |__ / _` || || || ' \\ / _|| ' \\ / -_)| '_| |\n" + "| /_/ \\_\\/__/ \\__||_| \\___/ |____|\\__,_| \\_,_||_||_|\\__||_||_|\\___||_| |\n" + "| |\n" + "|" + vText.center(74) + "|\n" + "|__________________________________________________________________________|" ) AstroLogging.logPrint( f"AstroLauncher - Unofficial Dedicated Server Launcher {self.version}" ) AstroLogging.logPrint( "If you encounter any bugs please open a new issue at:") AstroLogging.logPrint( "https://github.com/ricky-davis/AstroLauncher/issues") AstroLogging.logPrint( "To safely stop the launcher and server press CTRL+C") # AstroRequests.checkProxies() self.latestURL = "https://github.com/ricky-davis/AstroLauncher/releases/latest" bName = os.path.basename(sys.executable) if sys.argv[0] == os.path.splitext(bName)[0]: self.isExecutable = True else: self.isExecutable = os.path.samefile(sys.executable, sys.argv[0]) self.headers = AstroAPI.base_headers self.DaemonProcess = None self.saveObserver = None self.backupObserver = None self.hasUpdate = False self.is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 self.affinity = self.launcherConfig.CPUAffinity try: if self.affinity != "": affinityList = [ int(x.strip()) for x in self.affinity.split(',') ] p = psutil.Process() p.cpu_affinity(affinityList) except ValueError as e: AstroLogging.logPrint(f"CPU Affinity Error: {e}", "critical") AstroLogging.logPrint( "Please correct this in your launcher config", "critical") return self.DedicatedServer = AstroDedicatedServer(self.astroPath, self) self.check_for_update() AstroLogging.logPrint("Starting a new session") self.validate_playfab_certs() self.check_ports_free() if self.launcherConfig.AdminAutoConfigureFirewall: self.configure_firewall() if not self.launcherConfig.DisableNetworkCheck: AstroLogging.logPrint("Checking the network configuration..") self.check_network_config() self.save_reporting() if not self.launcherConfig.DisableBackupRetention: self.backup_retention() AstroLogging.logPrint("Backup retention started") # setup queue for data exchange self.webServer = None if not self.launcherConfig.DisableWebServer: # start http server self.webServer = self.start_WebServer() self.start_InfoLoop() # AstroLogging.logPrint( # f"HTTP Server started at 127.0.0.1:{self.launcherConfig.WebServerPort}") if self.launcherConfig.HideLauncherConsoleWindow: # hide window AstroLogging.logPrint( "HideLauncherConsoleWindow enabled, Hiding window in 5 seconds..." ) time.sleep(5) # pylint: disable=redefined-outer-name kernel32 = ctypes.WinDLL('kernel32') user32 = ctypes.WinDLL('user32') hWnd = kernel32.GetConsoleWindow() user32.ShowWindow(hWnd, 0) self.start_server(firstLaunch=True)
def __init__(self, astroPath, launcherINI="Launcher.ini", disable_auto_update=None): AstroLogging.setup_logging() # check if path specified if astroPath is not None: if os.path.exists(os.path.join(astroPath, "AstroServer.exe")): self.astroPath = astroPath else: AstroLogging.logPrint( "Specified path does not contain the server executable! (AstroServer.exe)", "critical") time.sleep(5) return # check if executable in current directory elif os.path.exists(os.path.join(os.getcwd(), "AstroServer.exe")): self.astroPath = os.getcwd() # fallback to automatic detection (experimental, do NOT rely on it) else: try: autoPath = AstroAPI.getInstallPath() if os.path.exists(os.path.join(autoPath, "AstroServer.exe")): self.astroPath = autoPath except: AstroLogging.logPrint( "Unable to find server executable anywhere! (AstroServer.exe)", "critical") time.sleep(5) return AstroLogging.setup_loggingPath(self.astroPath) self.launcherINI = launcherINI self.launcherConfig = self.LauncherConfig() self.launcherPath = os.getcwd() self.refresh_launcher_config() if disable_auto_update is not None: self.launcherConfig.DisableAutoUpdate = disable_auto_update self.version = "v1.6.0" AstroLogging.logPrint( f"AstroLauncher - Unofficial Dedicated Server Launcher {self.version}" ) AstroLogging.logPrint( "If you encounter any bugs please open a new issue at:") AstroLogging.logPrint( "https://github.com/ricky-davis/AstroLauncher/issues") AstroLogging.logPrint( "To safely stop the launcher and server press CTRL+C") self.latestURL = "https://github.com/ricky-davis/AstroLauncher/releases/latest" bName = os.path.basename(sys.executable) if sys.argv[0] == os.path.splitext(bName)[0]: self.isExecutable = True else: self.isExecutable = os.path.samefile(sys.executable, sys.argv[0]) self.headers = AstroAPI.base_headers self.DaemonProcess = None self.saveObserver = None self.backupObserver = None self.hasUpdate = False self.affinity = self.launcherConfig.CPUAffinity try: if self.affinity != "": affinityList = [ int(x.strip()) for x in self.affinity.split(',') ] p = psutil.Process() p.cpu_affinity(affinityList) except ValueError as e: AstroLogging.logPrint(f"CPU Affinity Error: {e}", "critical") AstroLogging.logPrint( "Please correct this in your launcher config", "critical") return self.DedicatedServer = AstroDedicatedServer(self.astroPath, self) self.check_for_update() AstroLogging.logPrint("Starting a new session") if not self.launcherConfig.DisableNetworkCheck: AstroLogging.logPrint("Checking the network configuration..") self.check_network_config() self.save_reporting() if not self.launcherConfig.DisableBackupRetention: self.backup_retention() AstroLogging.logPrint("Backup retention started") # setup queue for data exchange if not self.launcherConfig.DisableWebServer: # start http server self.webServer = self.start_WebServer() # AstroLogging.logPrint( # f"HTTP Server started at 127.0.0.1:{self.launcherConfig.WebServerPort}") if self.launcherConfig.HideLauncherConsoleWindow: # hide window AstroLogging.logPrint( "HideLauncherConsoleWindow enabled, Hiding window in 5 seconds..." ) time.sleep(5) # pylint: disable=redefined-outer-name kernel32 = ctypes.WinDLL('kernel32') user32 = ctypes.WinDLL('user32') hWnd = kernel32.GetConsoleWindow() user32.ShowWindow(hWnd, 0) self.start_server(firstLaunch=True)
def __init__(self, astroPath, launcherINI="Launcher.ini", disable_auto_update=None): # check if path specified if astroPath is not None: if os.path.exists(os.path.join(astroPath, "AstroServer.exe")): self.astroPath = astroPath else: print("Specified path does not contain the server executable") time.sleep(5) # check if executable in current directory elif os.path.exists(os.path.join(os.getcwd(), "AstroServer.exe")): self.astroPath = os.getcwd() # fallback to automatic detection (experimental, do NOT rely on it) else: try: autoPath = AstroAPI.getInstallPath() if os.path.exists(os.path.join(autoPath, "AstroServer.exe")): self.astroPath = autoPath except: AstroLogging.logPrint("Unable to find AstroServer.exe!", "critical") return AstroLogging.setup_logging(self.astroPath) self.launcherINI = launcherINI self.launcherConfig = self.LauncherConfig() self.launcherPath = os.getcwd() self.refresh_launcher_config() if disable_auto_update is not None: self.launcherConfig.DisableAutoUpdate = disable_auto_update self.version = "v1.4.6" self.latestURL = "https://github.com/ricky-davis/AstroLauncher/releases/latest" self.isExecutable = os.path.samefile(sys.executable, sys.argv[0]) self.headers = AstroAPI.base_headers self.DaemonProcess = None self.saveObserver = None self.backupObserver = None self.DSServerStats = None self.DedicatedServer = AstroDedicatedServer(self.astroPath, self) AstroLogging.logPrint( f"AstroLauncher - Unofficial Dedicated Server Launcher {self.version}" ) AstroLogging.logPrint( "If you encounter any bugs please open a new issue at:") AstroLogging.logPrint( "https://github.com/ricky-davis/AstroLauncher/issues") AstroLogging.logPrint( "To safely stop the launcher and server press CTRL+C") self.check_for_update() AstroLogging.logPrint("Starting a new session") if not self.launcherConfig.DisableNetworkCheck: AstroLogging.logPrint("Checking the network configuration..") self.check_network_config() self.headers['X-Authorization'] = AstroAPI.generate_XAUTH( self.DedicatedServer.settings.ServerGuid) self.save_reporting() if not self.launcherConfig.DisableBackupRetention: self.backup_retention() AstroLogging.logPrint("Backup retention started") # setup queue for data exchange if not self.launcherConfig.DisableWebServer: # start http server self.webServer = self.start_WebServer() AstroLogging.logPrint( f"HTTP Server started at 127.0.0.1:{self.launcherConfig.WebServerPort}" ) atexit.register(self.DedicatedServer.kill_server, reason="Launcher shutting down", save=True) self.start_server()