InnerMessageDispatcher.cs 996 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. namespace Model
  3. {
  4. public class InnerMessageDispatcher: IMessageDispatcher
  5. {
  6. public void Dispatch(Session session, ushort opcode, int offset, byte[] messageBytes, AMessage message)
  7. {
  8. // 收到actor消息分发给actor自己去处理
  9. if (message is ActorRequest actorRequest)
  10. {
  11. Entity entity = Game.Scene.GetComponent<ActorManagerComponent>().Get(actorRequest.Id);
  12. if (entity == null)
  13. {
  14. ActorResponse response = new ActorResponse
  15. {
  16. RpcId = actorRequest.RpcId,
  17. Error = ErrorCode.ERR_NotFoundActor
  18. };
  19. session.Reply(response);
  20. return;
  21. }
  22. entity.GetComponent<ActorComponent>().Add(new ActorMessageInfo() { Session = session, Message = actorRequest });
  23. return;
  24. }
  25. if (message is AMessage || message is ARequest)
  26. {
  27. Game.Scene.GetComponent<MessageDispatherComponent>().Handle(session, message);
  28. return;
  29. }
  30. throw new Exception($"message type error: {message.GetType().FullName}");
  31. }
  32. }
  33. }