Beispiel #1
0
def remove(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    friend_id = request._proto.id

    fm = FriendManager(server_id, char_id)
    fm.remove(friend_id)

    response = FriendRemoveResponse()
    response.ret = 0
    return ProtobufResponse(response)
Beispiel #2
0
def accept(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    friend_id = request._proto.id

    fm = FriendManager(server_id, char_id)
    fm.accept(friend_id)

    response = FriendAcceptResponse()
    response.ret = 0
    return ProtobufResponse(response)
Beispiel #3
0
def add(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    name = request._proto.name

    fm = FriendManager(server_id, char_id)
    fm.add(name)

    response = FriendAddResponse()
    response.ret = 0
    return ProtobufResponse(response)
Beispiel #4
0
def get_info(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    friend_id = request._proto.id

    fm = FriendManager(server_id, char_id)
    club = fm.get_info(friend_id)

    response = FriendGetInfoResponse()
    response.ret = 0
    response.club.MergeFrom(club.make_protomsg())

    return ProtobufResponse(response)
Beispiel #5
0
 def test_get_info_not_exist(self):
     try:
         FriendManager(1, 1).get_info(2)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id('FRIEND_NOT_EXIST')
     else:
         raise Exception('test_get_info_not_exist error')
Beispiel #6
0
    def help(self, friend_id, building_id):
        friend_id = int(friend_id)
        if not FriendManager(self.server_id,
                             self.char_id).check_friend_exist(friend_id):
            raise GameException(
                ConfigErrorMessage.get_error_id("FRIEND_NOT_OK"))

        if not self.get_remained_help_times():
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "TERRITORY_NO_HELP_FRIEND_TIMES"))

        if not TerritoryFriend(self.server_id,
                               friend_id).get_remained_got_help_times():
            raise GameException(
                ConfigErrorMessage.get_error_id("TERRITORY_NO_GOT_HELP_TIMES"))

        t = Territory(self.server_id, friend_id)
        building = t.get_building_object(building_id, slots_ids=[])

        event_id = building.event_id

        if not event_id:
            raise GameException(
                ConfigErrorMessage.get_error_id("TERRITORY_BUILDING_NO_EVENT"))

        MongoTerritory.db(self.server_id).update_one(
            {'_id': friend_id},
            {'$set': {
                'buildings.{0}.event_id'.format(building_id): 0
            }})

        config = ConfigTerritoryEvent.get(event_id)
        if not config.npc:
            resource_classified = ResourceClassification.classify(
                config.reward_win)
            resource_classified.add(self.server_id,
                                    self.char_id,
                                    message="TerritoryFriend.help")

            # NOTE: 战斗要等到结算的时候再记录次数
            ValueLogTerritoryHelpFriendTimes(self.server_id,
                                             self.char_id).record()
            self.send_remained_times_notify()

            Territory(self.server_id,
                      friend_id).got_help(self.char_id, building_id,
                                          config.target_exp)

            return None, resource_classified

        npc_club = ConfigNPCFormation.get(config.npc)
        my_club = Club(self.server_id, self.char_id)

        f = Formation(self.server_id, self.char_id)
        match = ClubMatch(my_club, npc_club, 6, f.get_skill_sequence(), {})
        msg = match.start()
        msg.key = "{0}:{1}:{2}".format(friend_id, building_id, event_id)
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_TERRITORY_FRIEND")
        return msg, None
Beispiel #7
0
 def test_add_char_not_exist(self):
     try:
         FriendManager(1, 1).add('test')
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id('CHAR_NOT_EXIST')
     else:
         raise Exception('add_char_not_exist error')
Beispiel #8
0
 def test_remove_friend_not_exist(self):
     try:
         FriendManager(1, 1).remove(2)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id("FRIEND_NOT_EXIST")
     else:
         raise Exception('test_remove_friend_not_exist error')
Beispiel #9
0
 def test_accept_already_friend(self):
     self.set_friend_data()
     try:
         FriendManager(1, 1).accept(2)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id("FRIEND_ALREADY_IS_FRIEND")
     else:
         raise Exception('test_accept_already_friend error')
Beispiel #10
0
    def test_add(self):
        FriendManager(1, 1).add('two')
        data = MongoDB.get(1).friend.find_one(
            {'_id': 1},
            {'friends.2': 1}
        )

        assert data['friends']['2'] == FRIEND_STATUS_PEER_CONFIRM
Beispiel #11
0
 def test_add_already_friend(self):
     self.set_friend_data()
     try:
         FriendManager(1, 1).add('two')
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id('FRIEND_ALREADY_IS_FRIEND')
     else:
         raise Exception('add_char_not_exist error')
Beispiel #12
0
 def test_match_staff_not_ready(self):
     self.set_friend_data()
     try:
         FriendManager(1, 1).match(2)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id("MATCH_STAFF_NOT_READY")
     else:
         raise Exception('error')
Beispiel #13
0
    def test_accept_error(self):
        self.make_friend_request()

        try:
            FriendManager(1, 1).accept(2)
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id("FRIEND_ACCEPT_ERROR")
        else:
            raise Exception('test_accept_error error')
Beispiel #14
0
    def test_add_request_already_sent(self):
        self.make_friend_request()

        try:
            FriendManager(1, 1).add('two')
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id('FRIEND_ADD_REQUEST_ALREADY_SENT')
        else:
            raise Exception('add_request_sended error')
Beispiel #15
0
def get_candidates(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    fm = FriendManager(server_id, char_id)
    candidates = fm.get_candidates()

    response = FriendCandidatesResponse()
    response.ret = 0

    online_char_ids = OperationLog.get_recent_action_char_ids(server_id)

    for c in candidates:
        response_friend = response.friends.add()
        response_friend.status = FRIEND_NOT
        response_friend.online = c in online_char_ids
        response_friend.club.MergeFrom(Club(server_id, c).make_protomsg())

    return ProtobufResponse(response)
Beispiel #16
0
    def test_match(self):
        self.set_friend_data()

        staff_ids = random.sample(ConfigStaff.INSTANCES.keys(), 10)
        for i in staff_ids:
            StaffManger(1, 1).add(i)
            StaffManger(1, 2).add(i)

        Club(1, 1).set_match_staffs(staff_ids)
        Club(1, 2).set_match_staffs(staff_ids)

        FriendManager(1, 1).match(2)
Beispiel #17
0
    def get_list(self):
        friend_ids = FriendManager(self.server_id,
                                   self.char_id).get_real_friends_ids()
        info = {}
        """:type: dict[int, list[dict]]"""

        for fid in friend_ids:
            t = Territory(self.server_id, fid)
            buildings = t.get_all_building_objects()

            b_list = []
            for _, b_obj in buildings.iteritems():
                b_obj.refresh_event_id()

                b_list.append({
                    'id': b_obj.id,
                    'level': b_obj.level,
                    'event_id': b_obj.event_id
                })

            info[fid] = b_list
        return info
Beispiel #18
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()
Beispiel #19
0
 def test_get_info(self):
     self.set_friend_data()
     char, club = FriendManager(1, 1).get_info(2)
     if not char or not club:
         raise Exception('test_get_info error')
Beispiel #20
0
    def test_accept(self):
        self.make_friend_request()
        FriendManager(1, 2).accept(1)

        assert FriendManager(1, 1).check_friend_exist(2) is True
        assert FriendManager(1, 2).check_friend_exist(1) is True
Beispiel #21
0
 def test_send_notify(self):
     FriendManager(1, 1).send_notify()
Beispiel #22
0
 def test_send_remove_notify(self):
     FriendManager(1, 1).send_remove_notify(2)
Beispiel #23
0
    def test_remove_friend(self):
        self.set_friend_data()

        FriendManager(1, 1).remove(2)
        assert FriendManager(1, 1).check_friend_exist(2) is False
        assert FriendManager(1, 2).check_friend_exist(1) is False