提交 7d488665 编写于 作者: T tanghai

1.MessageDispatherComponent 注册handler时只注册本服的handler,重构时搞没了,这里加上

2.修复proto2cs在mac的路径错误
3.log warning不要打栈
上级 22c26425
......@@ -12,8 +12,8 @@
<targets>
<target name="trace" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Trace/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
......@@ -23,8 +23,8 @@
<targets>
<target name="debug" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Debug/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
......@@ -34,8 +34,8 @@
<targets>
<target name="info" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Info/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
......@@ -45,8 +45,8 @@
<targets>
<target name="error" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Error/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
......@@ -56,19 +56,19 @@
<targets>
<target name="warn" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Warning/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message}" />
<target name="warnConsole" type="ColoredConsole"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message}" />
</targets>
<targets>
<target name="fatal" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Fatal/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
......@@ -79,16 +79,16 @@
<rules>
<logger name="*" minlevel="Trace" writeTo="all" />
<logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="trace" />
<logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="traceConsole" />
<logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="traceConsole" />
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debug" />
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debugConsole" />
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debugConsole" />
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="info" />
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="infoConsole" />
<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warn" />
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="infoConsole" />
<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warn" />
<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warnConsole" />
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="error" />
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="errorConsole" />
<logger name="*" minlevel="Fatal" maxlevel="Fatal" writeTo="fatal" />
<logger name="*" minlevel="Fatal" maxlevel="Fatal" writeTo="fatal" />
<logger name="*" minlevel="Fatal" maxlevel="Fatal" writeTo="fatalConsole" />
</rules>
</nlog>
\ No newline at end of file
using System;
using System.Collections.Generic;
namespace ETModel
{
[ObjectSystem]
public class MessageDispatherComponentAwakeSystem : AwakeSystem<MessageDispatherComponent>
{
public override void Awake(MessageDispatherComponent self)
{
self.AppType = Game.Scene.GetComponent<StartConfigComponent>().StartConfig.AppType;
self.Load();
}
}
[ObjectSystem]
public class MessageDispatherComponentLoadSystem : LoadSystem<MessageDispatherComponent>
{
public override void Load(MessageDispatherComponent self)
{
self.Load();
}
}
/// <summary>
/// 消息分发组件
/// </summary>
public class MessageDispatherComponent : Component
{
public AppType AppType;
private readonly Dictionary<ushort, List<IMHandler>> handlers = new Dictionary<ushort, List<IMHandler>>();
public void Load()
{
this.handlers.Clear();
Type[] types = DllHelper.GetMonoTypes();
foreach (Type type in types)
{
object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
if (attrs.Length == 0)
{
continue;
}
MessageHandlerAttribute messageHandlerAttribute = attrs[0] as MessageHandlerAttribute;
if (!messageHandlerAttribute.Type.Is(this.AppType))
{
continue;
}
IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
if (iMHandler == null)
{
Log.Error($"message handle {type.Name} 需要继承 IMHandler");
continue;
}
Type messageType = iMHandler.GetMessageType();
ushort opcode = this.Entity.GetComponent<OpcodeTypeComponent>().GetOpcode(messageType);
if (opcode == 0)
{
Log.Error($"消息opcode为0: {messageType.Name}");
continue;
}
this.RegisterHandler(opcode, iMHandler);
}
}
public void RegisterHandler(ushort opcode, IMHandler handler)
{
if (!this.handlers.ContainsKey(opcode))
{
this.handlers.Add(opcode, new List<IMHandler>());
}
this.handlers[opcode].Add(handler);
}
public void Handle(Session session, MessageInfo messageInfo)
{
List<IMHandler> actions;
if (!this.handlers.TryGetValue(messageInfo.Opcode, out actions))
{
Log.Error($"消息没有处理: {messageInfo.Opcode} {JsonHelper.ToJson(messageInfo.Message)}");
return;
}
foreach (IMHandler ev in actions)
{
try
{
ev.Handle(session, messageInfo.Message);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
public override void Dispose()
{
if (this.IsDisposed)
{
return;
}
base.Dispose();
}
}
}
\ No newline at end of file
......@@ -77,7 +77,6 @@
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\IMessagePacker.cs" Link="Module\Message\IMessagePacker.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\IMHandler.cs" Link="Module\Message\IMHandler.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessageAttribute.cs" Link="Module\Message\MessageAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessageDispatherComponent.cs" Link="Module\Message\MessageDispatherComponent.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessageHandlerAttribute.cs" Link="Module\Message\MessageHandlerAttribute.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\MessageInfo.cs" Link="Module\Message\MessageInfo.cs" />
<Compile Include="..\..\Unity\Assets\Scripts\Module\Message\NetworkComponent.cs" Link="Module\Message\NetworkComponent.cs" />
......
......@@ -23,10 +23,10 @@ namespace ETEditor
public class Proto2CSEditor : EditorWindow
{
private const string protoPath = @"..\Proto\";
private const string serverMessagePath = @"..\Server\Model\Module\Message\";
private const string clientMessagePath = @"Assets\Scripts\Module\Message\";
private const string hotfixMessagePath = @"Hotfix\Module\Message\";
private const string protoPath = "../Proto/";
private const string serverMessagePath = "../Server/Model/Module/Message/";
private const string clientMessagePath = "Assets/Scripts/Module/Message/";
private const string hotfixMessagePath = "Hotfix/Module/Message/";
private static readonly char[] splitChars = { ' ', '\t' };
private static readonly List<OpcodeInfo> msgOpcode = new List<OpcodeInfo>();
private static MultiMap<string, string> parentMsg = new MultiMap<string, string>();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册