OuterMessageDispatcher.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.IO;
  3. namespace ET
  4. {
  5. public class OuterMessageDispatcher: IMessageDispatcher
  6. {
  7. // 查找卡死问题临时处理
  8. public long lastMessageTime = long.MaxValue;
  9. public object LastMessage;
  10. public void Dispatch(Session session, MemoryStream memoryStream)
  11. {
  12. ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
  13. Type type = OpcodeTypeComponent.Instance.GetType(opcode);
  14. object message = MessageSerializeHelper.DeserializeFrom(opcode, type, memoryStream);
  15. if (TimeHelper.ClientFrameTime() - this.lastMessageTime > 3000)
  16. {
  17. Log.Info($"可能导致卡死的消息: {this.LastMessage}");
  18. }
  19. this.lastMessageTime = TimeHelper.ClientFrameTime();
  20. this.LastMessage = message;
  21. if (message is IResponse response)
  22. {
  23. session.OnRead(opcode, response);
  24. return;
  25. }
  26. OpcodeHelper.LogMsg(session.DomainZone(), opcode, message);
  27. // 普通消息或者是Rpc请求消息
  28. MessageDispatcherComponent.Instance.Handle(session, opcode, message);
  29. }
  30. }
  31. }