OuterMessageDispatcher.cs 1.2 KB

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