Esempio n. 1
0
def invoke(data):
    room = room_list.get(int(data['room']))

    if (room):
        room.addCommand(data)

    emit("invoke method", data, include_self=False, room=int(data['room']))
Esempio n. 2
0
def on_leave(data):
    room = room_list.get(int(data['room']))

    leave_room(data['room'])

    #update server room_list
    if room:
        room.removePlayer(request.sid)
Esempio n. 3
0
def disconnect():
    sid_data = sid_list.get(request.sid)
    room = room_list.get(int(sid_data['room']))

    #update server room_list
    if room:
        room.removePlayer(request.sid)

    sid_list.pop(request.sid)
    print(request.sid + " disconnected")
Esempio n. 4
0
def room(room_id):

    room = room_list.get(room_id)

    if (room):
        if room.getPlayerByNick(session['nickname']):
            return redirect(url_for('index'))
        else:
            return render_template('room.html',
                                   room_id=room_id,
                                   players=room.getPlayers())
    else:
        return redirect(url_for('index'))
Esempio n. 5
0
def create_room():
    if (len(room_list) == 300):
        return "Full"

    id = 1
    for i in range(1, 300):
        id = i
        if (not room_list.get(id)):
            break

    room_list.setdefault(
        id,
        Room(socketio, id, int(request.form['category']),
             int(request.form['subcategory'])))

    return redirect("/room/" + str(id))
Esempio n. 6
0
def on_join(data):
    username = session['nickname']
    join_room(int(data['room']))

    room = room_list.get(int(data['room']))
    if room:
        #add player and send current drawing
        print(username + ' has entered the room: ' + data['room'])

        sid_list.setdefault(request.sid, {
            'username': username,
            'room': data['room']
        })

        room.addPlayer(request.sid, {'username': username, 'points': 0})
        room.sendDraw(request.sid)

        #start game with 2 or more players
        if (room.getPlayersCount() > 1 and not room.isPlaying()):
            room.start()
Esempio n. 7
0
def sendMessage(data):
    room = room_list.get(int(data['room']))

    if (room):
        room.sendMessage(data['message'])
Esempio n. 8
0
def sendAnswer(data):
    room = room_list.get(int(data['room']))

    if (room):
        room.sendAnswer(data['answer'])