app_dongri.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. # -*- coding: utf-8 -*-
  2. from flask import Flask, render_template,jsonify
  3. from flask_socketio import SocketIO, emit
  4. from scriptBase.comon import *
  5. import pyautogui
  6. import base64
  7. import threading
  8. from dongri_task import *
  9. from collections import deque
  10. import json
  11. from concurrent.futures import ThreadPoolExecutor
  12. from flask_caching import Cache
  13. # 全局线程池,限制最大线程数为1
  14. executor = ThreadPoolExecutor(max_workers=1)
  15. cache = Cache(config={'CACHE_TYPE': 'null'}) # 使用 null 缓存类型
  16. app = Flask(__name__)
  17. cache.init_app(app)
  18. app.config['TEMPLATES_AUTO_RELOAD'] = True
  19. socketio = SocketIO(app, cors_allowed_origins="*", max_http_buffer_size=1e8)
  20. event = threading.Event()
  21. g_status_list = []
  22. last_time = 0.0
  23. task_queue = deque()
  24. last_process = ''
  25. isGameBegin = True
  26. autoTask = None
  27. isReset = False
  28. g_times = 0
  29. g_cureNum = 500
  30. g_switch = False
  31. g_isRestart = True
  32. last_change_time = time.time()
  33. @app.after_request
  34. def add_no_cache_header(response):
  35. # 添加禁用缓存的响应头
  36. response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
  37. response.headers["Pragma"] = "no-cache"
  38. response.headers["Expires"] = "0"
  39. return response
  40. def thread_runTask():
  41. global last_process
  42. global task_queue,isReset
  43. while True:
  44. if event.is_set():
  45. task_queue.clear()
  46. if len(task_queue) != 0:
  47. # 初始时间
  48. current_time = time.time()
  49. task = task_queue[-1]
  50. task_queue.pop()
  51. last_process = task.name
  52. task.run()
  53. cost_time = int(time.time() - current_time)
  54. send_status(f"{task.name} 执行完成,耗时{cost_time}秒")
  55. myTimeSleep_small()
  56. else:
  57. myTimeSleep_big()
  58. if isReset:
  59. isReset = False
  60. cfg = read_cfg()
  61. if cfg['switch']:
  62. type = update_rungame_type()
  63. print(f'启动游戏{type}')
  64. restart_game(type)
  65. else:
  66. restart_game(0)
  67. @app.route('/')
  68. def index():
  69. return render_template('index_dongri.html')
  70. @socketio.on('connect')
  71. def handle_connect():
  72. print('Client connected')
  73. @socketio.on('disconnect')
  74. def handle_disconnect():
  75. print('Client disconnected')
  76. def send_hint(msg):#数组信息
  77. emit('processing_hint', msg)
  78. def send_todo():
  79. emit('processing_todo', get_todo_msgList())
  80. def send_status(msg):#软件执行状态
  81. global g_status_list, g_times
  82. try:
  83. if not msg == "":
  84. # 添加新的状态消息和时间到列表
  85. timestamp = datetime.now().strftime('%H:%M:%S') # 获取当前时间
  86. status_entry = {'msg': msg, 'time': timestamp} # 存储消息和时间
  87. g_status_list.append(status_entry)
  88. # 如果列表超过 5 条,移除最早的一条
  89. if len(g_status_list) > 5:
  90. g_status_list.pop(0)
  91. else:
  92. sendStr = ''
  93. for item in g_status_list:
  94. sendStr = f"{g_times}次-{item['time']}-{item['msg']}<br>" + sendStr
  95. emit('processing_status', sendStr)
  96. # 如果消息是 "结束",发送所有状态并清空列表
  97. if msg == "结束":
  98. g_status_list = [] # 清空列表
  99. event.clear()
  100. except Exception as e:
  101. print(f"Error in send_status: {e}")
  102. return
  103. @socketio.on('monitor_begin')
  104. def monitor_begin():
  105. global last_time, last_process
  106. current_time = time.time()
  107. elapsed_time = current_time - last_time
  108. if elapsed_time < 0.5:
  109. return
  110. last_time = current_time
  111. regionRet, regionPos = game_region()
  112. screenshot = pyautogui.screenshot(region=regionPos)
  113. #binary_img = binarize_image(screenshot)
  114. compressed_data = compress_image(screenshot)
  115. image_data_base64 = base64.b64encode(compressed_data).decode('utf-8')
  116. socketio.emit('image_data', image_data_base64)
  117. task_arr = []
  118. if not event.is_set():
  119. task_arr.append(last_process)
  120. for item in reversed(task_queue):
  121. task_arr.append(item.name)
  122. send_hint(json.dumps(task_arr, ensure_ascii=False))
  123. send_todo()
  124. send_status('')
  125. #print("send img")
  126. @socketio.on('end_script')
  127. def handle_end_script():
  128. event.set()
  129. @socketio.on('end_game')
  130. def handle_end_game():
  131. event.set()
  132. task_close_game()
  133. send_status("结束2")
  134. event.clear()
  135. @socketio.on('get_title')
  136. def handle_get_title():
  137. str = task_getComputerName()
  138. dst = str + ' machine'
  139. emit('processing_title', dst)
  140. @socketio.on('reset_script')
  141. def handle_reset_script():
  142. python = sys.executable
  143. while '--reset' in sys.argv:
  144. # 从 sys.argv 列表中删除 --reset 参数
  145. sys.argv.remove('--reset')
  146. os.execl(python, python, *sys.argv)
  147. @socketio.on('restart_game')
  148. def handle_restart_game():
  149. python = sys.executable
  150. script = os.path.abspath(sys.argv[0]) # 获取当前脚本的绝对路径
  151. # 构建新的参数列表,移除旧的 --reset 并添加新的
  152. new_args = [arg for arg in sys.argv[1:] if arg != '--reset'] # 排除脚本名和旧的 --reset
  153. print(f"当前 Python 解释器: {python}")
  154. print(f"当前脚本路径: {script}")
  155. print(f"重启参数: {[python, script, *new_args, '--reset']}")
  156. try:
  157. # 使用 os.execv 是一种更“彻底”的重启方式,它会替换当前进程
  158. # 但 subprocess.Popen 也可以,前提是旧进程退出
  159. # subprocess.Popen([python, script, *new_args, '--reset'])
  160. os.execv(python, [python, script, *new_args, '--reset'])
  161. except Exception as e:
  162. print(f"重启失败: {e}")
  163. # 如果 os.execv 失败,可以尝试 subprocess.Popen 作为备用
  164. subprocess.Popen([python, script, *new_args, '--reset'])
  165. sys.exit(0) # 终止当前进程
  166. @app.route('/restart_game', methods=['POST'])
  167. def http_restart_game():
  168. print("HTTP 触发 restart_game")
  169. socketio.start_background_task(handle_restart_game)
  170. return jsonify({"status": "success", "message": "已重启"})
  171. @socketio.on('close_game')
  172. def handle_close_game():
  173. task_close_game()
  174. send_status("结束2")
  175. event.clear()
  176. @app.route('/close_game', methods=['POST'])
  177. def http_close_game():
  178. print("HTTP 触发 close_game")
  179. handle_close_game()
  180. socketio.start_background_task(handle_end_script)
  181. return jsonify({"status": "success", "message": "已关闭"})
  182. @socketio.on('read_cfg')
  183. def handle_read_cfg():
  184. cfg = read_cfg()
  185. emit('processing_cfg', cfg)
  186. def restart_game(type=0):
  187. global isGameBegin
  188. isGameBegin = False
  189. while True:
  190. task_close_game()
  191. if True == task_start_game(type):
  192. break
  193. else:
  194. send_status("启动失败")
  195. isGameBegin = True
  196. send_status("结束")
  197. config = read_cfg()
  198. print("config", config)
  199. auto_task(config)
  200. def auto_participate():
  201. task_queue.appendleft(task_returnAllLine())
  202. timeout = 40 * 60
  203. start_time = time.time() # 记录开始时间
  204. while not event.is_set():
  205. if len(task_queue) < 4:
  206. task_queue.appendleft(task_useAnnimalSkill(True))
  207. task_queue.appendleft(task_paticipateInTeam(False))
  208. task_queue.appendleft(task_paticipateInTeam())
  209. task_queue.appendleft(task_paticipateInTeam(False))
  210. task_queue.appendleft(task_paticipateInTeam())
  211. myTimeSleep_big()
  212. # 每次循环检查已用时间
  213. current_time = time.time()
  214. elapsed_time = current_time - start_time
  215. if elapsed_time >= timeout:
  216. handle_restart_game()
  217. break
  218. def auto_ranshuang():
  219. timeout = 40 * 60
  220. start_time = time.time() # 记录开始时间
  221. while not event.is_set():
  222. if len(task_queue) < 4:
  223. task_queue.appendleft(task_fight_ranshuang())
  224. myTimeSleep_big()
  225. current_time = time.time()
  226. elapsed_time = current_time - start_time
  227. if elapsed_time >= timeout:
  228. handle_restart_game()
  229. break
  230. def auto_palace():
  231. global g_times, g_cureNum
  232. timeout = 180 * 60
  233. start_time = time.time() # 记录开始时间
  234. read_cfg()
  235. while not event.is_set():
  236. g_times += 1
  237. if len(task_queue) < 4:
  238. task_queue.appendleft(task_cure(True, g_cureNum))
  239. task_queue.appendleft(task_cure(True, g_cureNum))
  240. task_queue.appendleft(task_fight_enemy())
  241. myTimeSleep_big()
  242. current_time = time.time()
  243. elapsed_time = current_time - start_time
  244. if elapsed_time >= timeout:
  245. handle_restart_game()
  246. def add_auto_task(isMaxCollect, isJina, isSimple = False, isAddStrengh = False, activity = 'None', isAutoParticipate = True, isDailyConfig = False, train_type = 'None', always = False):
  247. global g_times, g_cureNum, g_switch, g_isRestart
  248. collectArr = [int(x) for x in isMaxCollect.split(",")]
  249. print("collectArr", collectArr)
  250. while not event.is_set():
  251. config = read_Dailycfg()
  252. print("config, check daily", config)
  253. if isSimple == False and is_within_n_minutes(get_todo_time("巨熊行动"), 20, 30):
  254. print("in fight bear")
  255. if len(task_queue) < 5:
  256. start_recording()
  257. task_queue.appendleft(task_returnAllLine())
  258. task_queue.appendleft(task_useAnnimalSkill(True))
  259. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  260. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  261. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  262. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  263. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  264. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  265. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  266. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  267. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  268. myTimeSleep_big()
  269. send_status(f'巨熊行动中')
  270. continue
  271. elif isSimple == False and is_within_n_minutes(get_todo_time("巨熊行动"), 60, 0):
  272. # 设置无尽运行和启动的游戏为0
  273. always = True
  274. update_rungame_type(0)
  275. send_status(f'巨熊行动:在60min内,切换到无尽模式')
  276. stop_recording()
  277. print("add special activity")
  278. # special activity
  279. if activity == 'lianmeng':
  280. task_queue.appendleft(task_activity_lianmeng())
  281. elif activity == 'cure':
  282. task_queue.appendleft(task_cure(True, g_cureNum))
  283. elif activity == 'only_cure':
  284. task_queue.appendleft(task_cure(True, g_cureNum))
  285. task_queue.appendleft(task_cure(True, g_cureNum))
  286. task_queue.appendleft(task_cure(True, g_cureNum))
  287. return
  288. print("add normal activity")
  289. task_queue.appendleft(task_checkActivities())
  290. if g_switch == True:
  291. task_queue.appendleft(task_checkBenifitStatus())
  292. # first run
  293. #if g_times % 3 == 1:
  294. # task_queue.appendleft(check_safe_collect())
  295. if isSimple == False:
  296. task_queue.appendleft(task_information())
  297. task_queue.appendleft(task_check_Research())
  298. task_queue.appendleft(task_checkStoreRoom())
  299. if not isSimple:
  300. if isJina == 'jina':
  301. task_queue.appendleft(task_fight_jina(isAddStrengh))
  302. elif isJina == 'yongbing':
  303. task_queue.appendleft(task_fight_yongbing(isAddStrengh))
  304. elif isJina == 'monster':
  305. task_queue.appendleft(task_fightMonster(isAddStrengh, False, isSimple))
  306. elif isJina == 'big_monster' or isJina == 'bigMonster_max':
  307. task_queue.appendleft(task_fightMonster(isAddStrengh, True, isSimple))
  308. elif isJina == 'jina_call':
  309. ### 全部聊天记录都是新吉娜
  310. task_queue.appendleft(task_call_jina())
  311. task_queue.appendleft(task_call_jina())
  312. task_queue.appendleft(task_call_jina())
  313. task_queue.appendleft(task_call_jina())
  314. elif isJina == 'jina_onlyFight':
  315. task_queue.appendleft(task_fight_jina_only())
  316. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  317. task_queue.appendleft(task_train(train_type))
  318. if isSimple == False:
  319. if not isAddStrengh: # 如果不是添加体力,则添加一次采集
  320. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  321. if isJina == 'monster' and isAddStrengh:
  322. task_queue.appendleft(task_fightMonster(isAddStrengh, False, isSimple))
  323. else:
  324. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  325. else:
  326. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  327. print("add rare activity")
  328. if g_times % 5 == 1:
  329. if get_rungame_type() == 0:
  330. task_queue.appendleft(check_buildOrResearch())
  331. task_queue.appendleft(task_cure(True, g_cureNum))
  332. task_queue.appendleft(task_information())
  333. task_queue.appendleft(task_checkDonata())
  334. task_queue.appendleft(task_checkMaster())
  335. task_queue.appendleft(task_checkAdventure())
  336. task_queue.appendleft(task_train(train_type))
  337. task_queue.appendleft(task_useAnnimalSkill())
  338. task_queue.appendleft(task_read_mails())
  339. task_queue.appendleft(task_getStrength())
  340. if auto_participate:
  341. task_queue.appendleft(task_checkConfilits())
  342. task_queue.appendleft(task_checkDiamond())
  343. task_queue.appendleft(task_fight_campion())
  344. task_queue.appendleft(task_get_fire_crystal())
  345. task_queue.appendleft(task_checkUnionTreasure())
  346. #task_queue.appendleft(task_checkBenifitStatus())
  347. task_queue.appendleft(task_gotoTree())
  348. task_queue.appendleft(task_checkHelp())
  349. if activity == 'redPackage':
  350. task_queue.appendleft(task_get_redPackage())
  351. if isJina == 'bigMonster_max':
  352. task_queue.appendleft(task_fightMonster(isAddStrengh, True, isSimple))
  353. print("check restart")
  354. g_times += 1
  355. restart_times = 7
  356. if g_switch:
  357. restart_times = 4
  358. if g_times % restart_times == 0 and g_times != 0:
  359. if g_isRestart:
  360. handle_end_game()
  361. if g_switch == False:
  362. if always:
  363. myTimeSleep(random.randint(400, 450), send_status)
  364. else:
  365. myTimeSleep(random.randint(1000, 2000), send_status)
  366. else:
  367. myTimeSleep(random.randint(20, 50), send_status)
  368. if g_isRestart:
  369. handle_restart_game()
  370. else:
  371. myTimeSleep(random.randint(400, 450), send_status)
  372. task_queue.clear()
  373. send_status(f'自动模式结束')
  374. event.clear()
  375. daily_config = {
  376. "login_task": False,
  377. "fight_bigMonster_times": 0
  378. }
  379. def check_daily_config(config):
  380. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  381. print(f"Today: {today}") # 打印当前日期
  382. print(f"Config: {config}") # 打印传入的配置
  383. if "daily" not in config:
  384. print("Daily key not found, creating it.") # 调试信息
  385. config["daily"] = {}
  386. return False
  387. if today not in config["daily"]:
  388. print(f"Today's config not found: {today}") # 调试信息
  389. return False
  390. else:
  391. print(f"Today's config found: {today}") # 调试信息
  392. return True
  393. def update_rungame_type(dstType=None):
  394. config = read_Dailycfg()
  395. runTypeStr = 'runType'
  396. if runTypeStr not in config:
  397. if dstType is not None:
  398. config[runTypeStr] = dstType
  399. else:
  400. config[runTypeStr] = 1
  401. write_Dailycfg(config)
  402. print(f"更新下次启动{config[runTypeStr]}")
  403. return 0
  404. else:
  405. value = config[runTypeStr]
  406. if dstType is not None:
  407. config[runTypeStr] = dstType
  408. else:
  409. config[runTypeStr] = (value + 1) % 2
  410. write_Dailycfg(config)
  411. print(f"更新下次启动{config[runTypeStr]}")
  412. return value
  413. def get_rungame_type():
  414. config = read_Dailycfg()
  415. runTypeStr = 'runType'
  416. if runTypeStr not in config:
  417. return 0
  418. else:
  419. if config[runTypeStr] == 0:
  420. return 1
  421. else:
  422. return 0
  423. # 修改或添加 "login_task" 的值
  424. def set_login_task(config, value):
  425. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  426. if today not in config["daily"]: # 如果当天的配置不存在
  427. config["daily"][today] = {} # 创建当天的配置
  428. config["daily"][today]["login_task"] = value # 设置或更新 "login_task"
  429. return config
  430. # 修改或添加 "fight_bigMonster_times" 的值
  431. def set_fight_big_monster_times(config, value):
  432. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  433. if today not in config["daily"]: # 如果当天的配置不存在
  434. config["daily"][today] = {} # 创建当天的配置
  435. config["daily"][today]["fight_bigMonster_times"] = value # 设置或更新 "fight_bigMonster_times"
  436. return config
  437. def add_today_daily_config(config, daily_config, overwrite=False):
  438. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  439. if today not in config["daily"] or overwrite: # 如果不存在或允许覆盖
  440. config["daily"][today] = daily_config # 添加或更新
  441. return config
  442. # 清理非当天的每日配置
  443. def clean_old_daily_configs(config):
  444. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  445. keys_to_remove = [key for key in config["daily"] if key != today] # 找到非当天的每日配置
  446. for key in keys_to_remove:
  447. del config["daily"][key] # 删除非当天的每日配置
  448. return config
  449. def write_cfg(config):
  450. with open('config.json', 'w') as config_file:
  451. json.dump(config, config_file, indent=4)
  452. def read_cfg():
  453. global g_cureNum
  454. try:
  455. with open('config.json', 'r') as config_file:
  456. config = json.load(config_file)
  457. g_cureNum = config['cureNumber']
  458. return config
  459. except FileNotFoundError:
  460. print("配置文件不存在,请检查文件路径。")
  461. return None
  462. except PermissionError:
  463. print("没有权限读取配置文件。")
  464. return None
  465. except json.JSONDecodeError:
  466. print("配置文件格式错误,请检查文件内容是否为有效的 JSON。")
  467. return None
  468. def write_Dailycfg(config):
  469. with open('daily.json', 'w') as config_file:
  470. json.dump(config, config_file, indent=4)
  471. def read_Dailycfg():
  472. try:
  473. with open('daily.json', 'r') as config_file:
  474. config = json.load(config_file)
  475. return config
  476. except FileNotFoundError:
  477. print("配置文件不存在,请检查文件路径。")
  478. return None
  479. except PermissionError:
  480. print("没有权限读取配置文件。")
  481. return None
  482. except json.JSONDecodeError:
  483. print("配置文件格式错误,请检查文件内容是否为有效的 JSON。")
  484. return None
  485. @socketio.on('begin_auto')
  486. def handle_auto(data):
  487. write_cfg(data)
  488. config = read_cfg()
  489. print("config", config)
  490. auto_task(config)
  491. def auto_task(data):
  492. global autoTask, g_cureNum,g_isRestart,g_switch
  493. if data == None:
  494. isMaxCollect = '4,3,2,1'
  495. isSimple = False
  496. isJina = 'jina'
  497. isAddStrengh = False
  498. activity = 'none'
  499. participateJijie = False
  500. auto_daily = False
  501. train_type = 'none'
  502. always = False
  503. cureNumber = 500
  504. lineCheck = False
  505. switch = False
  506. g_isRestart = True
  507. else:
  508. isMaxCollect = data['maxCollect']
  509. isSimple = data['simple']
  510. isJina = data['jina']
  511. isAddStrengh = data['add_strength']
  512. activity = data['activity']
  513. participateJijie = data['participate_jijie']
  514. auto_daily = data['auto_daily']
  515. train_type = data['train']
  516. always = data['always']
  517. cureNumber = data['cureNumber']
  518. lineCheck = data['lineCheck']
  519. switch = data['switch']
  520. g_isRestart = data['is_restart']
  521. g_cureNum = cureNumber
  522. g_switch = switch
  523. set_lineCheck(lineCheck)
  524. send_status(f'开始自动模式')
  525. executor.submit(add_auto_task, isMaxCollect, isJina, isSimple, isAddStrengh, activity, participateJijie, auto_daily, train_type, always)
  526. @socketio.on('begin_auto_participate')
  527. def handle_auto_participate():
  528. global autoTask
  529. send_status(f'开始自动集结模式')
  530. executor.submit(auto_participate)
  531. @socketio.on('begin_testNewFun')
  532. def handle_auto_testNewFun():
  533. global autoTask
  534. send_status(f'开始自动测试新功能')
  535. task_testFun().run()
  536. @socketio.on('begin_auto_ranshuang')
  537. def handle_auto_ranshuang():
  538. global autoTask
  539. send_status(f'开始自动燃霜')
  540. executor.submit(auto_ranshuang)
  541. @socketio.on('auto_palace')
  542. def handle_auto_palace():
  543. global autoTask
  544. send_status(f'开始自动王城')
  545. executor.submit(auto_palace)
  546. def monitor_game_runtime():
  547. global g_times, last_change_time
  548. last_value = g_times
  549. while True:
  550. current_value = g_times
  551. if current_value != last_value:
  552. last_value = current_value
  553. last_change_time = time.time()
  554. print(f"g_times changed to {current_value}")
  555. # 检查是否超过60分钟没有变化
  556. if time.time() - last_change_time > 3600: # 3600秒=60分钟
  557. print("g_times hasn't changed for 60 minutes!")
  558. handle_restart_game()
  559. time.sleep(10)
  560. if __name__ == '__main__':
  561. init()
  562. if '--reset' in sys.argv:
  563. time.sleep(2)
  564. isReset = True
  565. print("需要重启游戏")
  566. runTask = threading.Thread(target=thread_runTask)#启动线程往里面添加任务
  567. runTask.daemon = True
  568. runTask.start()
  569. monitor_thread = threading.Thread(target=monitor_game_runtime, daemon=True)
  570. monitor_thread.start()
  571. socketio.run(app, host= '0.0.0.0', debug=True, use_reloader=False)#关闭自动重载