示例#1
0
        def populateData(res):
            failed = hasFailed(res)

            def actuallyPopulateData(theRes):
                if hasFailed(theRes):
                    self.parent.sendError("The server is currently not available. Please try again later.")
                    raise DatabaseServerLinkException(ERRORS["data_corrupt"])
                for key, value in u:
                    self.parent.player["key"] = value

            if not res:
                # User not found, populate with default variables
                u = User.create(
                    id=uuid.uuid5(UUID["cloudbox.users"], self.parent.player["username"]),
                    username=self.parent.player["username"],
                    firstseen=time.time(),
                    lastseen=time.time(),
                )

                def step2(theRes):
                    if hasFailed(theRes):
                        self.parent.sendError("The server is currently not available. Please try again later.")
                        raise DatabaseServerLinkException(ERRORS["data_corrupt"])
                    self.parent.db.runQuery(*UserServiceAssoc.create(
                        id=theRes,
                        service=1,  # Right now force ClassiCube
                        verified=1,  # Of course we're verified
                    ).sql()).addCallback(actuallyPopulateData)

                self.parent.db.runQuery(*u.sql()).addBoth(step2)
            else:
                # User found. Populate
                self.parent.db.runQuery(*User.select().where(User.id == res).sql()).addBoth(actuallyPopulateData)