コード例 #1
0
    async def from_sql(cls,
                       spc: Union[str, int],
                       discord=False) -> Optional["Player"]:
        if discord:
            typ = "discord"
        elif isinstance(spc, str):
            typ = "name"
        elif isinstance(spc, int):
            typ = "id"
        else:
            return  # ?

        user = await glob.db.fetchrow(f"SELECT * FROM users WHERE {typ} = %s",
                                      [spc])

        if not user:
            return

        self = cls(
            id=user["id"],
            name=user["name"],
            token="",
            offset=0,
            login_time=0,
            country_iso=user["country"],
            country=0,
            loc=[0, 0],
            pw="",
            priv=Privileges(user["priv"]),
            freeze_timer=user["freeze_timer"],
            discord=user.get("discord"),
        )

        if clan := user["clan"]:
            self.clan = glob.clans.get(clan)
コード例 #2
0
    async def from_sql(cls, spc: Union[str, int],
                       discord = False) -> Optional['Player']:
        if discord:
            typ = 'discord'
        elif isinstance(spc, str):
            typ = 'name'
        elif isinstance(spc, int):
            typ = 'id'
        else:
            return # ?

        user = await glob.db.fetchrow(f'SELECT * FROM users WHERE {typ} = %s', [spc])

        if not user:
            return

        self = cls(
            id=user['id'],
            name=user['name'],
            token='',
            offset=0,
            login_time=0,
            country_iso=user['country'],
            country=0,
            loc=[0, 0],
            pw='',
            priv=Privileges(user['priv']),
            freeze_timer=datetime.fromtimestamp(user['freeze_timer']),
            discord=user['discord']
        )

        if (clan := user['clan']):
            self.clan = glob.clans.get(clan)
コード例 #3
0
    def __init__(self, **kwargs) -> None:
        self.id: Optional[int] = kwargs.get("id")
        self.name: Optional[str] = kwargs.get("name")
        self.token: str = kwargs.get(
            "token",
            "",
        )  # we will set default token in case of bot which won't have a token provided
        self.pw: Optional[str] = kwargs.get("pw")  # used for /web/ auth
        self.offset: Optional[int] = kwargs.get("offset")
        self.login_time: Optional[int] = kwargs.get("login_time")
        self.priv: Privileges = kwargs.get("priv", Privileges(0))
        self.country_iso: Optional[str] = kwargs.get("country_iso")
        self.country: Optional[int] = kwargs.get("country")
        self.loc: Optional[list[float]] = kwargs.get(
            "loc",
            [0.0, 0.0],
        )  # store as list cus y not (long, lat)
        self.friends: list[int] = []
        self.queue = bytearray()
        self.action: int = 0
        self.base_info: str = ""
        self.map_md5: str = ""
        self.mods: int = 0
        self.mode: int = 0
        self.mode_vn: int = 0
        self.map_id: int = 0
        self.stats: dict[osuModes, Stats] = {}
        self.achievements: list["Achievement"] = []

        self.spectators: list["Player"] = []
        self.spectating: Optional["Player"] = None
        self.channels: list[Channel] = []

        self.match: Optional[Match] = None

        self.np: Optional[Beatmap] = None
        self.last_score: Optional[Score] = None

        self.clan: Optional[Clan] = None

        self.last_ping: int = 0

        self.restricted: bool = False
        self.frozen: bool = False

        self.freeze_timer: float = kwargs.get("freeze_timer", 0.0)

        self.registered_at: int = kwargs.get("registered_at", 0)
        self.silence_end: int = kwargs.get("silence_end", 0)
        self.donor_end: int = kwargs.get("donor_end", 0)

        self.discord: int = kwargs.get("discord", 0)
コード例 #4
0
    async def login(cls, user: dict) -> "Player":
        self = cls(
            id=user["id"],
            name=user["name"],
            token=user["token"],
            offset=user["offset"],
            login_time=user["ltime"],
            country_iso=user["country_iso"],
            country=user["country"],
            loc=[user["lon"], user["lat"]],
            pw=user["md5"].decode(),
            priv=Privileges(user["priv"]),
            freeze_timer=user["freeze_timer"],
        )

        if discord := user.get("discord"):
            self.discord = discord
コード例 #5
0
    def __init__(self, **kwargs) -> None:
        self.id: int = kwargs.get('id')
        self.name: str = kwargs.get('name')
        self.token: str = kwargs.get('token', '') # we will set default token in case of bot which won't have a token provided
        self.pw: str = kwargs.get('pw') # used for /web/ auth
        self.offset: int = kwargs.get('offset')
        self.login_time: int = kwargs.get('login_time')
        self.priv = kwargs.get('priv', Privileges(0))
        self.country_iso: str = kwargs.get('country_iso')
        self.country: int = kwargs.get('country')
        self.loc: list[float, float] = kwargs.get('loc', [0.0, 0.0]) # store as list cus y not (long, lat)
        self.friends: list[int] = []
        self.queue = queue.SimpleQueue()
        self.action: int = 0
        self.info: str = ''
        self.map_md5: str = ''
        self.mods: int = 0
        self.mode: int = 0
        self.mode_vn: int = 0
        self.map_id: int = 0
        self.stats: dict[osuModes, Stats] = {}
        self.achievements: list['Achievement'] = []

        self.spectators: list['Player'] = []
        self.spectating: Optional['Player'] = None
        self.channels: list[Channel] = []

        self.match: Optional[Match] = None

        self.np: Optional[Beatmap] = None
        self.last_score: Optional[Score] = None

        self.clan: Optional[Clan] = None

        self.last_ping: int = 0

        self.restricted: bool = False
        self.frozen: bool = False

        self.freeze_timer: int = kwargs.get('freeze_timer', 0)

        self.registered_at: int = kwargs.get('registered_at', 0)
        self.silence_end: int = kwargs.get('silence_end', 0)
        self.donor_end: int = kwargs.get('donor_end', 0)

        self.discord: int = kwargs.get('discord', 0)
コード例 #6
0
async def expired_donor() -> None:
    while True:  # this sux
        for user in list(donors):
            if user['donor_end'] < time.time():  # donor expired
                log(f"Removing {user['name']}'s expired donor.")
                donors.remove(user)

                if (p := await glob.players.get(id=user['id'])):
                    p.enqueue(
                        writer.serverRestart(0)
                    )  # login will handle the removal, we just need to force a relog
                    continue  # go to next player

                # user isn't online, we'll remove it ourselves
                user_priv = Privileges(user['priv'])
                user_priv &= ~Privileges.Supporter
                await glob.db.execute(
                    'UPDATE users SET priv = %s WHERE id = %s',
                    [int(user_priv), user['id']])

        await asyncio.sleep(600)  # run every 10 mins
コード例 #7
0
    async def login(cls, user: dict) -> 'Player':
        self = cls(
            id=user['id'],
            name=user['name'],
            token=user['token'],
            offset=user['offset'],
            login_time=user['ltime'],
            country_iso=user['country_iso'],
            country=user['country'],
            loc=[user['lon'], user['lat']],
            pw=user['md5'].decode(),
            priv=Privileges(user['priv']),
            freeze_timer=datetime.fromtimestamp(user['freeze_timer']),
            discord=user['discord']
        )

        self.friends = []
        async for user in glob.db.iter('SELECT user2 FROM friends WHERE user1 = %s', [self.id]):
            self.friends.append(user['user2'])

        clan = await glob.db.fetchval('SELECT clan FROM users WHERE id = %s', [self.id])
        if clan:
            self.clan = glob.clans.get(clan)

        if self.priv & Privileges.Restricted:
            self.restricted = True

        if self.priv & Privileges.Frozen:
            self.frozen = True

        db_achs = await glob.db.fetch('SELECT ach FROM user_achievements WHERE uid = %s', [self.id])
        for db in db_achs:
            for ach in glob.achievements:
                if db['ach'] == ach.id:
                    self.achievements.append(ach)

        return self