OuterMessageDispatcher.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. namespace Model
  3. {
  4. public class OuterMessageDispatcher: IMessageDispatcher
  5. {
  6. public async void Dispatch(Session session, ushort opcode, int offset, byte[] messageBytes, object message)
  7. {
  8. // gate session收到actor消息直接转发给actor自己去处理
  9. if (message is AActorMessage aActorMessage)
  10. {
  11. ActorProxy actorProxy = Game.Scene.GetComponent<ActorProxyComponent>().Get(aActorMessage.Id);
  12. aActorMessage.Id = session.GetComponent<SessionGamerComponent>().Gamer.Id;
  13. actorProxy.Send(aActorMessage);
  14. return;
  15. }
  16. // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
  17. if (message is AActorRequest aActorRequest)
  18. {
  19. ActorProxy actorProxy = Game.Scene.GetComponent<ActorProxyComponent>().Get(aActorRequest.Id);
  20. aActorRequest.Id = session.GetComponent<SessionGamerComponent>().Gamer.Id;
  21. uint rpcId = aActorRequest.RpcId;
  22. AActorResponse aActorResponse = await actorProxy.Call<AActorRequest, AActorResponse>(aActorRequest);
  23. aActorResponse.RpcId = rpcId;
  24. session.Reply(aActorResponse);
  25. return;
  26. }
  27. if (message is AMessage || message is ARequest)
  28. {
  29. Game.Scene.GetComponent<MessageDispatherComponent>().Handle(session, message);
  30. return;
  31. }
  32. throw new Exception($"message type error: {message.GetType().FullName}");
  33. }
  34. }
  35. }