Selaa lähdekoodia

!2 add http api to close and restart game

pcacc 2 kuukautta sitten
vanhempi
sitoutus
54914d7fa5
1 muutettua tiedostoa jossa 13 lisäystä ja 1 poistoa
  1. 13 1
      app_dongri.py

+ 13 - 1
app_dongri.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
-from flask import Flask, render_template
+from flask import Flask, render_template,jsonify
 from flask_socketio import SocketIO, emit
 from flask_socketio import SocketIO, emit
 from scriptBase.comon import *
 from scriptBase.comon import *
 import pyautogui
 import pyautogui
@@ -171,12 +171,24 @@ def handle_restart_game():
     python = sys.executable
     python = sys.executable
     os.execl(python, python, *sys.argv, '--reset')
     os.execl(python, python, *sys.argv, '--reset')
 
 
+@app.route('/restart_game', methods=['POST'])
+def http_restart_game():
+    print("HTTP 触发 restart_game")
+    socketio.start_background_task(handle_restart_game)
+    return jsonify({"status": "success", "message": "已重启"})
+
 @socketio.on('close_game')
 @socketio.on('close_game')
 def handle_close_game():
 def handle_close_game():
     task_close_game()
     task_close_game()
     send_status("结束2")
     send_status("结束2")
     event.clear()
     event.clear()
 
 
+@app.route('/close_game', methods=['POST'])
+def http_close_game():
+    print("HTTP 触发 close_game")
+    handle_close_game()
+    return jsonify({"status": "success", "message": "已关闭"})
+
 
 
 @socketio.on('read_cfg')
 @socketio.on('read_cfg')
 def handle_read_cfg():
 def handle_read_cfg():