MsgProcesser.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. namespace XGame.Framework.Network
  3. {
  4. internal class MsgProcesser : IMsgProcesser
  5. {
  6. private ISessionContext _context;
  7. private IMsgReceiverListener _listener;
  8. public MsgProcesser(ISessionContext context, IMsgReceiverListener listener)
  9. {
  10. _context = context;
  11. _listener = listener;
  12. }
  13. public void Process(IMessage message)
  14. {
  15. if (message != null)
  16. {
  17. _listener.OnPreMessage(message);
  18. IMsgController msgController = _context.Generator.GetController(message.ProtocolID);
  19. if (null != msgController)
  20. {
  21. try
  22. {
  23. msgController.Process(message, _listener);
  24. _context.Generator.RecycleMessage(message);
  25. }
  26. catch (Exception e)
  27. {
  28. Log.Exception($"[Net] {msgController.GetType().FullName}.Process protoId: {message.ProtocolID}, Error: \n", e);
  29. _context.Generator.RecycleMessage(message);
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }