예제 #1
0
def on_join(data):
    print("ON JOIN")
    room_id = data[DATA_ROOM_ID]
    username = data[DATA_USERNAME]
    sid = request.sid

    if not room_id in ROOMS:
        print("EMITTING ERROR")
        emit('error', {'error': 'Unable to join room. Room does not exist.'})
    else:
        # if data[DATA_USERNAME] in ROOMS[data[DATA_ROOM_ID]].players:
        #     print ("User already exists in room")
        #     emit ('error', {'error': 'Unable to join room. A user with that name is currently connected.'})
        print("EMITTING JOIN ROOM")
        game = ROOMS[data[DATA_ROOM_ID]]
        #game.players.append(data[DATA_USERNAME])
        game.add_id_to_player(username, sid)
        print(json.dumps(game.to_dic()))
        #emit ('join_room', game.to_dic())
        join_room(room_id)
        #SID_TO_ROOM[sid] = room_id
        #emit (saladbowl_sockets.SOCKET_JOIN_ROOM_CAST, saladbowl_sockets.msg_join_room_cast(game), room=room_id)
        emit(saladbowl_sockets.SOCKET_GAME_UPDATE_CAST,
             saladbowl_sockets.msg_game_update_cast(game),
             room=room_id)
예제 #2
0
def on_start(data):
    room_id = data[DATA_ROOM_ID]
    print("RECEIVED START")
    game = ROOMS[room_id]
    game.game_state = Saladbowl_game.GS_WAITING_ON_TURN
    game.cur_player = random.choice(list(game.players_by_username.keys()))
    emit(saladbowl_sockets.SOCKET_GAME_UPDATE_CAST,
         saladbowl_sockets.msg_game_update_cast(game),
         room=room_id)
예제 #3
0
def on_change_team(data):
    username = data[DATA_USERNAME]
    room_id = data[DATA_ROOM_ID]
    print("RECEIVED CHANGE TEAM: " + username)
    game = ROOMS[room_id]
    game.get_player(username).change_team()
    print(json.dumps(game.to_dic()))
    emit(saladbowl_sockets.SOCKET_GAME_UPDATE_CAST,
         saladbowl_sockets.msg_game_update_cast(game),
         room=room_id)
예제 #4
0
def on_leave(data):
    username = data[DATA_USERNAME]
    room_id = data[DATA_ROOM_ID]
    print("RECEIVED LEAVE GAME: " + username)

    game = ROOMS[room_id]
    game.remove_player(username)
    print(json.dumps(game.to_dic()))
    emit(saladbowl_sockets.SOCKET_GAME_UPDATE_CAST,
         saladbowl_sockets.msg_game_update_cast(game),
         room=room_id)
예제 #5
0
def on_submit_words(data):
    room_id = data[DATA_ROOM_ID]
    username = data[DATA_USERNAME]
    words = data[DATA_WORD_LIST]
    game = ROOMS[room_id]
    game.players_by_username[username].submitted_words = True
    game.word_list.extend([x.strip() for x in words.split(';')])
    print("RECEIVED MESSAGE: {} {} WORDS: {}".format(room_id, username, words))
    emit(saladbowl_sockets.SOCKET_GAME_UPDATE_CAST,
         saladbowl_sockets.msg_game_update_cast(game),
         room=room_id)
예제 #6
0
def on_submit_pass_and_play_player(data):
    sid = request.sid
    room_id = data[DATA_ROOM_ID]
    username = data[DATA_USERNAME]
    words = data[DATA_WORD_LIST]
    team = data[DATA_TEAM]
    game = ROOMS[room_id]
    game.add_id_to_player(username, sid)
    new_player = game.get_player(username)
    new_player.team = team
    new_player.submitted_words = True
    print("ADDED PLAYER: " + username + " TO GAME")
    emit(saladbowl_sockets.SOCKET_GAME_UPDATE_CAST,
         saladbowl_sockets.msg_game_update_cast(game),
         room=room_id)