diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-02-17 12:37:03 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-02-17 12:37:03 +0100 |
commit | 72d8c0178a8b21a8f0d19da9689a5bac30ccbcbb (patch) | |
tree | 423cd81dd77508bd783a97a89c889b1fbad709b3 /api/game/socket.py | |
parent | c45d0923b65c7409dcb18554c3e1dd00324e3f92 (diff) |
beginsels website game dings
Diffstat (limited to 'api/game/socket.py')
-rw-r--r-- | api/game/socket.py | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/api/game/socket.py b/api/game/socket.py index c4e5ac7..d6dff1b 100644 --- a/api/game/socket.py +++ b/api/game/socket.py @@ -1,30 +1,33 @@ from flask import Blueprint, request, make_response -from flask_socketio import SocketIO, emit, disconnect, Namespace, emit +from flask_socketio import SocketIO, emit, disconnect, emit +from game.voerbak_connector import bord +from db import cursor import time import json -class GameSocketNamespace(Namespace): - def connect(self): - print("new connection") - emit("gert", {"gert": "banaan"}) +namespace = "/game/socket" - def on_connect(self): - print("new connection") - emit("gert", {"gert": "banaan"}) +class game: + def __init__(self, game_id): + self.game_id = game_id + self.board = bord(7, 6) - def on_disconnect(self): - print("disconnect") + def move(self, user_id, column): + # player_1 = cursor.execute("select player_1_id from games where game_id = ?", [self.game_id]).fetchone()[0] + # player_1_move = player_1 == user_id + # if not self.board.player_1 == player_1_move: return + self.board.drop_fisje(column) - def new_move(self, data): - print("new_move") +def run(app): + io = SocketIO(app) + + @io.on("new_move", namespace) + def new_move(data): print(data) - def resign(self, data): - print("resign") + @io.on("resign", namespace) + def resign(data): print(data) -def run(app): - socketio = SocketIO(app) - socketio.on_namespace(GameSocketNamespace("/game/socket")) - socketio.run(app, host="127.0.0.1", port=5000, debug=True) + io.run(app, host="127.0.0.1", port=5000, debug=True) |