OuterMessageDispatcher.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using ETModel;
  3. using Google.Protobuf;
  4. namespace ETHotfix
  5. {
  6. public class OuterMessageDispatcher: IMessageDispatcher
  7. {
  8. public void Dispatch(Session session, ushort opcode, object message)
  9. {
  10. DispatchAsync(session, opcode, message).NoAwait();
  11. }
  12. public async ETVoid DispatchAsync(Session session, ushort opcode, object message)
  13. {
  14. try
  15. {
  16. switch (message)
  17. {
  18. case IActorLocationRequest actorLocationRequest: // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
  19. {
  20. long unitId = session.GetComponent<SessionPlayerComponent>().Player.UnitId;
  21. ActorLocationSender actorLocationSender = Game.Scene.GetComponent<ActorLocationSenderComponent>().Get(unitId);
  22. int rpcId = actorLocationRequest.RpcId; // 这里要保存客户端的rpcId
  23. IResponse response = await actorLocationSender.Call(actorLocationRequest);
  24. response.RpcId = rpcId;
  25. session.Reply(response);
  26. return;
  27. }
  28. case IActorLocationMessage actorLocationMessage:
  29. {
  30. long unitId = session.GetComponent<SessionPlayerComponent>().Player.UnitId;
  31. ActorLocationSender actorLocationSender = Game.Scene.GetComponent<ActorLocationSenderComponent>().Get(unitId);
  32. actorLocationSender.Send(actorLocationMessage);
  33. return;
  34. }
  35. }
  36. Game.Scene.GetComponent<MessageDispatherComponent>().Handle(session, new MessageInfo(opcode, message));
  37. }
  38. catch (Exception e)
  39. {
  40. Log.Error(e);
  41. }
  42. }
  43. }
  44. }