Esempio n. 1
0
    def handleIgloos(self):
        igloos = yield self.penguin.dbpenguin.igloos.get()
        o_igloos = set(map(lambda x: x.igloo.id, self.cache.igloos))
        n_igloos = set(map(lambda x: x.id, igloos))

        #added_igloos = n_igloos - o_igloos
        #removed_igloos = o_igloos - n_igloos

        igloo_config = {i.igloo.id: i for i in self.cache.igloos}

        for igloo in igloos:
            if igloo.id not in igloo_config:
                iglooCache = PenguinObject()
                iglooCache.igloo = igloo
                self.cache.igloos.append(iglooCache)
            else:
                iglooCache = igloo_config[igloo.id]

            iglooCache.iglooFurnitures = yield igloo.iglooFurnitures.get()
            iglooCache.iglooLikes = yield igloo.iglooLikes.get()

            removeFurns = tuple(
                map(lambda x: x.id, iglooCache.iglooFurnitures[99:]))
            if len(removeFurns) > 0:
                yield IglooFurniture.deleteAll(
                    where=['igloo_id = ? AND id in ?', igloo.id, removeFurns])
Esempio n. 2
0
    def buildPenguin(self):
        self.handshakeStage = -1

        self.canRecvPacket = False
        self.ReceivePacketEnabled = True  # Penguin can receive packet only if both this and self.canRecvPacket is true.

        # Some XT packets are sent before J#JS to make sure client is alive, just to make sure to ignore it ;)
        # ('category', 'handler', 0 or 1 : execute : don't execute)
        self.ignorableXTPackets = [('s', 'j#js', 1),
                                   ('s', 'p#getdigcooldown', 0),
                                   ('s', 'u#h', 0), ('s', 'f#epfgf', 0),
                                   ('l', 'login', 1)]

        self.penguin = PenguinObject()
        self.penguin.name = None
        self.penguin.id = None

        self.penguin.room = None
        self.penguin.prevRooms = list()

        self.ref = weakref.proxy(self)

        # Initiate Packet Handler
        self.PacketHandler = PacketHandler(self.ref)
        self.CryptoHandler = Crypto(self.ref)
Esempio n. 3
0
    def __init__(self, penguin):
        self.penguin = penguin
        self.logger = logging.getLogger(TIMELINE_LOGGER)

        super(Refresh, self).__init__()

        self.logger.info(
            "Penguin ASync-Refresh service initialized : Penguin - {}".format(
                self.penguin['nickname']))
        self.RefreshManagerLoop = LoopingCall(self._refresh)
        self.firstTimeCall = True
        self.CacheInitializedDefer = Deferred()
        self.cache = PenguinObject()

        self.penguin.penguin.data = self.cache  # for easier access

        self.cacheHandlers = PenguinObject()

        self.logger.info(
            "Penguin ASync-Refresh Loop started, every {}(s) : Penguin - {}".
            format(self.REFRESH_INTERVAL, self.penguin['nickname']))

        self.RefreshManagerLoop.start(self.REFRESH_INTERVAL)
Esempio n. 4
0
    def _setupCache(self):
        self.penguin.penguin.recentStamps = []
        database_penguin = self.penguin.dbpenguin

        self.cache.avatar = yield database_penguin.avatar.get()
        if self.cache.avatar is None:
            self.cache.avatar = yield Avatar(
                penguin_id=self.penguin['id']).save()
            yield self.cache.avatar.refresh()

        self.cache.inventories = yield database_penguin.inventories.get()
        self.cache.assets = yield database_penguin.assets.get()
        self.cache.friends = yield database_penguin.friends.get()
        self.cache.requests = []
        friends_data = []
        for friend in self.cache.friends:
            friendObj = (yield Penguin.find(where=['swid = ?', friend.friend],
                                            limit=1))
            if friendObj is None:
                continue

            friend.friend_id = friendObj.id
            friend.onlinePresence = {'online_status': False}
            data = [
                int(friendObj.id), friendObj.nickname, friendObj.swid,
                friend.bff
            ]
            friends_data.append('|'.join(map(str, data)))

        self.penguin.send('fl', (yield database_penguin.requests.count()),
                          *friends_data)

        self.cache.ignores = yield database_penguin.ignores.get()
        self.cache.careItems = yield database_penguin.careItems.get()
        self.cache.stamps = yield database_penguin.stamps.get()
        self.cache.mails = yield database_penguin.mails.get()
        self.cache.bans = yield database_penguin.bans.get()
        self.cache.puffles = yield database_penguin.puffles.get()
        self.cache.stampCovers = yield database_penguin.stampCovers.get()
        self.cache.igloos = deque()

        igloos = yield database_penguin.igloos.get(limit=6)
        for igloo in igloos:
            iglooCache = PenguinObject()
            iglooCache.igloo = igloo
            iglooCache.iglooFurnitures = yield igloo.iglooFurnitures.get(
                limit=99)
            iglooCache.iglooLikes = yield igloo.iglooLikes.get()

            self.cache.igloos.append(iglooCache)

        self.cache.memberships = yield database_penguin.memberships.get()

        self.cacheHandlers.inventories = self.handleInventory
        self.cacheHandlers.assets = self.handleAssets
        self.cacheHandlers.friends = self.handleFriends
        self.cacheHandlers.requests = self.handleRequests
        self.cacheHandlers.ignores = self.handleIgnores
        self.cacheHandlers.careItems = self.handleCareItems
        self.cacheHandlers.stamps = self.handleStamps
        self.cacheHandlers.mails = self.handleMails
        self.cacheHandlers.bans = self.handleBans
        self.cacheHandlers.puffles = self.handlePuffles
        self.cacheHandlers.stampCovers = self.handleStampCovers
        self.cacheHandlers.igloos = self.handleIgloos

        self.penguin.penguin.coins = (yield Registry.getConfig().\
            execute("SELECT COALESCE(SUM(transaction), 0) FROM coins where penguin_id = %s" % self.penguin['id']))[0][0]

        self.penguin.penguin.igloo = yield self.initPenguinIglooRoom(
            self.penguin['id'])
        if self.penguin['igloo']._id not in self.getIgloos():
            igloo = yield database_penguin.igloos.get(
                where=['id = ?', self.penguin['igloo']._id], limit=1)
            iglooCache = PenguinObject()
            iglooCache.igloo = igloo
            iglooCache.iglooFurnitures = yield igloo.iglooFurnitures.get(
                limit=99)
            iglooCache.iglooLikes = yield igloo.iglooLikes.get()

            self.cache.igloos.append(iglooCache)

        self.penguin.penguin.currentIgloo = self.getIgloos()[
            self.penguin.dbpenguin.igloo].igloo
        self.setupCJMats()

        membership = yield database_penguin.memberships.get(
            orderby='expires desc', limit=1)
        if membership is None:
            #no membership records, give a free 7 day trial
            trialExpiry = time.time() + 7 * 24 * 60 * 60

            membership = yield \
                Membership(penguin_id=self.penguin['id'],
                           expires=Registry.getDBAPIClass("TimestampFromTicks")(trialExpiry),
                           comments='Redeemed 7-day auto free trial membership. - Timeline Server').save()

        self.penguin.penguin.member = MembershipHandler(
            membership, self.penguin)
        self.cache.avatar = yield database_penguin.avatar.get()
        if self.cache.avatar is None:
            self.cache.avatar = yield Avatar(
                penguin_id=self.penguin['id']).save()

        GeneralEvent('Setup-Cache', self)

        self.CacheInitializedDefer.callback(True)