Exemplo n.º 1
0
    def process_request(self, request):
        super(UnpackAndVerifyData, self).process_request(request)

        if request.path.startswith('/api/'):
            return

        if not server.active:
            return HttpResponse(status=502)

        char_id = getattr(request, '_char_id', None)
        if char_id:
            if request.path != '/resume/':
                p = Player(char_id)
                login_id = p.get_login_id()
                if not login_id:
                    msg = ReLoginResponse()
                    msg.ret = errormsg.SESSION_EXPIRE
                    data = pack_msg(msg)
                    return HttpResponse(data, content_type='text/plain')

                if login_id != request._game_session.login_id:
                    # NEED RE LOGIN
                    msg = ReLoginResponse()
                    msg.ret = errormsg.LOGIN_RE
                    data = pack_msg(msg)
                    return HttpResponse(data, content_type='text/plain')

                p.refresh()

            ap = ActivePlayers()
            ap.set(request._char_id)
Exemplo n.º 2
0
    def process_request(self, request):
        super(UnpackAndVerifyData, self).process_request(request)

        if request.path.startswith('/api/'):
            return

        server_id = getattr(request, '_server_id', None)
        char_id = getattr(request, 'char_id', None)
        if server_id and char_id:
            ap = ActivePlayers(request._server_id)
            ap.set(request._char_id)

        if char_id and request.path == '/player/login/':
            message_clean(char_id)
Exemplo n.º 3
0
    def process_request(self, request):
        super(UnpackAndVerifyData, self).process_request(request)

        if request.path.startswith('/api/'):
            return

        server_id = getattr(request, '_server_id', None)
        char_id = getattr(request, 'char_id', None)
        if server_id and char_id:
            ap = ActivePlayers(request._server_id)
            ap.set(request._char_id)

        if char_id and request.path == '/player/login/':
            message_clean(char_id)
Exemplo n.º 4
0
def clean():
    logger = Logger("clean_active_players.log")
    logger.write("Start.")

    result = ActivePlayers().clean()

    logger.write("Complete. {0}".format(result))
    logger.close()
Exemplo n.º 5
0
    def _cmd_status(self):
        from core.mongoscheme import MongoCharacter
        from core.activeplayers import ActivePlayers

        total_amount = MongoCharacter.objects.count()
        active_amount = ActivePlayers().amount
        self.stdout.write("Total amount {0}. Active amount {1}".format(
            total_amount, active_amount))
Exemplo n.º 6
0
def clean():
    logger = Logger("clean_active_players.log")
    logger.write("Start.")

    amount = ActivePlayers.clean_all()

    logger.write("Complete. Cleaned Amount: {0}".format(amount))
    logger.close()
Exemplo n.º 7
0
def clean():
    logger = Logger("clean_active_players.log")
    logger.write("Start.")

    amount = ActivePlayers.clean_all()

    logger.write("Complete. Cleaned Amount: {0}".format(amount))
    logger.close()
Exemplo n.º 8
0
def ping(request):
    ap = ActivePlayers()
    amount = ap.amount

    return {
        'ret': 0,
        'data': {
            'active_amount': amount,
        }
    }
Exemplo n.º 9
0
    def candidate_list(self, level_diff=FRIEND_CANDIDATE_LEVEL_DIFF):
        # 候选人列表

        # 先从最近活跃用户找,如果没有再通找
        ap = ActivePlayers()
        ap_list = ap.get_list()

        random.shuffle(ap_list)

        char_ids = []
        for c in ap_list:
            if c == self.char_id:
                continue
            if self.is_general_friend(c):
                continue

            char_ids.append(c)
            if len(char_ids) >= FRIEND_CANDIDATE_LIST_AMOUNT:
                break

        if len(char_ids) >= FRIEND_CANDIDATE_LIST_AMOUNT:
            return char_ids

        # 数量不够,补充
        level = self.char.mc.level
        supply_char_ids = get_char_ids_by_level_range(
            level - level_diff,
            level + level_diff,
            exclude_char_ids=[self.char_id])

        for c in supply_char_ids:
            if self.is_general_friend(c):
                continue

            if c in char_ids:
                continue

            char_ids.append(c)
            if len(char_ids) >= FRIEND_CANDIDATE_LIST_AMOUNT:
                break

        return char_ids
Exemplo n.º 10
0
def clean(signum):
    logger = Logger("clean_active_players.log")
    logger.write("Start.")

    try:
        result = ActivePlayers().clean()
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Complete. {0}".format(result))
    finally:
        logger.close()
Exemplo n.º 11
0
    def candidate_list(self, level_diff=FRIEND_CANDIDATE_LEVEL_DIFF):
        # 候选人列表

        # 先从最近活跃用户找,如果没有再通找
        ap = ActivePlayers()
        ap_list = ap.get_list()

        random.shuffle(ap_list)

        char_ids = []
        for c in ap_list:
            if c == self.char_id:
                continue
            if self.is_general_friend(c):
                continue

            char_ids.append(c)
            if len(char_ids) >= FRIEND_CANDIDATE_LIST_AMOUNT:
                break

        if len(char_ids) >= FRIEND_CANDIDATE_LIST_AMOUNT:
            return char_ids


        # 数量不够,补充
        level = self.char.mc.level
        supply_char_ids = get_char_ids_by_level_range(level-level_diff, level+level_diff, exclude_char_ids=[self.char_id])

        for c in supply_char_ids:
            if self.is_general_friend(c):
                continue

            if c in char_ids:
                continue

            char_ids.append(c)
            if len(char_ids) >= FRIEND_CANDIDATE_LIST_AMOUNT:
                break

        return char_ids
Exemplo n.º 12
0
    def process_request(self, request):
        try:
            super(UnpackAndVerifyData, self).process_request(request)
        except VersionCheckFailure:
            version_msg = VersionCheckResponse()
            version_msg.ret = 0
            version_msg.version = version.version
            return HttpResponse(pack_msg(version_msg),
                                content_type='text/plain')

        if request.path.startswith('/api/'):
            return

        if not server.active:
            return HttpResponse(status=502)

        char_id = getattr(request, '_char_id', None)
        if char_id:
            if request.path != '/resume/':
                p = Player(char_id)
                login_id = p.get_login_id()
                if not login_id:
                    msg = ReLoginResponse()
                    msg.ret = errormsg.SESSION_EXPIRE
                    data = pack_msg(msg)
                    return HttpResponse(data, content_type='text/plain')

                if login_id != request._game_session.login_id:
                    # NEED RE LOGIN
                    msg = ReLoginResponse()
                    msg.ret = errormsg.LOGIN_RE
                    data = pack_msg(msg)
                    return HttpResponse(data, content_type='text/plain')

                p.refresh()

            ap = ActivePlayers()
            ap.set(request._char_id)
Exemplo n.º 13
0
def ping(request):
    ap = ActivePlayers()
    amount = ap.amount

    status = None
    for n, s in SERVER_STATUS:
        if amount >= n:
            status = s
            break

    if not status:
        status = 1

    return {
        'ret': 0,
        'data': {
            'active_amount': amount,
            'status': status,
        }
    }
Exemplo n.º 14
0
 def to_server(self, text):
     self.check(text)
     ap = ActivePlayers(self.server_id)
     active_list = ap.get_list()
     for cid in active_list:
         self.to_char(cid, text)
Exemplo n.º 15
0
 def to_server(self, text):
     self.check(text)
     ap = ActivePlayers()
     active_list = ap.get_list()
     for cid in active_list:
         self.to_char(cid, text, check=False)