using System; using System.Collections.Generic; using System.Linq; using XGame; using XGame.Framework.Data; using XGame.Framework.Network; namespace FL.Data { public class GmToolsService : DataSingleton, IDisposable { private Dictionary _msgRequestMap; /// /// 查询消息 /// /// /// public IMsgRequest QueryMessage(int protoId) { if (_msgRequestMap == null) { _msgRequestMap = new Dictionary(); var msgAssembly = "Business.Domain"; var msgRequestType = typeof(IMsgRequest); var types = AppDomain.CurrentDomain.GetAssemblies() .First(assembly => assembly.GetName().Name.Equals(msgAssembly)) .GetTypes(); foreach (var type in types) { if (! msgRequestType.IsAssignableFrom(type)) continue; var instance = Activator.CreateInstance(type) as IMessage; _msgRequestMap.Add(instance.ProtocolID, type); //Log.Info($"MsgRequest Id:{instance.ProtocolID} Type:{type}"); } } if (_msgRequestMap.TryGetValue(protoId, out var protoType)) { return Activator.CreateInstance(protoType) as IMsgRequest; } Log.Info($"找不到 MsgRequest. ProtoId:{protoId}"); return null; } /// /// 发送修改后的消息 /// /// public void SendMessage(IMsgRequest msg) { NetModule.Request(msg); } void IDisposable.Dispose() { _msgRequestMap?.Clear(); _msgRequestMap = null; } } }