Exemplo n.º 1
0
    def do_request(self):
        method = self.request.get_argument("method", u"")
        self.num = int(self.request.get_argument("num", u"0"))
        self.type = self.request.get_argument("type", u"")
        self.fids = self.request.get_argument("fid", u"")
        if not self.uid:
            raise gen.Return({"status": 404, "content": []})

        self.mail = Mail.get(self.uid)
        #if (not self.mail) and self.uid != self.sbs_uid:
        #    fbbind = FBIdBind.get(self.uid)
        #    if fbbind:
        #        self.mail = Mail.get(fbbind.sbs_user_id)
        #        if self.mail:
        #            self.mail.pkey = self.uid
        #            self.mail.put()

        if not self.mail:
            self.mail = Mail()
            self.mail.pkey = self.uid

        if method == "list":
            result = self.mail_list()
        elif method == "send":
            result = self.mail_send()
        elif method == "recieve":
            result = self.mail_recieve()
        elif method == "count":
            result = self.mail_count()
        else:
            result = {"status": 404, "content": []}
        raise gen.Return(result)
Exemplo n.º 2
0
def msg_send(msg_types, target_id):
    if target_id:
        msgobj = Mail.get(target_id)
        if not msgobj:
            msgobj = Mail()
            msgobj.pkey = target_id

        for msg_type in msg_types:
            msg = {
                "mid": shortuuid.uuid()[:8],
                "local_mid": msg_type,
                "opened": False,
                "time": int(time.time()),
                "type": "reward",
                "num": 1,
                "name": "",
                "fbname": "",
                "avatar": "",
                "sender": "gmuser"
            }
            msgobj.delete_old()
            msgobj.mail.insert(0, msg)
            logging.info("target_id: %s %s" % (target_id, msg))

        msgobj.put()
Exemplo n.º 3
0
    def friend_request(self):
        player = Player.get(self.uid)
        name = ''
        fbname = ''
        avatar = ''
        if player:
            name = player.name
            fbname = player.fbname
            avatar = player.avatar
        fid = self.request.get_argument("fid", "")
        if not fid:
            return {"status": 404, "content": []}

        friend = Friends.get(fid)
        if not friend:
            friend = Friends()
            friend.pkey = fid

        if fid in self.friends.friends:
            return {"status": 405, "content": []}

        if len(friend.friends) >= FRIEND_LIMIT:
            return {"status": 406, "content": []}

        if len(self.friends.friends) >= FRIEND_LIMIT:
            return {"status": 407, "content": []}

        message = {
            "mid": shortuuid.uuid()[:8],
            "local_mid": "",
            "opened": False,
            "time": int(time.time()),
            "type": 'friend_request',
            "num": 1,
            "name": name,
            "fbname": fbname,
            "avatar": avatar,
            "sender": self.uid
        }

        mail = Mail.get(fid)
        if not mail:
            mail = Mail()
            mail.pkey = fid
        mail.delete_old()

        for message in mail.mail:
            if message.get("type") == "friend_request" and message.get(
                    "sender") == self.uid:
                return {"status": 408, "content": []}

        mail.mail.insert(0, message)
        mail.put()
        return {"status": 200, "content": []}
Exemplo n.º 4
0
    def friend_add(self):
        player = Player.get(self.uid)
        name = ''
        fbname = ''
        avatar = ''
        if player:
            name = player.name
            fbname = player.fbname
            avatar = player.avatar

        fid = self.request.get_argument("fid", "")
        code = self.request.get_argument("code", "")
        invite = False
        if code:
            invite = True
            regcode = RegCode.get(code)
            if regcode:
                fid = regcode.uid
            else:
                return {"status": 404, "first_invite": False, "content": []}

        if not fid:
            return {"status": 404, "first_invite": False, "content": []}

        if fid == self.uid:
            return {"status": 408, "first_invite": False, "content": []}

        friend = Friends.get(fid)
        if not friend:
            friend = Friends()
            friend.pkey = fid

        invite_ok = False
        if invite and (not self.friends.inviter
                       ) and self.device_id not in friend.invited:
            invited_count = len(friend.invited)
            if invited_count < FRIEND_LIMIT:
                friend.invited.append(self.device_id)
                invited_count += 1

                mail = Mail.get(fid)
                if not mail:
                    mail = Mail()
                    mail.pkey = fid
                count_set = (1, 3, 10, 20)
                if invited_count in count_set:
                    msg = {
                        "mid":
                        shortuuid.uuid()[:8],
                        "local_mid":
                        "invite_success_%d" %
                        (count_set.index(invited_count) + 1),
                        "opened":
                        False,
                        "time":
                        int(time.time()),
                        "type":
                        "reward",
                        "num":
                        1,
                        "name":
                        "",
                        "fbname":
                        "",
                        "avatar":
                        "",
                        "sender":
                        "gmuser"
                    }
                    mail.delete_old()
                    mail.mail.insert(0, msg)

                msg = {
                    "mid": shortuuid.uuid()[:8],
                    "local_mid": "invite_everytime_1",
                    "opened": False,
                    "time": int(time.time()),
                    "type": "reward",
                    "num": 1,
                    "name": "",
                    "fbname": "",
                    "avatar": "",
                    "sender": "gmuser"
                }
                mail.delete_old()
                mail.mail.insert(0, msg)

                msg = {
                    "mid": shortuuid.uuid()[:8],
                    "local_mid": "invite_everytime_2",
                    "opened": False,
                    "time": int(time.time()),
                    "type": "reward",
                    "num": 1,
                    "name": "",
                    "fbname": "",
                    "avatar": "",
                    "sender": "gmuser"
                }
                mail.delete_old()
                mail.mail.insert(0, msg)

                mail.put()
                invite_ok = True
                friend.put()
            else:
                return {"status": 409, "first_invite": False, "content": []}

        if len(friend.friends) >= FRIEND_LIMIT:
            return {
                "status": 205 if invite_ok else 407,
                "first_invite": False,
                "content": []
            }

        if len(self.friends.friends) >= FRIEND_LIMIT:
            return {
                "status": 205 if invite_ok else 406,
                "first_invite": False,
                "content": []
            }

        if self.uid not in friend.friends:
            friend.friends.append(self.uid)
            friend.put()

            message = {
                "mid": shortuuid.uuid()[:8],
                "local_mid": "",
                "opened": False,
                "time": int(time.time()),
                "type": 'friend',
                "num": 1,
                "name": name,
                "fbname": fbname,
                "avatar": avatar,
                "sender": self.uid,
                "gift": {
                    "type": 4,
                    "amount": 1
                }
            }

            mail = Mail.get(fid)
            if not mail:
                mail = Mail()
                mail.pkey = fid
            mail.delete_old()
            mail.mail.insert(0, message)
            mail.put()

        first_invite = False
        if fid not in self.friends.friends:
            self.friends.friends.append(fid)
            if invite and not self.friends.inviter:
                self.friends.inviter = fid
                first_invite = True
            self.friends.put()
        else:
            return {
                "status": 205 if invite_ok else 405,
                "first_invite": False,
                "content": []
            }
        return {
            "status": 200 if invite_ok else 206,
            "first_invite": first_invite,
            "content": self.friends.friends
        }
Exemplo n.º 5
0
    def mail_send(self):
        player = Player.get(self.uid)
        name = ''
        fbname = ''
        avatar = ''
        if player:
            name = player.name
            fbname = player.fbname
            avatar = player.avatar

        message = {
            "mid": shortuuid.uuid()[:8],
            "local_mid": "",
            "opened": False,
            "time": int(time.time()),
            "type": self.type,
            "num": self.num,
            "name": name,
            "fbname": fbname,
            "avatar": avatar,
            "sender": self.uid
        }

        if self.type == "heart":
            friends = Friends.get(self.uid)
            if not friends:
                friends = Friends()
                friends.pkey = self.uid

        for fid in self.fids.split(","):
            mail = Mail.get(fid)
            if not mail:
                mail = Mail()
                mail.pkey = fid

            if self.type == "heart":
                # 送体力检测
                f_obj = Player.get(fid)
                if not f_obj:
                    logging.info("[%s]赠送体力给好友[%s]时,好友不存在!" % (self.uid, fid))
                    continue  #好友不存在

                # 判断好友是关闭了接收体力
                if int(f_obj.recieve_heart) == 0:
                    logging.info("[%s]赠送体力给好友[%s]时,好友关闭了体力接收!" %
                                 (self.uid, fid))
                    continue
            message["mid"] = shortuuid.uuid()[:8]
            mail.delete_old()
            mail.mail.insert(0, message)
            mail.put()

            if self.type == "heart":
                friends.hearts[fid] = int(time.time())

        #if self.type == "heart":
        #    for key,value in copy.copy(friends.hearts.items()):
        #        if (int(time.time()) - value) > SENDHEART_INTERVAL:
        #            del friends.hearts[key]
        #    friends.put()

        result = {"status": 200, "content": []}
        return result
Exemplo n.º 6
0
    def do_request(self):
        method = self.request.get_argument("method", u"")
        if not self.uid:
            raise gen.Return({"status": 404, "content": []})
        self.player = Player.get(self.uid)
        result = {"status": 200, "content": []}
        if not self.player:
            self.player = Player()
            self.player.pkey = self.uid
            self.player.put()

        if method == "save":
            self.player.pkey = self.uid
            self.player.name = self.request.get_argument("name", u"nobody")
            self.player.fbname = self.request.get_argument("fbname", u"")
            self.player.avatar = self.request.get_argument("avatar", u"")
            self.player.banner = self.request.get_argument("banner", u"")
            self.player.stars = int(self.request.get_argument("stars", u"0"))
            self.player.fb_id = self.request.get_argument("fb_id", u"")
            self.player.level = int(self.request.get_argument("level", u"0"))
            self.player.recieve_heart = int(
                self.request.get_argument("recieve_heart", u"1"))

            maillist = self.system_mails
            m = Mail.get(self.uid)
            if not m:
                m = Mail()
                m.pkey = self.uid
            newmail = False
            for mail in self.system_mails:
                if mail.get("mid") and mail.get(
                        "mid") not in self.player.system_mail:
                    mail_send = copy.deepcopy(mail)
                    mail_send["mid"] = shortuuid.uuid()[:8]
                    self.player.system_mail.append(mail.get("mid"))
                    m.append(mail_send)
                    newmail = True
            if newmail:
                m.put()

            self.player.put()

            if self.sbs_uid and self.player.fb_id:
                sbs_bind = FBIdBind.get(self.player.fb_id)
                if not sbs_bind:
                    sbs_bind = FBIdBind()
                    sbs_bind.pkey = self.player.fb_id
                    sbs_bind.sbs_user_id = self.sbs_uid
                    sbs_bind.put()

            level = self.request.get_argument("cur_level", u"0")
            level_star = int(self.request.get_argument("level_star", u"0"))
            level_score = int(self.request.get_argument("level_score", u"0"))

            level_key = "%s_%s" % (self.uid, level)

            l = Level.get(level_key)
            if not l:
                l = Level()
                l.pkey = level_key
                l.stars = level_star
                l.score = level_score
            elif level_star > l.stars:
                l.stars = level_star
            elif level_score > l.score:
                l.score = level_score
            l.put()

        elif method == "del":
            self.player.delete()
        elif method == "finance":
            f = Finance.get(self.uid)
            if not f:
                f = Finance()
                f.pkey = self.uid
            f.source = self.request.get_argument("source", u"")
            f.total_gold = int(self.request.get_argument("total_gold", u"0"))
            f.total_free_gold = int(
                self.request.get_argument("total_free_gold", u"0"))
            f.total_pay_gold = int(
                self.request.get_argument("total_pay_gold", u"0"))
            f.total_ruby = int(self.request.get_argument("total_ruby", u"0"))
            f.total_free_ruby = int(
                self.request.get_argument("total_free_ruby", u"0"))
            f.total_pay_ruby = int(
                self.request.get_argument("total_pay_ruby", u"0"))
            f.gold = int(self.request.get_argument("gold", u"0"))
            f.free_gold = int(self.request.get_argument("free_gold", u"0"))
            f.pay_gold = int(self.request.get_argument("pay_gold", u"0"))
            old_ruby = f.ruby
            ruby_changed = False
            f.ruby = int(self.request.get_argument("ruby", u"0"))
            if old_ruby != f.ruby:
                ruby_changed = True

            f.free_ruby = int(self.request.get_argument("free_ruby", u"0"))
            f.pay_ruby = int(self.request.get_argument("pay_ruby", u"0"))

            delta_ruby = int(self.request.get_argument("delta_ruby", u"0"))
            delta_free_ruby = int(
                self.request.get_argument("delta_free_ruby", u"0"))

            f.put()

            if ruby_changed:
                r = Ruby.get(self.uid)
                if not r:
                    r = Ruby()
                    r.pkey = self.uid
                if len(r.list) > 500:
                    r.list.pop()
                if ruby_changed:
                    r.list.insert(0, [
                        f.source, f.ruby, f.pay_ruby, delta_ruby,
                        delta_free_ruby,
                        time.time()
                    ])
                r.put()

        elif method == "getbind":
            pid = self.request.get_argument("pid", u"")
            player = Player.get(pid)
            if player and player.fb_id:
                result["content"].append(player.fb_id)
        elif method == "getfbbind":
            pid = self.request.get_argument("pid", u"")
            sbs_bind = FBIdBind.get(pid)
            if sbs_bind and sbs_bind.sbs_user_id:
                result["content"].append(sbs_bind.sbs_user_id)
            result = {"status": 404, "content": []}
        elif method == "checkin":
            starttime = self.request.get_argument("start", "0000")
            endtime = self.request.get_argument("end", "9999")
            c = Checkin.get(self.uid)
            if not c:
                c = Checkin()
                c.pkey = self.uid

            now = (datetime.datetime.now() -
                   datetime.timedelta(hours=3)).strftime("%Y%m%d")
            if c.data.get(now) == 1:
                result["status"] = 201
            else:
                c.data[now] = 1
                for key in c.data.keys():
                    if key < starttime or key > endtime:
                        del c.data[key]
                c.put()

                l = len(c.data)
                if l in (1, 2, 3, 4, 5, 6, 7, 8):
                    msgobj = Mail.get(self.uid)
                    if not msgobj:
                        msgobj = Mail()
                        msgobj.pkey = self.uid

                    msg = {
                        "mid": shortuuid.uuid()[:8],
                        "local_mid": "checkInActivity_%d" % (l),
                        "opened": False,
                        "time": int(time.time()),
                        "type": "reward",
                        "num": 1,
                        "name": "",
                        "fbname": "",
                        "avatar": "",
                        "sender": "gmuser"
                    }

                    msgobj.delete_old()
                    msgobj.mail.insert(0, msg)
                    msgobj.put()

            result["content"] = c.data.keys()

        # 签到事件2
        elif method == "checkin_event":
            logging.info("checkin_event:%s" % self.uid)
            c = CheckinEvent.get(self.uid)
            if not c:
                c = CheckinEvent()
                c.pkey = self.uid

            now = (datetime.datetime.now() -
                   datetime.timedelta(hours=3)).strftime("%Y%m%d")
            if c.data.get(now) == 1:
                result["status"] = 201
            else:
                c.data[now] = 1
                for key in c.data.keys():
                    if not key.startswith(now[:6]):
                        del c.data[key]
                c.put()

            result["content"] = c.data.keys()

        elif method == "getservertime":
            result["content"] = int(time.time())

        elif method == "checkinlist":
            starttime = self.request.get_argument("start", "0000")
            endtime = self.request.get_argument("end", "9999")
            c = Checkin.get(self.uid)
            if not c:
                c = Checkin()
                c.pkey = self.uid
            now = (datetime.datetime.now() -
                   datetime.timedelta(hours=3)).strftime("%Y%m")
            for key in c.data.keys():
                if key < starttime or key > endtime:
                    del c.data[key]
            c.put()
            result["content"] = c.data.keys()
        raise gen.Return(result)
Exemplo n.º 7
0
        #logging.info("activity notice data %s" % (data))
    except Exception, e:
        logging.info(str(e))

    try:
        f = open(os.path.join(os.path.dirname(__file__), "config/apl.json"))
        f.seek(0)
        data = f.read(1024 * 64)
        MainHandler.APL_CONFIG = tornado.escape.json_decode(data)
        f.close()
        logging.info("apl config data %s" % (data))
    except Exception, e:
        logging.info(str(e))

    from api.data.mail import Mail
    m = Mail.get("ALL_INVOKE")
    if m:
        MainHandler.SYSTEM_MAIL = m.mail
    else:
        MainHandler.SYSTEM_MAIL = []


@gen.coroutine
def shell():
    BaseModel.install()
    request = XRequest()
    yield watchdog()
    code.interact(local=locals())


if __name__ == "__main__":