Example #1
0
    async def like(
        self, item_id: int, typeid: int, special: int, dislike: bool = False, *, client: Client
    ) -> None:
        like = dislike ^ 1

        rs, udid, uuid = Coder.gen_rs(), Params.gen_udid(), Params.gen_uuid()
        values = [special, item_id, like, typeid, rs, client.account_id, udid, uuid]
        chk = Coder.gen_chk(type="like_rate", values=values)

        payload = (
            Params()
            .create_new(game_version=20)
            .put_definer("accountid", client.account_id)
            .put_password(client.encodedpass)
            .put_udid(udid)
            .put_uuid(uuid)
            .put_definer("itemid", item_id)
            .put_like(like)
            .put_type(typeid)
            .put_special(special)
            .put_rs(rs)
            .put_chk(chk)
            .finish()
        )

        resp = await self.http.request(Route.LIKE_ITEM, payload)

        if resp != 1:
            raise MissingAccess(f"Failed to like an item by ID: {item_id}.")
Example #2
0
    async def rate_level(self, level_id: int, rating: int, *, client: Client) -> None:
        assert 0 < rating <= 10, "Invalid star value given."

        rs, udid, uuid = Coder.gen_rs(), Params.gen_udid(), Params.gen_uuid()
        values = [level_id, rating, rs, client.account_id, udid, uuid]
        chk = Coder.gen_chk(type="like_rate", values=values)

        payload = (
            Params()
            .create_new()
            .put_definer("levelid", level_id)
            .put_definer("accountid", client.account_id)
            .put_password(client.encodedpass)
            .put_udid(udid)
            .put_uuid(uuid)
            .put_definer("stars", rating)
            .put_rs(rs)
            .put_chk(chk)
            .finish()
        )

        resp = await self.http.request(Route.RATE_LEVEL_STARS, payload)

        if resp != 1:
            raise MissingAccess(f"Failed to rate level by ID: {level_id}.")
Example #3
0
    async def update_profile(self, settings: Dict[str, int], *, client: Client) -> None:
        settings_cased = {Converter.snake_to_camel(name): value for name, value in settings.items()}

        rs = Coder.gen_rs()

        req_chk_params = [client.account_id]
        req_chk_params.extend(
            settings.get(param, 0)
            for param in (
                "user_coins",
                "demons",
                "stars",
                "coins",
                "icon_type",
                "icon",
                "diamonds",
                "acc_icon",
                "acc_ship",
                "acc_ball",
                "acc_bird",
                "acc_dart",
                "acc_robot",
                "acc_glow",
                "acc_spider",
                "acc_explosion",
            )
        )

        chk = Coder.gen_chk(type="userscore", values=req_chk_params)

        payload = (
            Params()
            .create_new()
            .put_definer("accountid", client.account_id)
            .put_password(client.encodedpass)
            .put_username(client.name)
            .put_seed(rs)
            .put_seed(chk, suffix=str(2))
            .finish()
        )

        payload.update(settings_cased)

        resp = await self.http.request(Route.UPDATE_USER_SCORE, payload)

        if not resp > 0:
            raise MissingAccess(f"Failed to update profile of a client: {client!r}")
Example #4
0
    async def upload_level(
        self,
        data: str,
        name: str,
        level_id: int,
        version: int,
        length: LevelLength,
        audio_track: int,
        desc: str,
        song_id: int,
        is_auto: bool,
        original: int,
        two_player: bool,
        objects: int,
        coins: int,
        stars: int,
        unlisted: bool,
        ldm: bool,
        password: Optional[Union[int, str]],
        copyable: bool,
        *,
        client: Client,
    ) -> int:
        data = Coder.zip(data)
        extra_string = "_".join(map(str, (0 for _ in range(55))))
        desc = Coder.do_base64(desc)

        upload_seed = Coder.gen_level_upload_seed(data)
        seed2 = Coder.gen_chk(type="level", values=[upload_seed])
        seed = Coder.gen_rs()

        pwd = 0

        if copyable and password is None:
            pwd = 1

        check, add = str(password), 1000000

        if check.isdigit() and int(check) < add:
            pwd = add + int(password)

        payload = (
            Params()
            .create_new()
            .put_definer("accountid", client.account_id)
            .put_definer("levelid", level_id)
            .put_definer("song", song_id)
            .put_seed(seed)
            .put_seed(seed2, suffix=2)
            .put_seed(0, prefix="wt")
            .put_seed(0, prefix="wt", suffix=2)
            .put_password(client.encodedpass)
            .put_username(client.name)
            .finish()
        )

        options = {
            "level_name": name,
            "level_desc": desc,
            "level_version": version,
            "level_length": length.value,
            "audio_track": audio_track,
            "auto": int(is_auto),
            "original": int(original),
            "two_player": int(two_player),
            "objects": objects,
            "coins": coins,
            "requested_stars": stars,
            "unlisted": int(unlisted),
            "ldm": int(ldm),
            "password": pwd,
            "level_string": data,
            "extra_string": extra_string,
            "level_info": "H4sIAAAAAAAAC_NIrVQoyUgtStVRCMpPSi0qUbDStwYAsgpl1RUAAAA=",
        }

        payload_cased = {
            Converter.snake_to_camel(key): str(value) for key, value in options.items()
        }

        payload.update(payload_cased)

        level_id = await self.http.request(Route.UPLOAD_LEVEL, payload)

        if level_id == -1:
            raise MissingAccess("Failed to upload a level.")

        return level_id