OuterMessageDispatcher.cs 1.3 KB

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