blob: ef3ae125040a799c1dcb576f14e24ffc7b241201 (
plain)
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
|
from flask import Blueprint, request, make_response
from flask_socketio import SocketIO, emit, Namespace, join_room, leave_room, rooms
from socket_io import io
from auth.login_token import token_login
from http import cookies
from game.cleanup import set_interval
import time
# get token from flask_socketio's request.environment
def get_token(environ):
cookie = environ.get("HTTP_COOKIE")
if not cookie: return None
parsed = cookies.SimpleCookie()
parsed.load(cookie)
token = parsed.get("token")
if not token: return None
return token.value
# global socket connection
@io.on("connect")
def connect():
token = get_token(request.environ)
if not token: return
user_id = token_login(token)
if not user_id: return
join_room("user-" + user_id)
|