Ejemplo n.º 1
0
    async def get_sql(self, **kwargs: object) -> Optional[Player]:
        """Get a player by token, id, or name from sql."""
        attr, val = self._parse_attr(kwargs)

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

        if not res:
            return

        # encode pw_bcrypt from str -> bytes.
        res["pw_bcrypt"] = res["pw_bcrypt"].encode()

        if res["clan_id"] != 0:
            res["clan"] = glob.clans.get(id=res["clan_id"])
            res["clan_priv"] = ClanPrivileges(res["clan_priv"])
        else:
            res["clan"] = res["clan_priv"] = None

        return Player(**res, token="")
Ejemplo n.º 2
0
    async def get_sql(self, **kwargs) -> Optional[Player]:
        """Get a player by token, id, or name from sql."""
        attr, val = self._parse_attr(kwargs)

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

        if not res:
            return

        # encode pw_bcrypt from str -> bytes.
        res['pw_bcrypt'] = res['pw_bcrypt'].encode()

        if res['clan_id'] != 0:
            res['clan'] = glob.clans.get(id=res['clan_id'])
            res['clan_priv'] = ClanPrivileges(res['clan_priv'])
        else:
            res['clan'] = res['clan_priv'] = None

        return Player(**res, token='')
Ejemplo n.º 3
0
        # if this is the first user to create an account,
        # grant them all gulag privileges.
        if user_info['id'] == 3:
            user_info['priv'] |= (Privileges.Nominator | Privileges.Mod
                                  | Privileges.Admin | Privileges.Dangerous
                                  | Privileges.Supporter | Privileges.Premium
                                  | Privileges.Tournament
                                  | Privileges.Whitelisted)

        await glob.db.execute('UPDATE users SET priv = %s WHERE id = %s',
                              [user_info['priv'], user_info['id']])

    # get clan & clan rank if we're in a clan
    if user_info['clan_id'] != 0:
        clan = glob.clans.get(id=user_info.pop('clan_id'))
        clan_priv = ClanPrivileges(user_info.pop('clan_priv'))
    else:
        del user_info['clan_id']
        del user_info['clan_priv']
        clan = clan_priv = None

    extras = {
        'utc_offset': utc_offset,
        'osu_ver': osu_ver,
        'pm_private': pm_private,
        'login_time': login_time,
        'clan': clan,
        'clan_priv': clan_priv
    }

    p = Player(