Example #1
0
    def join(self, party_owner_id):
        ret = api_handle.API.Party.JoinDone()
        ret.ret = 0

        union = Union(self.server_id, self.char_id)
        if not union.get_joined_union_id():
            ret.ret = ConfigErrorMessage.get_error_id(
                "PARTY_CANNOT_JOIN_NO_UNION")

        if union.get_joined_union_owner_id() != Union(
                self.server_id, party_owner_id).get_joined_union_owner_id():
            ret.ret = ConfigErrorMessage.get_error_id(
                "PARTY_CANNOT_JOIN_NOT_SAME_PARTY")

        return ret
Example #2
0
    def create(self, party_level):
        ret = api_handle.API.Party.CreateDone()
        ret.ret = 0

        config = ConfigPartyLevel.get(party_level)
        if not config:
            ret.ret = ConfigErrorMessage.get_error_id("INVALID_OPERATE")
            return ret

        union = Union(self.server_id, self.char_id)
        union_id = union.get_joined_union_id()
        if not union_id:
            ret.ret = ConfigErrorMessage.get_error_id(
                "PARTY_CANNOT_CREATE_NO_UNION")

        try:
            union.check_level(config.need_union_level)
            cost = [
                (money_text_to_item_id('diamond'), config.need_diamond),
            ]
            rc = ResourceClassification.classify(cost)
            rc.check_exist(self.server_id, self.char_id)
        except GameException as e:
            ret.ret = e.error_id
            return ret

        ret.union_id = union_id
        return ret
Example #3
0
    def send_notify(self):
        notify = ChatNotify()
        notify.act = ACT_INIT

        values = []
        value1 = CommonPublicChat(self.server_id).get()
        if value1:
            values.append(value1)

        union = Union(self.server_id, self.char_id)
        union_id = union.get_joined_union_id()
        if union_id:
            value2 = CommonUnionChat(self.server_id, union_id).get()
            if value2:
                values.append(value2)

        for value in values:
            for v in value:
                msg = ChatMessage()
                try:
                    msg.MergeFromString(base64.b64decode(v))
                except:
                    continue

                notify_msg = notify.msgs.add()
                notify_msg.MergeFrom(msg)

        MessagePipe(self.char_id).put(msg=notify)
Example #4
0
def harass_buy_times(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    u = Union(server_id, char_id)
    u.harass_buy_times()

    response = UnionHarassBuyTimesResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #5
0
def quit(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    u = Union(server_id, char_id)
    u.quit()

    response = UnionQuitResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #6
0
def skill_level_up(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    skill_id = request._proto.skill_id
    u = Union(server_id, char_id)
    u.skill_level_up(skill_id)

    response = UnionSkillLevelupResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #7
0
def set_bulletin(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    content = request._proto.bulletin

    u = Union(server_id, char_id)
    u.set_bulletin(content)

    response = UnionSetBulletinResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #8
0
def transfer(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    target_id = request._proto.char_id

    u = Union(server_id, char_id)
    u.transfer(int(target_id))

    response = UnionTransferResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #9
0
def apply_union(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    union_id = request._proto.union_id

    u = Union(server_id, char_id)
    u.apply_union(union_id)

    response = UnionApplyResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #10
0
def create(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    name = request._proto.name

    u = Union(server_id, char_id)
    u.create(name)

    response = UnionCreateResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #11
0
def kick(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    target_id = request._proto.char_id

    u = Union(server_id, char_id)
    u.kick(int(target_id))

    response = UnionKickResponse()
    response.ret = 0
    return ProtobufResponse(response)
Example #12
0
def signin(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    _id = request._proto.id

    u = Union(server_id, char_id)
    rc = u.sign_in(_id)

    response = UnionSigninResponse()
    response.ret = 0
    response.drop.MergeFrom(rc.make_protomsg())
    return ProtobufResponse(response)
Example #13
0
def explore(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    staff_id = request._proto.staff_id

    u = Union(server_id, char_id)
    explore_point, rc = u.explore(staff_id)

    response = UnionExploreResponse()
    response.ret = 0
    response.explore_point = explore_point
    response.drop.MergeFrom(rc.make_protomsg())

    return ProtobufResponse(response)
Example #14
0
def get_info(request):
    msg = api_handle.decode(request.body)
    """:type: api_handle.API.Union.GetInfo"""

    print msg

    ret = api_handle.API.Union.GetInfoDone()
    ret.ret = 0

    union = Union(msg.server_id, msg.char_id)

    ret.union_id = union.get_joined_union_id()
    ret.owner_id = union.get_joined_union_owner_id()

    ret.extras = get_extra_msgs([msg.char_id])
    return ret
Example #15
0
def harass(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    union_id = request._proto.union_id
    staff_id = request._proto.staff_id

    u = Union(server_id, char_id)
    explore_point, rc, my_explore_point = u.harass(union_id, staff_id)

    response = UnionHarassResponse()
    response.ret = 0
    response.explore_point = explore_point
    response.my_explore_point = my_explore_point
    response.drop.MergeFrom(rc.make_protomsg())

    return ProtobufResponse(response)
Example #16
0
def broadcast_union_chat(args):
    try:
        payload = cPickle.loads(args['payload'])
        server_id = payload['server_id']
        exclude_chars = payload['exclude_chars']
        data = payload['data']
        char_id = payload['char_id']
    except:
        traceback.print_exc()
        return

    union = Union(server_id, char_id)
    member_ids = union.get_member_ids()

    for cid in member_ids:
        if cid not in exclude_chars:
            MessagePipe(cid).put(data=data)
Example #17
0
def harass_query_union(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    u = Union(server_id, char_id)

    # TODO 这里是消息把 my_union 定义成 required 的了。
    if not u.get_joined_union_id():
        response = UnionHarassQueryResponse()
        response.ret = ConfigErrorMessage.get_error_id("INVALID_OPERATE")

        response.my_union.rank = 0
        response.my_union.id = ""
        response.my_union.name = ""
        response.my_union.explore_point = 0

        return ProtobufResponse(response)

    unions, self_union = u.query_by_explore_point_rank()

    response = UnionHarassQueryResponse()
    response.ret = 0

    if not self_union:
        response.my_union.rank = 0
        response.my_union.id = u.union_doc['_id']
        response.my_union.name = u.union_doc['name']
        response.my_union.explore_point = 0
    else:
        response.my_union.rank = self_union.rank
        response.my_union.id = self_union.id
        response.my_union.name = self_union.name
        response.my_union.explore_point = self_union.explore_point

    for u in unions:
        res_union = response.union.add()
        res_union.rank = u.rank
        res_union.id = u.id
        res_union.name = u.name
        res_union.explore_point = u.explore_point

    return ProtobufResponse(response)
Example #18
0
    def normal_chat(self, channel, text):
        from tasks import world

        char_doc = MongoCharacter.db(self.server_id).find_one(
            {'_id': self.char_id},
            {'name': 1, 'vip': 1, 'level': 1}
        )

        union_id = 0
        if channel == CHAT_CHANNEL_PUBLIC:
            if char_doc['level'] < GlobalConfig.value("CHAT_LEVEL_LIMIT"):
                raise GameException(ConfigErrorMessage.get_error_id("CHAT_LEVEL_NOT_ENOUGH"))

            if ChatCD(self.server_id, self.char_id).get_cd_seconds():
                raise GameException(ConfigErrorMessage.get_error_id("CHAT_TOO_FAST"))

            if len(text) > CHAT_MAX_SIZE:
                raise GameException(ConfigErrorMessage.get_error_id("CHAT_TOO_LARGE"))

            ChatCD(self.server_id, self.char_id).set(GlobalConfig.value("CHAT_CD"))

        elif channel == CHAT_CHANNEL_UNION:
            union_id = Union(self.server_id, self.char_id).get_joined_union_id()
            if not union_id:
                raise GameException(ConfigErrorMessage.get_error_id("UNION_CHAT_NO_UNION"))
        else:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        # 创建一个消息
        msg = ChatMessage()
        msg.channel = channel
        msg.club.id = str(self.char_id)
        msg.club.name = char_doc['name']
        msg.club.vip = VIP(self.server_id, self.char_id).level
        msg.msg = text
        data = base64.b64encode(msg.SerializeToString())

        # 立即通知自己
        notify = ChatNotify()
        notify.act = ACT_UPDATE
        notify_msg = notify.msgs.add()
        notify_msg.MergeFrom(msg)

        notify_bin = MessageFactory.pack(notify)
        MessagePipe(self.char_id).put(data=notify_bin)

        # 放入公共空间,让后面登陆的人都能看到
        # 等于离线消息
        if channel == CHAT_CHANNEL_PUBLIC:
            CommonPublicChat(self.server_id).push(data, slice_amount=20)
            # 给其他人广播通知
            arg = {
                'server_id': self.server_id,
                'exclude_chars': [self.char_id],
                'data': MessageFactory.pack(notify)
            }

            payload = cPickle.dumps(arg)
            world.broadcast(payload=payload)
        else:
            CommonUnionChat(self.server_id, union_id).push(data, slice_amount=20)
            arg = {
                'server_id': self.server_id,
                'exclude_chars': [self.char_id],
                'data': MessageFactory.pack(notify),
                'char_id': self.char_id
            }

            payload = cPickle.dumps(arg)
            world.broadcast_union_chat(payload=payload)

        chat_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id
        )
Example #19
0
    def _single_response(_char):
        context['show'] = True
        context['char_id'] = _char.id
        context['char_name'] = _char.name
        context['server_id'] = _char.server_id

        _club = Club(_char.server_id, _char.id)
        _bag = Bag(_char.server_id, _char.id)
        _vip = VIP(_char.server_id, _char.id)
        _sm = StaffManger(_char.server_id, _char.id)
        _fm = Formation(_char.server_id, _char.id)
        _te = Territory(_char.server_id, _char.id)
        _union = Union(_char.server_id, _char.id)

        context['last_login'] = arrow.get(_club.last_login).to(settings.TIME_ZONE).format("YYYY-MM-DD HH:mm:ss")
        context['club_level'] = _club.level
        context['vip_level'] = _vip.doc['vip']
        context['vip_exp'] = _vip.doc['exp']
        context['power'] = _club.power

        context['diamond'] = _club.diamond
        context['gold'] = _club.gold
        context['crystal'] = _club.crystal
        context['gas'] = _club.gas
        context['item_30007'] = _bag.get_amount_by_item_id(30007)
        context['item_30008'] = _bag.get_amount_by_item_id(30008)
        context['item_30009'] = _bag.get_amount_by_item_id(30009)
        context['item_30015'] = _te.get_work_card_amount()

        _res = MongoResource.db(_char.server_id).find_one({'_id': _char.id})
        if not _res:
            _res = {'resource': {}}
        context['item_30022'] = _res['resource'].get('30022', 0)
        context['item_30023'] = _res['resource'].get('30023', 0)
        context['item_30019'] = _res['resource'].get('30019', 0)

        _union_id = _union.get_joined_union_id()
        if not _union_id:
            context['union'] = {}
        else:
            context['union'] = {
                'id': _union_id,
                'name': _union.union_doc['name'],
                'joined_at': arrow.get(_union.member_doc['joined_at']).to(settings.TIME_ZONE).format(
                    "YYYY-MM-DD HH:mm:ss"),
                'contribution': _union.member_doc['contribution']
            }

        in_formation_staffs = _fm.in_formation_staffs()
        staffs_data = []
        equip_data = []

        for k, v in in_formation_staffs.iteritems():
            staff_obj = _sm.get_staff_object(k)
            staff_name = ConfigItemNew.get(staff_obj.oid).name

            staffs_data.append({
                'id': staff_obj.id,
                'oid': staff_obj.oid,
                'name': staff_name,
                'level': staff_obj.level,
                'step': staff_obj.step,
                'star': staff_obj.star,
                'power': staff_obj.power,
                'unit_id': v['unit_id'],
                'position': v['position'],
            })

            for bag_slot_id in [staff_obj.equip_special, staff_obj.equip_decoration, staff_obj.equip_keyboard,
                                staff_obj.equip_monitor, staff_obj.equip_mouse]:

                if not bag_slot_id:
                    continue

                equip = _bag.get_slot(bag_slot_id)
                equip_data.append({
                    'oid': equip['item_id'],
                    'level': equip['level'],
                    'name': ConfigItemNew.get(equip['item_id']).name,
                    'staff_name': staff_name
                })

        context['staffs'] = staffs_data
        context['equips'] = equip_data

        return render_to_response(
            'dianjing_statistics_char.html',
            context=context
        )
Example #20
0
def explore_leader_board(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    members, self_member = get_members_ordered_by_explore_point(server_id,
                                                                char_id,
                                                                limit=10)
    unions, self_union = get_unions_ordered_by_explore_point(
        server_id, char_id)

    response = UnionExploreLeaderboardResponse()
    response.ret = 0

    if self_member:
        response.my_club.rank = self_member.rank
        response.my_club.id = str(self_member.id)
        response.my_club.name = self_member.name
        response.my_club.explore_point = self_member.explore_point
    else:
        response.my_club.rank = 0
        response.my_club.id = str(char_id)
        response.my_club.name = get_club_property(server_id, char_id, 'name')
        response.my_club.explore_point = 0

    if self_union:
        response.my_union.rank = self_union.rank
        response.my_union.id = self_union.id
        response.my_union.name = self_union.name
        response.my_union.explore_point = self_union.explore_point
    else:
        _union = Union(server_id, char_id)
        _union_id = _union.get_joined_union_id()
        if not _union_id:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        response.my_union.rank = 0
        response.my_union.id = _union_id
        response.my_union.name = _union.union_doc['name']
        response.my_union.explore_point = 0

    for i in range(10):
        try:
            m = members[i]
        except IndexError:
            break

        res_club = response.club.add()
        res_club.rank = m.rank
        res_club.id = str(m.id)
        res_club.name = m.name
        res_club.explore_point = m.explore_point

    for i in range(10):
        try:
            u = unions[i]
        except IndexError:
            break

        res_union = response.union.add()
        res_union.rank = u.rank
        res_union.id = u.id
        res_union.name = u.name
        res_union.explore_point = u.explore_point

    return ProtobufResponse(response)
Example #21
0
    def buy(self, tp, goods_id):
        if tp not in ALL_TYPES:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        config = ConfigStore.get(goods_id)
        if not config:
            raise GameException(
                ConfigErrorMessage.get_error_id("STORE_GOODS_NOT_EXIST"))

        try:
            data = self.doc['tp'][str(tp)]['goods'][str(goods_id)]
        except KeyError:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if data['times'] >= config.times_limit:
            raise GameException(
                ConfigErrorMessage.get_error_id("STORE_GOODS_NO_TIMES"))

        if config.condition_id == 1:
            # VIP 等级
            VIP(self.server_id, self.char_id).check(config.condition_value)
        elif config.condition_id == 2:
            # 爬塔历史最高星
            Tower(self.server_id,
                  self.char_id).check_history_max_star(config.condition_value)
        elif config.condition_id == 3:
            # 竞技场当前排名
            Arena(self.server_id,
                  self.char_id).check_current_rank(config.condition_value)
        elif config.condition_id == 4:
            # 当前公会等级
            Union(self.server_id,
                  self.char_id).check_level(config.condition_value)

        item_id, item_amount, need_id, need_amount = config.content[
            data['index']]
        resource_classify = ResourceClassification.classify([(need_id,
                                                              need_amount)])
        resource_classify.check_exist(self.server_id, self.char_id)
        resource_classify.remove(self.server_id,
                                 self.char_id,
                                 message="Store.buy:{0}".format(goods_id))

        resource_classify = ResourceClassification.classify([(item_id,
                                                              item_amount)])
        resource_classify.add(self.server_id,
                              self.char_id,
                              message="Store.buy:{0}".format(goods_id))

        data['times'] += 1

        MongoStore.db(self.server_id).update_one({'_id': self.char_id}, {
            '$set': {
                'tp.{0}.goods.{1}.times'.format(tp, goods_id): data['times']
            }
        })

        self.send_notify(tp=tp)
        return resource_classify
Example #22
0
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()
Example #23
0
    def force_load_staffs(self, send_notify=False):
        from core.staff import StaffManger, Staff
        from core.formation import Formation
        from core.unit import UnitManager
        from core.talent import TalentManager
        from core.collection import Collection
        from core.party import Party
        from core.inspire import Inspire
        from core.union import Union
        from core.bag import Bag

        self.formation_staffs = []

        sm = StaffManger(self.server_id, self.char_id)
        fm = Formation(self.server_id, self.char_id)
        um = UnitManager(self.server_id, self.char_id)
        ins = Inspire(self.server_id, self.char_id)

        staffs = sm.get_staffs_data()
        in_formation_staffs = fm.in_formation_staffs()

        staff_objs = {}
        """:type: dict[str, core.staff.Staff]"""
        for k, v in staffs.items():
            staff_objs[k] = Staff(self.server_id, self.char_id, k, v)

        for k, v in staff_objs.iteritems():
            if k in in_formation_staffs:
                self.formation_staffs.append(v)

                v.policy = in_formation_staffs[k]['policy']
                v.formation_position = in_formation_staffs[k]['position']
                unit_id = in_formation_staffs[k]['unit_id']
                if unit_id:
                    v.set_unit(um.get_unit_object(unit_id))

        working_staff_oids = fm.working_staff_oids()

        for k in in_formation_staffs:
            staff_objs[k].check_qianban(working_staff_oids)
            staff_objs[k].add_self_talent_effect(self)

        talent_effects_1 = TalentManager(self.server_id, self.char_id).get_talent_effects()
        talent_effects_2 = Collection(self.server_id, self.char_id).get_talent_effects()
        talent_effects_3 = fm.get_talent_effects()
        talent_effects_4 = Party(self.server_id, self.char_id).get_talent_effects()
        talent_effects_5 = Union(self.server_id, self.char_id).get_union_skill_talent_effects()

        self.add_talent_effects(talent_effects_1)
        self.add_talent_effects(talent_effects_2)
        self.add_talent_effects(talent_effects_3)
        self.add_talent_effects(talent_effects_4)
        self.add_talent_effects(talent_effects_5)

        config_inspire_level_addition, config_inspire_step_addition = ins.get_addition_config()

        bag = Bag(self.server_id, self.char_id)
        for _, v in staff_objs.iteritems():
            v.config_inspire_level_addition = config_inspire_level_addition
            v.config_inspire_step_addition = config_inspire_step_addition
            v.calculate(bag=bag, um=um)
            v.make_cache()

        if send_notify:
            self.send_notify()
            in_formation_staff_ids = fm.in_formation_staffs().keys()
            sm.send_notify(ids=in_formation_staff_ids)