add friend table, start work on ws

This commit is contained in:
2026-02-24 19:23:34 +01:00
parent b1556515a1
commit e8d6306714
7 changed files with 32 additions and 5 deletions
+4 -1
View File
@@ -1,10 +1,11 @@
from typing import Optional
from flask import Flask
from flask import Flask, app
from flask_socketio import SocketIO
from flask_login import LoginManager
from .db import close_db, init_db
from app.models.user import User
sIO = SocketIO()
login_manager = LoginManager()
@@ -16,6 +17,8 @@ def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'dev' #! ofc not intended for prod use
from .sockets import socket as _socket
app.teardown_appcontext(close_db)
sIO.init_app(app)
+11
View File
@@ -53,6 +53,17 @@ def init_db(app):
CREATE INDEX IF NOT EXISTS idx_game_players_player_id
ON game_players(player_id);
CREATE TABLE IF NOT EXISTS friendships (
requester_id INTEGER NOT NULL,
addressee_id INTEGER NOT NULL,
status TEXT NOT NULL CHECK(status IN ('pending','accepted','blocked')),
PRIMARY KEY (requester_id, addressee_id),
FOREIGN KEY (requester_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (addressee_id) REFERENCES users(id) ON DELETE CASCADE
);
"""
)
db.commit()
+10 -3
View File
@@ -13,10 +13,17 @@ main_bp = Blueprint("main", __name__)
"""
@main_bp.route("/", methods=["GET", "POST"])
def main():
return render_template("main.html")
def index():
return render_template("index.html")
@main_bp.route("/home", methods=["GET", "POST"])
@login_required
def home():
return render_template("home.html", username=current_user.username)
print(f"Current user: {current_user.username}")
return render_template("home.html")
@main_bp.route("/play", methods=["GET"])
@login_required
def play():
return render_template("play.html")
+5
View File
@@ -0,0 +1,5 @@
from app import sIO
@sIO.on('auth')
def handle_auth(msg):
print(msg)
+1 -1
View File
@@ -11,5 +11,5 @@
</head>
<body>
<h1>logged in</h1>
<p>hi, {{ username }}!</p>
<p>hi, {{ current_user.username }}!</p>
</html>
+1
View File
@@ -3,4 +3,5 @@ from app import create_app, sIO
app = create_app()
if __name__ == "__main__":
print("Starting server...")
sIO.run(app, debug=True)