Exemple #1
0
def _win_battle_broadcast(data, battle):
    """获得积分发广播"""
    union_name = data.union.get(True).name

    broadcast_id = int(
        float(data_loader.OtherBasicInfo_dict['broadcast_id_win_unionbattle'].
              value))
    mode_id = data_loader.BroadcastTemplate_dict[broadcast_id].modeId
    life_time = data_loader.BroadcastTemplate_dict[broadcast_id].lifeTime
    template = data_loader.BroadcastTemplate_dict[
        broadcast_id].template.encode("utf-8")
    priority = data_loader.BroadcastBasicInfo_dict[mode_id].priority

    content = template.replace("#str#", base64.b64decode(union_name), 1)
    content = content.replace("#str#", str(battle.score), 1)

    req = broadcast_pb2.AddBroadcastInfoReq()
    req.user_id = data.id
    req.mode_id = mode_id
    req.priority = priority
    req.life_time = life_time
    req.content = content
    request = req.SerializeToString()

    defer = GlobalObject().remote["common"].callRemote("add_broadcast_record",
                                                       1, request)
Exemple #2
0
    def _receive_broadcast(self, data, req, timer):
        """发送广播"""
        user_name = data.user.get(True).name
        rival_user_name = req.record.user.user.name
        city_name = data_loader.LegendCityBasicInfo_dict[
            req.city_id].nameKey.encode("utf-8")

        broadcast_id = int(
            float(data_loader.
                  OtherBasicInfo_dict['broadcast_id_legendcity_defeat'].value))
        mode_id = data_loader.BroadcastTemplate_dict[broadcast_id].modeId
        life_time = data_loader.BroadcastTemplate_dict[broadcast_id].lifeTime
        template = data_loader.BroadcastTemplate_dict[
            broadcast_id].template.encode("utf-8")
        priority = data_loader.BroadcastBasicInfo_dict[mode_id].priority

        content = template.replace("#str#", base64.b64decode(rival_user_name),
                                   1)
        content = content.replace("#str#", "@%s@" % city_name, 1)
        content = content.replace("#str#", base64.b64decode(user_name), 1)

        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = data.id
        req.mode_id = mode_id
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        defer = GlobalObject().remote["common"].callRemote(
            "add_broadcast_record", 1, request)
Exemple #3
0
    def add_notice(self, user_id, request):
        """添加公告(内部请求)
        """
        timer = Timer(user_id)

        req = broadcast_pb2.AddBroadcastInfoReq()
        req.ParseFromString(request)

        defer = DataBase().get_data(user_id)
        defer.addCallback(self._calc_add_notice, request, req, timer)
        defer.addErrback(self._add_notice_failed, req, timer)
        return defer
Exemple #4
0
    def add(self, common_id, request):
        """添加广播信息
        """
        timer = Timer(common_id)

        req = broadcast_pb2.AddBroadcastInfoReq()
        req.ParseFromString(request)

        defer = DataBase().get_data(common_id)
        defer.addCallback(self._calc_add, req, timer)
        defer.addErrback(self._add_failed, req, timer)
        return defer
Exemple #5
0
    def _add_chest_broadcast(self, data, gold):
        (mode_id, priority, life_time, content) = chest_business.create_broadcast(
                data, gold)
        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = data.id
        req.mode_id = mode_id
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        logger.debug("Add chest broadcast[req=%s]" % req)
        defer = GlobalObject().remote["common"].callRemote("add_broadcast_record", 1, request)
        defer.addCallback(self._check_add_chest_broadcast_result)
        return defer
Exemple #6
0
    def _add_get_herostar_broadcast(self, data, star_id, constellation_num):
        (mode_id, priority, life_time,
         content) = herostar_business.create_broadcast(
             data, HeroStarInfo.get_constellation_id(star_id),
             constellation_num)
        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = data.id
        req.mode_id = mode_id
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        logger.debug("Add get herostar visit broadcast[req=%s]" % req)
        defer = GlobalObject().remote["common"].callRemote(
            "add_broadcast_record", 1, request)
        defer.addCallback(self._check_add_herostar_broadcast_result)
        return defer
Exemple #7
0
    def _add_melee_broadcast_title(self, user, melee):
        """广播玩家演武场战况
        Args:

        """
        (mode, priority, life_time, content) = melee_business.create_broadcast_content_title(user, melee)
        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = user.id
        req.mode_id = mode
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        logger.debug("Add melee broadcast title[req=%s]" % req)
        defer = GlobalObject().remote["common"].callRemote("add_broadcast_record", 1, request)
        defer.addCallback(self._check_add_melee_broadcast_title_result)
        return defer
Exemple #8
0
    def _add_get_hero_broadcast(self, user, draw, hero_basic_id):
        """广播玩家获得S级英雄数据
        Args:

        """
        (mode, priority, life_time, content) = hero_business.create_broadcast_content(user, hero_basic_id, type = 1)
        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = user.id
        req.mode_id = mode
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        logger.debug("Add get hero draw broadcast[req=%s]" % req)
        defer = GlobalObject().remote["common"].callRemote("add_broadcast_record", 1, request)
        defer.addCallback(self._check_add_get_hero_broadcast_result)
        return defer
Exemple #9
0
    def _add_upgrade_star_level_broadcast(self, user, hero):
        """广播玩家英雄升星数据
        Args:

        """
        (mode, priority, life_time,
         content) = hero.create_broadcast_content_star_level(user)
        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = user.id
        req.mode_id = mode
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        logger.debug("Add upgrade star level broadcast[req=%s]" % req)
        defer = GlobalObject().remote["common"].callRemote(
            "add_broadcast_record", 1, request)
        defer.addCallback(self._check_add_upgrade_star_level_broadcast_result)
        return defer
Exemple #10
0
    def _update_broadcast(self, data, req, timer):
        user_name = data.user.get(True).name
        city_name = data_loader.LegendCityBasicInfo_dict[
            req.city_id].nameKey.encode("utf-8")
        if req.HasField("slogan"):
            broadcast_id = int(
                float(data_loader.
                      OtherBasicInfo_dict['broadcast_id_update_slogan'].value))
            value = str(req.slogan)
        elif req.HasField("tax"):
            broadcast_id = int(
                float(data_loader.
                      OtherBasicInfo_dict['broadcast_id_update_tex'].value))
            value = str(req.tax)
        else:
            defer = Deferred()
            defer.callback(False)
            return defer

        mode_id = data_loader.BroadcastTemplate_dict[broadcast_id].modeId
        life_time = data_loader.BroadcastTemplate_dict[broadcast_id].lifeTime
        template = data_loader.BroadcastTemplate_dict[
            broadcast_id].template.encode("utf-8")
        priority = data_loader.BroadcastBasicInfo_dict[mode_id].priority

        content = template.replace("#str#", "@%s@" % city_name, 1)
        content = content.replace("#str#", base64.b64decode(user_name), 1)
        content = content.replace("#str#", value, 1)

        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = data.id
        req.mode_id = mode_id
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        defer = GlobalObject().remote["common"].callRemote(
            "add_broadcast_record", 1, request)
        defer.addCallback(self._update_broadcast_result)
        return defer
Exemple #11
0
    def _add_protect_broadcast(self, user, rival_user_name):
        """广播玩家开保护罩
        Args:

        """
        (mode, priority, life_time,
         content) = battle_business.create_broadcast_content_protect(
             rival_user_name, user)
        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = user.id
        req.mode_id = mode
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        logger.debug("Add protect broadcast[req=%s]" % req)
        defer = GlobalObject().remote["common"].callRemote(
            "add_broadcast_record", 1, request)
        defer.addCallback(self._check_add_protect_broadcast_result)
        return defer
Exemple #12
0
    def _add_technology_broadcast(self, user, technology):
        """广播玩家科技升级
        Args:

        """
        (mode, priority, life_time,
         content) = technology.create_broadcast_content(user)
        if mode == 0:
            #不需要播广播
            return True

        req = broadcast_pb2.AddBroadcastInfoReq()
        req.user_id = user.id
        req.mode_id = mode
        req.priority = priority
        req.life_time = life_time
        req.content = content
        request = req.SerializeToString()

        logger.debug("Add technology broadcast[req=%s]" % req)
        defer = GlobalObject().remote["common"].callRemote(
            "add_broadcast_record", 1, request)
        defer.addCallback(self._check_add_technology_broadcast_result)
        return defer
Exemple #13
0
    def _respond_broadcast_match(self, users, data, req, timer):
        try:
            user_name = data.user.get(True).name
            target_user_name = users[req.target_user_id].name
            item_name_key = data_loader.ItemBasicInfo_dict[
                req.item.basic_id].nameKey.encode("utf-8")

            broadcast_id = int(
                float(data_loader.OtherBasicInfo_dict[
                    'broadcast_id_respond_unionaid'].value))
            mode_id = data_loader.BroadcastTemplate_dict[broadcast_id].modeId
            life_time = data_loader.BroadcastTemplate_dict[
                broadcast_id].lifeTime
            template = data_loader.BroadcastTemplate_dict[
                broadcast_id].template.encode("utf-8")
            priority = data_loader.BroadcastBasicInfo_dict[mode_id].priority

            content = template.replace("#str#", base64.b64decode(user_name), 1)
            content = content.replace("#str#", "@%s@" % item_name_key, 1)
            content = content.replace("#str#",
                                      base64.b64decode(target_user_name), 1)

            req = broadcast_pb2.AddBroadcastInfoReq()
            req.user_id = data.id
            req.mode_id = mode_id
            req.priority = priority
            req.life_time = life_time
            req.content = content
            request = req.SerializeToString()

            defer = GlobalObject().remote["common"].callRemote(
                "add_broadcast_record", 1, request)
            defer.addCallback(self._respond_broadcast_result)
            return defer
        except:
            return False