using System; using Model; namespace Hotfix { [MessageHandler(AppType.Gate)] public class C2G_LoginGateHandler : AMRpcHandler { protected override async void Run(Session session, C2G_LoginGate message, Action reply) { G2C_LoginGate response = new G2C_LoginGate(); try { string account = Game.Scene.GetComponent().Get(message.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(response); return; } Player player = EntityFactory.Create(account); Game.Scene.GetComponent().Add(player); session.AddComponent().Player = player; session.AddComponent(new GateSessionEntityActorHandler()); // 在map服务器上创建战斗Unit string mapAddress = Game.Scene.GetComponent().MapConfig.GetComponent().Address; Session mapSession = Game.Scene.GetComponent().Get(mapAddress); M2G_CreateUnit createUnit = await mapSession.Call(new G2M_CreateUnit() { PlayerId = player.Id, GateSessionId = session.Id }); player.UnitId = createUnit.UnitId; response.PlayerId = player.Id; response.UnitId = createUnit.UnitId; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } } } }