Esempio n. 1
0
    def _parse_attr(kwargs: dict[str, Any]) -> Optional[tuple[str, Any]]:
        """Get first matched attr & val from input kwargs. Used in get() methods."""
        for attr in ('token', 'id', 'name'):
            if val := kwargs.pop(attr, None):
                if attr == 'name':
                    attr = 'safe_name'
                    val = make_safe_name(val)

                return attr, val
Esempio n. 2
0
File: cho.py Progetto: Mxnuuel/gulag
    client_hashes.pop(1)  # no need for non-md5 adapters
    if client_hashes in ("f11423b10398dfbd7d460ab49615e997",
                         "0d9a67a7d3ba6cd75a4f496c9898c59d"):
        if not (t := await glob.players.get(name=username, sql=True)):
            return f'"{username}" not found.'
        reason = 'Cheat client found.'
        await t.ban(p, reason)

    del p

    pm_private = s[4] == '1'

    user_info = await glob.db.fetch(
        'SELECT id, name, priv, pw_bcrypt, '
        'silence_end, clan_id, clan_rank, frozen, freezetime '
        'FROM users WHERE safe_name = %s', [make_safe_name(username)])

    if not user_info:
        # no account by this name exists.
        return packets.userID(-1), 'no'

    verif = await glob.db.fetch(
        'SELECT verif, code FROM users WHERE safe_name = %s',
        [make_safe_name(username)])
    if not int(verif['verif']) and not glob.config.keys:
        return (packets.notification(
            f'You have not verified your account!\nIncase you need the instructions/code again, please do `!reg {verif["code"]}` in the Discord!\n\n(https://{glob.config.domain}/discord is the invite link if you need it)'
        ) + packets.userID(-1)), 'no'

    # get our bcrypt cache.
    bcrypt_cache = glob.cache['bcrypt']
Esempio n. 3
0
            if p not in immune:
                p.enqueue(data)

    async def get(self, sql: bool = False, **kwargs) -> Optional[Player]:
        """Get a player by token, id, or name."""
        for attr in ('token', 'id', 'name'):
            if val := kwargs.pop(attr, None):
                break
        else:
            raise ValueError(
                'must provide valid kwarg (token, id, name) to get()')

        if attr == 'name':
            # name -> safe_name
            attr = 'safe_name'
            val = make_safe_name(val)

        for p in self.players:
            if getattr(p, attr) == val:
                return p

        if not sql:
            # don't fetch from sql
            # if not specified
            return

        # try to get from sql.
        res = await glob.db.fetch(
            'SELECT id, name, priv, pw_bcrypt, '
            'silence_end, clan_id, clan_rank '
            f'FROM users WHERE {attr} = %s', [val])