コード例 #1
0
    def try_auto_transfer(cls, server_id):
        transfer = []

        for doc in MongoUnion.db(server_id).find({}, {'owner': 1}):
            if Club.days_since_last_login(server_id, doc['owner']) <= 7:
                continue

            u = Union(server_id, doc['owner'])
            assert isinstance(u, UnionOwner)

            if u.get_members_amount() == 1:
                continue

            members = u.get_members()
            next_char_id = members[1].id
            u.transfer(next_char_id, send_mail=False)

            MailManager(server_id, doc['owner']).add(
                title=UNION_AUTO_TRANSFER_OLD_OWNER_MAIL_TITLE,
                content=UNION_AUTO_TRANSFER_OLD_OWNER_MAIL_CONTENT)

            MailManager(server_id, next_char_id).add(
                title=UNION_AUTO_TRANSFER_NEW_OWNER_MAIL_TITLE,
                content=UNION_AUTO_TRANSFER_NEW_OWNER_MAIL_CONTENT)

            transfer.append((doc['_id'], doc['owner'], next_char_id))

        return transfer
コード例 #2
0
    def end(self, party_level, member_ids):
        ret = api_handle.API.Party.EndDone()
        ret.ret = 0

        config = ConfigPartyLevel.get(party_level)
        talent_id = random.choice(config.talent_skills)
        self.doc['talent_id'] = talent_id

        MongoParty.db(self.server_id).update_one(
            {'_id': self.char_id}, {'$set': {
                'talent_id': talent_id
            }})

        # apply talent_id to club
        Club(self.server_id, self.char_id).force_load_staffs(send_notify=True)

        reward = [
            (config.item_id, 1),
        ]
        rc = ResourceClassification.classify(reward)
        attachment = rc.to_json()

        char_ids = [self.char_id]
        char_ids.extend(member_ids)
        for c in char_ids:
            m = MailManager(self.server_id, c)
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)

        ret.talent_id = talent_id
        return ret
コード例 #3
0
ファイル: tower.py プロジェクト: zhifuliu/dianjing
    def send_rank_reward_and_reset_star(cls, server_id):
        char_ids = Club.get_recent_login_char_ids(server_id)
        char_ids = [i for i in char_ids]

        condition = {'$and': [
            {'_id': {'$in': char_ids}},
            {'today_max_star': {'$ne': 0}}
        ]}
        docs = MongoTower.db(server_id).find(condition, {'_id': 1}).sort('today_max_star', -1)

        rank = 1
        for doc in docs:
            cid = doc['_id']

            config = ConfigTowerRankReward.get(rank)

            rc = ResourceClassification.classify(config.reward)

            m = MailManager(server_id, cid)
            m.add(
                config.mail_title,
                config.mail_content,
                attachment=rc.to_json(),
            )

            rank += 1

        # reset today max star
        MongoTower.db(server_id).update_many(
            {},
            {'$set': {
                'today_max_star': 0,
            }}
        )
コード例 #4
0
ファイル: arena.py プロジェクト: zhifuliu/dianjing
    def send_rank_reward(cls, server_id):
        char_ids = Club.get_recent_login_char_ids(server_id)

        # 加上一分钟,确保已经到了第二天
        # 定时任务要是 23:59:59 启动,那天数判断就错了
        weekday = arrow.utcnow().to(
            settings.TIME_ZONE).replace(minutes=1).weekday()

        for cid in char_ids:
            arena = Arena(server_id, cid)
            rank = arena.get_current_rank()

            # 每日奖励
            config = ConfigArenaRankReward.get(rank)
            rc = ResourceClassification.classify(config.reward)

            m = MailManager(server_id, cid)
            m.add(
                config.mail_title,
                config.mail_content,
                attachment=rc.to_json(),
            )

            if weekday == 0:
                # 周一发周奖励
                config_weekly = ConfigArenaRankRewardWeekly.get(rank)
                rc = ResourceClassification.classify(config_weekly.reward)

                m = MailManager(server_id, cid)
                m.add(config_weekly.mail_title,
                      config_weekly.mail_content,
                      attachment=rc.to_json())

        if weekday == 0:
            docs = MongoArena.db(server_id).find({'_id': {
                '$regex': '^\d+$'
            }}, {'_id': 1})

            default_score_doc = MongoArenaScore.db(server_id).find_one(
                {'_id': ARENA_DEFAULT_SCORE})
            for doc in docs:
                if doc['_id'] in default_score_doc['char_ids']:
                    continue

                ArenaScore(server_id,
                           int(doc['_id'])).set_score(ARENA_DEFAULT_SCORE)
コード例 #5
0
ファイル: club.py プロジェクト: zhifuliu/dianjing
    def create(cls, server_id, char_id, club_name, club_flag):
        from core.staff import StaffManger
        from core.formation import Formation
        from core.mail import MailManager
        from apps.config.models import Mail as ModelMail

        doc = MongoCharacter.document()
        doc['_id'] = char_id
        doc['create_at'] = arrow.utcnow().timestamp

        doc['name'] = club_name
        doc['flag'] = club_flag
        doc['gold'] = CHAR_INIT_GOLD
        doc['diamond'] = CHAR_INIT_DIAMOND
        doc['crystal'] = CHAR_INIT_CRYSTAL
        doc['gas'] = CHAR_INIT_GAS

        sm = StaffManger(server_id, char_id)

        formation_init_data = []
        for staff_id, unit_id in CHAR_INIT_STAFFS:
            uid = sm.add(staff_id, send_notify=False, trig_signal=False)
            formation_init_data.append((uid, unit_id))

        fm = Formation(server_id, char_id)
        fm.initialize(formation_init_data)

        MongoCharacter.db(server_id).insert_one(doc)

        # add welfare mail
        start_time = get_start_time_of_today()
        condition = Q(send_at__gte=start_time.format("YYYY-MM-DD HH:mm:ssZ")) &\
                    Q(send_at__lte=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ"))
        mails = ModelMail.objects.filter(condition)

        m = MailManager(server_id, char_id)
        for m_obj in mails:
            if not m_obj.welfare:
                continue

            ok = False
            if m_obj.condition_type == 1:
                ok = True
            elif m_obj.condition_type == 2 and server_id in m_obj.get_parsed_condition_value():
                ok = True
            elif m_obj.condition_type == 3 and server_id not in m_obj.get_parsed_condition_value():
                ok = True

            if not ok:
                continue

            if m_obj.items:
                rc = ResourceClassification.classify(m_obj.get_parsed_items())
                attachment = rc.to_json()
            else:
                attachment = ""

            m.add(m_obj.title, m_obj.content, attachment=attachment, send_notify=False)
コード例 #6
0
ファイル: chat.py プロジェクト: zhifuliu/dianjing
    def gift(self, gift_code_record):
        """

        :type gift_code_record: GiftCodeRecord
        """

        gen_id = gift_code_record.gen_id
        category = GiftCodeGen.objects.get(id=gen_id).category.id
        gift = GiftCode.objects.get(id=category)
        """:type: GiftCode"""

        if not gift.active:
            raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_NOT_ACTIVE"))

        if gift.time_range1:
            time1 = arrow.get(gift.time_range1).timestamp
            if arrow.utcnow().timestamp < time1:
                raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_NOT_STARTED"))

        if gift.time_range2:
            time2 = arrow.get(gift.time_range2).timestamp
            if arrow.utcnow().timestamp > time2:
                raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_EXPIRED"))

        if gift.times_limit:
            using_times = GiftCodeUsingLog.objects.filter(gift_code=gift_code_record.id).count()
            if using_times >= gift.times_limit:
                raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_NO_TIMES"))

        # 每个礼品码默认每个玩家每个服只能用一次
        condition = Q(server_id=self.server_id) & Q(char_id=self.char_id) & Q(gift_code=gift_code_record.id)
        if GiftCodeUsingLog.objects.filter(condition).exists():
            raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_ALREADY_USED"))

        # 同类同服不可以多次使用
        condition = Q(server_id=self.server_id) & Q(char_id=self.char_id) & Q(category=gift.id)
        if GiftCodeUsingLog.objects.filter(condition).exists():
            raise GameException(ConfigErrorMessage.get_error_id("GIFT_CODE_CATEGORY_ALREADY_USED"))

        # ALL OK
        items = gift.get_parsed_items()
        rc = ResourceClassification.classify(items)

        m = MailManager(self.server_id, self.char_id)
        m.add(title=gift.mail_title, content=gift.mail_content, attachment=rc.to_json())

        GiftCodeUsingLog.objects.create(
            server_id=self.server_id,
            char_id=self.char_id,
            gift_code=gift_code_record.id,
            category=category,
        )

        GiftCodeGen.objects.filter(id=gen_id).update(used_amount=F('used_amount') + 1)
コード例 #7
0
def delete(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    id = request._proto.id

    m = MailManager(server_id, char_id)
    m.delete(id)

    response = MailDeleteResponse()
    response.ret = 0
    return ProtobufResponse(response)
コード例 #8
0
def read(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    id = request._proto.id

    m = MailManager(server_id, char_id)
    m.open(id)

    response = MailOpenResponse()
    response.ret = 0
    return ProtobufResponse(response)
コード例 #9
0
def send(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    to_id = request._proto.to_id
    content = request._proto.content

    m = MailManager(server_id, char_id)
    m.send(to_id, content)

    response = MailSendResponse()
    response.ret = 0
    return ProtobufResponse(response)
コード例 #10
0
    def send_score_reward_mail(self, club_id, score):
        if is_npc(club_id):
            return

        config = ConfigChampionScoreReward.get(score)
        if not config:
            return

        rc = ResourceClassification.classify(config.reward)
        attachment = rc.to_json()

        m = MailManager(self.server_id, int(club_id))
        m.add(config.mail_title, config.mail_content, attachment=attachment)
コード例 #11
0
def get_attachment(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    id = request._proto.id

    m = MailManager(server_id, char_id)
    package = m.get_attachment(id)

    response = MailGetAttachmentResponse()
    response.ret = 0
    response.attachment.MergeFrom(package.make_protomsg())
    return ProtobufResponse(response)
コード例 #12
0
def cronjob_of_union_explore(server_id):
    members, _ = get_members_ordered_by_explore_point(server_id,
                                                      0,
                                                      names=False)
    unions, _ = get_unions_ordered_by_explore_point(server_id, 0)

    MongoUnionMember.db(server_id).update_many(
        {}, {'$set': {
            'explore_point': 0,
        }})

    MongoUnion.db(server_id).update_many({}, {'$set': {
        'explore_point': 0,
    }})

    for m in members:
        reward = ConfigUnionMemberExploreRankReward.get_by_rank(m.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        m = MailManager(server_id, m.id)
        m.add(reward.mail_title, reward.mail_content, attachment=attachment)

    for u in unions:
        reward = ConfigUnionExploreRankReward.get_by_rank(u.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        docs = MongoUnionMember.db(server_id).find({'joined': u.id},
                                                   {'_id': 1})

        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(reward.mail_title,
                  reward.mail_content,
                  attachment=attachment)
コード例 #13
0
    def quit(self, *args):
        super(UnionOwner, self).quit(send_notify=False)
        if self.get_members_amount() == 0:
            MongoUnion.db(self.server_id).delete_one(
                {'_id': self.union_doc['_id']})
            return

        members = self.get_members()
        next_char_id = members[0].char_id
        self.transfer(next_char_id, send_mail=False)

        MailManager(self.server_id, next_char_id).add(
            title=UNION_QUIT_TRANSFER_NEW_OWNER_MAIL_TITLE,
            content=UNION_QUIT_TRANSFER_NEW_OWNER_MAIL_CONTENT,
        )
コード例 #14
0
    def send_rank_reward_mail(self, level):
        config = ConfigChampionRankReward.get(level)

        member_ids = self.doc['levels'][str(level)]['member_ids']

        rc = ResourceClassification.classify(config.reward)
        attachment = rc.to_json()

        for m in member_ids:
            if is_npc(m):
                continue

            m = MailManager(self.server_id, int(m))
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)
コード例 #15
0
    def send_bet_reward_mail(self, level, win_ids):
        # 找到所有bet的玩家,然后遍历
        docs = MongoChampionship.db(self.server_id).find({'has_bet': True})
        for doc in docs:
            bet_info = doc['bet'].get(str(level), {})
            if not bet_info:
                continue

            config = ConfigChampionBet.get(bet_info['bet_id'])
            if bet_info['club_id'] in win_ids:
                m_title = config.win_mail_title
                m_content = config.win_mail_content
                m_reward = config.win_reward
            else:
                m_title = config.lose_mail_title
                m_content = config.lose_mail_content
                m_reward = config.lose_reward

            rc = ResourceClassification.classify(m_reward)
            attachment = rc.to_json()
            m = MailManager(self.server_id, doc['_id'])
            m.add(m_title, m_content, attachment=attachment)
コード例 #16
0
    def transfer(self, char_id, send_mail=True):
        if char_id == self.char_id:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        u = Union(self.server_id, char_id)
        if not isinstance(u, UnionMember
                          ) or u.member_doc['joined'] != self.union_doc['_id']:
            raise GameException(
                ConfigErrorMessage.get_error_id("UNION_TARGET_NOT_MEMBER"))

        self.union_doc['owner'] = char_id
        MongoUnion.db(self.server_id).update_one(
            {'_id': self.union_doc['_id']}, {'$set': {
                'owner': char_id
            }})

        if send_mail:
            MailManager(self.server_id, char_id).add(
                title=UNION_MANUAL_TRANSFER_NEW_OWNER_MAIL_TITLE,
                content=UNION_MANUAL_TRANSFER_NEW_OWNER_MAIL_CONTENT)

        self.send_notify_to_all_members(send_my_check_notify=True)
コード例 #17
0
    def send_yueka_reward(cls, server_id):
        config = ConfigPurchaseYueka.get(YUEKA_ID)

        condition = {
            '$and': [{
                'yueka_remained_days': {
                    '$gt': 0
                }
            }, {
                'yueka_new': False
            }]
        }

        docs = MongoPurchase.db(server_id).find(condition)
        MongoPurchase.db(server_id).update_many(
            condition, {'$inc': {
                'yueka_remained_days': -1
            }})

        # 把今天新购买的,设置为False,以便后面的定时任务好发送月卡
        MongoPurchase.db(server_id).update_many({'yueka_new': True},
                                                {'$set': {
                                                    'yueka_new': False
                                                }})

        rc = ResourceClassification.classify(config.rewards)
        attachment = rc.to_json()

        amount = 0
        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)
            amount += 1

        return amount
コード例 #18
0
ファイル: game.py プロジェクト: zhifuliu/dianjing
def game_start_handler(server_id, char_id, **kwargs):
    MessagePipe(char_id).clean()

    msg = UTCNotify()
    msg.timestamp = arrow.utcnow().timestamp
    MessagePipe(char_id).put(msg=msg)

    msg = SocketServerNotify()
    ss = random.choice(settings.SOCKET_SERVERS)
    msg.ip = ss['host']
    msg.port = ss['tcp']
    MessagePipe(char_id).put(msg=msg)

    _Resource.send_notify(server_id, char_id)

    UnitManager(server_id, char_id).send_notify()

    Bag(server_id, char_id).send_notify()

    StaffManger(server_id, char_id).send_notify()
    StaffRecruit(server_id, char_id).send_notify()

    f = Formation(server_id, char_id)
    f.send_formation_notify()
    f.send_slot_notify()

    club = Club(server_id, char_id)
    club.set_login()
    club.send_notify()

    msg = CreateDaysNotify()
    msg.days = days_passed(club.create_at)
    msg.create_at = club.create_at
    MessagePipe(char_id).put(msg=msg)

    chall = Challenge(server_id, char_id)
    chall.send_chapter_notify()
    chall.send_challenge_notify()

    FriendManager(server_id, char_id).send_notify()
    MailManager(server_id, char_id).send_notify()

    TaskMain(server_id, char_id).send_notify()
    TaskDaily(server_id, char_id).send_notify()

    Chat(server_id, char_id).send_notify()

    Notification(server_id, char_id).send_notify()

    FinanceStatistics(server_id, char_id).send_notify()

    TalentManager(server_id, char_id).send_notify()

    Dungeon(server_id, char_id).send_notify()

    a = Arena(server_id, char_id)
    a.send_notify()
    a.send_honor_notify()

    t = Tower(server_id, char_id)
    t.send_notify()
    t.send_goods_notify()

    Territory(server_id, char_id).send_notify()
    TerritoryStore(server_id, char_id).send_notify()
    TerritoryFriend(server_id, char_id).send_remained_times_notify()

    Store(server_id, char_id).send_notify()
    VIP(server_id, char_id).send_notify()
    Collection(server_id, char_id).send_notify()

    Energy(server_id, char_id).send_notify()

    w = Welfare(server_id, char_id)
    w.send_signin_notify()
    w.send_new_player_notify()
    w.send_level_reward_notify()
    w.send_energy_reward_notify()

    Union(server_id, char_id).send_all_notify()

    Purchase(server_id, char_id).send_notify()

    ac = ActivityNewPlayer(server_id, char_id)
    ac.send_notify()
    ac.send_daily_buy_notify()

    ActivityOnlineTime(server_id, char_id).send_notify()
    ActivityChallenge(server_id, char_id).send_notify()
    ActivityPurchaseDaily(server_id, char_id).send_notify()
    ActivityPurchaseContinues(server_id, char_id).send_notify()
    ActivityLevelGrowing(server_id, char_id).send_notify()

    p = Plunder(server_id, char_id)

    p.send_search_notify()
    p.send_result_notify()
    p.send_revenge_notify()
    p.send_station_notify()
    p.send_formation_notify()
    p.send_plunder_times_notify()
    p.send_plunder_daily_reward_notify()

    SpecialEquipmentGenerator(server_id, char_id).send_notify()

    Party(server_id, char_id).send_notify()

    ins = Inspire(server_id, char_id)
    ins.try_open_slots(send_notify=False)
    ins.send_notify()

    cs = Championship(server_id, char_id)
    cs.try_initialize(send_notify=False)
    cs.send_notify()

    WinningPlunder(server_id, char_id).send_notify()
    WinningArena(server_id, char_id).send_notify()
    WinningChampionship(server_id, char_id).send_notify()
    Worship(server_id, char_id).send_notify()
    CommonArenaWinningChat(server_id, char_id).send_notify()
    CommonPlunderWinningChat(server_id, char_id).send_notify()
    CommonChampionshipChat(server_id, char_id).send_notify()

    send_system_notify(server_id, char_id)
    BroadCast(server_id, char_id).try_cast_login_notify()
コード例 #19
0
    def send_reward(self, goods_id):
        if goods_id == YUEKA_ID:
            # 月卡买了就立即发送
            # 后面的再定时发送
            config = ConfigPurchaseYueka.get(YUEKA_ID)
            got = 0
            actual_got = 0

            MongoPurchase.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': {
                    'yueka_remained_days': 29,
                    'yueka_new': True
                }})

            self.doc['yueka_remained_days'] = 29
            self.doc['yueka_new'] = True

            rc = ResourceClassification.classify(config.rewards)
            attachment = rc.to_json()

            m = MailManager(self.server_id, self.char_id)
            m.add(config.mail_title,
                  config.mail_content,
                  attachment=attachment)
        else:
            config = ConfigPurchaseGoods.get(goods_id)

            got = config.diamond
            actual_got = config.diamond + config.diamond_extra
            if self.get_purchase_times() == 0:
                # 首充
                actual_got = config.diamond * 2 + config.diamond_extra

        doc = MongoPurchaseLog.document()
        doc['_id'] = make_string_id()
        doc['char_id'] = self.char_id
        doc['goods_id'] = goods_id
        doc['got'] = got
        doc['actual_got'] = actual_got
        doc['timestamp'] = arrow.utcnow().timestamp
        MongoPurchaseLog.db(self.server_id).insert_one(doc)

        reward = [(VIP_EXP_ITEM_ID, config.vip_exp),
                  (money_text_to_item_id('diamond'), actual_got)]

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id,
               self.char_id,
               message="Purchase.send_reward:{0}".format(goods_id))

        purchase_done_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            goods_id=goods_id,
            got=got,
            actual_got=actual_got,
        )

        self.send_notify()