Esempio n. 1
0
def chat_private(p, req):
    ''' 私聊 '''
    cid, [rcv_nick_name, content] = req

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( CONNECTION_LOSE )

    _status = yield check_character_mute(int(cid))
    if _status:
        defer.returnValue( CHAR_IN_MUTE )

    rcv_cid = yield redis.hget(DICT_NICKNAME_REGISTERED, rcv_nick_name)
    if not rcv_cid:
        log.error('Can not find user. sender_id: {0}, rcv_cid: {1}, rcv_nick_name: {2}.'.format( cid, rcv_cid, rcv_nick_name ))
        defer.returnValue( UNKNOWN_CHAR )

    if rcv_cid == cid:
        defer.returnValue( UNKNOWN_ERROR )

    rcv_user = g_UserMgr.getUserByCid( rcv_cid )
    if not rcv_user:
        log.error('The user had not online. sender_id: {0}, rcv_cid: {1}.'.format( cid, rcv_cid ))
        defer.returnValue( CHAR_NOT_ONLINE )

    res_err = g_Private.new_msg( user, rcv_user, content )

    defer.returnValue( res_err )
Esempio n. 2
0
def write_mail(p, req):
    ''' 保存新的邮件 
    page_type: 1:全部; 2:好友; 3:系统; 4:战斗
    '''
    try:
        rcv_cid, page_type, module_id, detail = req
        send_time = int(time())
    except:
        rcv_cid, page_type, module_id, detail, send_time = req

    _key = HASH_MAIL_CONTENT % (page_type, rcv_cid )
    _primary = yield redis.hincrby( _key, MAIL_PRIMARY_INC, 1 )
 
    content = dumps( (_primary, send_time, page_type, module_id, detail) )
    yield redis.hset(_key, _primary, content)

    # 最多保存100条 
    _del_fields = []

    _all_fields = yield redis.hkeys( _key )
    _all_fields = sorted( _all_fields, reverse=True )
    if len(_all_fields) > 101:
        _del_fields = _all_fields[101:]
        if MAIL_PRIMARY_INC in _del_fields:
            _del_fields.remove( MAIL_PRIMARY_INC )

    if _del_fields:
        yield redis.hdel( _key, *_del_fields )

    # 通知在线玩家有新邮件
    rcv_user = g_UserMgr.getUserByCid(rcv_cid)
    if rcv_user and not rcv_user.notify_mail:
        rcv_user.notify_mail = True
        gw_send(rcv_cid, 'new_mail_notify', None)
Esempio n. 3
0
def ms_alliance_info(p, req):
    ''' 同步玩家的公会信息 '''
    cid, alliance_info = req

    user = g_UserMgr.getUserByCid(cid)
    if user:
        user.update_alliance( alliance_info )
Esempio n. 4
0
def chat_room_join(p, req):
    ''' 玩家进入房间, 返回20条记录 '''
    cid, [room_type] = req

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        return CONNECTION_LOSE

    res_err = []
    user.in_room = True
    if room_type == 1:
        res_err = g_Channel.last_msgs()
    elif room_type == 2:
        res_err = g_Private.last_msgs( cid )
    elif room_type == 3:
        if user.alliance_id < 1:
            return ALLIANCE_NOT_MEMBER_ERROR
        _alliance = g_UserMgr.getAlliance( user.alliance_id )
        if not _alliance:
            _alliance = Alliance( user.alliance_id )
            g_UserMgr.addAlliance( _alliance )
        res_err = _alliance.last_msgs()

    return res_err[-20:]
Esempio n. 5
0
def ms_alliance_position(p, req):
    ''' 同步玩家的职位 '''
    cid, position = req

    user = g_UserMgr.getUserByCid(cid)
    if user:
        user.update_position( position )
Esempio n. 6
0
def ms_alliance_info(p, req):
    ''' 同步玩家的公会信息 '''
    cid, alliance_info = req

    user = g_UserMgr.getUserByCid(cid)
    if user:
        user.update_alliance(alliance_info)
Esempio n. 7
0
def write_mail(p, req):
    ''' 保存新的邮件 
    page_type: 1:全部; 2:好友; 3:系统; 4:战斗
    '''
    try:
        rcv_cid, page_type, module_id, detail = req
        send_time = int(time())
    except:
        rcv_cid, page_type, module_id, detail, send_time = req

    _key = HASH_MAIL_CONTENT % (page_type, rcv_cid)
    _primary = yield redis.hincrby(_key, MAIL_PRIMARY_INC, 1)

    content = dumps((_primary, send_time, page_type, module_id, detail))
    yield redis.hset(_key, _primary, content)

    # 最多保存100条
    _del_fields = []

    _all_fields = yield redis.hkeys(_key)
    _all_fields = sorted(_all_fields, reverse=True)
    if len(_all_fields) > 101:
        _del_fields = _all_fields[101:]
        if MAIL_PRIMARY_INC in _del_fields:
            _del_fields.remove(MAIL_PRIMARY_INC)

    if _del_fields:
        yield redis.hdel(_key, *_del_fields)

    # 通知在线玩家有新邮件
    rcv_user = g_UserMgr.getUserByCid(rcv_cid)
    if rcv_user and not rcv_user.notify_mail:
        rcv_user.notify_mail = True
        gw_send(rcv_cid, 'new_mail_notify', None)
Esempio n. 8
0
def ms_alliance_position(p, req):
    ''' 同步玩家的职位 '''
    cid, position = req

    user = g_UserMgr.getUserByCid(cid)
    if user:
        user.update_position(position)
Esempio n. 9
0
def chat_room_leave(p, req):
    ''' 玩家退出房间 '''
    cid, = req

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        return CONNECTION_LOSE

    user.in_room     = False
    user.notice_flag = False

    return NO_ERROR
Esempio n. 10
0
def mail_list(p, req):
    ''' 分页获取邮件列表 
    page_type: 1:全部; 2:好友; 3:系统; 4:战斗
    '''
    cid, [page_type, index] = req

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format(cid))
        defer.returnValue(CONNECTION_LOSE)

    user.notify_mail = False

    all_types = []
    now_time = int(time())
    mails_time = []  # for sort
    all_mails = []

    if page_type == MAIL_PAGE_ALL:
        all_types = [MAIL_PAGE_FRIEND, MAIL_PAGE_SYSTEM, MAIL_PAGE_BATTLE]
    else:
        all_types = [page_type]

    for _type in all_types:
        # 每个type 最多保存100条
        del_mail = []  # 已过期的邮件ID
        _all = yield redis.hgetall(HASH_MAIL_CONTENT % (_type, cid))
        for _field, _value in _all.iteritems():
            if _field == MAIL_PRIMARY_INC:
                continue
            _value = loads(_value)

            # 判断邮件是否过期
            if _value[1] + MAIL_VALID_SECONDS < now_time:
                del_mail.append(_field)
                continue
            # 根据时间点先后组织数据
            for _i, _time in enumerate(mails_time):
                if _value[1] > _time:
                    all_mails.insert(_i, _value)
                    break
            else:
                _i = len(mails_time)
                all_mails.append(_value)
            mails_time.insert(_i, _value[1])

        if del_mail:
            yield redis.hdel(HASH_MAIL_CONTENT % (_type, cid), *del_mail)

    defer.returnValue(
        (page_type, index, len(all_mails), all_mails[index:index + 10]))
Esempio n. 11
0
def mail_list(p, req):
    ''' 分页获取邮件列表 
    page_type: 1:全部; 2:好友; 3:系统; 4:战斗
    '''
    cid, [page_type, index] = req

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( CONNECTION_LOSE )

    user.notify_mail = False
 
    all_types  = []
    now_time   = int(time())
    mails_time = [] # for sort
    all_mails  = []

    if page_type == MAIL_PAGE_ALL:
        all_types = [MAIL_PAGE_FRIEND, MAIL_PAGE_SYSTEM, MAIL_PAGE_BATTLE]
    else:
        all_types = [page_type]

    for _type in all_types:
        # 每个type 最多保存100条 
        del_mail   = [] # 已过期的邮件ID
        _all = yield redis.hgetall( HASH_MAIL_CONTENT % (_type, cid) )
        for _field, _value in _all.iteritems():
            if _field == MAIL_PRIMARY_INC:
                continue
            _value = loads(_value)

            # 判断邮件是否过期
            if _value[1] + MAIL_VALID_SECONDS < now_time:
                del_mail.append( _field )
                continue
            # 根据时间点先后组织数据
            for _i, _time in enumerate(mails_time):
                if _value[1] > _time:
                    all_mails.insert(_i, _value)
                    break
            else:
                _i = len(mails_time)
                all_mails.append( _value )
            mails_time.insert(_i, _value[1])

        if del_mail:
            yield redis.hdel( HASH_MAIL_CONTENT % (_type, cid), *del_mail )

    defer.returnValue( (page_type, index, len(all_mails), all_mails[index:index+10]) )
Esempio n. 12
0
def chat_channel(p, req):
    ''' 群聊 '''
    cid, [msg] = req

    _status = yield check_character_mute(int(cid))
    if _status:
        defer.returnValue( CHAR_IN_MUTE )

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        defer.returnValue( CONNECTION_LOSE )

    res_err = g_Channel.new_msg( user, msg )

    defer.returnValue( res_err )
Esempio n. 13
0
def sync_char_data(p, req):
    ''' _type: 1-nick_name, 2-lead_id, 3-vip_level, 4-level, 5-might '''
    cid, _type, _value = req

    user = g_UserMgr.getUserByCid(cid)
    if user:
        if _type == SYNC_NICK_NAME:
            user.rename(_value)
        elif _type == SYNC_LEAD_ID:
            user.update_lead_id(_value)
        elif _type == SYNC_VIP_LEVEL:
            user.update_vip_level(_value)
        elif _type == SYNC_LEVEL:
            user.update_level(_value)
        elif _type == SYNC_MIGHT:
            yield user.update_might(_value)
Esempio n. 14
0
def sync_char_data(p, req):
    ''' _type: 1-nick_name, 2-lead_id, 3-vip_level, 4-level, 5-might '''
    cid, _type, _value = req

    user = g_UserMgr.getUserByCid(cid)
    if user:
        if _type == SYNC_NICK_NAME:
            user.rename( _value )
        elif _type == SYNC_LEAD_ID:
            user.update_lead_id( _value )
        elif _type == SYNC_VIP_LEVEL:
            user.update_vip_level( _value )
        elif _type == SYNC_LEVEL:
            user.update_level( _value )
        elif _type == SYNC_MIGHT:
            yield user.update_might( _value )
Esempio n. 15
0
def chat_alliance(p, req):
    ''' 公会聊天 '''
    cid, [msg] = req

    _status = yield check_character_mute(int(cid))
    if _status:
        defer.returnValue( CHAR_IN_MUTE ) 

    user = g_UserMgr.getUserByCid(cid)
    if not user:
        defer.returnValue( CONNECTION_LOSE )

    if user.alliance_id < 1:
        defer.returnValue( ALLIANCE_NOT_MEMBER_ERROR )

    _alliance = g_UserMgr.getAlliance( user.alliance_id )
    if not _alliance:
        _alliance = Alliance( user.alliance_id )
        g_UserMgr.addAlliance( _alliance )
    res_err = _alliance.new_msg( user, msg )

    defer.returnValue( res_err )
Esempio n. 16
0
def revise_name(p, req):
    cid, new_name = req
    user = g_UserMgr.getUserByCid(cid)
    if user:
        user.rename(new_name)
        g_UserMgr.revise_dict_user_name(cid, new_name)
Esempio n. 17
0
def revise_name(p, req):
    cid, new_name = req
    user = g_UserMgr.getUserByCid(cid)
    if user:
        user.rename(new_name)
        g_UserMgr.revise_dict_user_name(cid, new_name)