Example #1
0
def _doChildConnect(name, transport):
    """当server节点连接到master的处理
    """
    # 当前启动的server 的配置
    server_config = GlobalObject().json_config.get('servers', {}).get(name, {})
    remoteport = server_config.get('remoteport', [])
    child_host = transport.transport.address[0]
    root_list = [rootport.get('rootname') for rootport in remoteport]
    GlobalObject().remote_map[name] = {
        "host": child_host,
        "root_list": root_list
    }
    # 通知有需要连的node节点连接到此root节点
    for servername, remote_list in GlobalObject().remote_map.items():
        remote_host = remote_list.get("host", "")
        remote_name_host = remote_list.get("root_list", "")
        if name in remote_name_host:
            child_name = GlobalObject().root.childsmanager.child(servername)
            child_name.callbackChild("remote_connect", name, remote_host)
    # 查看当前是否有可供连接的root节点
    master_node_list = GlobalObject().remote_map.keys()
    for root_name in root_list:
        if root_name in master_node_list:
            root_host = GlobalObject().remote_map[root_name]['host']
            child_name = GlobalObject().root.childsmanager.child(name)
            child_name.callbackChild("remote_connect", root_name, root_host)
Example #2
0
def send_message_1002(command_id, dynamic_id, request_proto):
    """发送消息
    @param command_id: 协议号
    @param dynamic_id: 动态ID
    #param request_proto: 消息体
    """

    argument = chat_pb2.ChatConectingRequest()
    argument.ParseFromString(request_proto)
    response = chat_pb2.ChatResponse()

    character_id = argument.owner.id
    character_nickname = argument.owner.nickname
    room_id = argument.channel
    content = argument.content
    to_character_id = argument.other.id
    to_character_nickname = argument.other.nickname
    guild_id = argument.guild_id

    child_chat = GlobalObject().root.childsmanager.child('chat')
    info = child_chat.callbackChild(command_id, character_id, dynamic_id,
                                    room_id, content, character_nickname,
                                    to_character_id, to_character_nickname,
                                    guild_id)

    # info = localservice.callTarget(command_id, character_id, dynamic_id,
    # room_id, content, character_nickname, \
    #                                to_character_id, to_character_nickname)
    result = info.get('result', False)
    response.result = result
    if info.get('result_no'):
        response.result_no = info.get('result_no')
    return response.SerializeToString()
Example #3
0
def forwarding_remote(key, dynamic_id, data):
    """
    """
    if key in local_service._targets:
        return local_service.callTarget(key, dynamic_id, data)
    else:
        oldvcharacter = VCharacterManager().get_by_dynamic_id(dynamic_id)
        if not oldvcharacter:
            return
        child_node = GlobalObject().child(oldvcharacter.node)
        result = child_node.callbackChild(key, dynamic_id, data)

        return result
Example #4
0
def forwarding_remote(key, dynamic_id, data):
    """
    """
    if key in local_service._targets:
        return local_service.callTarget(key, dynamic_id, data)
    else:
        oldvcharacter = VCharacterManager().get_by_dynamic_id(dynamic_id)
        if not oldvcharacter:
            logger.error('cant find player:%s', dynamic_id)
            return
        child_node = GlobalObject().child(oldvcharacter.node)
        result = child_node.callbackChild(key, dynamic_id, data)

        return result
Example #5
0
def _doChildConnect(name, transport):
    """当server节点连接到master的处理
    """
    # 当前启动的server 的配置
    server_config = GlobalObject().json_config.get('servers', {}).get(name, {})
    remoteport = server_config.get('remoteport', [])
    child_host = transport.transport.address[0]
    root_list = [rootport.get('rootname') for rootport in remoteport]
    GlobalObject().remote_map[name] = {"host": child_host, "root_list": root_list}
    # 通知有需要连的node节点连接到此root节点
    for servername, remote_list in GlobalObject().remote_map.items():
        remote_host = remote_list.get("host", "")
        remote_name_host = remote_list.get("root_list", "")
        if name in remote_name_host:
            child_name = GlobalObject().root.childsmanager.child(servername)
            child_name.callbackChild("remote_connect", name, remote_host)
    # 查看当前是否有可供连接的root节点
    master_node_list = GlobalObject().remote_map.keys()
    for root_name in root_list:
        if root_name in master_node_list:
            root_host = GlobalObject().remote_map[root_name]['host']
            child_name = GlobalObject().root.childsmanager.child(name)
            child_name.callbackChild("remote_connect", root_name, root_host)
Example #6
0
def send_message_1002(command_id, dynamic_id, request_proto):
    """发送消息
    @param command_id: 协议号
    @param dynamic_id: 动态ID
    #param request_proto: 消息体
    """

    argument = chat_pb2.ChatConectingRequest()
    argument.ParseFromString(request_proto)
    logger.debug("argument %s" % argument)
    response = chat_pb2.ChatResponse()

    character_id = argument.owner.id
    character_nickname = argument.owner.nickname
    room_id = argument.channel
    content = argument.content
    guild_position = argument.guild_position
    to_character_id = argument.other.id
    to_character_nickname = argument.other.nickname
    guild_id = argument.guild_id
    vip_level = argument.vip_level
    head = argument.other.head

    child_chat = GlobalObject().root.childsmanager.child('chat')
    info = child_chat.callbackChild(command_id, character_id, dynamic_id,
                                    room_id, content, character_nickname,
                                    to_character_id, to_character_nickname,
                                    guild_id, vip_level, guild_position, head)

    # info = localservice.callTarget(command_id, character_id, dynamic_id,
    # room_id, content, character_nickname, \
    #                                to_character_id, to_character_nickname)
    result = info.get('result', False)
    response.result = result
    if info.get('result_no'):
        response.result_no = info.get('result_no')
    if info.get('gag_time'):
        response.gag_time = info.get('gag_time')
    return response.SerializeToString()