-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
37 lines (27 loc) · 853 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from flask import Flask, render_template, request
from flask_socketio import SocketIO, emit
import uuid
app = Flask(__name__)
app.config['SECRET_KEY'] = 'c8m349cty02x'
socketio = SocketIO(app)
games = []
def findgame(sid):
global games
if not games or games[-1]['player2'] is not None:
gameid = str(uuid.uuid4())
games.append({'player1': sid, 'player2': None, 'gameid': gameid})
return gameid
else:
games[-1]['player2'] = sid
return games[-1]['gameid']
@app.route('/')
def sessions():
return render_template('gamepage.html')
@socketio.on('login')
def login(json):
print('new user: {}'.format(request.sid))
gameid = findgame(request.sid)
print('match assigned: {}'.format(gameid))
emit('match_created', gameid)
if __name__ == '__main__':
socketio.run(app, debug=True)