예제 #1
0
파일: inspire.py 프로젝트: yueyoum/dianjing
    def try_open_slots(self, send_notify=True):
        opened = []
        updater = {}

        c = Challenge(self.server_id, self.char_id)
        passed_challenge_ids = c.get_passed_challenge_ids()

        for challenge_id, slot_id in ConfigInspire.LIST:
            if challenge_id not in passed_challenge_ids:
                continue

            if str(slot_id) in self.doc['slots']:
                continue

            self.doc['slots'][str(slot_id)] = ""
            opened.append(slot_id)
            updater['slots.{0}'.format(slot_id)] = ""

        if updater:
            MongoInspire.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': updater}
            )

        if send_notify and opened:
            self.send_notify(opened)
예제 #2
0
    def init_challenge(self,
                       tool_name: str,
                       challenge_name: str,
                       remove_patch: bool = False) -> Challenge:
        wd = Path(self.configuration.paths.working_dir,
                  f"{tool_name}_{challenge_name}_{self.seed}")
        lock = LockFile(self.configuration.paths.root,
                        self.configuration.lock_file)
        cmd_str = self.checkout(working_directory=wd,
                                challenge_name=challenge_name,
                                remove_patch=remove_patch)

        if wd.exists():
            shutil.rmtree(wd)
        try:
            lock.wait_lock()
            lock()
            out, err = super().__call__(
                cmd_str=cmd_str,
                msg=f"Checking out challenge {challenge_name} to {wd}.\n")
        finally:
            lock.unlock()

        if not err:
            return Challenge(challenge_name, wd)

        return Challenge("", "")
예제 #3
0
def reset(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    challenge_id = request._proto.id

    c = Challenge(server_id, char_id)
    c.reset(challenge_id)

    response = ChallengeResetResponse()
    response.ret = 0
    return ProtobufResponse(response)
예제 #4
0
def reset(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    challenge_id = request._proto.id

    c = Challenge(server_id, char_id)
    c.reset(challenge_id)

    response = ChallengeResetResponse()
    response.ret = 0
    return ProtobufResponse(response)
예제 #5
0
def chapter_reward(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    chapter_id = request._proto.id
    index = request._proto.index

    resource_classified = Challenge(server_id, char_id).get_chapter_reward(chapter_id, index)
    response = ChapterGetStarRewardResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
예제 #6
0
def report(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    key = request._proto.key
    star = request._proto.star

    resource_classified = Challenge(server_id, char_id).report(key, star)
    response = ChallengeMatchReportResponse()
    response.ret = 0
    if resource_classified:
        response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
예제 #7
0
def chapter_reward(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    chapter_id = request._proto.id
    index = request._proto.index

    resource_classified = Challenge(server_id, char_id).get_chapter_reward(
        chapter_id, index)
    response = ChapterGetStarRewardResponse()
    response.ret = 0
    response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
예제 #8
0
def report(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    key = request._proto.key
    star = request._proto.star

    resource_classified = Challenge(server_id, char_id).report(key, star)
    response = ChallengeMatchReportResponse()
    response.ret = 0
    if resource_classified:
        response.drop.MergeFrom(resource_classified.make_protomsg())

    return ProtobufResponse(response)
예제 #9
0
def sweep(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    challenge_id = request._proto.id
    tp = request._proto.tp

    c = Challenge(server_id, char_id)
    resource_classified_list = c.sweep(challenge_id, tp)

    response = ChallengeSweepResponse()
    response.ret = 0
    for r in resource_classified_list:
        response_drop = response.drop.add()
        response_drop.MergeFrom(r.make_protomsg())
    return ProtobufResponse(response)
예제 #10
0
    def init_challenge(self,
                       tool_name: str,
                       challenge_name: str,
                       remove_patch: bool = False,
                       wrap_dir: str = None) -> Challenge:
        wd = Path(self.configuration.paths.working_dir, tool_name,
                  f"{challenge_name}_{self.seed}")
        if wrap_dir:
            wd = wd / wrap_dir
        lock = LockFile(self.configuration.paths.root,
                        self.configuration.lock_file)
        cmd_str = self.checkout(working_directory=wd,
                                challenge_name=challenge_name,
                                remove_patch=remove_patch)

        if wd.exists():
            shutil.rmtree(wd.parent if wrap_dir else wd)
        try:
            lock.wait_lock()
            lock()
            _, _ = super().__call__(
                cmd_str=cmd_str,
                msg=f"Checking out challenge {challenge_name} to {wd}.\n",
                exit_err=True)
            pos_tests, neg_tests = self.count_tests(
                working_directory=wd, challenge_name=challenge_name)
            return Challenge(name=challenge_name,
                             working_dir=wd,
                             pos_tests=pos_tests,
                             neg_tests=neg_tests)
        finally:
            lock.unlock()
예제 #11
0
def start(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    challenge_id = request._proto.id

    formation_slots = parse_protocol_sync_formation_slots(request._proto.slots)

    c = Challenge(server_id, char_id)
    msg = c.start(challenge_id, formation_slots)

    response = ChallengeStartResponse()
    response.ret = 0
    response.match.MergeFrom(msg)

    return ProtobufResponse(response)
예제 #12
0
def start(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    challenge_id = request._proto.id

    formation_slots = parse_protocol_sync_formation_slots(request._proto.slots)

    c = Challenge(server_id, char_id)
    msg = c.start(challenge_id, formation_slots)

    response = ChallengeStartResponse()
    response.ret = 0
    response.match.MergeFrom(msg)

    return ProtobufResponse(response)
예제 #13
0
def sweep(request):
    server_id = request._game_session.server_id
    char_id = request._game_session.char_id

    challenge_id = request._proto.id
    tp = request._proto.tp

    c = Challenge(server_id, char_id)
    resource_classified_list = c.sweep(challenge_id, tp)

    response = ChallengeSweepResponse()
    response.ret = 0
    for r in resource_classified_list:
        response_drop = response.drop.add()
        response_drop.MergeFrom(r.make_protomsg())
    return ProtobufResponse(response)
예제 #14
0
파일: task.py 프로젝트: zhifuliu/dianjing
    def trig(self, challenge_id):
        if not self.doing:
            # 任务都做完了
            return

        config = ConfigTaskMain.get(self.doing)
        if not Challenge(self.server_id, self.char_id).is_challenge_id_passed(
                config.challenge_id):
            return

        if self.doing >= ConfigTaskMain.MAX_ID:
            self.doing = 0
        else:
            self.doing += 1

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

        resource_classified = ResourceClassification.classify(config.items)
        resource_classified.add(
            self.server_id,
            self.char_id,
            message="TaskMain.trig:{0}".format(challenge_id))

        self.send_notify(update=True)
예제 #15
0
 def test_match_staff_not_ready(self):
     try:
         Challenge(1, 1).start()
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "MATCH_STAFF_NOT_READY")
     else:
         raise Exception("can not be here!")
예제 #16
0
    def test_match(self):
        staff_ids = ConfigStaff.INSTANCES.keys()
        staff_ids = random.sample(staff_ids, 10)

        sm = StaffManger(1, 1)
        for i in staff_ids:
            sm.add(i)

        Club(1, 1).set_match_staffs(staff_ids)

        Challenge(1, 1).start()
예제 #17
0
    def test_match_all_finished(self):
        MongoDB.get(1).character.update_one({'_id': 1},
                                            {'$set': {
                                                'challenge_id': 0
                                            }})

        try:
            Challenge(1, 1).start()
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id(
                "CHALLENGE_ALL_FINISHED")
        else:
            raise Exception("can not be here!")
예제 #18
0
    def try_open_slots(self, send_notify=True):
        opened = []
        updater = {}

        c = Challenge(self.server_id, self.char_id)
        passed_challenge_ids = c.get_passed_challenge_ids()

        for challenge_id, slot_id in ConfigInspire.LIST:
            if challenge_id not in passed_challenge_ids:
                continue

            if str(slot_id) in self.doc['slots']:
                continue

            self.doc['slots'][str(slot_id)] = ""
            opened.append(slot_id)
            updater['slots.{0}'.format(slot_id)] = ""

        if updater:
            MongoInspire.db(self.server_id).update_one({'_id': self.char_id},
                                                       {'$set': updater})

        if send_notify and opened:
            self.send_notify(opened)
예제 #19
0
파일: task.py 프로젝트: zhifuliu/dianjing
    def compare_value(self, server_id, char_id, value, target_value):
        from core.challenge import Challenge
        if self.id == 21:
            return Challenge(server_id, char_id).is_challenge_id_passed(target_value)

        if self.compare_type == '>=':
            op = operator.ge
        elif self.compare_type == '<=':
            op = operator.le
        else:
            raise RuntimeError(
                "Unknown Compare Type {0} of Condition {1}".format(
                    self.compare_type, self.id)
            )

        return op(value, target_value)
예제 #20
0
    def __init__(self, server_id, char_id, passed_challenge_ids=None):
        from core.challenge import Challenge

        self.server_id = server_id
        self.char_id = char_id
        self.doc = MongoActivityChallenge.db(self.server_id).find_one(
            {'_id': self.char_id})
        if not self.doc:
            self.doc = MongoActivityChallenge.document()
            self.doc['_id'] = self.char_id
            self.doc['done'] = []
            MongoActivityChallenge.db(self.server_id).insert_one(self.doc)

        self.passed_challenge_ids = passed_challenge_ids
        if not self.passed_challenge_ids:
            self.passed_challenge_ids = Challenge(
                self.server_id, self.char_id).get_passed_challenge_ids()
예제 #21
0
파일: task.py 프로젝트: zhifuliu/dianjing
    def refresh(self):
        club_level = get_club_property(self.server_id, self.char_id, 'level')
        vip_level = VIP(self.server_id, self.char_id).level
        passed_challenge_ids = Challenge(
            self.server_id, self.char_id).get_passed_challenge_ids()

        task_ids = []
        for k, v in ConfigTaskDaily.INSTANCES.iteritems():
            if club_level < v.club_level:
                continue

            if vip_level < v.vip_level:
                continue

            if v.challenge_id and v.challenge_id not in passed_challenge_ids:
                continue

            task_ids.append(k)

        return task_ids
예제 #22
0
    def __init__(self, server_id, char_id):
        self.server_id = server_id
        self.char_id = char_id

        self.is_active = Challenge(server_id, char_id).is_challenge_id_passed(
            GlobalConfig.value("PLUNDER_ACTIVE_CHALLENGE_ID"))

        self.doc = MongoPlunder.db(self.server_id).find_one(
            {'_id': self.char_id})
        if not self.doc:
            self.doc = MongoPlunder.document()
            self.doc['_id'] = self.char_id
            self.doc['plunder_remained_times'] = PLUNDER_TIMES_INIT_TIMES
            MongoPlunder.db(self.server_id).insert_one(self.doc)

        _, today_daily_reward_info = self.get_daily_reward_info()
        if not today_daily_reward_info:
            # 可以清理数据
            self.doc['daily_reward'] = {}
            MongoPlunder.db(self.server_id).update_one(
                {'_id': self.char_id}, {'$set': {
                    'daily_reward': {}
                }})
예제 #23
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()
예제 #24
0
파일: game.py 프로젝트: yueyoum/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()
예제 #25
0
파일: chat.py 프로젝트: zhifuliu/dianjing
    def command(self, tp, data):
        from core.challenge import Challenge

        if tp == ChatSendRequest.ADD_ITEM:
            items = []
            try:
                for x in data.split(';'):
                    if not x or x == '\n' or x == '\r\n':
                        continue

                    _id, _amount = x.split(',')
                    items.append((int(_id), int(_amount)))

                resource_classified = ResourceClassification.classify(items)
                for _id, _amount in resource_classified.staff:
                    # GM命令可能会添加大量的staff, 这是错误情况
                    assert _amount < 1000
            except:
                raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

            resource_classified.add(self.server_id, self.char_id, message="Chat.command")

        elif tp == ChatSendRequest.SET_MONEY:
            setter = {}
            for x in data.split(";"):
                _id, _amount = x.split(',')
                name = item_id_to_money_text(int(_id))

                setter[name] = int(_amount)

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

            Club(self.server_id, self.char_id).send_notify()

        elif tp == ChatSendRequest.SET_CLUB_LEVEL:
            try:
                level = int(data)
            except ValueError:
                raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

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

            Club(self.server_id, self.char_id).send_notify()
        elif tp == ChatSendRequest.OPEN_ALL_CHALLENGE:
            Challenge(self.server_id, self.char_id).open_all()
        elif tp == ChatSendRequest.TEST_PURCHASE:
            try:
                goods_id = int(data)
            except ValueError:
                raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

            Purchase(self.server_id, self.char_id).send_reward(goods_id)

        else:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))
예제 #26
0
 def test_send_notify(self):
     Challenge(1, 1).send_notify()