Пример #1
0
def get_user_server_list(req):
    """# login: 交给前端用户的server_list(此步不需要验证)
    args:
        req:    ---    arg
    returns:
        0    ---
    """
    account = req.get_argument('account', '')
    version = req.get_argument('version', '')
    # 给前端填坑
    account = account.replace('37wanA545_', '37wan_')  # 用37wan_去替换37wanA545_
    account = account.replace('pipa_new_', 'pipa_')
    replace_lua_url = True if settings.ENV_NAME in [settings.ENV_IOS, settings.ENV_STG_IOS, settings.ENV_TEST_IOS] \
                                and version >= '1.2.7' else False
    if not UnameUid.check_exist(account):
        return 0, None, {   # 查无此人
            'server_list': ServerConfig.get().server_list(replace_lua_url=replace_lua_url),     # lua的url不一样
            'current_server': '',
        }
    uu = UnameUid.get(account)
    sid, expired = uu.get_or_create_session_and_expired()
    server_list = ServerConfig.get().server_list(replace_lua_url=replace_lua_url)
    device_mark = req.get_argument('device_mark', '')
    device_mem = req.get_argument('device_mem', '')
    ip = req.request.headers.get('X-Real-Ip', '')
    for s in server_list:
        uid = s['uid'] = uu.servers.get(s['server'], '')
        s['level'] = 0
        if uid:
            u = User.get(uid)
            s['level'] = u.level
            if u.regist_time and u.name:
                commit = False
                if not (u.device_mark and u.device_mark == device_mark):
                    u.device_mark = device_mark
                    commit = True
                if not (u.device_mem and u.device_mem == device_mem):
                    u.device_mem = device_mem
                    commit = True
                if not (u.ip and u.ip == ip):
                    u.ip = ip
                    commit = True
                if u.update_session_and_expired(sid, expired):
                    commit = True
                if commit:
                    u.save()

    return 0, None, {
        'server_list': server_list,
        'current_server': '',
        'ks': sid,
    }
Пример #2
0
 def fetch_server_open_time(self):
     '''
     获取开服的时间
     :return:
     '''
     if not self.server_open_time:
         server_list = ServerConfig.get().server_list()
         server_name = self.uid[:-7]
         for i in server_list:
             if i['server'] == server_name:
                 self.server_open_time = i['open_time']
     return self.server_open_time
Пример #3
0
def new_account(req):
    """# new_account: 创建一个账户,作为用户绑定账户前的替代物
    args:
        env:    ---    arg
    returns:
        0    ---
    """
    version = req.get_argument('version', '')

    f_account = 'fake_account_' + rand_string(8)
    while UnameUid.check_exist(f_account):
        f_account = 'fc' + rand_string(8)
    replace_lua_url = True if settings.ENV_NAME in [settings.ENV_IOS, settings.ENV_STG_IOS, settings.ENV_TEST_IOS] and \
                              version >= '1.2.7' else False
    return 0, None, {
        'fake_account': f_account,
        'server_list': ServerConfig.get().server_list(replace_lua_url=replace_lua_url)
    }
Пример #4
0
def login(req):
    """# login: 登录用户
    args:
        req:    ---    arg
    returns:
        0    ---
        1: unicode('查无此人', 'utf-8'),
        2: unicode('接头暗号不对', 'utf-8'),
    """
    account = req.get_argument('account', '')
    platform = req.get_argument('pt', '')
    if not UnameUid.check_exist(account):
        return 1, None, {}  # 查无此人
    device_mark = req.get_argument('device_mark', '')
    device_mem = req.get_argument('device_mem', '')
    uu = UnameUid.get(account)
    sid, expired = uu.get_or_create_session_and_expired(force=True)
    server_list = ServerConfig.get().server_list()
    for s in server_list:
        uid = s['uid'] = uu.servers.get(s['server'], '')
        if uid:
            u = User.get(uid)
            commit = False
            if not (u.device_mark and u.device_mark == device_mark):
                u.device_mark = device_mark
                commit = True
            if not (u.device_mem and u.device_mem == device_mem):
                u.device_mem = device_mem
                commit = True
            if u.update_session_and_expired(sid, expired):
                commit = True

            if commit:
                u.save()

    uu.cur_platform = platform

    uu.save()

    return 0, None, {
        'server_list': server_list,
        'current_server': uu.current_server,
        'ks': sid,
    }
Пример #5
0
def get_new_server(config_type):
    '''
    1 新服 2老服 3老老服 4新区
    :param config_type:
    :return:
    '''
    if isinstance(config_type, int):
        config_type = [config_type]
    from models.config import ServerConfig
    servers = []
    sc = ServerConfig.get()
    for server, value in sc.config_value.iteritems():
        if server == "master":
            continue
        if not value['is_open']:
            continue
        if get_config_type(server) not in config_type:
            continue
        servers.append(server)
    return servers
Пример #6
0
def register(req):
    """# register: 注册新用户,并且将当前的uid绑定到用户上
    args:
        req:    ---    arg
    returns:
        0    ---
        1: unicode('没有用户名或者密码', 'utf-8'),
        3: unicode('这个账户已经有人了', 'utf-8'),
        5: unicode('已经绑定的账户', 'utf-8'),
        6: unicode('缺少uid', 'utf-8'),
        7:unicode('账号只能为6-20位的字母数字组合', 'utf-8')
    """
    account = req.get_argument('account', '')
    if not (account.isalnum() and 6 <= len(account) <= 20):
        return 7, None, {}
    print account, 'zzzzzzzzzzzzzzz00000000000'
    password = req.get_argument('passwd', '')
    old_account = req.get_argument('old_account', '')
    uid = req.get_argument('user_token', '')
    if not account or not password:
        return 1, None, {}          # 没有用户名或者密码
    # if not old_account:
    #     return 2, None, {}        # 没有老账户
    if UnameUid.check_exist(account):
        return 3, None, {}          # 这个账户已经有人了
    if 'fake_account_' not in old_account or not UnameUid.check_exist(old_account):
        if old_account != account:
            uu = UnameUid.get(account)
            uu.passwd = hashlib.md5(password).hexdigest()
            server_list = ServerConfig.get().server_list()
            sid, expired = uu.get_or_create_session_and_expired()
            current_server = server_list[0]['server']
            uu.current_server = current_server
            uu.save()
            print 'ddddddddddddddddd'
            return 0, None, {
                'server_list': server_list,
                'current_server': uu.current_server,
                'ks': sid,          # now + uid 唯一标识
            }
        return 5, None, {}          # 已经绑定的账户
    if uid:
        user = User.get(uid)
    else:
        return 6, None, {}          # 缺少uid
    # server_key = settings.SERVICE_NAME

    uu = UnameUid.get(old_account)
    uu.change_account_name(account)
    uu.passwd = hashlib.md5(password).hexdigest()
    # uu.servers[server_key] = user.uid
    # uu.current_server = server_key
    sid, expired = uu.get_or_create_session_and_expired(force=True)
    uu.save()

    for uid in uu.servers.itervalues():
        us = UidServer.get(uid)
        us.account = account
        us.save()

    device_mark = req.get_argument('device_mark', '')
    device_mem = req.get_argument('device_mem', '')
    user.device_mark = device_mark
    user.device_mem = device_mem
    user.update_session_and_expired(sid, expired)
    user.account = account
    user.save()

    server_list = ServerConfig.get().server_list()
    for s in server_list:
        s['uid'] = user.uid

    return 0, user, {
        'server_list': server_list,
        'current_server': uu.current_server,
        'ks': sid,
    }
Пример #7
0
def new_user(req):
    """# new_user: 新进入一个分服
    args:
        env:    ---    arg
    returns:
        0    ---
        return 1, None, {}      # 必须指定account
        return 2, None, {}      # 在这个服务器上已经有账户了
    """
    role = int(req.get_argument('role', '1'))
    account = req.get_argument('account', '')   # 如果不是空字符串
    # 给前端填坑
    account = account.replace('37wanA545_', '37wan_')
    account = account.replace('pipa_new_', 'pipa_')
    platform = req.get_argument('pt', '')
    server_name = req.get_argument('server_name', '')
    if not server_name:
        server_list = ServerConfig.get().server_list()
        server_name = server_list[0]['server']

    if not account:
        return 1, None, {}                      # 必须指定account

    try:
        for_ip = req.request.headers.get('X-Forwarded-For', '')
        ip = for_ip.replace('127.0.0.1', '').replace(',', '').replace(' ', '')
    except:
        ip = ''

    uid = new_uid(server_name)
    user = User.get(uid)
    user.account = account
    user.ip = ip

    us = UidServer.get(uid)
    us.server = server_name
    us.account = account

    uu = UnameUid.get(account)
    if server_name in uu.servers:
        return 2, None, {}        # 在这个服务器上已经有账户了

    uu.servers[server_name] = uid
    uu.current_server = server_name
    uu.init_platform = platform
    sid, expired = uu.get_or_create_session_and_expired(force=True)     # 服务器中各个session_sid, session_expired过期时间

    user.update_session_and_expired(sid, expired)                       # 更新本服服务器的session_sid, session_expired
    user.role = role
    role_detail_config = game_config.role_detail[role]
    role_config = game_config.role

    user.cards.position_num = role_config[1]['position_num']            # 位置数量
    user.cards.alternate_num = role_config[1]['alternate_num']          # 助威数量
    # user.cards.open_position = [int(x) for x in role_config[1]['open_position']]      # 开启的位置
    # user.cards.formation['own'] = [role_config[1]['open_formation']]                  # 阵型
    # user.cards.formation['current'] = [role_config[1]['open_formation']]              # 当前阵型

    user.food_ability = role_detail_config['food_produce']      # 生食物能力
    user.metal_ability = role_detail_config['metal_produce']    # 生铁能力
    user.energy_ability = role_detail_config['energy_produce']
    user.harbor_ability = role_config[1]['harbor']              # 避难所等级
    user.school_ability = role_config[1]['school']              # 学校等级
    user.factory_ability = role_config[1]['factory']
    user.hospital_ability = role_config[1]['hospital']
    user.laboratory_ability = role_config[1]['laboratory']

    # 初始 food、metal 都为1000
    # user.food = 99999
    # user.metal = 99999
    # user.crystal = 99999          # 能晶
    # user.energy = 99999
    # user.coin = 99999
    user.food = 3000
    user.metal = 1000
    user.energy = 1000              # 精力
    user.coin = 20
    user.silver = 300               # 银币
    user.crystal = 50

    for i in xrange(1, 11):
        card = role_detail_config['position%d' % i]
        if not card: continue
        card_id = user.cards.new(card)
        user.cards.set_alignment(card_id, i if i <= 5 else i + 5)

    for i in role_detail_config['character_bag']:
        for j in xrange(i[1]):
            card_id = user.cards.new(i[0])

    for i in role_detail_config['item']:
        user.item.add_item(i[0], i[1])

    for i in role_detail_config['equip']:
        for ii in xrange(i[1]):
            user.equip.new(i[0])

    user.is_new = 0
    user.regist_time = int(time.time())
    user.update_regist_status(user.regist_time)
    # user.exp += 20450       # 给渠道升级爽一爽
    us.save()
    uu.save()
    user.save()
    user.cards.save()
    user.item.save()
    user.equip.save()
    return 0, user, {'uid': user.uid, 'ks': sid}
Пример #8
0
def get_user_server_list_huawei(req):
    """# login: 交给前端用户的server_list(此步不需要验证)
    args:
        req:    ---    arg
    returns:
        0    ---
    """
    account = req.get_argument('account')
    old_account = req.get_argument('old_account')
    if not UnameUid.check_exist(account) and not UnameUid.check_exist(old_account):
        return 0, None, {       # 查无此人
            'server_list': ServerConfig.get().server_list(),
            'current_server': '',
        }
    if UnameUid.check_exist(account):
        uu = UnameUid.get(account)
    else:
        if UnameUid.check_exist(old_account):
            uu = UnameUid.get(account)
            old_uu = UnameUid.get(old_account)
            for k in uu._attrs.iterkeys():
                setattr(uu, k, getattr(old_uu, k))
                uu.save()
            old_uu_copy_key = old_account + '____copy'
            uu_copy = UnameUid.get(old_uu_copy_key)
            for k in uu_copy._attrs.iterkeys():
                setattr(uu_copy, k, getattr(old_uu, k))
                uu_copy.save()
            old_uu.redis.delete(old_uu._model_key)
            del old_uu
        else:
            return 0, None, {   # 查无此人
                'server_list': ServerConfig.get().server_list(),
                'current_server': '',
            }
    sid, expired = uu.get_or_create_session_and_expired()
    device_mark = req.get_argument('device_mark', '')
    device_mem = req.get_argument('device_mem', '')
    ip = req.request.headers.get('X-Real-Ip', '')
    server_list = ServerConfig.get().server_list()
    for s in server_list:
        uid = s['uid'] = uu.servers.get(s['server'], '')
        s['level'] = 0
        if uid:
            u = User.get(uid)
            s['level'] = u.level
            if u.regist_time and u.name:
                commit = False
                if not (u.device_mark and u.device_mark == device_mark):
                    u.device_mark = device_mark
                    commit = True
                if not (u.device_mem and u.device_mem == device_mem):
                    u.device_mem = device_mem
                    commit = True
                if not (u.ip and u.ip == ip):
                    u.ip = ip
                    commit = True
                if u.update_session_and_expired(sid, expired):
                    commit = True
                if commit:
                    u.save()

    return 0, None, {
        'server_list': server_list,
        'current_server': '',
        'ks': sid,
    }