示例#1
0
async def handle_get_mail(p):
    mail_query = PenguinPostcard.load(parent=Penguin.on(
        Penguin.id == PenguinPostcard.sender_id)).where(
            PenguinPostcard.penguin_id == p.id).order_by(
                PenguinPostcard.send_date.desc())

    postcards = []
    pst = pytz.timezone(p.server.config.timezone)
    async with p.server.db.transaction():
        async for postcard in mail_query.gino.iterate():
            sender_name, sender_id = ('sys',
                                      0) if postcard.sender_id is None else (
                                          postcard.parent.safe_nickname(
                                              p.server.config.lang),
                                          postcard.sender_id)

            pst_send_date = postcard.send_date.astimezone(pst)
            pst_send_date = pst_send_date.replace(tzinfo=None)

            offset = datetime.timedelta(
                seconds=(postcard.send_date - pst_send_date).total_seconds())
            sent_timestamp = int((postcard.send_date + offset).timestamp())

            postcards.append(
                f'{sender_name}|{sender_id}|{postcard.postcard_id}|'
                f'{postcard.details}|{sent_timestamp+1}|{postcard.id}|{int(postcard.has_read)}'
            )
    await p.send_xt('mg', *postcards)
示例#2
0
async def handle_get_buddies(p):
    buddies_query = BuddyList.load(parent=Penguin.on(Penguin.id == BuddyList.buddy_id)).where(
        BuddyList.penguin_id == p.id)
    request_query = BuddyRequest.load(parent=Penguin.on(Penguin.id == BuddyRequest.requester_id)).where(
        BuddyRequest.penguin_id == p.id)

    buddies = []
    best_buddies = []
    characters = []
    best_characters = []

    async with p.server.db.transaction():
        buddy_list = buddies_query.gino.iterate()
        buddy_requests = request_query.gino.iterate()

        async for buddy in buddy_list:
            buddy_presence = int(buddy.buddy_id in p.server.penguins_by_id)
            buddies.append(f'{buddy.buddy_id}|{buddy.parent.safe_nickname(p.server.config.lang)}|{buddy_presence}')

            if buddy.best_buddy:
                best_buddies.append(str(buddy.buddy_id))

        for character in p.character_buddies.values():
            character_presence = int(character.character_id in p.server.penguins_by_character_id)
            characters.append(f'{character.character_id}|{character_presence}')

            if character.best_buddy:
                best_characters.append(str(character.character_id))

        requests = [f'{request.requester_id}|{request.parent.safe_nickname(p.server.config.lang)}'
                    async for request in buddy_requests]

    best_friend_count = len(best_buddies) + len(best_characters)
    notification_aware = int(best_friend_count >= 1)
    best_friends_enabled = int((len(buddies) + len(characters)) >= 6)
    await p.send_xt('gs', best_friend_count, notification_aware, int(p.active), best_friends_enabled)

    await p.send_xt('gb', *buddies)
    await p.send_xt('pbr', *requests)
    await p.send_xt('gc', *characters)

    if best_friends_enabled:
        await p.send_xt('gbf', *best_buddies)
        await p.send_xt('gbc', *best_characters)

    await update_player_presence(p)
示例#3
0
async def get_active_igloo_string(p, penguin_id):
    igloo = await PenguinIglooRoom.load(parent=Penguin.on(Penguin.igloo == PenguinIglooRoom.id))\
         .where(PenguinIglooRoom.penguin_id == penguin_id).gino.first()

    furniture_string = await get_layout_furniture(p, igloo.id)
    like_count = await get_layout_like_count(igloo.id)
    return f'{igloo.id}:1:0:{int(igloo.locked)}:{igloo.music}:{igloo.flooring}:' \
           f'{igloo.location}:{igloo.type}:{like_count}:{furniture_string}'
示例#4
0
async def create_temporary_room(p, penguin_id):
    igloo = None
    if penguin_id in p.server.penguins_by_id:
        igloo_owner = p.server.penguins_by_id[penguin_id]
        igloo = igloo_owner.igloo_rooms[igloo_owner.igloo]
        p.server.igloos_by_penguin_id[penguin_id] = igloo
    elif penguin_id not in p.server.igloos_by_penguin_id:
        igloo = await PenguinIglooRoom.load(parent=Penguin.on(Penguin.igloo == PenguinIglooRoom.id)) \
            .where(PenguinIglooRoom.penguin_id == penguin_id).gino.first()
        if igloo is not None:
            p.server.igloos_by_penguin_id[penguin_id] = igloo
    return igloo
示例#5
0
async def handle_get_ignore_list(p):
    ignore_query = IgnoreList.load(parent=Penguin.on(
        Penguin.id == IgnoreList.ignore_id)).where(
            IgnoreList.penguin_id == p.id)

    async with p.server.db.transaction():
        ignore_list = ignore_query.gino.iterate()
        ignores = [
            f'{ignore.ignore_id}|{ignore.parent.safe_nickname(p.server.config.lang)}'
            async for ignore in ignore_list
        ]

    await p.send_xt('gn', *ignores)
示例#6
0
async def handle_get_mail(p):
    mail_query = PenguinPostcard.load(parent=Penguin.on(Penguin.id == PenguinPostcard.sender_id)).where(
        PenguinPostcard.penguin_id == p.data.id).order_by(
        PenguinPostcard.send_date.desc())

    postcards = []
    async with p.server.db.transaction():
        async for postcard in mail_query.gino.iterate():
            sender_name, sender_id = ('sys', 0) if postcard.sender_id is None else (
                postcard.parent.nickname, postcard.sender_id)
            sent_timestamp = int(time.mktime(postcard.send_date.timetuple()))
            postcards.append(f'{sender_name}|{sender_id}|{postcard.postcard_id}|'
                             f'{postcard.details}|{sent_timestamp}|{postcard.id}|{int(postcard.has_read)}')
    await p.send_xt('mg', *postcards)
示例#7
0
async def handle_get_buddies_legacy(p):
    buddies_query = BuddyList.load(parent=Penguin.on(Penguin.id == BuddyList.buddy_id)).where(
        BuddyList.penguin_id == p.data.id)

    buddies = []

    async with p.server.db.transaction():
        buddy_list = buddies_query.gino.iterate()

        async for buddy in buddy_list:
            buddy_presence = int(buddy.buddy_id in p.server.penguins_by_id)
            buddies.append(f'{buddy.buddy_id}|{buddy.parent.nickname}|{buddy_presence}')

    await p.send_xt('gb', *buddies)
    await update_player_presence(p)
示例#8
0
async def get_igloo(penguin_id):
    return await PenguinIglooRoom.load(parent=Penguin.on(Penguin.igloo == PenguinIglooRoom.id))\
        .where(PenguinIglooRoom.penguin_id == penguin_id).gino.first()
示例#9
0
async def get_legacy_igloo_string(p, penguin_id):
    igloo = await PenguinIglooRoom.load(parent=Penguin.on(Penguin.igloo == PenguinIglooRoom.id))\
         .where(PenguinIglooRoom.penguin_id == penguin_id).gino.first()

    furniture_string = await get_layout_furniture(p, igloo.id)
    return f'{igloo.type}%{igloo.music}%{igloo.flooring}%{furniture_string}'