Example #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)
Example #2
0
 def getUserByUsername(self, username):
     """
     Fetches the user record given an username.
     @param username The username to query for.
     @return tuple The user record.
     """
     return self.db.runQuery(*User.select().where(User.username == username).sql())
Example #3
0
 def getUserByUserID(self, userID):
     """
     Fetches the user record given an user.
     @param userID The user ID to query for.
     @return tuple The user record.
     """
     return self.db.runQuery(*User.select().where(User.id == userID).sql())
Example #4
0
    def getBans(self, username=None, ip=None):
        """
        Fetches the ban information using the information given - username, IP, or both.
        @param username The username to query for.
        @param ip The IP to query for.
        @return Deferred The deferred object.
        """
        assert not (username is None and ip is None)

        def afterGetUser(res):
            hasFailed(res)
            if not res:  # First time user
                return []
            return self.db.runQuery(*Bans.select().where(Bans.type == BAN_TYPES["globalBan"] & Bans.username == res[0]["username"]).sql()).addBoth(afterGetBans, username)

        def afterGetIP(res):
            hasFailed(res)
            if not res:  # First time visitor
                return []
            return self.db.runQuery(*Bans.select().where(Bans.type == BAN_TYPES["globalIPBan"] & Bans.recordID == res[0]["id"])).addBoth(afterGetBans, str(ip))

        def afterGetBans(res, lookupEntity):
            hasFailed(res)
            if not res:
                return {}
            elif len(res) > 1:
                # More than one record...
                self.logger.warn("Multiple global ban detected for lookup entity {}.", lookupEntity)
            return res[0]

        self.logger.debug("getBans for username {}, IP {}".format(username, ip))
        if username and ip is None:
            # We need the user id first
            return self.db.runQuery(*User.select(User.id).where(User.username == username).sql()).addBoth(afterGetUser)
        elif ip and username is None:
            # We need the IP id first
            if not isinstance(ip, IPAddress):
                ip = IPAddress(ip)
            return self.db.runQuery(*UserIP.select(UserIP.id).where(UserIP.ip == int(ip)).sql()).addBoth(afterGetIP)
        #elif ip and username: # TODO
        return {}