using System.Net.NetworkInformation; using System.Reflection; using ControlCenter.NamedPipe; using Google.Protobuf; using Google.Protobuf.WellKnownTypes; using ServerCore; using ServerBase; using ServerControlCenter; namespace ServerBase; public static class NamedPipeMonitor { public static async Task ChangeServerStatus(ServerStatus status) => await NamedPipeClientHelper.Instance.SetServerStatus(status); public static async Task SetStopReason(StopReason reason) => await NamedPipeClientHelper.Instance.SetStopReason(reason); public static NamedPipeResultCode SetUserConnectionBlockStatus(bool user_connection_block_status) => NamedPipeClientHelper.Instance.SetUserConnectionBlockStatus(user_connection_block_status); public static NamedPipeResultCode SetCurrentClientConnection(int connectionCount, ServerType serverType) { var result = NamedPipeClientHelper.Instance.SetCurrentClientConnection(connectionCount); if (serverType != ServerType.Indun) { result = SetCurrentCapacity(connectionCount); } return result; } public static NamedPipeResultCode setCommonDetail(string key, Value value) => NamedPipeClientHelper.Instance.SetDetail(key, value); public static NamedPipeResultCode setCommonDetails(Dictionary list) => NamedPipeClientHelper.Instance.SetDetails(list); public static NamedPipeResultCode setContentDetail(string key, Value value) => NamedPipeClientHelper.Instance.SetContentDetail(key, value); public static NamedPipeResultCode setContentDetails(Dictionary list) => NamedPipeClientHelper.Instance.SetContentDetails(list); public static NamedPipeResultCode SetCurrentCapacity(int capacity) => NamedPipeClientHelper.Instance.SetCurrentCapacity(capacity); public static async Task SendMessageAsync(T message, string message_id) where T : IMessage => await NamedPipeClientHelper.Instance.SendMessageAsync(message, message_id); public static async Task StopNamedPipeService() { Log.getLogger().debug($"NamedPipeClientHelper : StopNamedPipeService Call !!!"); await NamedPipeClientHelper.Instance.StopPipeClient(); } public static async Task StartNamedPipeService(bool enable_named_pipe, ServerType server_type, int port, ServiceCategory serviceCategory, int max_connection_count, int? channel_no = null, int? world_id = null) { var ip = NetworkHelper.getEthernetLocalIPv4(); var type = server_type switch { ServerType.Auth => ServerControlCenter.ServerType.Login, ServerType.Login => ServerControlCenter.ServerType.Login, ServerType.Channel => ServerControlCenter.ServerType.Channel, ServerType.Indun => ServerControlCenter.ServerType.Indun, ServerType.Chat => ServerControlCenter.ServerType.Chat, ServerType.UgqApi => ServerControlCenter.ServerType.UgqApi, ServerType.UgqAdmin => ServerControlCenter.ServerType.UgqAdmin, ServerType.UgqIngame => ServerControlCenter.ServerType.UgqIngame, ServerType.BrokerApi => ServerControlCenter.ServerType.BrokerApi, _ => ServerControlCenter.ServerType.None }; if (type == ServerControlCenter.ServerType.None) return; var named_pipe_options = new NamedPipeClientHelper.NamedPipeClientOption { m_enable_pipe = enable_named_pipe, m_service_category = serviceCategory.ToString(), m_type = type, m_ip = ip, m_port = port, m_channel_no = channel_no, m_world_id = world_id, m_max_client_connection = max_connection_count, m_assemblies = GetAssemblies().ToList(), m_max_retry_count = 5, m_retry_delay_time_ms = 5_000 }; Log.getLogger().debug($"Start NamedPipe Client - Name[Agent_{named_pipe_options.m_ip}.{named_pipe_options.m_port}]"); await NamedPipeClientHelper.Instance.StartNamedPipeClientAsync(named_pipe_options); } private static IEnumerable GetAssemblies() => new List(AppDomain.CurrentDomain.GetAssemblies()); }