MCPcopy Create free account
hub / github.com/ZyphrZero/palworld-python-script / start_program

Method start_program

src/task_scheduler.py:277–336  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

275
276 # 启动服务端
277 def start_program(self):
278 server_name = self.read_server_name()
279 safe_server_name = server_name.replace('|', '^|').replace(':', '^:')
280 INFO.logger.info(safe_server_name)
281 os.system(f'title {safe_server_name}') # 设置标题
282 INFO.logger.info("[ 启动任务 ] 正在启动程序......")
283 print("[ 启动任务 ] 正在启动程序......")
284
285 if self.palinject_enabled:
286 program_args = [self.palinject_path]
287 else:
288 program_args = [self.program_path]
289
290 if self.arguments:
291 INFO.logger.info("[ 启动任务 ] 已配置额外参数")
292 print("[ 启动任务 ] 已配置额外参数")
293 program_args.extend(self.arguments)
294 if self.use_multicore_options:
295 INFO.logger.info("[ 启动任务 ] 已开启多核选项")
296 print("[ 启动任务 ] 已开启多核选项")
297 program_args.extend(["-useperfthreads", "-NoAsyncLoadingThread", "-UseMultithreadForDS"])
298 INFO.logger.info(f"[ 启动任务 ] 启动参数:{program_args}")
299
300 try:
301 program_args_str = ' '.join(map(str, program_args))
302 cmd = f'cmd.exe /c & start "{server_name}" {program_args_str}'
303 INFO.logger.info(cmd)
304 subprocess.Popen(cmd, creationflags=subprocess.CREATE_NEW_CONSOLE, shell=True)
305
306 except FileNotFoundError:
307 INFO.logger.error(f"[ 启动任务 ] 启动失败,请检查config.ini中main_directory路径配置")
308 print(f"\r[ 启动任务 ] 启动失败,请检查config.ini中main_directory路径配置")
309 time.sleep(3)
310 exit(1)
311
312 # 尝试连接
313 if not self.palinject_enabled:
314 if self.rcon_enabled:
315 if self.is_first_run: # 只有在首次运行时才检查RCON连接
316 INFO.logger.info("[ RCON ] 已开启RCON功能")
317 print("[ RCON ] 已开启RCON功能")
318 INFO.logger.info("[ RCON ] 正在检查RCON连接,请等待最多60秒......")
319 print("[ RCON ] 正在检查RCON连接,请等待最多60秒......")
320
321 start_time = time.time()
322 while time.time() - start_time < 60:
323 if self.check_rcon():
324 break
325 time.sleep(1)
326
327 else:
328 INFO.logger.error("[ RCON ] 无法在60秒内建立RCON连接")
329 print("[ RCON ] 无法在60秒内建立RCON连接")
330 sys.exit(0)
331
332 self.is_first_run = False
333
334 else:

Callers 2

polling_taskMethod · 0.95
start_daemonMethod · 0.95

Calls 2

read_server_nameMethod · 0.95
check_rconMethod · 0.95

Tested by

no test coverage detected