app_dongri.py 22 KB

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