示例#1
0
文件: service.py 项目: fcua/x8623
 def login(self, msgtype, body):
     limited, message = self.access_limited()
     if limited:
         return fail_msg(msgtype, reason=message)
     req = poem_pb.LoginWorldRequest()
     req.ParseFromString(body)
     if not req.verify_code:
         logger.error(
             'invalid verify_code %s, body %r', req.verify_code, body)
         return fail_msg(msgtype, msgTips.FAIL_MSG_INVALID_REQUEST)
     session = SessionStore(get_session_pool(), str(req.verify_code))
     if not req.userID or session.uid != req.userID:
         return fail_msg(msgtype, reason="登录超时,请重试")
     self.userID = req.userID
     # get role list
     user = User.load(self.userID)
     rsp = poem_pb.LoginWorldResponse()
     entityIDs = user.roles.get(settings.REGION['ID'])
     if not entityIDs:
         return success_msg(msgtype, rsp)
     #  if len(entityIDs) == 1:
     #      entityID = entityIDs[0]
     #  else:
     #      entityID = req.entityID
     if not req.entityID:
         entityID = min(entityIDs)
     else:
         entityID = req.entityID
     rsp.roles.add(id=entityID)
     rsp.need_rename = PlayerDuplicateNamesIndexing.exists(entityID)
     logger.debug(rsp)
     return success_msg(msgtype, rsp)
示例#2
0
文件: service.py 项目: fcua/x8623
 def alter_name(self, msgtype, body):
     limited, message = self.access_limited()
     if limited:
         return fail_msg(msgtype, reason=message)
     req = poem_pb.AlterNameRequest()
     req.ParseFromString(body)
     entityID = req.entityID
     if not entityID:
         user = User.load(self.userID)
         entityIDs = user.roles.get(settings.REGION['ID'])
         if len(entityIDs) > 1:
             return fail_msg(msgtype, reason="未指定角色")
         if entityIDs:
             entityID = entityIDs[0]
     if not PlayerDuplicateNamesIndexing.exists(entityID):
         return fail_msg(msgtype, reason="不可修改名称")
     session = SessionStore(get_session_pool(), str(req.verify_code))
     if not req.userID or session.uid != req.userID:
         return fail_msg(msgtype, reason="登录超时,请重试")
     name, error = validate_name(req.name)
     if error:
         return fail_msg(msgtype, error)
     # 名字去重复
     try:
         PlayernameIndexing.register(0, name)  # 占位
         p = Player.simple_load(entityID, ["name"])
         p.name = name
         p.save()
         PlayernameIndexing.pool.execute(
             'HSET', PlayernameIndexing.key, name, entityID)  # 更新
     except DuplicateIndexException:
         return fail_msg(msgtype, reason=_YYTEXT('该名称已存在'))
     PlayerDuplicateNamesIndexing.unregister(entityID)
     return success_msg(msgtype, '')
示例#3
0
def blocktime():
    # userID = int(request.POST.get("userID") or 0)
    entityID = int(request.POST.get("entityID") or 0)
    blocktime = int(request.POST.get("blocktime") or 0)
    if not entityID:
        return FAILURE
    now = int(time.time())
    if blocktime and blocktime < now:
        return FAILURE
    from player.model import Player
    userID = Player.simple_load(entityID, ['userID']).userID
    if not userID:
        return FAILURE

    from user.model import User
    user = User.load(userID)
    user.blocktime = blocktime
    user.save()

    for regionID, entityIDs in user.roles.items():
        for entityID in entityIDs:
            spawn(proxy_batch_call, 'chat.manager.clear_blocked_message',
                  regionID, entityID)

    return SUCCESS
示例#4
0
def blockdevice():
    entityID = int(request.POST.get("entityID") or 0)
    block = request.POST["block"] == 'True'
    if not entityID:
        return FAILURE
    from player.model import Player
    userID = Player.simple_load(entityID, ['userID']).userID
    if not userID:
        return FAILURE
    from user.model import User
    user = User.load(userID)
    imsi = user.imsi
    if not imsi:
        return FAILURE
    from session.regions import r_block_devices
    if block:
        r_block_devices.sadd(imsi)
    else:
        r_block_devices.srem(imsi)

    if block:
        for regionID, entityIDs in user.roles.items():
            for entityID in entityIDs:
                spawn(proxy_batch_call, 'chat.manager.clear_blocked_message',
                      regionID, entityID)

    return SUCCESS
示例#5
0
def query_player():
    value = request.POST.getone('value')
    type = request.POST.getone('type')
    regionID = int(request.GET['regionID'])
    if not type or not value:
        return FAILURE
    import settings
    from player.model import Player
    from yy.entity.index import UniqueIndexing
    from user.model import User, UsernameIndexing
    if type == 'playername':
        indexing = UniqueIndexing('index_p_name{%d}' % regionID,
                                  settings.REDISES['index'])
        entityID = indexing.get_pk(value)
        if entityID:
            entityIDs = [indexing.get_pk(value)]
        else:
            entityIDs = []
    elif type == 'username':
        userID = UsernameIndexing.get_pk(value)
        u = User.load(userID)
        entityIDs = u.roles[regionID]
    elif type == 'entityID':
        entityIDs = [int(value)]

    attrs = [
        'entityID', 'username', 'name', 'sex', 'career', 'level', 'userID'
    ]
    header = ['ID', u'用户名', u'名称', u'性别', u'职业', u'等级', u"用户ID"]
    rows = []
    players = Player.batch_load(entityIDs, attrs)
    for player in players:
        ll = [getdisplayattr(player, s) for s in attrs]
        rows.append(ll)
    return dict(rows=rows, header=header)
示例#6
0
def clear_blocked_message():
    userID = int(request.POST.get("userID") or 0)
    if not userID:
        return FAILURE

    from user.model import User
    user = User.load(userID)

    for regionID, entityIDs in user.roles.items():
        for entityID in entityIDs:
            spawn(proxy_batch_call, 'chat.manager.clear_blocked_message',
                  regionID, entityID)

    return SUCCESS
示例#7
0
文件: service.py 项目: fcua/x8623
    def create_role(self, msgtype, body):
        limited, message = self.access_limited()
        if limited:
            return fail_msg(msgtype, reason=message)
        req = poem_pb.CreateRoleRequest()
        req.ParseFromString(body)
        modelID = req.iconID
        user = User.load(self.userID)
        roleID = user.roles.get(settings.REGION['ID'])
        if roleID:
            return fail_msg(msgtype, msgTips.FAIL_MSG_ALREADY_CREATEROLE)
        name, error = validate_name(req.name)
        if error:
            return fail_msg(msgtype, error)

        # 名字去重复
        try:
            PlayernameIndexing.register(0, name)  # 占位
            player = Player.create(name=name, modelID=modelID, sex=req.sex, level=1, career=req.school)
            player.save()
            PlayernameIndexing.pool.execute('HSET', PlayernameIndexing.key, name, player.entityID)  # 更新
        except DuplicateIndexException:
            return fail_msg(msgtype, reason=_YYTEXT('该名称已存在'))
        except EntityExistsException:  # 已经存在的entityID, 一般由于自增ID被清零,但entityID数据还存在
            return fail_msg(msgtype, reason=_YYTEXT('该名称已存在'))
        if not player or not player.entityID:
            PlayernameIndexing.unregister(name)
            return fail_msg(msgtype, reason=_YYTEXT('该名称已存在'))
        PlayerLevelRanking.update_score(player.entityID, player.level)
        user.roles[settings.REGION['ID']] = player.entityID
        user.save()
        rsp = poem_pb.CreateRoleResponse()
        rsp.roleId = player.entityID
        role = rsp.roles.add()
        role.name, role.level, role.resourceId, role.school, role.sex = \
            player.name, player.level, player.modelID, player.career, player.sex

        from common.log import gm_logger
        gm_logger.info({'createrole': {'entityID': player.entityID,
                                       'userID': self.userID,
                                       'type': 'createrole',
                                       'username': player.username,
                                       'playername': player.name,
                                       'worldID': settings.SESSION['ID'],
                                       'createrolename': player.name,
                                       'career': player.career,
                                       'username_alias': user.username_alias}})
        role.id = rsp.roleId
        return success_msg(msgtype, rsp)
示例#8
0
def reset_password():
    userID = int(request.POST.get("userID") or 0)
    if not userID:
        return FAILURE

    from user.model import User
    from yy.rpc.http import get_random_string
    from yy.utils import make_password
    u = User.load(userID)
    s = get_random_string(8)
    if u.password == 'dummy':
        return FAILURE
    u.password = make_password(s)
    u.save()
    return json.dumps(s)