Exemplo n.º 1
0
def decrease_clients(room_id):
    room = Room.objects(Q(name=room_id['room'])).first()
    if room_id['client'] in room.clients:
        room.clients.remove(room_id['client'])
        log.info('Leave game room: ' + str(room_id) + ". Current clients: " +
                 str(room.clients))
        if len(room.clients) == 0:
            close_room(room_id['room'])
        else:
            room.save()
Exemplo n.º 2
0
def get_languages():
    lang_dict = {}
    path = 'language_cards/static/languages/'
    files = os.listdir(path)
    for filename in files:
        if (filename.count('_') == 0):
            lang_code = ""
        else:
            lang_code = filename[filename.find('_') + 1:filename.find('.')]
        with codecs.open(path + filename, 'r', 'utf-8') as f:
            lines = f.readlines()
            if ((lines[0])[0] == '#' and is_properties(lines)):
                lang_dict[lang_code] = lines[0][1:len(lines[0]) - 1]
            else:
                log.info('Wrong language file ' + filename)
    return lang_dict
Exemplo n.º 3
0
def get_default_settings():
    try:
        config = configparser.RawConfigParser()
        config.read('settings.properties')
        sett = {
            'minCardWidth': config['room']['minCardWidth'],
            'defaultCardWidth': config['room']['defaultCardWidth'],
            'maxCardWidth': config['room']['maxCardWidth'],
            'stepCardWidth': config['room']['stepCardWidth'],
            'minCardHeight': config['room']['minCardHeight'],
            'defaultCardHeight': config['room']['defaultCardHeight'],
            'maxCardHeight': config['room']['maxCardHeight'],
            'stepCardHeight': config['room']['stepCardHeight'],
            'minCardFontSize': config['room']['minCardFontSize'],
            'defaultCardFontSize': config['room']['defaultCardFontSize'],
            'maxCardFontSize': config['room']['maxCardFontSize'],
            'stepCardFontSize': config['room']['stepCardFontSize']
        }
        return sett
    except Exception:
        log.info('Error in config file')
Exemplo n.º 4
0
def add_room(room):
    decks = []
    current_numbers = []
    for deckname in room['decks']:
        deck = Deck.objects(Q(name=deckname)).first()
        cards = deck.cards
        random.shuffle(cards)
        if len(cards) > 1:
            decks.append(cards)
        else:
            l = []
            l.append(cards)
            decks.append(l)
        current_numbers.append(0)
    time = datetime.datetime.utcnow
    new_room = Room(name=room['id'],
                    decks=decks,
                    current_numbers=current_numbers,
                    last_update=time)
    new_room.save()
    log.info('Created game room with id: ' + str(new_room['id']))
    delete_old_rooms()
Exemplo n.º 5
0
def close_room(room_id):
    room = Room.objects(Q(name=room_id)).first()
    room.delete()
    log.info('Close game room: ' + str(room_id))
Exemplo n.º 6
0
def increase_clients(room_id):
    room = Room.objects(Q(name=room_id['room'])).first()
    room.clients.append(room_id['client'])
    log.info('Join game room: ' + str(room_id['room']) +
             ". Current clients: " + str(room.clients))
    room.save()