Ejemplo n.º 1
0
    def buy_exp(self, userid, shop_template):
        jewel, exp_time = user_data.get_user_attrs(userid, "jewel", "exp_time")
        if not jewel or not exp_time or int(jewel) < shop_template.price:
            raise tornado.gen.Return(const.ERROR_NO_JEWEL)

        exp_next_time = long(exp_time)
        if exp_next_time < util.now_time():
            exp_next_time = util.now_time(
            ) + shop_template.arg * 24 * 60 * 60 * 1000
        else:
            exp_next_time = exp_next_time + shop_template.arg * 24 * 60 * 60 * 1000

        user_data.inc_user_attr(userid, "jewel", -(shop_template.price))
        user_data.set_user_attr(userid, "exp_time", exp_next_time)
        raise tornado.gen.Return(0)
Ejemplo n.º 2
0
def import_map_ex(template_id, name, url, data, hard):
    url_content = ""
    data_content = ""

    try:
        with open(map_path + url, "rb") as f:
            url_content = f.read()
        with open(map_path + data, "rb") as f:
            data_content = f.read()
    except:
        return

    mapid = client.incr(const.TAG_MAP_COUNT)
    client.hmset(
        const.TAG_MAP.format(mapid), {
            "id": mapid,
            "name": name,
            "url": url_content,
            "ownerid": 0,
            "ownername": "BoxMaker",
            "country": "CN",
            "head": 1,
            "favorite": 0,
            "amount": 0,
            "pass": 0,
            "template": 0,
            "date": util.now_date_str(),
            "hard": 0,
            "data": data_content
        })
    client.zadd(const.TAG_RANK_MOST_POPULAR, 0, mapid)
    client.zadd(const.TAG_RANK_NEWER_UPLOAD, util.now_time(), mapid)
    client.sadd(const.TAG_PRIMARY_SET, mapid)
Ejemplo n.º 3
0
    def post(self, cmsg):
        if not user_data.check_life(cmsg.common.userid, self.application.static_data):
            user_life_time = user_data.get_user_attr(cmsg.common.userid, "life_time")
            error = msg_life_error()
            error.server_time   = util.now_time()
            error.life_time     = long(user_life_time)
            return  auth.pack(None, -1, cmsg.common.userid, error)

        mapatts = map_data.get_map_attrs(cmsg.id, 
                                         "ownerid", 
                                         "template",
                                         "data",
                                         "hard",
                                         "amount")

        user_data.play_map(cmsg.common.userid, 
                           cmsg.id,
                           const.GAME_NORMAL_MODE)
        if mapatts[0] != '0':
            user_data.inc_user_attr(mapatts[0], "master_exp", 1)
        map_data.play_map(cmsg.id)

        dead_coordinate = map_data.get_dead_coordinate(cmsg.id, int(mapatts[4]))
        smsg = smsg_play_map()
        smsg.map_data = mapatts[2]
        for coord in dead_coordinate:
            x, y = coord.split(":")
            smsg.x.append(int(x))
            smsg.y.append(int(y))
        return auth.pack(smsg, 0, cmsg.common.userid)
Ejemplo n.º 4
0
    def post(self, cmsg):   
        if not user_data.check_life(cmsg.common.userid, self.application.static_data):
            user_life_time = user_data.get_user_attr(cmsg.common.userid, "life_time")
            error = msg_life_error()
            error.server_time   = util.now_time()
            error.life_time     = long(user_life_time) if user_life_time else util.now_time()
            return auth.pack(None, -1, cmsg.common.userid, error)
        
        mapcache = user_data.get_user_attr(cmsg.common.userid, "mapid")
        if not mapcache:
            return auth.pack(None, const.ERROR_SYSTEM)
        user_data.play_map(cmsg.common.userid, mapcache, const.GAME_NORMAL_MODE)

        ownerid =  map_data.replay_map(mapcache)
        if ownerid != '0':
            user_data.inc_user_attr(ownerid, "master_exp", 1)
        return auth.pack(None, 0, cmsg.common.userid)
Ejemplo n.º 5
0
def set_userid_and_log(conn, key, openid, userid, pt):
    '''
    保存用户ID并日志
    '''
    shared_key = client._shared_key(key, openid, 256)
    pack = dict(od=openid, ud=userid, op=1, pt=pt, dt=util.now_time())
    pack = msgpack.dumps(pack)
    pipe = conn.pipeline(True)
    pipe.hset(shared_key, openid, userid)
    pipe.rpush(const.TAG_INFO_LOG, pack)
    pipe.execute()
Ejemplo n.º 6
0
    def post(self, cmsg):
        platform = const.TAG_OPENID_TO_USERID
        notify_addr = self.application.notify_addr + cmsg.channel

        # TODO 读写分离
        userid, review, invalid = global_data.get_userid_and_version(
            platform, cmsg.openid, cmsg.ver)
        can_login = 0
        if invalid:
            can_login = -1
        elif review:
            can_login = 1

        if userid:
            user = user_data.get_user(userid)
            if user:
                # 验证密码
                if util.check_passwd(cmsg.openkey,
                                     user.get("opensalt", "f**k"),
                                     user.get("openkey", "shit")):

                    # 检查充值
                    jewel = 0
                    try:
                        rechargs = self.application.db.query(
                            "select id, amount from pay_t where userid = 0 and openid = %s and pt = %s",
                            cmsg.openid, cmsg.channel)
                        for recharge in rechargs:
                            jewel += recharge["amount"] / 10
                            self.application.db.update(
                                "update pay_t set userid = %s where id = %s",
                                userid, recharge["id"])
                    except:
                        pass

                    # 用户登录
                    user_data.login(userid, user, self.application.static_data,
                                    jewel)

                    # 登录日志
                    global_data.log(const.TAG_INFO_LOG,
                                    od=cmsg.openid,
                                    ud=userid,
                                    op=2,
                                    pt=cmsg.channel,
                                    dt=util.now_time())

                    challenge_info = cache_data.get_cache(
                        const.TAG_CHALLENGE_INFO, 1)
                    challenge_version = user.get("mission_ver", None)
                    challenge_start = 0
                    if challenge_version is None or int(
                            challenge_version) != challenge_info.get(
                                "version", 0):
                        challenge_start = 1

                    smsg = smsg_login()
                    smsg.openid = cmsg.openid
                    smsg.openkey = cmsg.openkey
                    smsg.sig = user.get("sig")
                    smsg.userid = int(userid)
                    smsg.nationality = user.get("country")
                    smsg.name = user.get("name")
                    smsg.visitor = int(user.get("visitor"))
                    smsg.head = int(user.get("head"))
                    smsg.level = user.get("level")
                    smsg.exp = user.get("exp")
                    smsg.jewel = user.get("jewel")
                    smsg.life = user.get("life")
                    smsg.life_time = user.get("life_time")
                    smsg.upload = user.get("upload")
                    smsg.testify = int(user.get("support"))
                    smsg.exp_time = long(user.get("exp_time"))
                    smsg.guide = int(user.get("guide"))
                    smsg.mapid = user.get("test_mapid")
                    smsg.support = user.get("test_maphard")
                    smsg.server_time = util.now_time()
                    smsg.review = can_login
                    smsg.notify_uri = notify_addr
                    smsg.init_life = const.LIFE_MAX
                    smsg.life_per_time = const.LIEF_TIME / 1000
                    smsg.challenge_start = challenge_start
                    smsg.download_num = user.get("download_num")
                    smsg.download_max = const.DOWNLOAD_MAX
                    return auth.pack(smsg)

        # 创建游客
        userid = global_data.get_counter(const.TAG_USER_COUNT)
        global_data.set_userid(platform, const.YOUKE_ACCOUNT.format(userid),
                               userid)
        sig = user_data.create_visitor(userid, cmsg.nationality, cmsg.channel)

        # 创角日志
        global_data.log(const.TAG_INFO_LOG,
                        od=const.YOUKE_ACCOUNT.format(userid),
                        ud=userid,
                        op=1,
                        pt=cmsg.channel,
                        dt=util.now_time())

        smsg = smsg_login()
        smsg.openid = const.YOUKE_ACCOUNT.format(userid)
        smsg.openkey = "empty"
        smsg.sig = sig
        smsg.userid = userid
        smsg.nationality = cmsg.nationality
        smsg.name = "empty"
        smsg.visitor = 1
        smsg.head = 0
        smsg.level = 1
        smsg.exp = 0
        smsg.jewel = 0
        smsg.life = 20
        smsg.life_time = 0
        smsg.upload = 0
        smsg.testify = 0
        smsg.exp_time = 0
        smsg.guide = 0
        smsg.mapid = 10000001
        smsg.support = 1
        smsg.server_time = util.now_time()
        smsg.review = can_login
        smsg.notify_uri = notify_addr
        smsg.init_life = const.LIFE_MAX
        smsg.life_per_time = const.LIEF_TIME / 1000
        smsg.challenge_start = 1
        smsg.download_num = 0
        smsg.download_max = const.DOWNLOAD_MAX
        return auth.pack(smsg)
Ejemplo n.º 7
0
    def post(self):
        cmsg = yield self.parse()
        if not cmsg:
            return

        openid = cmsg.userid
        if cmsg.channel == "360":
            try:
                user_info = yield self.qihu360_request("/user/me", cmsg.token)
            except:
                self.response(const.ERROR_SYSTEM)
                return
            openid = user_info.get("id", None)
            if openid is None:
                self.response(const.ERROR_SYSTEM)
                return
        elif cmsg.channel == "web_facebook":
            pass
        else:
            verify = "true"
            try:
                verify = yield self.lengjing_request("/game_agent/checkLogin",
                                                     cmsg.token, cmsg.userid,
                                                     cmsg.channel)
            except:
                verify = "false"
            if verify == "false":
                self.response(const.ERROR_SYSTEM)
                return

        platform = const.TAG_OPENID_TO_USERID
        pt = cmsg.channel
        if pt == "360":
            platform += "-qihu360"
        elif pt == "web_facebook":
            platform += "-facebook"
        else:
            pt = "lengjing"
            platform += "-lengjing"
        notify_addr = self.application.notify_addr + pt

        userid, review, invalid = global_data.get_userid_and_version(
            platform, openid, cmsg.ver)
        can_login = 0
        if invalid:
            can_login = -1
        elif review:
            can_login = 1

        if userid:
            user = user_data.get_user(userid)
            if user:
                jewel = 0
                try:
                    rechargs = self.application.db.query(
                        "select id, amount from pay_t where userid = 0 and openid = %s and pt = %s",
                        openid, pt)
                    for recharge in rechargs:
                        jewel += recharge["amount"] / 10
                        self.application.db.update(
                            "update pay_t set userid = %s where id = %s",
                            userid, recharge["id"])
                except:
                    pass
                user_data.login(userid, user, self.application.static_data,
                                jewel)

                global_data.log(const.TAG_INFO_LOG,
                                od=openid,
                                ud=userid,
                                op=2,
                                pt=cmsg.channel,
                                dt=util.now_time())

                challenge_info = cache_data.get_cache(const.TAG_CHALLENGE_INFO,
                                                      1)
                challenge_version = user.get("mission_ver", None)
                challenge_start = 0
                if challenge_version is None or int(
                        challenge_version) != challenge_info.get("version", 0):
                    challenge_start = 1

                smsg = smsg_login()
                smsg.openid = openid
                smsg.openkey = "empty"
                smsg.sig = user.get("sig")
                smsg.userid = int(userid)
                smsg.nationality = user.get("country")
                smsg.name = user.get("name")
                smsg.visitor = int(user.get("visitor"))
                smsg.head = int(user.get("head"))
                smsg.level = user.get("level")
                smsg.exp = user.get("exp")
                smsg.jewel = user.get("jewel")
                smsg.life = user.get("life")
                smsg.life_time = user.get("life_time")
                smsg.upload = user.get("upload")
                smsg.testify = int(user.get("support"))
                smsg.exp_time = long(user.get("exp_time"))
                smsg.guide = int(user.get("guide"))
                smsg.mapid = user.get("test_mapid")
                smsg.support = user.get("test_maphard")
                smsg.server_time = util.now_time()
                smsg.review = can_login
                smsg.notify_uri = notify_addr
                smsg.init_life = const.LIFE_MAX
                smsg.life_per_time = const.LIEF_TIME / 1000
                smsg.challenge_start = challenge_start
                smsg.download_num = user.get("download_num")
                smsg.download_max = const.DOWNLOAD_MAX
                self.response(0, smsg)
                return

        userid = global_data.get_counter(const.TAG_USER_COUNT)
        global_data.set_userid(platform, openid, userid)
        sig = user_data.create_pt_account(userid, openid, cmsg.nationality, pt)

        # 日志
        global_data.log(const.TAG_INFO_LOG,
                        od=openid,
                        ud=userid,
                        op=1,
                        pt=cmsg.channel,
                        dt=util.now_time())

        smsg = smsg_login()
        smsg.openid = openid
        smsg.openkey = "emtpy"
        smsg.sig = sig
        smsg.userid = userid
        smsg.nationality = cmsg.nationality
        smsg.name = "empty"
        smsg.visitor = 1
        smsg.head = 0
        smsg.level = 1
        smsg.exp = 0
        smsg.jewel = 0
        smsg.life = 50
        smsg.life_time = 0
        smsg.upload = 0
        smsg.testify = 0
        smsg.exp_time = 0
        smsg.guide = 0
        smsg.mapid = 10000001
        smsg.support = 1
        smsg.server_time = util.now_time()
        smsg.review = can_login
        smsg.notify_uri = notify_addr
        smsg.init_life = const.LIFE_MAX
        smsg.life_per_time = const.LIEF_TIME / 1000
        smsg.challenge_start = 1
        smsg.download_num = 0
        smsg.download_max = const.DOWNLOAD_MAX
        self.response(0, smsg)
Ejemplo n.º 8
0
    def post(self, cmsg):
        userattrs = user_data.get_user_attrs(cmsg.common.userid, "level",
                                             "exp", "exp_time", "support",
                                             "mapid")
        userattrs = filter(None, userattrs)
        if not userattrs or len(userattrs) != 5:
            return auth.pack(None, const.ERROR_SYSTEM)
        mapid = userattrs[4]

        # 更新地图数据
        amount, pas, rank, template_id = map_data.complete_map(
            mapid, cmsg.common.userid, cmsg.suc, cmsg.x, cmsg.y, cmsg.time,
            self.application.update_map_script)

        exp_inc = 0
        exp_etra = 0
        support = 0
        hard = 0
        next_mapid = 0
        next_templateid = 0
        if cmsg.suc == 0:
            # 考试地图
            if template_id != '0':
                map_template = self.application.static_data.get_map_template(
                    int(template_id))
                if map_template:
                    if map_template.support > int(userattrs[3]):
                        support = map_template.support
                    next_templateid = map_template.nextid
                    next_map_template = self.application.static_data.get_map_template(
                        next_templateid)
                    if next_map_template:
                        hard = next_map_template.hard
                        next_mapid = next_templateid
                    else:
                        hard = 0
                        next_mapid = -1
            # 经验
            exp_inc = 2
            if not user_data.is_pass_map(cmsg.common.userid, mapid):
                exp_inc = self._get_exp(amount, pas)
            if util.now_time() < long(userattrs[2]):
                exp_etra = exp_inc

        # 升级
        level, exp, shengji = self._check_levelup(
            int(userattrs[0]), exp_inc + exp_etra + int(userattrs[1]))
        user_life_time1 = None
        if shengji:
            level_template = self.application.static_data.get_level_template(
                level)
            if level_template:
                user_life, user_life_time = user_data.get_user_attrs(
                    cmsg.common.userid, "life", "life_time")
                if int(user_life) < level_template.life_max and long(
                        user_life_time) < util.now_time():
                    user_life_time1 = util.now_time() + const.LIEF_TIME
        user_data.complete_map(cmsg.common.userid, mapid, cmsg.suc, cmsg.point,
                               cmsg.video, level, exp, rank, support,
                               next_templateid, user_life_time1, cmsg.time)

        smsg = smsg_complete_map()
        smsg.exp = exp_inc
        smsg.rank = rank
        smsg.testify = support
        smsg.extra_exp = exp_etra
        smsg.mapid = next_mapid
        smsg.support = hard
        return auth.pack(smsg, 0, cmsg.common.userid)
Ejemplo n.º 9
0
    def post(self, cmsg):
        if not util.check_input(cmsg.openid, 20, True, True):
            return auth.pack(None, const.ERROR_INPUT)
        if not util.check_input(cmsg.openkey, 20, True, True):
            return auth.pack(None, const.ERROR_INPUT)

        platform = const.TAG_OPENID_TO_USERID

        userid = global_data.get_userid(platform, cmsg.openid)
        if not userid:
            return auth.pack(None, const.ERROR_NO_ACCOUNT)

        if int(userid) == cmsg.common.userid:
            return auth.pack(None, const.ERROR_HAS_LOGIN)

        user = user_data.get_user(userid)
        if not user:
            return auth.pack(None, const.ERROR_NO_ACCOUNT)

        if not util.check_passwd(cmsg.openkey, user.get("opensalt", "f**k"),
                                 user.get("openkey", "shit")):
            return auth.pack(None, const.ERROR_PASSWD)

        # 用户登录
        user_data.login(userid, user, self.application.static_data, 0)

        global_data.log(const.TAG_INFO_LOG,
                        od=cmsg.openid,
                        ud=userid,
                        op=2,
                        pt=cmsg.channel,
                        dt=util.now_time())

        smsg = smsg_login()
        smsg.openid = cmsg.openid
        smsg.openkey = cmsg.openkey
        smsg.sig = user.get("sig")
        smsg.userid = int(userid)
        smsg.nationality = user.get("country")
        smsg.name = user.get("name")
        smsg.visitor = int(user.get("visitor"))
        smsg.head = int(user.get("head"))
        smsg.level = user.get("level")
        smsg.exp = user.get("exp")
        smsg.jewel = user.get("jewel")
        smsg.life = user.get("life")
        smsg.life_time = user.get("life_time")
        smsg.upload = user.get("upload")
        smsg.testify = int(user.get("support"))
        smsg.exp_time = long(user.get("exp_time"))
        smsg.guide = int(user.get("guide"))
        smsg.mapid = user.get("test_mapid")
        smsg.support = user.get("test_maphard")
        smsg.server_time = util.now_time()
        smsg.review = 0
        smsg.notify_uri = self.application.notify_addr + cmsg.channel
        smsg.init_life = const.LIFE_MAX
        smsg.life_per_time = const.LIEF_TIME / 1000
        smsg.challenge_start = 1
        smsg.download_num = user.get("download_num")
        smsg.download_max = const.DOWNLOAD_MAX
        return auth.pack(smsg)