Exemple #1
0
 def send(self, msg: str, sender: 'Player', to_self: bool = False) -> None:
     """Enqueue `msg` to all connected clients from `sender`."""
     self.enqueue(packets.sendMessage(sender=sender.name,
                                      msg=msg,
                                      recipient=self.name,
                                      sender_id=sender.id),
                  immune=() if to_self else (sender.id, ))
Exemple #2
0
 def send_selective(self, client, msg: str, targets) -> None:
     # Accept a set of players to enqueue the data to.
     for p in targets:
         p.enqueue(
             packets.sendMessage(client=client.name,
                                 msg=msg,
                                 target=self.name,
                                 client_id=client.id))
Exemple #3
0
    def send_bot(self, msg: str) -> None:
        """Enqueue `msg` to all connected clients from bot."""
        bot = glob.bot

        self.enqueue(
            packets.sendMessage(sender=bot.name,
                                msg=msg,
                                recipient=self.name,
                                sender_id=bot.id))
Exemple #4
0
 async def send(self,
                client: 'Player',
                msg: str,
                to_client: bool = False) -> None:
     self.enqueue(packets.sendMessage(client=client.name,
                                      msg=msg,
                                      target=self.name,
                                      client_id=client.id),
                  immune=() if to_client else (client.id, ))
Exemple #5
0
 async def send_selective(self, client: 'Player', msg: str,
                          targets: list['Player']) -> None:
     """Accept a set of players to enqueue the data to."""
     for p in targets:
         p.enqueue(
             packets.sendMessage(client=client.name,
                                 msg=msg,
                                 target=self.name,
                                 client_id=client.id))
Exemple #6
0
    def send(self, msg: str, sender: 'Player', to_self: bool = False) -> None:
        """Enqueue `msg` to all appropriate clients from `sender`."""
        data = packets.sendMessage(sender=sender.name,
                                   msg=msg,
                                   recipient=self.name,
                                   sender_id=sender.id)

        for p in self.players:
            if (sender.id not in p.blocks and (to_self or p.id != sender.id)):
                p.enqueue(data)
Exemple #7
0
 async def send_selective(self, client: 'Player', msg: str,
                          targets: list['Player']) -> None:
     """Enqueue `client`'s `msg` to `targets`."""
     for p in targets:
         p.enqueue(packets.sendMessage(
             client = client.name,
             msg = msg,
             target = self.name,
             client_id = client.id
         ))
Exemple #8
0
 async def send(self, client: 'Player', msg: str,
                to_self: bool = False) -> None:
     """Enqueue `client`'s `msg` to all connected clients."""
     self.enqueue(
         packets.sendMessage(
             client = client.name,
             msg = msg,
             target = self.name,
             client_id = client.id
         ),
         immune = () if to_self else (client.id,)
     )
Exemple #9
0
    def send_bot(self, msg: str) -> None:
        """Enqueue `msg` to all connected clients from bot."""
        bot = glob.bot

        msg_len = len(msg)

        if msg_len >= 31979:  # TODO ??????????
            msg = f'message would have crashed games ({msg_len} chars)'

        self.enqueue(
            packets.sendMessage(sender=bot.name,
                                msg=msg,
                                recipient=self.name,
                                sender_id=bot.id))
Exemple #10
0
                     utc_offset=utc_offset,
                     osu_ver=s[0],
                     pm_private=pm_private,
                     login_time=login_time,
                     clan=clan,
                     clan_rank=clan_rank)

    data = bytearray(packets.userID(p.id))
    data += packets.protocolVersion(19)
    data += packets.banchoPrivileges(p.bancho_priv
                                     | ClientPrivileges.Supporter)
    if first_login:
        data += packets.sendMessage(
            'Ruji',
            'Welcome to Iteki!\n\nIteki has a relatively unique experience from other servers as it is based on different source code and has many unique features.'
            '\n\nTo get started, you may be interested in knowing some useful commands:\n\n!req <rank/love> <set/map> - this is our request system:'
            '\nTo use this command you must first /np a map to Ruji (our bot) and you will then be able to request maps.'
            '\nThe choice between rank/love depends on whether you would like to request the map to be ranked or loved.\nThe map/set choices are depending on whether you want the entire set to be requested, or just the difficulty you did /np to.'
            '\n\nThats all you need to know for now.\nIf you have any issues please report them and have fun playing Iteki!\n\n',
            p.name, 1)

    if p.priv & Privileges.Nominator and not p.priv & Privileges.Staff:
        request = await glob.db.fetch('SELECT COUNT(id) AS count FROM requests'
                                      )
        if int(request["count"]) > 0:
            data += packets.notification(
                f'There is {request["count"]} outstanding map requests!')

    if int(user_info['frozen']) == 1:
        if dt.now().timestamp() > user_info['freezetime']:
            return (packets.notification(
                'You are banned as a result of not providing a liveplay.') +
Exemple #11
0
                data += packets.userStats(o)

        # the player may have been sent mail while offline,
        # enqueue any messages from their respective authors.
        # (thanks osu for doing this by name rather than id very cool)
        query = ('SELECT m.`msg`, m.`time`, m.`from_id`, '
                 '(SELECT name FROM users WHERE id = m.`from_id`) AS `from`, '
                 '(SELECT name FROM users WHERE id = m.`to_id`) AS `to` '
                 'FROM `mail` m WHERE m.`to_id` = %s AND m.`read` = 0')

        async for msg in glob.db.iterall(query, [p.id]):
            msg_time = dt.fromtimestamp(msg['time'])
            msg_ts = f'[{msg_time:%a %b %d @ %H:%M%p}] {msg["msg"]}'

            data += packets.sendMessage(client=msg['from'],
                                        msg=msg_ts,
                                        target=msg['to'],
                                        client_id=msg['from_id'])

        if first_login:
            # this is the player's first login, send them
            # some basic info about the server and its usage.

            if p.id == 3:
                # this is the first player registering on
                # the server, grant them full privileges.
                p.add_privs(Privileges.Staff | Privileges.Nominator
                            | Privileges.Whitelisted | Privileges.Tournament
                            | Privileges.Donator | Privileges.Alumni)

            data += packets.sendMessage(client=glob.bot.name,
                                        msg=WELCOME_MSG,
Exemple #12
0
class SendPrivateMessage(BanchoPacket, type=Packets.OSU_SEND_PRIVATE_MESSAGE):
    msg: osuTypes.message

    async def handle(self, p: Player) -> None:
        if p.silenced:
            log(f'{p} tried to send a dm while silenced.', Ansi.YELLOW)
            return

        msg = self.msg.msg
        target = self.msg.target

        if not (t := await glob.players.get_by_name(target)):
            log(f'{p} tried to write to non-existant user {target}.',
                Ansi.YELLOW)
            return

        if t.pm_private and p.id not in t.friends:
            p.enqueue(packets.userPMBlocked(target))
            log(f'{p} tried to message {t}, but they are blocking dms.')
            return

        if t.silenced:
            p.enqueue(packets.targetSilenced(target))
            log(f'{p} tried to message {t}, but they are silenced.')
            return

        msg = f'{msg[:2045]}...' if msg[2048:] else msg
        client, client_id = p.name, p.id

        if t.status.action == Action.Afk and t.away_msg:
            # send away message if target is afk and has one set.
            p.enqueue(
                packets.sendMessage(client, t.away_msg, target, client_id))

        if t.id == 1:
            # target is the bot, check if message is a command.
            cmd = msg.startswith(glob.config.command_prefix) \
            and await commands.process_commands(p, t, msg)

            if cmd and 'resp' in cmd:
                # command triggered and there is a response to send.
                p.enqueue(
                    packets.sendMessage(t.name, cmd['resp'], client, t.id))

            else:
                # no commands triggered.
                if match := regexes.now_playing.match(msg):
                    # user is /np'ing a map.
                    # save it to their player instance
                    # so we can use this elsewhere owo..
                    p.last_np = await Beatmap.from_bid(int(match['bid']))

                    if p.last_np:
                        if match['mods']:
                            # [1:] to remove leading whitespace
                            mods = Mods.from_np(match['mods'][1:])
                        else:
                            mods = Mods.NOMOD

                        if mods not in p.last_np.pp_cache:
                            await p.last_np.cache_pp(mods)

                        # since this is a DM to the bot, we should
                        # send back a list of general PP values.
                        # TODO: !acc and !mods in commands to
                        #       modify these values :P
                        _msg = [p.last_np.embed]
                        if mods:
                            _msg.append(f'{mods!r}')

                        msg = f"{' '.join(_msg)}: " + ' | '.join(
                            f'{acc}%: {pp:.2f}pp'
                            for acc, pp in zip((90, 95, 98, 99, 100
                                                ), p.last_np.pp_cache[mods]))

                    else:
                        msg = 'Could not find map.'

                    p.enqueue(packets.sendMessage(t.name, msg, client, t.id))
Exemple #13
0
                packets.silenceEnd(p.remaining_silence))

    # thank u osu for doing this by username rather than id
    query = ('SELECT m.`msg`, m.`time`, m.`from_id`, '
             '(SELECT name FROM users WHERE id = m.`from_id`) AS `from`, '
             '(SELECT name FROM users WHERE id = m.`to_id`) AS `to` '
             'FROM `mail` m WHERE m.`to_id` = %s AND m.`read` = 0')

    # the player may have been sent mail while offline,
    # enqueue any messages from their respective authors.
    async for msg in glob.db.iterall(query, p.id):
        msg_time = dt.fromtimestamp(msg['time'])
        msg_ts = f'[{msg_time:%Y-%m-%d %H:%M:%S}] {msg["msg"]}'

        data.extend(
            packets.sendMessage(msg['from'], msg_ts, msg['to'],
                                msg['from_id']))

    # TODO: enqueue ingame admin panel to staff members.
    """
    if p.priv & Privileges.Staff:
        async def get_server_stats():
            notif = packets.notification('\n'.join((
                f'Players online: {len(glob.players)}',
                f'Staff online: {len(glob.players.staff)}'
            )))

            p.enqueue(notif)

        server_stats = await p.add_to_menu(get_server_stats, reusable=True)

        admin_panel = (
Exemple #14
0
    data += packets.silenceEnd(p.remaining_silence)

    # thank u osu for doing this by username rather than id
    query = ('SELECT m.`msg`, m.`time`, m.`from_id`, '
             '(SELECT name FROM users WHERE id = m.`from_id`) AS `from`, '
             '(SELECT name FROM users WHERE id = m.`to_id`) AS `to` '
             'FROM `mail` m WHERE m.`to_id` = %s AND m.`read` = 0')

    # the player may have been sent mail while offline,
    # enqueue any messages from their respective authors.
    async for msg in glob.db.iterall(query, p.id):
        msg_time = dt.fromtimestamp(msg['time'])
        msg_ts = f'[{msg_time:%a %b %d @ %H:%M%p}] {msg["msg"]}'

        data += packets.sendMessage(
            msg['from'], msg_ts,
            msg['to'], msg['from_id']
        )

    # TODO: enqueue ingame admin panel to staff members.
    """
    if p.priv & Privileges.Staff:
        async def get_server_stats():
            notif = packets.notification('\n'.join((
                f'Players online: {len(glob.players)}',
                f'Staff online: {len(glob.players.staff)}'
            )))

            p.enqueue(notif)

        server_stats = await p.add_to_menu(get_server_stats, reusable=True)
Exemple #15
0
    if t.pm_private and p.id not in t.friends:
        p.enqueue(packets.userPMBlocked(target))
        printlog(f'{p} tried to message {t}, but they are blocking dms.')
        return

    if t.silenced:
        p.enqueue(packets.targetSilenced(target))
        printlog(f'{p} tried to message {t}, but they are silenced.')
        return

    msg = f'{msg[:2045]}...' if msg[2048:] else msg
    client, client_id = p.name, p.id

    if t.status.action == Action.Afk and t.away_msg:
        # Send away message if target is afk and has one set.
        p.enqueue(packets.sendMessage(client, t.away_msg, target, client_id))

    if t.id == 1:
        # Target is Aika, check if message is a command.
        cmd = msg.startswith(glob.config.command_prefix) \
            and commands.process_commands(p, t, msg)

        if cmd and 'resp' in cmd:
            # Command triggered and there is a response to send.
            p.enqueue(packets.sendMessage(t.name, cmd['resp'], client, t.id))
        else:  # No command triggered.
            if match := _np_regex.match(msg):
                # User is /np'ing a map.
                # Save it to their player instance
                # so we can use this elsewhere owo..
                p.last_np = Beatmap.from_bid(int(match['bid']), cache_pp=True)
Exemple #16
0
 def send(self, client, msg: str) -> None:
     self.enqueue(packets.sendMessage(client=client.name,
                                      msg=msg,
                                      target=self.name,
                                      client_id=client.id),
                  immune={client.id})