broadcast players to all in game room
This commit is contained in:
parent
5cc2de004b
commit
f6fc5764aa
2 changed files with 13 additions and 15 deletions
|
@ -26,7 +26,8 @@ def get_room(game_id):
|
||||||
game.player_black = user['id']
|
game.player_black = user['id']
|
||||||
db.session.add(game)
|
db.session.add(game)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
join_game_notice(game_id, user)
|
print(game.player_black)
|
||||||
|
join_game_notice(game)
|
||||||
response = {'game': game_schema.dumps(game)}
|
response = {'game': game_schema.dumps(game)}
|
||||||
if game.player_black:
|
if game.player_black:
|
||||||
response['black'] = user_schema.dumps(User.query.filter_by(id=game.player_black).first())
|
response['black'] = user_schema.dumps(User.query.filter_by(id=game.player_black).first())
|
||||||
|
|
|
@ -18,19 +18,16 @@ def new_game_notice(room, game):
|
||||||
def new_room_notice(room):
|
def new_room_notice(room):
|
||||||
socketio.emit('new room', room, broadcast=True)
|
socketio.emit('new room', room, broadcast=True)
|
||||||
|
|
||||||
def join_game_notice(game_id, user):
|
def join_game_notice(game):
|
||||||
@socketio.on('join game')
|
|
||||||
def handle_join_game(data):
|
|
||||||
print(data)
|
|
||||||
game_id = data['game']
|
|
||||||
user_id = data['user']
|
|
||||||
game = Game.query.filter_by(id=game_id).first()
|
|
||||||
print('join game')
|
print('join game')
|
||||||
print(game)
|
print(game)
|
||||||
print(game['player_black'])
|
black = user_schema.dumps(User.query.filter_by(id=game.player_black).first())
|
||||||
|
white = user_schema.dumps(User.query.filter_by(id=game.player_white).first())
|
||||||
|
room_id = game.game_room
|
||||||
|
game_id = game.id
|
||||||
|
print(black)
|
||||||
|
@socketio.on('join game', namespace=f'/{room_id}')
|
||||||
|
def handle_join_game(data):
|
||||||
|
print('emit join game')
|
||||||
join_room(game_id)
|
join_room(game_id)
|
||||||
if not game['player_black']:
|
emit('join game', {'black': black, 'white': white}, broadcast=True)
|
||||||
game['player_black'] = user
|
|
||||||
user = user_schema.dumps(User.query.filter_by(id=user_id).first())
|
|
||||||
emit('new player', {'black': user}, broadcast=True)
|
|
||||||
emit('join game', data, room=f'game')
|
|
||||||
|
|
Loading…
Reference in a new issue