File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,40 @@ def player_status():
150150 return jsonify ({"message" : "gameRoomID does not exist" }), 400
151151
152152
153+ @app .route ("/endgame" , methods = ["DELETE" ])
154+ @jwt_required
155+ def end_game (current_user , nickname ):
156+ data = request .json
157+ gameRoomID = data .get ("gameRoomID" )
158+ if not gameRoomID :
159+ return jsonify ({"message" : "gameRoomID is required" }), 400
160+
161+ token = None
162+ if "Authorization" in request .headers :
163+ auth_header = request .headers ["Authorization" ]
164+ try :
165+ token = auth_header .split (" " )[1 ]
166+ except IndexError :
167+ return jsonify ({"message" : "Invalid token format" }), 401
168+
169+ headers = {"Authorization" : f"Bearer { token } " }
170+ response = requests .post (
171+ f"https://api.gaas.waterballsa.tw/rooms/{ gameRoomID } :endGame" ,
172+ headers = headers ,
173+ )
174+ if response .status_code != 204 :
175+ return (
176+ jsonify (
177+ {
178+ "message" : f"Failed to end game on GaaS platform: { response .status_code } " ,
179+ }
180+ ),
181+ 400 ,
182+ )
183+ else :
184+ return jsonify ({"message" : "Game ended successfully" }), 204
185+
186+
153187@app .route ("/health" , methods = ["GET" ])
154188def health_check ():
155189 return jsonify ({"status" : "healthy" }), 200
You can’t perform that action at this time.
0 commit comments