app_dongri.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  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_end_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. #config = read_Dailycfg()
  248. #print("config, check daily", config)
  249. if isSimple == False and is_within_n_minutes(get_todo_time("巨熊行动"), 20, 30):
  250. print("in fight bear")
  251. if len(task_queue) < 5:
  252. start_recording()
  253. task_queue.appendleft(task_returnAllLine())
  254. task_queue.appendleft(task_useAnnimalSkill(True))
  255. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  256. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  257. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  258. task_queue.appendleft(task_paticipateInTeam(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(not g_switch))
  262. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  263. task_queue.appendleft(task_paticipateInTeam(not g_switch))
  264. myTimeSleep_big()
  265. send_status(f'巨熊行动中')
  266. continue
  267. elif isSimple == False and is_within_n_minutes(get_todo_time("巨熊行动"), 60, 0):
  268. # 设置无尽运行和启动的游戏为0
  269. always = True
  270. #if g_switch:
  271. #update_rungame_type(0)
  272. send_status(f'巨熊行动:在60min内,切换到无尽模式')
  273. stop_recording()
  274. print("add special activity")
  275. # special activity
  276. if activity == 'lianmeng':
  277. task_queue.appendleft(task_activity_lianmeng())
  278. elif activity == 'cure':
  279. task_queue.appendleft(task_cure(True, g_cureNum))
  280. elif activity == 'only_cure':
  281. task_queue.appendleft(task_cure(True, g_cureNum))
  282. task_queue.appendleft(task_cure(True, g_cureNum))
  283. task_queue.appendleft(task_cure(True, g_cureNum))
  284. return
  285. print("add normal activity")
  286. task_queue.appendleft(task_checkActivities())
  287. if g_switch == True:
  288. task_queue.appendleft(task_checkBenifitStatus())
  289. # first run
  290. #if g_times % 3 == 1:
  291. # task_queue.appendleft(check_safe_collect())
  292. if isSimple == False:
  293. task_queue.appendleft(task_information())
  294. task_queue.appendleft(task_check_Research())
  295. task_queue.appendleft(task_checkStoreRoom())
  296. if not isSimple:
  297. if isJina == 'jina':
  298. task_queue.appendleft(task_fight_jina(isAddStrengh))
  299. elif isJina == 'yongbing':
  300. task_queue.appendleft(task_fight_yongbing(isAddStrengh))
  301. elif isJina == 'monster':
  302. task_queue.appendleft(task_fightMonster(isAddStrengh, False, isSimple))
  303. elif isJina == 'big_monster' or isJina == 'bigMonster_max':
  304. task_queue.appendleft(task_fightMonster(isAddStrengh, True, isSimple))
  305. elif isJina == 'jina_call':
  306. ### 全部聊天记录都是新吉娜
  307. task_queue.appendleft(task_call_jina())
  308. task_queue.appendleft(task_call_jina())
  309. task_queue.appendleft(task_call_jina())
  310. task_queue.appendleft(task_call_jina())
  311. elif isJina == 'jina_onlyFight':
  312. task_queue.appendleft(task_fight_jina_only())
  313. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  314. task_queue.appendleft(task_train(train_type))
  315. if isSimple == False:
  316. if not isAddStrengh: # 如果不是添加体力,则添加一次采集
  317. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  318. if isJina == 'monster' and isAddStrengh:
  319. task_queue.appendleft(task_fightMonster(isAddStrengh, False, isSimple))
  320. else:
  321. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  322. else:
  323. task_queue.appendleft(task_collect(collectArr, isSimple, isAddStrengh))
  324. print("add rare activity")
  325. if g_times % 5 == 1:
  326. if get_rungame_type() == 0:
  327. task_queue.appendleft(check_buildOrResearch())
  328. task_queue.appendleft(task_cure(True, g_cureNum))
  329. task_queue.appendleft(task_information())
  330. task_queue.appendleft(task_checkDonata())
  331. task_queue.appendleft(task_checkMaster())
  332. task_queue.appendleft(task_checkAdventure())
  333. task_queue.appendleft(task_train(train_type))
  334. task_queue.appendleft(task_useAnnimalSkill())
  335. task_queue.appendleft(task_read_mails())
  336. task_queue.appendleft(task_getStrength())
  337. if auto_participate:
  338. task_queue.appendleft(task_checkConfilits())
  339. task_queue.appendleft(task_checkDiamond())
  340. task_queue.appendleft(task_fight_campion())
  341. task_queue.appendleft(task_get_fire_crystal())
  342. task_queue.appendleft(task_checkUnionTreasure())
  343. #task_queue.appendleft(task_checkBenifitStatus())
  344. task_queue.appendleft(task_gotoTree())
  345. task_queue.appendleft(task_checkHelp())
  346. if activity == 'redPackage':
  347. task_queue.appendleft(task_get_redPackage())
  348. if isJina == 'bigMonster_max':
  349. task_queue.appendleft(task_fightMonster(isAddStrengh, True, isSimple))
  350. print("check restart")
  351. g_times += 1
  352. restart_times = 7
  353. if g_switch:
  354. restart_times = 4
  355. if g_times % restart_times == 0 and g_times != 0:
  356. if g_isRestart:
  357. handle_end_game()
  358. if g_switch == False:
  359. if always:
  360. nextTaskTime = random.randint(400, 450)
  361. set_nextTaskTime(nextTaskTime)
  362. myTimeSleep(nextTaskTime, send_status)
  363. else:
  364. nextTaskTime = random.randint(1000, 2000)
  365. set_nextTaskTime(nextTaskTime)
  366. myTimeSleep(nextTaskTime, send_status)
  367. else:
  368. nextTaskTime = random.randint(20, 50)
  369. set_nextTaskTime(nextTaskTime)
  370. myTimeSleep(nextTaskTime, send_status)
  371. if g_isRestart:
  372. handle_restart_game()
  373. else:
  374. nextTaskTime = random.randint(400, 450)
  375. set_nextTaskTime(nextTaskTime)
  376. myTimeSleep(nextTaskTime, send_status)
  377. task_queue.clear()
  378. send_status(f'自动模式结束')
  379. event.clear()
  380. daily_config = {
  381. "login_task": False,
  382. "fight_bigMonster_times": 0
  383. }
  384. def check_daily_config(config):
  385. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  386. print(f"Today: {today}") # 打印当前日期
  387. print(f"Config: {config}") # 打印传入的配置
  388. if "daily" not in config:
  389. print("Daily key not found, creating it.") # 调试信息
  390. config["daily"] = {}
  391. return False
  392. if today not in config["daily"]:
  393. print(f"Today's config not found: {today}") # 调试信息
  394. return False
  395. else:
  396. print(f"Today's config found: {today}") # 调试信息
  397. return True
  398. def update_rungame_type(dstType=None):
  399. config = read_Dailycfg()
  400. runTypeStr = 'runType'
  401. if runTypeStr not in config:
  402. if dstType is not None:
  403. config[runTypeStr] = dstType
  404. else:
  405. config[runTypeStr] = 1
  406. write_Dailycfg(config)
  407. print(f"更新下次启动{config[runTypeStr]}")
  408. return 0
  409. else:
  410. value = config[runTypeStr]
  411. if dstType is not None:
  412. config[runTypeStr] = dstType
  413. else:
  414. config[runTypeStr] = (value + 1) % 2
  415. write_Dailycfg(config)
  416. print(f"更新下次启动{config[runTypeStr]}")
  417. return value
  418. def get_rungame_type():
  419. config = read_Dailycfg()
  420. runTypeStr = 'runType'
  421. if runTypeStr not in config:
  422. return 0
  423. else:
  424. if config[runTypeStr] == 0:
  425. return 1
  426. else:
  427. return 0
  428. # 修改或添加 "login_task" 的值
  429. def set_login_task(config, value):
  430. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  431. if today not in config["daily"]: # 如果当天的配置不存在
  432. config["daily"][today] = {} # 创建当天的配置
  433. config["daily"][today]["login_task"] = value # 设置或更新 "login_task"
  434. return config
  435. # 修改或添加 "fight_bigMonster_times" 的值
  436. def set_fight_big_monster_times(config, value):
  437. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  438. if today not in config["daily"]: # 如果当天的配置不存在
  439. config["daily"][today] = {} # 创建当天的配置
  440. config["daily"][today]["fight_bigMonster_times"] = value # 设置或更新 "fight_bigMonster_times"
  441. return config
  442. def add_today_daily_config(config, daily_config, overwrite=False):
  443. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  444. if today not in config["daily"] or overwrite: # 如果不存在或允许覆盖
  445. config["daily"][today] = daily_config # 添加或更新
  446. return config
  447. # 清理非当天的每日配置
  448. def clean_old_daily_configs(config):
  449. today = datetime.now().strftime('%Y-%m-%d') # 获取当前日期
  450. keys_to_remove = [key for key in config["daily"] if key != today] # 找到非当天的每日配置
  451. for key in keys_to_remove:
  452. del config["daily"][key] # 删除非当天的每日配置
  453. return config
  454. def write_cfg(config):
  455. with open('config.json', 'w') as config_file:
  456. json.dump(config, config_file, indent=4)
  457. def read_cfg():
  458. global g_cureNum
  459. try:
  460. with open('config.json', 'r') as config_file:
  461. config = json.load(config_file)
  462. g_cureNum = config['cureNumber']
  463. return config
  464. except FileNotFoundError:
  465. print("配置文件不存在,请检查文件路径。")
  466. return None
  467. except PermissionError:
  468. print("没有权限读取配置文件。")
  469. return None
  470. except json.JSONDecodeError:
  471. print("配置文件格式错误,请检查文件内容是否为有效的 JSON。")
  472. return None
  473. def write_Dailycfg(config):
  474. with open('daily.json', 'w') as config_file:
  475. json.dump(config, config_file, indent=4)
  476. def read_Dailycfg():
  477. try:
  478. with open('daily.json', 'r') as config_file:
  479. config = json.load(config_file)
  480. return config
  481. except FileNotFoundError:
  482. print("配置文件不存在,请检查文件路径。")
  483. return None
  484. except PermissionError:
  485. print("没有权限读取配置文件。")
  486. return None
  487. except json.JSONDecodeError:
  488. print("配置文件格式错误,请检查文件内容是否为有效的 JSON。")
  489. return None
  490. @socketio.on('begin_auto')
  491. def handle_auto(data):
  492. write_cfg(data)
  493. config = read_cfg()
  494. print("config", config)
  495. auto_task(config)
  496. def auto_task(data):
  497. global autoTask, g_cureNum,g_isRestart,g_switch
  498. if data == None:
  499. isMaxCollect = '4,3,2,1'
  500. isSimple = False
  501. isJina = 'jina'
  502. isAddStrengh = False
  503. activity = 'none'
  504. participateJijie = False
  505. auto_daily = False
  506. train_type = 'none'
  507. always = False
  508. cureNumber = 500
  509. lineCheck = False
  510. switch = False
  511. g_isRestart = True
  512. else:
  513. isMaxCollect = data['maxCollect']
  514. isSimple = data['simple']
  515. isJina = data['jina']
  516. isAddStrengh = data['add_strength']
  517. activity = data['activity']
  518. participateJijie = data['participate_jijie']
  519. auto_daily = False
  520. train_type = data['train']
  521. always = data['always']
  522. cureNumber = data['cureNumber']
  523. lineCheck = data['lineCheck']
  524. switch = data['switch']
  525. g_isRestart = data['is_restart']
  526. g_cureNum = cureNumber
  527. g_switch = switch
  528. set_lineCheck(lineCheck)
  529. send_status(f'开始自动模式')
  530. executor.submit(add_auto_task, isMaxCollect, isJina, isSimple, isAddStrengh, activity, participateJijie, auto_daily, train_type, always)
  531. @socketio.on('begin_auto_participate')
  532. def handle_auto_participate():
  533. global autoTask
  534. send_status(f'开始自动集结模式')
  535. executor.submit(auto_participate)
  536. @socketio.on('begin_testNewFun')
  537. def handle_auto_testNewFun():
  538. global autoTask
  539. send_status(f'开始自动测试新功能')
  540. task_testFun().run()
  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)#关闭自动重载