OuterMessageDispatcher.cs 1.5 KB

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