Exemplo n.º 1
0
def read(context):
    """阅读邮件内容

    Args:
        mail_id 邮件ID

    Returns:
        mc
    """
    ki_user = context.user

    mail_id = context.get_parameter("mail_id")

    state = MailService.check_mail_state(ki_user.uid, mail_id)

    if state is None:
        context.result['mc'] = MsgCode['MailNotExist']
        return
    elif state != MAIL_STATE_NEW:
        context.result['mc'] = MsgCode['MailAlreadyRead']
        return
    else:
        pass

    MailService.update_mail_state(ki_user.uid, mail_id, MAIL_STATE_READ)

    context.result["mc"] = MsgCode["MailReadSucc"]
Exemplo n.º 2
0
def payback_diamonds(sid, plat, account_id, uid, login_days):
    """4.13 ios越狱删档测试 充值返现

        走邮件形式发送
    """
    if int(sid) not in (1,2) or login_days > 60:
        return

    payback_amount = redis_client.hget(rediskey_config.ACT_PAYBACK_KEY % sid, "%s_%s" % (plat, account_id))
    if not payback_amount:
        return
    else:
        payback_amount = int(payback_amount)
        if 0 < login_days <= 7:
            get = int(math.ceil(payback_amount * 15.0 / 7))
            left = payback_amount * 50 - get * login_days
        else:
            get = int(math.ceil(payback_amount * 35.0 / 53))
            left = payback_amount * 35 - get * (login_days - 7)

        left = left if left >= 0 else 0

        # 第一次返还的时候 所有的vip经验都返还
        awards = {static_const.DIAMOND: get}
        if login_days == 1:
            awards = {static_const.DIAMOND: get, static_const.VIP_EXP: payback_amount * 10}

        MailService.send_game(uid, 3006, [get, left, 60 - login_days], awards)
Exemplo n.º 3
0
def fight_rank_send_mail_awards(sid, act_id):
    """到活动结束时间点发送排行奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    max_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (sid, RANK_KEY_MAPPING[RANK_FIGHT])
    top = redis_client.zrevrange(rank_name, 0, max_cfg["cond_a"]-1, withscores=True)

    for index, player in enumerate(top):
        fight_rank = index + 1
        try:
            award_index = min([rank for rank in indexes if rank >= fight_rank])
        except:
            award_index = 0

        if not award_index:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, award_index))
        # 排名前10 且 战力达到指定值才有奖励
        if player[1] >= cfg["cond_b"]:
            MailService.send_game(player[0], 1001, [fight_rank], cfg["awards"])
            print "[act:%s] fight_rank_send_mail_awards: receiver: %s, rank: %s, fight: %s, awards: %s" % (act_id, player[0], fight_rank, player[1], cfg["awards"])
Exemplo n.º 4
0
def fight_rank_send_mail_awards(sid, act_id):
    """到活动结束时间点发送排行奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    max_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (
        sid, RANK_KEY_MAPPING[RANK_FIGHT])
    top = redis_client.zrevrange(rank_name,
                                 0,
                                 max_cfg["cond_a"] - 1,
                                 withscores=True)

    for index, player in enumerate(top):
        fight_rank = index + 1
        try:
            award_index = min([rank for rank in indexes if rank >= fight_rank])
        except:
            award_index = 0

        if not award_index:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, award_index))
        # 排名前10 且 战力达到指定值才有奖励
        if player[1] >= cfg["cond_b"]:
            MailService.send_game(player[0], 1001, [fight_rank], cfg["awards"])
            print "[act:%s] fight_rank_send_mail_awards: receiver: %s, rank: %s, fight: %s, awards: %s" % (
                act_id, player[0], fight_rank, player[1], cfg["awards"])
Exemplo n.º 5
0
    def award_today_rank_players(sid):
        """给今日伤害榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(
                game_config.boss_daily_award_cfg, index + 1)
            if award_cfg:
                MailService.send_game(value[0], 3009, [index + 1],
                                      award_cfg["awards"])
                print "[boss] award_today_rank_players: receiver: %s, dmg: %s, awards: %s" % (
                    value[0], index + 1, award_cfg["awards"])

        # 支持了今日第一名的玩家额外获得金币
        support_key = rediskey_config.WORLD_BOSS_SUPPORT_KEY % sid
        try:
            number_one = ranking_list[0][0]
        except:
            number_one = None

        if isinstance(number_one, str):
            supports = redis_client.hget(support_key, number_one)
            l = [] if not supports else pickle.loads(supports)
            for uid in l:
                MailService.send_game(uid, 3010, [number_one],
                                      WORLD_BOSS_SUPPORT_EXTRA_AWARD)
                print "[boss] award_today_support_awards: receiver: %s, number_one: %s, awards: %s" % (
                    uid, number_one, WORLD_BOSS_SUPPORT_EXTRA_AWARD)
Exemplo n.º 6
0
def payback_diamonds(sid, plat, account_id, uid, login_days):
    """4.13 ios越狱删档测试 充值返现

        走邮件形式发送
    """
    if int(sid) not in (1, 2) or login_days > 60:
        return

    payback_amount = redis_client.hget(rediskey_config.ACT_PAYBACK_KEY % sid,
                                       "%s_%s" % (plat, account_id))
    if not payback_amount:
        return
    else:
        payback_amount = int(payback_amount)
        if 0 < login_days <= 7:
            get = int(math.ceil(payback_amount * 15.0 / 7))
            left = payback_amount * 50 - get * login_days
        else:
            get = int(math.ceil(payback_amount * 35.0 / 53))
            left = payback_amount * 35 - get * (login_days - 7)

        left = left if left >= 0 else 0

        # 第一次返还的时候 所有的vip经验都返还
        awards = {static_const.DIAMOND: get}
        if login_days == 1:
            awards = {
                static_const.DIAMOND: get,
                static_const.VIP_EXP: payback_amount * 10
            }

        MailService.send_game(uid, 3006, [get, left, 60 - login_days], awards)
Exemplo n.º 7
0
def divorce(context):
    """与机甲解除誓言

    Args:
        hero_id 姬甲ID
    """
    ki_user = context.user

    hero_id = context.get_parameter("hero_id")
    hero = ki_user.hero.get_by_hero_id(hero_id)
    if not hero:
        context.result['mc'] = MsgCode['HeroNotExist']
        return

    # 是否已经许誓
    if not hero["marry_id"]:
        context.result['mc'] = MsgCode['HeroFavorNoMarried']
        return

    marry_cfg = game_config.favor_marry_cfg.get(hero["marry_id"])
    if not user_logic.check_game_values1(ki_user, diamond=marry_cfg["break_need_diamond"]):
        context.result['mc'] = MsgCode['DiamondNotEnough']
        return

    user_logic.consume_game_values1(ki_user, diamond=marry_cfg["break_need_diamond"])
    # 解除契约,戒指通过邮箱返还玩家
    from apps.services.mail import MailService
    marry_cfg = game_config.favor_marry_cfg.get(hero["marry_id"])
    MailService.send_game(ki_user.uid, 2000, [], marry_cfg["items"])

    ki_user.hero.divorce(hero_id) # 解除契约

    context.result['mc'] = MsgCode['HeroFavorDivorceSucc']
Exemplo n.º 8
0
    def award_today_rank_players(sid):
        """给今日伤害榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_DAILY_RANK_KEY % sid
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(game_config.boss_daily_award_cfg, index+1)
            if award_cfg:
                MailService.send_game(value[0], 3009, [index+1], award_cfg["awards"])
                print "[boss] award_today_rank_players: receiver: %s, dmg: %s, awards: %s" % (value[0], index+1, award_cfg["awards"])

        # 支持了今日第一名的玩家额外获得金币
        support_key = rediskey_config.WORLD_BOSS_SUPPORT_KEY % sid
        try:
            number_one = ranking_list[0][0]
        except:
            number_one = None

        if isinstance(number_one, str):
            supports = redis_client.hget(support_key, number_one)
            l = [] if not supports else pickle.loads(supports)
            for uid in l:
                MailService.send_game(uid, 3010, [number_one], WORLD_BOSS_SUPPORT_EXTRA_AWARD)
                print "[boss] award_today_support_awards: receiver: %s, number_one: %s, awards: %s" % (uid, number_one, WORLD_BOSS_SUPPORT_EXTRA_AWARD)
Exemplo n.º 9
0
def read(context):
    """阅读邮件内容

    Args:
        mail_id 邮件ID

    Returns:
        mc
    """
    ki_user = context.user

    mail_id = context.get_parameter("mail_id")

    state = MailService.check_mail_state(ki_user.uid, mail_id)

    if state is None:
        context.result['mc'] = MsgCode['MailNotExist']
        return
    elif state != MAIL_STATE_NEW:
        context.result['mc'] = MsgCode['MailAlreadyRead']
        return
    else:
        pass

    MailService.update_mail_state(ki_user.uid, mail_id, MAIL_STATE_READ)

    context.result["mc"] = MsgCode["MailReadSucc"]
Exemplo n.º 10
0
def _act_add_awards_mail(sid, actid):
    """
    """
    receivers = rank_service.get_all_players(sid)
    for uid in receivers:
        user = User.get(uid)
        if not isinstance(user, User):
            print "uid: [ %s ] not exist." % uid
        else:
            if actid not in user.activity.acts:
                continue

            act_data = user.activity.acts[actid]
            index_list = game_config.act_sample_detail_cfg.get(actid)
            awards_indexes = [
                index for index in index_list
                if utils.bit_test(act_data["canget"], index)
            ]
            if not awards_indexes:
                print "[act:%s] act add mail awards: receiver: %s, count: %s, award_level: 0, awards: {}" % (
                    actid, uid, act_data["data"])
                continue

            award_index = max(awards_indexes)
            award_cfg = game_config.act_detail_cfg.get("%s-%s" %
                                                       (actid, award_index))
            MailService.send_game(uid, 3008, [act_data["data"]],
                                  award_cfg["awards"])

            print "[act:%s] act add mail awards: receiver: %s, count: %s, award_level: %s, awards: %s" % (
                actid, uid, act_data["data"], award_index, award_cfg["awards"])
Exemplo n.º 11
0
def fight_send_mail_awards(sid, act_id):
    """到活动结束时间点发送战力达标奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    min_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (sid, RANK_KEY_MAPPING[RANK_FIGHT])
    max_score = 9999999
    targets = redis_client.zrangebyscore(rank_name, min_cfg["cond_a"], max_score, withscores=True)

    for index, player in enumerate(targets):
        try:
            def is_reached(level):
                cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, level), {})
                if not cfg:
                    return False
                else:
                    return player[1] >= cfg["cond_a"]

            fight_level = min(filter(is_reached, indexes))
        except:
            fight_level = 0

        if not fight_level:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, fight_level))
        MailService.send_game(player[0], 1002, [player[1]], cfg["awards"])
        print "[act:%s] fight_send_mail_awards: receiver: %s, fight_level: %s, fight: %s, awards: %s" % (act_id, player[0], fight_level, player[1], cfg["awards"])
Exemplo n.º 12
0
    def award_boss_ender(sid, uid):
        """给该版本BOSS最后一击的玩家发奖
        """
        if not uid:
            return

        award_cfg = common_helper.get_award_by_data(game_config.boss_total_award_cfg, 1)
        MailService.send_game(uid, 3011, [], award_cfg["awards"])
        print "[boss] award_boss_ender: receiver: %s, awards: %s" % (uid, award_cfg["awards"])
Exemplo n.º 13
0
    def award_boss_ender(sid, uid):
        """给该版本BOSS最后一击的玩家发奖
        """
        if not uid:
            return

        award_cfg = common_helper.get_award_by_data(
            game_config.boss_total_award_cfg, 1)
        MailService.send_game(uid, 3011, [], award_cfg["awards"])
        print "[boss] award_boss_ender: receiver: %s, awards: %s" % (
            uid, award_cfg["awards"])
Exemplo n.º 14
0
    def install_default_datas(self):
        """默认获得姬甲,排布阵容等
        """
        from apps.logics import hero as hero_logic
        hero_logic.add_heros(self, [{100050: 1}])
        self.array.update(1, [0, 100050, 0, 0, 0, 0])
        self.arena.init_when_install(self.sid)

        # 创建角色时,检测是否需要发[ 应用宝的预约礼包 | uc封测测试奖励 | 360封测测试奖励 ]
        if self.platform in ["YSDK", "UC", "QIHOO"]:
            account = Account.get_account("%s_%s" % (self.platform, self.account_id))
            if not isinstance(account, Account):
                return

            if self.platform == "YSDK" and redis_client.sismember(rediskey_config.YYB_ORDERED_SET % self.sid, account.open_id):
                order_awards_cfg = game_config.gift_key_config.get("YY02", {})
                if order_awards_cfg:
                    MailService.send_game(self.uid, 5003, [], order_awards_cfg["award"])

            if self.platform in ["UC", "QIHOO"]:
                # 1.最终等级达到x级 2.累计登陆x天 3.竞技场最终排名x
                awards,logins = pregift_service.uc_qihoo_test_award_4003(self.sid, self.platform, account.open_id)
                if awards:
                    MailService.send_game(self.uid, 5000, [logins], awards)

                awards1,days = pregift_service.uc_qihoo_test_award_4004(self.sid, self.platform, account.open_id)
                if awards1:
                    MailService.send_game(self.uid, 5001, [days], awards1)

                awards2,rank = pregift_service.uc_qihoo_test_award_4005(self.sid, self.platform, account.open_id)
                if awards2:
                    MailService.send_game(self.uid, 5002, [rank], awards2)
Exemplo n.º 15
0
def heartbeat(context):
    """心跳协议,玩家在主场景时,
       每隔几分钟向服务器请求一次,
       检测服务器是否有需要提醒前端的功能

    包括:
        1.新邮件
        2.私聊消息
        3.跑马灯公告
        4.竞技场被击败
    """
    ki_user = context.user

    uid = ki_user.uid
    sid = ki_user.sid
    group_id = ki_user.group.group_id
    plat = ki_user.platform

    data = {}
    data["new_mails"] = len(MailService.query_mails(uid, 0))

    private_msgs = ChatService.get_private_msgs(
        sid, uid, ki_user.game_info.last_chat_read)
    data["private_msgs"] = 1 if private_msgs else 0

    broadcast_msgs = NoticeService.get_broadcasts(
        sid, ki_user.game_info.broadcast_id)
    data["broadcast_msgs"] = broadcast_msgs

    ki_user.game_info.refresh_broadcast_stamp()

    # arena_last_sign = ki_user.arena.extra_data.get("heartbeat_last_sign", 0)
    # arena_info = ArenaService.heartbeat_info(plat, sid, uid, arena_last_sign)
    # data["arena_info"] = {"fail_times": 0}

    # 充值付费标记,1 - 有已完成付费的充值订单,0 - 没有已完成充值付费的订单
    data["paid_tag"] = charge_service.ismember_of_paid_set(uid)

    # 通关心跳来检测玩家新活动  从数据库中取活配置
    # activity = {}
    # activity["info"] = act_helper.get_active_act_info(sid, ki_user.game_info.role_level)
    # activity["data"] = ki_user.activity.get_effective_acts(sid, ki_user.game_info.role_level)
    # data["activity"] = activity

    # 公会数据  玩家被审核或者被踢出公会之后  通过心跳通知前端
    data["group"] = {}
    data["group"]["group_id"] = group_id
    data["group"]["cd"] = ki_user.group.cd

    # 处理训练所 姬甲挂机经验
    # train_heros = [i for i in ki_user.group.train_list if i not in [0,-1]]
    # if group_id and train_heros:
    #     group_data = GroupService.find(sid, group_id)
    #     if group_data:
    #         data["group"]["level"] = group_data["level"]
    #         gcfg = game_config.group_cfg.get(group_data["level"], {})
    #         # if gcfg["open_train"]:
    #         data["group"]["train_hero_exps"] = handle_group_train_heros(train_heros, ki_user, gcfg["train_exp"])

    context.result["data"] = data
Exemplo n.º 16
0
    def admin_send_mail(cls, params):
        sid = params.get("sid")
        uids = params.get("uids")
        title = params.get("title")
        sender = params.get("sender")
        msg = params.get("msg")
        attachments = params.get("attachments")

        from apps.services.mail import MailService
        if str(uids) == "@all":
            receivers = rank_service.get_all_players(int(sid))
        else:
            receivers = str(uids).split("/")

        MailService.send_system(receivers, title, sender, msg, eval(attachments))

        return {"mc": 900002}
Exemplo n.º 17
0
def heartbeat(context):
    """心跳协议,玩家在主场景时,
       每隔几分钟向服务器请求一次,
       检测服务器是否有需要提醒前端的功能

    包括:
        1.新邮件
        2.私聊消息
        3.跑马灯公告
        4.竞技场被击败
    """
    ki_user = context.user

    uid = ki_user.uid
    sid = ki_user.sid
    group_id = ki_user.group.group_id
    plat = ki_user.platform

    data = {}
    data["new_mails"] = len(MailService.query_mails(uid, 0))

    private_msgs = ChatService.get_private_msgs(sid, uid, ki_user.game_info.last_chat_read)
    data["private_msgs"] = 1 if private_msgs else 0

    broadcast_msgs = NoticeService.get_broadcasts(sid, ki_user.game_info.broadcast_id)
    data["broadcast_msgs"] = broadcast_msgs

    ki_user.game_info.refresh_broadcast_stamp()

    # arena_last_sign = ki_user.arena.extra_data.get("heartbeat_last_sign", 0)
    # arena_info = ArenaService.heartbeat_info(plat, sid, uid, arena_last_sign)
    # data["arena_info"] = {"fail_times": 0}

    # 充值付费标记,1 - 有已完成付费的充值订单,0 - 没有已完成充值付费的订单
    data["paid_tag"] = charge_service.ismember_of_paid_set(uid)

    # 通关心跳来检测玩家新活动  从数据库中取活配置
    # activity = {}
    # activity["info"] = act_helper.get_active_act_info(sid, ki_user.game_info.role_level)
    # activity["data"] = ki_user.activity.get_effective_acts(sid, ki_user.game_info.role_level)
    # data["activity"] = activity

    # 公会数据  玩家被审核或者被踢出公会之后  通过心跳通知前端
    data["group"] = {}
    data["group"]["group_id"] = group_id
    data["group"]["cd"] = ki_user.group.cd

    # 处理训练所 姬甲挂机经验
    # train_heros = [i for i in ki_user.group.train_list if i not in [0,-1]]
    # if group_id and train_heros:
    #     group_data = GroupService.find(sid, group_id)
    #     if group_data:
    #         data["group"]["level"] = group_data["level"]
    #         gcfg = game_config.group_cfg.get(group_data["level"], {})
    #         # if gcfg["open_train"]:
    #         data["group"]["train_hero_exps"] = handle_group_train_heros(train_heros, ki_user, gcfg["train_exp"])

    context.result["data"] = data
Exemplo n.º 18
0
    def award_total_rank_players(sid, version):
        """给击杀该版本BOSS伤害总榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid,version)
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(game_config.boss_total_award_cfg, index+1)
            if award_cfg:
                awards = copy.deepcopy(award_cfg["awards"])
                for k,v in awards.items():
                    awards[k] = v * 2

                MailService.send_game(value[0], 3010, [index+1], awards)

                print "[boss] award_total_rank_players: receiver: %s, dmg: %s, awards: %s" % (value[0], index+1, awards)
Exemplo n.º 19
0
    def award_total_rank_players(sid, version):
        """给击杀该版本BOSS伤害总榜玩家发奖
        """
        key = rediskey_config.WORLD_BOSS_DMG_TOTAL_RANK_KEY % (sid, version)
        ranking_list = redis_client.zrevrange(key, 0, -1, withscores=True)
        if not ranking_list:
            return

        for index, value in enumerate(ranking_list):
            award_cfg = common_helper.get_award_by_data(
                game_config.boss_total_award_cfg, index + 1)
            if award_cfg:
                awards = copy.deepcopy(award_cfg["awards"])
                for k, v in awards.items():
                    awards[k] = v * 2

                MailService.send_game(value[0], 3010, [index + 1], awards)

                print "[boss] award_total_rank_players: receiver: %s, dmg: %s, awards: %s" % (
                    value[0], index + 1, awards)
Exemplo n.º 20
0
    def crontab_act_send_award_mail(sid, act_id):
        """每日晚上九点,运维活动中有给玩家发送奖励的活动
        """
        # 检查活动是否还在有效时间内
        from apps.services import act as act_service
        act_info = act_service.get_act_info(sid, act_id)

        now = int(time.time())

        if not act_info:
            return

        # 计算是否在有效范围内
        if now >= act_info["end"] or now < act_info["start"]:
            return

        indexes = game_config.act_sample_detail_cfg.get(act_id, [])
        max_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

        # 最低名次,即取N多名竞技场玩家
        key = rediskey_config.RANK_KEY_PREFIX % (sid, "arena")
        top = redis_client.zrangebyscore(key, 0, max_cfg["cond_a"])

        for index, fighter in enumerate(top):
            # 机器人不发奖励
            if fighter.startswith("robot_"):
                continue

            fighter_rank = index + 1
            try:
                award_index = min([rank for rank in indexes if game_config.act_detail_cfg.get("%s-%s" % (act_id, rank))["cond_a"] >= fighter_rank])
            except:
                award_index = 0

            if not award_index:
                continue

            cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, award_index))
            MailService.send_game(fighter, 3000, [fighter_rank], cfg["awards"])

            print "[act:%s] crontab_send_award_mail: receiver: %s, rank: %s, awards: %s" % (act_id, fighter, fighter_rank, cfg["awards"])
Exemplo n.º 21
0
def fight_send_mail_awards(sid, act_id):
    """到活动结束时间点发送战力达标奖励

    Args:
        sid  服务器ID
        act_id  活动ID
    """
    indexes = game_config.act_sample_detail_cfg.get(act_id, [])
    min_cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, max(indexes)))

    rank_name = rediskey_config.RANK_KEY_PREFIX % (
        sid, RANK_KEY_MAPPING[RANK_FIGHT])
    max_score = 9999999
    targets = redis_client.zrangebyscore(rank_name,
                                         min_cfg["cond_a"],
                                         max_score,
                                         withscores=True)

    for index, player in enumerate(targets):
        try:

            def is_reached(level):
                cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, level),
                                                     {})
                if not cfg:
                    return False
                else:
                    return player[1] >= cfg["cond_a"]

            fight_level = min(filter(is_reached, indexes))
        except:
            fight_level = 0

        if not fight_level:
            continue

        cfg = game_config.act_detail_cfg.get("%s-%s" % (act_id, fight_level))
        MailService.send_game(player[0], 1002, [player[1]], cfg["awards"])
        print "[act:%s] fight_send_mail_awards: receiver: %s, fight_level: %s, fight: %s, awards: %s" % (
            act_id, player[0], fight_level, player[1], cfg["awards"])
Exemplo n.º 22
0
def get_attachments(context):
    """收取附件

    Args:
        mail_ids 收取附件的邮件ID列表 []

    Returns:
        mc
    """
    ki_user = context.user

    mail_ids = context.get_parameter("mail_ids", "[]")
    try:
        mail_ids = eval(mail_ids)
        if (not isinstance(mail_ids, list)) or (len(mail_ids) <= 0):
            raise

        mail_ids = [int(mid) for mid in mail_ids]
    except:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    items = []
    for mail_id in mail_ids:
        state = MailService.check_mail_state(ki_user.uid, mail_id)
        if state is None:
            context.result['mc'] = MsgCode['MailNotExist']
            return
        elif state == MAIL_STATE_GOT:
            context.result['mc'] = MsgCode['MailAlreadyGot']
            return
        else:
            items.append(MailService.get_attachments(ki_user.uid, mail_id))

    pack_logic.add_items(ki_user, common_helper.handle_pack_items(items))
    for mail_id in mail_ids:
        MailService.update_mail_state(ki_user.uid, mail_id, MAIL_STATE_GOT)

    context.result["mc"] = MsgCode["MailGetAttachmentsSucc"]
Exemplo n.º 23
0
def get_attachments(context):
    """收取附件

    Args:
        mail_ids 收取附件的邮件ID列表 []

    Returns:
        mc
    """
    ki_user = context.user

    mail_ids = context.get_parameter("mail_ids", "[]")
    try:
        mail_ids = eval(mail_ids)
        if (not isinstance(mail_ids, list)) or (len(mail_ids) <= 0):
            raise

        mail_ids = [int(mid) for mid in mail_ids]
    except:
        context.result['mc'] = MsgCode['ParamIllegal']
        return

    items = []
    for mail_id in mail_ids:
        state = MailService.check_mail_state(ki_user.uid, mail_id)
        if state is None:
            context.result['mc'] = MsgCode['MailNotExist']
            return
        elif state == MAIL_STATE_GOT:
            context.result['mc'] = MsgCode['MailAlreadyGot']
            return
        else:
            items.append(MailService.get_attachments(ki_user.uid, mail_id))

    pack_logic.add_items(ki_user, common_helper.handle_pack_items(items))
    for mail_id in mail_ids:
        MailService.update_mail_state(ki_user.uid, mail_id, MAIL_STATE_GOT)

    context.result["mc"] = MsgCode["MailGetAttachmentsSucc"]
Exemplo n.º 24
0
def debug(context):
    """api调试工具
    """
    # 测试副本获得星星,更新临时排行榜中数据

    ki_user = context.user
    action = context.get_parameter("action")

    if action == "clean_sign_data":
        ki_user.sign.last_sign = 0
        ki_user.sign.put()

    if action == "send_mails":
        from apps.services.mail import MailService
        # send(ids, mtype, title, fromwho, msg, attachments)
        for i in range(10):
            if i % 2 == 0:
                MailService.send_system(["110000004"], "test_%s" % i, "军需官",
                                        "我要一个打五个!!", {1: 10000 + i})
            else:
                MailService.send_system(["110000004"], "test_%s" % i, "军需官",
                                        "我要一个打五个!!", {})

    if action == "add_items":
        items = context.get_parameter("items", "{}")
        try:
            items = eval(items)
            if not isinstance(items, dict):
                raise 1
        except:
            context.result['mc'] = MsgCode['ParamIllegal']
            return

        import apps.logics.package as pack_logic
        pack_logic.add_items(ki_user, items)

    context.result["mc"] = 100
Exemplo n.º 25
0
    def post(self):
        request_context = self.request.request_context
        method = request_context.get_parameter("method", "")

        result = {"mc": 100}
        if method == "add_game_value":
            items = request_context.get_parameter("items").strip()
            user_logic.add_game_values(request_context.user, eval(items))

        elif method == "reset_user_data":
            module = request_context.get_parameter("module").strip()

            debug_handle_reset_user_data(request_context.user, module)

        elif method == "add_items":
            items = request_context.get_parameter("items").strip()

            debug_handle_add_items(request_context.user, items)

        elif method == "send_mails":
            receiver = request_context.get_parameter("receiver").strip()
            title = request_context.get_parameter("title").strip()
            sender = request_context.get_parameter("sender").strip()
            msg = request_context.get_parameter("msg").strip()
            attachments = request_context.get_parameter("attachments").strip()
            attachments = eval(attachments)
            if not isinstance(attachments, dict):
                raise 1

            from apps.services.mail import MailService
            MailService.send_system([receiver], title, sender, msg,
                                    attachments)
        else:
            result = {"mc": 404}

        self.write(json_encode(result))
Exemplo n.º 26
0
    def crontab_send_award_mail(sid):
        """每日晚九点,结算竞技场排行榜,发奖励
        """
        key = rediskey_config.RANK_KEY_PREFIX % (sid, "arena")
        top = redis_client.zrangebyscore(key, 0, ARENA_ROBOTS_NUM)

        for index, fighter in enumerate(top):
            # 机器人不发奖励
            if fighter.startswith("robot_"):
                continue

            fighter_rank = index + 1
            try:
                award_index = min([rank for rank in game_config.arena_mail_award_cfg if rank >= fighter_rank])
            except:
                award_index = 0

            if not award_index:
                continue

            cfg = game_config.arena_mail_award_cfg.get(award_index)
            MailService.send_game(fighter, 1000, [fighter_rank], cfg["awards"])

            print "crontab_send_award_mail: receiver: %s, rank: %s, awards: %s" % (fighter, fighter_rank, cfg["awards"])
Exemplo n.º 27
0
def info(context):
    """读取邮箱数据

    Args:

    Returns:

    """
    ki_user = context.user

    new_mails, read_mails = MailService.get_user_mails(ki_user.uid)

    data = {}
    data["new_mails"] = new_mails
    data["read_mails"] = read_mails

    context.result["data"] = data
Exemplo n.º 28
0
def info(context):
    """读取邮箱数据

    Args:

    Returns:

    """
    ki_user = context.user

    new_mails, read_mails = MailService.get_user_mails(ki_user.uid)

    data = {}
    data["new_mails"] = new_mails
    data["read_mails"] = read_mails

    context.result["data"] = data
Exemplo n.º 29
0
    def install_default_datas(self):
        """默认获得姬甲,排布阵容等
        """
        from apps.logics import hero as hero_logic
        hero_logic.add_heros(self, [{100050: 1}])
        self.array.update(1, [0, 100050, 0, 0, 0, 0])
        self.arena.init_when_install(self.sid)

        # 创建角色时,检测是否需要发[ 应用宝的预约礼包 | uc封测测试奖励 | 360封测测试奖励 ]
        if self.platform in ["YSDK", "UC", "QIHOO"]:
            account = Account.get_account("%s_%s" %
                                          (self.platform, self.account_id))
            if not isinstance(account, Account):
                return

            if self.platform == "YSDK" and redis_client.sismember(
                    rediskey_config.YYB_ORDERED_SET % self.sid,
                    account.open_id):
                order_awards_cfg = game_config.gift_key_config.get("YY02", {})
                if order_awards_cfg:
                    MailService.send_game(self.uid, 5003, [],
                                          order_awards_cfg["award"])

            if self.platform in ["UC", "QIHOO"]:
                # 1.最终等级达到x级 2.累计登陆x天 3.竞技场最终排名x
                awards, logins = pregift_service.uc_qihoo_test_award_4003(
                    self.sid, self.platform, account.open_id)
                if awards:
                    MailService.send_game(self.uid, 5000, [logins], awards)

                awards1, days = pregift_service.uc_qihoo_test_award_4004(
                    self.sid, self.platform, account.open_id)
                if awards1:
                    MailService.send_game(self.uid, 5001, [days], awards1)

                awards2, rank = pregift_service.uc_qihoo_test_award_4005(
                    self.sid, self.platform, account.open_id)
                if awards2:
                    MailService.send_game(self.uid, 5002, [rank], awards2)
Exemplo n.º 30
0
def trial_rank_send_mail_awards(sid):
    """每日凌晨五点结算终极试炼排行榜,给玩家发送排行奖励
    """
    all_players = get_all_players(sid)

    rank_name = rediskey_config.RANK_KEY_PREFIX % (sid, RANK_KEY_MAPPING[RANK_TRIAL])
    ranking_list = redis_client.zrevrange(rank_name, 0, -1, withscores=True)

    if not ranking_list:
        return

    user_ranking = []
    from apps.models.user import User
    for key, value in enumerate(ranking_list):
        rank_data = {'uid': value[0], 'score': int(value[1])}
        user = User.get(rank_data['uid'])
        if user:
            rank_data['score1'] = user.trial.daily_scores
        else:
            rank_data['score1'] = 0

        user_ranking.append(rank_data)

    def tsorted(x,y):
        if x["score"] == y["score"]:
           return y["score1"] - x["score1"]
        else:
           return y["score"] - x["score"]

    user_ranking = sorted(user_ranking, cmp=tsorted)

    a = 1
    for x in user_ranking:
        x['rank'] = a
        a += 1

    user_ranking1 = {}
    for i in user_ranking:
        user_ranking1[str(i['uid'])] = i['rank']

    for uid in all_players:
        user = User.get(uid)
        if not user or user.game_info.role_level <= game_config.user_func_cfg.get(4020, 999):
            continue

        player_rank = user_ranking1.get(uid, 0)
        if player_rank < 0:
            continue

        try:
            award_index = min([rank for rank in game_config.trial_mail_award_cfg if rank >= player_rank])
        except:
            award_index = -1

        if award_index < 0:
            continue

        cfg = game_config.trial_mail_award_cfg.get(award_index)
        MailService.send_game(uid, 1003, [player_rank], cfg["awards"])

        print "trial_rank_awards: receiver: %s, rank: %s, awards: %s" % (uid, player_rank, cfg["awards"])

    trial_delete_daily_rank(sid)
Exemplo n.º 31
0
def trial_rank_send_mail_awards(sid):
    """每日凌晨五点结算终极试炼排行榜,给玩家发送排行奖励
    """
    all_players = get_all_players(sid)

    rank_name = rediskey_config.RANK_KEY_PREFIX % (
        sid, RANK_KEY_MAPPING[RANK_TRIAL])
    ranking_list = redis_client.zrevrange(rank_name, 0, -1, withscores=True)

    if not ranking_list:
        return

    user_ranking = []
    from apps.models.user import User
    for key, value in enumerate(ranking_list):
        rank_data = {'uid': value[0], 'score': int(value[1])}
        user = User.get(rank_data['uid'])
        if user:
            rank_data['score1'] = user.trial.daily_scores
        else:
            rank_data['score1'] = 0

        user_ranking.append(rank_data)

    def tsorted(x, y):
        if x["score"] == y["score"]:
            return y["score1"] - x["score1"]
        else:
            return y["score"] - x["score"]

    user_ranking = sorted(user_ranking, cmp=tsorted)

    a = 1
    for x in user_ranking:
        x['rank'] = a
        a += 1

    user_ranking1 = {}
    for i in user_ranking:
        user_ranking1[str(i['uid'])] = i['rank']

    for uid in all_players:
        user = User.get(uid)
        if not user or user.game_info.role_level <= game_config.user_func_cfg.get(
                4020, 999):
            continue

        player_rank = user_ranking1.get(uid, 0)
        if player_rank < 0:
            continue

        try:
            award_index = min([
                rank for rank in game_config.trial_mail_award_cfg
                if rank >= player_rank
            ])
        except:
            award_index = -1

        if award_index < 0:
            continue

        cfg = game_config.trial_mail_award_cfg.get(award_index)
        MailService.send_game(uid, 1003, [player_rank], cfg["awards"])

        print "trial_rank_awards: receiver: %s, rank: %s, awards: %s" % (
            uid, player_rank, cfg["awards"])

    trial_delete_daily_rank(sid)