From a7ff4f2a3d8de13f16a7460ac45ec4738c67da91 Mon Sep 17 00:00:00 2001 From: Boyan Date: Fri, 3 Nov 2023 17:06:39 +0100 Subject: [PATCH] Updated some stuff --- README.md | 12 ++++++++++-- src/app.py | 14 +++++++++++--- src/tests/create_game.http | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 src/tests/create_game.http diff --git a/README.md b/README.md index 53d1ad8..4aa8de1 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,16 @@ This is the platform from which one can host any "game" that they have defined. * Developed protocols, which clients can use. ## TODOs -* [ ] Create websocket server -* [ ] Implement the description of the protocol from the client(s) +* Web server + * [ ] Figure out some sort of identification that is not external IP(cuz that's dumb) + * [ ] Hand it out + * [ ] Start accepting requests to the websocket server ONLY to the users who have joined the game + +* Websocket server + * [ ] Ping players while waiting for people + * Game creation + * [ ] Rules exchange -> Have to think about that one lol + * [ ] Game start ## Flowcharts ### Creation diff --git a/src/app.py b/src/app.py index b1384fa..28f9515 100644 --- a/src/app.py +++ b/src/app.py @@ -1,7 +1,11 @@ -from flask import Flask, render_template, request, redirect, url_for, flash, session +from flask import Flask, render_template, request, redirect, url_for, flash, session, jsonify from uuid import uuid4 -from .classes import Game +from flask_socketio import SocketIO +import json + app = Flask(__name__) +app.config['SECRET_KEY'] = 'DEV' +socketio = SocketIO(app) def find_game_by_id(id:str) -> dict: @@ -24,7 +28,7 @@ def start_game(game:dict): def index(): return "Empty for now" -@app.route('/new//', methods=['POST']) +@app.route('/new//', methods=['POST']) def new_game(name, players): # Log new game into json file and return a websocket url for the game games = [] @@ -46,6 +50,8 @@ def new_game(name, players): with open('games.json', 'w') as f: json.dump(games, f) + return jsonify(game) + @app.route('/join/', methods=['POST']) def join_game(game_id): @@ -77,5 +83,7 @@ def join_game(game_id): with open('games.json', 'w') as f: json.dump(games, f) +if __name__ == '__main__': + socketio.run(app, debug=True) diff --git a/src/tests/create_game.http b/src/tests/create_game.http new file mode 100644 index 0000000..27e3ed4 --- /dev/null +++ b/src/tests/create_game.http @@ -0,0 +1 @@ +POST http://127.0.0.1:5000/new/game/2 \ No newline at end of file