C2G_EnterMapHandler.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Net;
  3. using ETModel;
  4. namespace ETHotfix
  5. {
  6. [MessageHandler(AppType.Gate)]
  7. public class C2G_EnterMapHandler : AMRpcHandler<C2G_EnterMap, G2C_EnterMap>
  8. {
  9. protected override void Run(Session session, C2G_EnterMap message, Action<G2C_EnterMap> reply)
  10. {
  11. RunAsync(session, message, reply).NoAwait();
  12. }
  13. protected async ETVoid RunAsync(Session session, C2G_EnterMap message, Action<G2C_EnterMap> reply)
  14. {
  15. G2C_EnterMap response = new G2C_EnterMap();
  16. try
  17. {
  18. Player player = session.GetComponent<SessionPlayerComponent>().Player;
  19. // 在map服务器上创建战斗Unit
  20. IPEndPoint mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent<InnerConfig>().IPEndPoint;
  21. Session mapSession = Game.Scene.GetComponent<NetInnerComponent>().Get(mapAddress);
  22. M2G_CreateUnit createUnit = (M2G_CreateUnit)await mapSession.Call(new G2M_CreateUnit() { PlayerId = player.Id, GateSessionId = session.InstanceId });
  23. player.UnitId = createUnit.UnitId;
  24. response.UnitId = createUnit.UnitId;
  25. reply(response);
  26. }
  27. catch (Exception e)
  28. {
  29. ReplyError(response, e, reply);
  30. }
  31. }
  32. }
  33. }