123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- namespace ET.Server
- {
- /// <summary>
- /// 加载100%
- /// </summary>
- [MessageHandler(SceneType.Game)]
- public class C2G_EnterMapHandler: AMRpcHandler<C2G_EnterMap, G2C_EnterMap>
- {
- protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response, Action reply)
- {
- if (session.DomainScene().SceneType != SceneType.Game)
- {
- Log.Debug($"Game 请求的Scene错误...SceneType={session.DomainScene().SceneType}");
- session.Dispose();
- return;
- }
- // 移除session自动超时组件
- session.RemoveComponent<SessionAcceptTimeoutComponent>();
- WNPlayer player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
- if (player == null)
- {
- Log.Debug($"操作错误, player is null");
- response.Error = ErrorCode.ERR_OperationError;
- reply();
- return;
- }
- Log.Info($"玩家请求进入场景: playerId={player.GetId()}, instanceId={request.InstanceId}");
- Map map = player.Map;
- // 当客户端所要进入的场景不为空且不等于当前场景,忽略掉本次请求
- if (request.InstanceId > 0 && map.Id != request.InstanceId)
- {
- Log.Debug(
- $"连续切图吗? playerId={player.GetId()}, name={player.GetName()}, mapId={map.MapId}, map.InstanceId={map.Id}, request.InstanceId={request.InstanceId}");
- response.Error = ErrorCode.ERR_OperationToFast;
- reply();
- return;
- }
- if (map == null)
- {
- Log.Debug($"进入场景出错, 场景不存在...playerId={player.GetId()}, instanceId={request.InstanceId}");
- response.Error = ErrorCode.ERR_EnterMapError;
- reply();
- return;
- }
- map.PlayerEnterRequest(player);
- map.PlayerEntered(player);
- response.MapInstanceId = player.Map.Id;
- reply();
- await ETTask.CompletedTask;
- }
- }
- }
|