Exemplo n.º 1
0
    def response(self) -> etree:
        user = User.from_refid(self.data.refid)
        if user is None:
            raise Exception("This user should theoretically exist here")
        if user.card.cardid != self.data.uid:
            raise Exception(
                f"Card ID is incorrect: {user.card.cardid} != {self.data.uid}"
            )

        user_account = UserAccount(
            userid=user.userid,
            name=self.data.name,
            chara=self.data.chara,
            is_succession=self.data.is_succession,
        )
        db.session.add(user_account)

        user_data = UserData(
            userid=user.userid,
            style=2097152,
            style_2=0,
            secret_music=[0 for _ in range(0, 32)],
            secret_chara=0,
            syogo=[0, 0],
            perfect=0,
            great=0,
            good=0,
            poor=0,
            miss=0,
            time=0,
        )
        db.session.add(user_data)
        db.session.commit()

        return load_xml_template("cardutil", "regist")
Exemplo n.º 2
0
    def response(self) -> etree:
        refid = db.session.query(RefID).filter(RefID.refid == self.refid).one_or_none()

        if refid is None:
            raise Exception("RefID is None Here!")

        return load_xml_template("cardmng", "bindmodel", {"refid": refid.refid})
Exemplo n.º 3
0
 def response(self) -> etree:
     # tag is the crc8 checksum of free_music and free_chara
     # I also don't actually know what these free_music/chara values mean
     args = {
         "free_music": 262143,
         "free_chara": 1824,
         "tag": calculate_crc8(str(262143 + 1824)),
         "division": 14,
     }
     return load_xml_template("gameinfo", "get", args)
Exemplo n.º 4
0
    def response(self) -> etree:
        # Save the syogo data (assume single player right now)
        user = User.from_refid(self.players[0].refid)
        if user is None:
            raise Exception("user should not be none")

        user_data = user.user_data
        user_data.syogo = self.players[0].syogodata.get.syogo
        db.session.commit()

        return load_xml_template("customize", "regist")
Exemplo n.º 5
0
    def response(self) -> etree:
        # TODO: The facility data should be read in from a config file instead of being
        # hard coded here

        args = {
            "id": "CA-123",
            "country": "CA",
            "region": "MB",
            "name": "SenPi Arcade",
        }
        return load_xml_template("facility", "get", args)
Exemplo n.º 6
0
    def response(self) -> etree:
        rank_items = HitChart.get_ranking(self.hitchart_nr)

        # Generate all hitchart data xml
        hitchart_xml_str = ""
        for rank_item in rank_items:
            hitchart_xml_str += etree.tostring(
                load_xml_template("demodata", "get.data", {
                    "musicid": rank_item,
                    "last1": 0
                })).decode("UTF-8")

        args = {
            "hitchart_nr": self.hitchart_nr,
            "start": datetime.now().strftime(self.DT_FMT),
            "end": datetime.now().strftime(self.DT_FMT),
            "hitchart_data": hitchart_xml_str,
            "division": 14,
            "message": "SenPi's Kickass DrumMania V8 Machine",
        }

        return load_xml_template("demodata", "get", args)
Exemplo n.º 7
0
    def response(self) -> etree:
        # Grab the refid
        refid = db.session.query(RefID).filter(RefID.refid == self.refid).one_or_none()

        if refid is None:
            raise Exception("RefID Is None Here!")

        # Check if the pin is valid for the user
        user = refid.user
        status = (
            CardStatus.SUCCESS if user.pin == self.passwd else CardStatus.INVALID_PIN
        )

        return load_xml_template("cardmng", "authpass", {"status": status})
Exemplo n.º 8
0
    def response(self) -> etree:
        # Create a new user object with the given pin
        user = User(pin=self.passwd)
        db.session.add(user)
        db.session.commit()

        # Create the card, tie it to the user account
        card = Card(cardid=self.cardid, userid=user.userid)
        db.session.add(card)
        db.session.commit()

        # Generate the refid and return it
        refid = RefID.create_with_userid(user.userid)

        return load_xml_template("cardmng", "getrefid", {"refid": refid.refid})
Exemplo n.º 9
0
    def response(self) -> etree:
        # Grab user_data
        user = User.from_refid(self.player.refid)
        if user is None:
            raise Exception("User should not be none here")

        user_data = user.user_data

        # Generate history rounds (blank for now)
        history_rounds = ""
        for _ in range(0, 10):
            history_rounds += etree.tostring(
                load_xml_template("gametop",
                                  "get.history.round")).decode("UTF-8")

        music_hist_rounds = ""
        for _ in range(0, 20):
            music_hist_rounds += etree.tostring(
                load_xml_template("gametop",
                                  "get.music_hist.round")).decode("UTF-8")

        secret_music = user_data.secret_music
        secret_chara = user_data.secret_chara
        tag = calculate_crc8(str(sum(secret_music) + secret_chara))

        args = {
            "secret_music": " ".join(map(str, secret_music)),
            "style": user_data.style,
            "style_2": user_data.style_2,
            "secret_chara": secret_chara,
            "tag": tag,
            "history_rounds": history_rounds,
            "music_hist_rounds": music_hist_rounds,
        }

        return load_xml_template("gametop", "get", args)
Exemplo n.º 10
0
    def response(self) -> etree:
        user = User.from_refid(self.card.refid)

        new_user = (
            user is None or (account := UserAccount.from_userid(user.userid)) is None
        )

        # New User
        args: Dict[str, Any] = {"state": CheckStatus.NEW_USER}
        drop_children: Optional[Dict[str, List[str]]] = {
            "cardutil/card": [
                "name",
                "gdp",
                "skill",
                "all_skill",
                "chara",
                "syogo",
                "penalty",
            ],
        }

        # Existing User
        if not new_user and account is not None and user is not None:
            user_data = user.user_data
            # TODO: Add GDP, skill, all_skill here
            args = {
                "state": CheckStatus.EXISTING_USER,
                "name": account.name,
                "gdp": 0,
                "skill": 0,
                "all_skill": 0,
                "syogo": " ".join(map(str, user_data.syogo)),
                "chara": account.chara,
            }
            drop_children = None

        return load_xml_template("cardutil", "check", args, drop_children=drop_children)
Exemplo n.º 11
0
    def response(self) -> etree:
        for musicid in self.hitchart.musicids:
            hc = HitChart(musicid=musicid, playdate=datetime.now())
            logger.debug(f"Saving HitChart: {hc}")
            db.session.add(hc)
        db.session.commit()

        # Save player data
        playerinfo = self.player.playerinfo
        user = User.from_refid(playerinfo.refid)
        if user is not None:
            user_data = UserData.from_userid(user.userid)

            if user_data is None:
                raise Exception("user data shouldn't be none here")

            user_data.style = playerinfo.styles
            user_data.style_2 = playerinfo.styles_2
            user_data.secret_music = playerinfo.secret_music
            user_data.secret_chara = playerinfo.secret_chara
            user_data.perfect = playerinfo.perfect
            user_data.great = playerinfo.great
            user_data.good = playerinfo.good
            user_data.poor = playerinfo.poor
            user_data.miss = playerinfo.miss
            user_data.time = playerinfo.time
            db.session.commit()
        else:
            raise Exception("This user doesn't exist")

        # Save playdata
        for idx, data in enumerate(self.player.playdata):
            musicid = self.modedata.stages[idx].musicid
            play_data = PlayData(
                userid=user.userid,
                no=data.no,
                musicid=musicid,
                seqmode=data.seqmode,
                clear=data.clear,
                auto_clear=data.auto_clear,
                score=data.score,
                flags=data.flags,
                fullcombo=data.fullcombo,
                excellent=data.excellent,
                combo=data.combo,
                skill_point=data.skill_point,
                skill_perc=data.skill_perc,
                result_rank=data.result_rank,
                difficulty=data.difficulty,
                combo_rate=data.combo_rate,
                perfect_rate=data.perfect_rate,
            )
            db.session.add(play_data)
        db.session.commit()

        # Just send back a dummy object for now
        now_time = datetime.now().strftime(self.DT_FMT)

        # Generate history rounds (blank for now)
        history_rounds = ""
        for _ in range(0, 10):
            history_rounds += etree.tostring(
                load_xml_template("gameend",
                                  "regist.history.round")).decode("UTF-8")

        music_hist_rounds = ""
        for _ in range(0, 20):
            music_hist_rounds += etree.tostring(
                load_xml_template("gameend",
                                  "regist.music_hist.round")).decode("UTF-8")

        args = {
            "gamemode": self.gamemode.mode,
            "player_card": self.player.card,
            "player_no": self.player.no,
            "now_time": now_time,
            "history_rounds": history_rounds,
            "music_hist_rounds": music_hist_rounds,
        }

        return load_xml_template("gameend", "regist", args)
Exemplo n.º 12
0
 def response(self) -> etree:
     return load_xml_template(
         "pcbtracker", "alive", {"ecenable": btoi(self.paseli_active)}
     )
Exemplo n.º 13
0
 def response(self) -> etree:
     return load_xml_template("shopinfo", "regist")
Exemplo n.º 14
0
 def response(self) -> etree:
     return load_xml_template("message", "get")
Exemplo n.º 15
0
class Inquire(object):
    """
    Handle the CardMng Inquire request.

    Given the Card ID, determine if we have a brand new user or a returning one.

    <call model="K32:J:B:A:2011033000" srcid="00010203040506070809">
        <cardmng
            cardid="E00401007F7AD7A4"
            cardtype="1"
            method="inquire"
            model="HCV:J:A:A"
            update="1"
        />
    </call>
    """

    def __init__(self, req: ServiceRequest) -> None:
        self.cardid = get_xml_attrib(req.xml[0], "cardid")
        self.cardtype = int(get_xml_attrib(req.xml[0], "cardtype"))
        self.update = int(get_xml_attrib(req.xml[0], "update"))

        # Model doesn't always exist in the request, unsure what it's used for
        model_value = get_xml_attrib(req.xml[0], "model")
        self.model = model_value if model_value != "None" else None

    def response(self) -> etree:
        """
        Modifyable XML Text Replacements:
            refid: The RefID.refid value for an existing user
            newflag: Set to true for a new user, else 0
            binded: Set to true if the user has a profile/account, else 0
            status: See CardMng status consts at the top of this class
        """
        # New unregistered user
        args: Dict[str, Any] = {
            "newflag": 1,
            "binded": 0,
            "status": CardStatus.NOT_REGISTERED,
        }
        drop_attributes: Optional[Dict[str, List[str]]] = {
            "cardmng": [
                "refid",
                "dataid",
                "expired",
                "exflag",
                "useridflag",
                "extidflag",
            ]
        }

        # We have a returning user
        if (user := User.from_cardid(self.cardid)) is not None:
            refid = RefID.from_userid(user.userid)
            bound = UserAccount.from_userid(user.userid) is not None

            if refid is None:
                # TODO: better exception?
                raise Exception("RefID Should not be None here!")

            args = {
                "refid": refid.refid,
                "newflag": 0,
                "binded": btoi(bound),
                "status": CardStatus.SUCCESS,
            }
            drop_attributes = None

        return load_xml_template(
            "cardmng", "inquire", args, drop_attributes=drop_attributes
        )
Exemplo n.º 16
0
 def response(self) -> etree:
     return load_xml_template("pcbevent", "put")
Exemplo n.º 17
0
 def response(self) -> etree:
     return load_xml_template("dlstatus", "progress")