Example #1
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)
Example #2
0
    def post(self, cmsg):
        index, life, start = user_data.get_user_attrs(cmsg.common.userid,
                                                      "mission",
                                                      "mission_life",
                                                      "mission_next")
        if int(life) <= 0:
            return auth.pack(None, const.ERROR_SYSTEM)

        mapinfo = global_data.get_challenge_mapid(const.TAG_CHALLENGE_MAP_LIST,
                                                  index)
        if mapinfo is None:
            return auth.pack(None, const.ERROR_SYSTEM)
        mapinfo = msgpack.loads(mapinfo)

        user_data.play_map(cmsg.common.userid, mapinfo[0],
                           const.GAME_CHALLENGE_PLAY_MODE)
        if start == "0":
            user_data.inc_user_attr(cmsg.common.userid, "mission_next", 1)
        map_data.play_map(mapinfo[0])

        if mapinfo[3] != '0':
            user_data.inc_user_attr(mapinfo[3], "master_exp", 1)

        smsg = smsg_challenge_play()
        smsg.map_name = mapinfo[1]
        smsg.user_name = mapinfo[2]
        smsg.user_country = mapinfo[4]
        smsg.user_head = int(mapinfo[5])
        smsg.map_data = mapinfo[6]
        map_coordinate = map_data.get_dead_coordinate(mapinfo[0], 50)
        for coord in map_coordinate:
            x, y = coord.split(":")
            smsg.x.append(int(x))
            smsg.y.append(int(y))
        return auth.pack(smsg, 0, cmsg.common.userid)
Example #3
0
    def buy_support(self, userid, shop_template):
        jewel, support = user_data.get_user_attrs(userid, "jewel", "support")
        if not jewel or not support or int(jewel) < shop_template.price or int(
                support) >= shop_template.arg:
            raise tornado.gen.Return(const.ERROR_NO_JEWEL)

        user_data.inc_user_attr(userid, "jewel", -(shop_template.price))
        user_data.set_user_attr(userid, "support", shop_template.arg)
        raise tornado.gen.Return(0)
Example #4
0
 def post(self, cmsg):
     video_data = ""
     if cmsg.video_id == cmsg.common.userid:
         video_data = user_data.watch_video_map(cmsg.video_id, cmsg.map_id, True)
     else:
         user_data.inc_user_attr(cmsg.common.userid, "video", 1)
         video_data = user_data.watch_video_map(cmsg.video_id, cmsg.map_id, False)
     
     smsg = smsg_view_video()
     smsg.video_data = video_data if video_data else ""
     smsg.map_data   = map_data.get_map_attr(cmsg.map_id, "data") or ""
     return auth.pack(smsg, 0, cmsg.common.userid)
Example #5
0
    def post(self, cmsg):
        mapid, life = user_data.get_user_attrs(cmsg.common.userid, "mapid",
                                               "mission_life")

        if int(life) <= 0:
            return auth.pack(None, const.ERROR_SYSTEM)

        user_data.play_map(cmsg.common.userid, mapid,
                           const.GAME_CHALLENGE_PLAY_MODE)
        ownerid = map_data.replay_map(mapid)
        if ownerid != '0':
            user_data.inc_user_attr(ownerid, "master_exp", 1)

        return auth.pack(None, 0, cmsg.common.userid)
Example #6
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)
Example #7
0
class PayHandler(tornado.web.RequestHandler):
    @auth.authenticated
    def post(self, cmsg):
        openid = user_data.get_user_attr(cmsg.common.userid, "openid")
        if openid is None:
            return auth.pack(None, const.ERROR_SYSTEM)

        jewel = 0
        try:
            rechargs = self.application.db.query(
                "select id, amount from pay_t where userid = 0 and openid = %s and pt = %s",
                openid, cmsg.channel)
            for recharge in rechargs:
                jewel += recharge["amount"] / 10
                self.application.db.update(
                    "update pay_t set userid = %s where id = %s",
                    cmsg.common.userid, recharge["id"])
        except Exception, e:
            LOGGER.error("%s@%s", cmsg.channel, e)
            return auth.pack(None, const.ERROR_PAY)

        if jewel == 0:
            return auth.pack(None, -1, cmsg.common.userid)

        user_data.inc_user_attr(cmsg.common.userid, "jewel", jewel)

        smsg = smsg_pay()
        smsg.jewel = jewel
        return auth.pack(smsg, 0, cmsg.common.userid)
Example #8
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)
Example #9
0
    def post(self, cmsg):
        if not util.check_input(cmsg.code, 16, True, True):
            return auth.pack(None, const.ERROR_INPUT)

        try:
            libao_pici = cmsg.code[:2]
            libao_type = cmsg.code[2:3]
            libao_reward = cmsg.code[3:5]
        except:
            return auth.pack(None, const.ERROR_LIBAO)

        if libao_type == '0':
            if user_data.has_libao(cmsg.common.userid, cmsg.code):
                return auth.pack(None, const.ERROR_LIBAO)

            key = const.TAG_GAME_LIBAO + libao_pici
            if not global_data.has_libao(key, cmsg.code):
                return auth.pack(None, const.ERROR_LIBAO)

        else:
            if user_data.has_libao(cmsg.common.userid, libao_pici):
                return auth.pack(None, const.ERROR_LIBAO)

            key = const.TAG_GAME_LIBAO + libao_pici
            if not global_data.has_libao(key, cmsg.code):
                return auth.pack(None, const.ERROR_LIBAO)

        reward = global_data.get_libao_reward(const.TAG_GAME_LIBAO_REWARD, libao_reward)
        life = reward.get("life", 0) if reward else 0
        if life > 0:
            user_data.inc_user_attr(cmsg.common.userid, "life", life)

        if libao_type == '0':
            user_data.add_libao(cmsg.common.userid, cmsg.code)
        else:
            user_data.add_libao(cmsg.common.userid, libao_pici)
            key = const.TAG_GAME_LIBAO + libao_pici
            global_data.remove_libao(key, cmsg.code)

        smsg = smsg_libao()
        smsg.life = life
        return auth.pack(smsg, 0, cmsg.common.userid)
Example #10
0
            self.response(res, None, cmsg.common.userid)


    @tornado.gen.coroutine
    def verify(self, userid, bill_id, product_id, package_name, purchase_token, shop_template):
        url = 'http://23.252.167.50:8070/google_pay'
        params = {"bill_id":bill_id,
                  "packageName":package_name,
                  "productId":product_id,
                  "purchase_token":purchase_token}
        url += "?" + urllib.urlencode(params)
        LOGGER.info(url)
        http_client = AsyncHTTPClient()
        try:
            respone = yield http_client.fetch(url, method = 'GET')
        except Exception, e:
            LOGGER.error("google@%s", e)
            raise tornado.gen.Return(const.ERROR_PAY)

        if respone.error:
            raise tornado.gen.Return(const.ERROR_PAY)

        if respone.body != "ok":
            raise tornado.gen.Return(const.ERROR_PAY)

        user_data.inc_user_attr(userid, "jewel", shop_template.arg)
        raise tornado.gen.Return(0)

    @tornado.gen.coroutine
    def get_token(self):
        pass
Example #11
0
    def post(self, cmsg):
        mapid, index, life, top, total = user_data.get_user_attrs(cmsg.common.userid,
                                               "mapid",
                                               "mission",
                                               "mission_life",
                                               "mission_hard",
                                               "mission_total")

        map_data.complete_map(mapid,
                              cmsg.common.userid,
                              -1,
                              0,
                              0,
                              cmsg.point,
                              self.application.update_map_script)

        # 成功结束
        if int(index) + 1 >= 8:
            global_data.challenge_rank(const.TAG_RANK_CHALLENGE,
                                          cmsg.common.userid, 
                                          (int(index) + 1) * 100000 + 100000 - int(total),
                                          self.application.challenge_rank_script,
                                          top)

            challenge_info = cache_data.get_cache(const.TAG_CHALLENGE_INFO, 300)
            inc_exp = challenge_info.get("exp") or 0
            inc_jewel = challenge_info.get("jewel") or 0
            user_data.challenge_complete(cmsg.common.userid, inc_exp, inc_jewel, self.application.static_data)

            rank = 0
            rank = global_data.challenge_finish_rank(const.TAG_RANK_CHALLENGE_CUR,
                                                  cmsg.common.userid, 
                                                  int(index) * 100000 + 100000 - int(total),
                                                  self.application.challenge_rank_finish_script)
            
            smsg = smsg_challenge_finish()
            smsg.suc = 0
            smsg.exp = inc_exp
            smsg.jewel = inc_jewel
            smsg.rank = rank
            all_map = global_data.get_challenge_map(const.TAG_CHALLENGE_MAP_LIST, 0, -1)
            for mapid in all_map:
                author = smsg.authors.add()
                submap = msgpack.loads(mapid)
                author.user_head    = int(submap[5])
                author.user_name    = submap[2]
                author.user_country = submap[4]
                author.map_name     = submap[1]
            return auth.pack(None, -1, cmsg.common.userid, smsg)

        
        mapinfo = global_data.get_challenge_mapid(const.TAG_CHALLENGE_MAP_LIST, int(index) + 1)
        if mapinfo is None:
            return auth.pack(None, const.ERROR_SYSTEM)
        mapinfo = msgpack.loads(mapinfo)
        
        user_data.play_map(cmsg.common.userid, mapinfo[0], const.GAME_CHALLENGE_SUCC_MODE)
        map_data.play_map(mapinfo[0])
        if mapinfo[3] != '0':
            user_data.inc_user_attr(mapinfo[3], "master_exp", 1)

        smsg = smsg_challenge_play()
        smsg.map_name       = mapinfo[1]
        smsg.user_name      = mapinfo[2]
        smsg.user_country   = mapinfo[4]
        smsg.user_head      = int(mapinfo[5])
        smsg.map_data       = mapinfo[6]
        map_coordinate = map_data.get_dead_coordinate(mapinfo[0], 50)
        for coord in map_coordinate:
            x, y = coord.split(":")
            smsg.x.append(int(x))
            smsg.y.append(int(y))

        return auth.pack(smsg, 0, cmsg.common.userid)