protected override async ETTask Run(Session session, C2G_DLoginGate request, G2C_DLoginGate response, Action reply) { Scene scene = session.DomainScene(); string account = scene.GetComponent <DGateSessionKeyComponent>().Get(request.Key); if (account == null) { response.Error = ErrorCode.ERR_ConnectGateKeyError; response.Message = "Gate key验证失败!"; reply(); return; } DBComponent db = session.Domain.GetComponent <DBComponent>(); DPlayer player = await PlayerDBHelper.GetPlayerFromDB(db, account); scene.GetComponent <DPlayerComponent>().Add(player); session.AddComponent <DSessionPlayerComponent>().Player = player; session.AddComponent <MailBoxComponent, MailboxType>(MailboxType.GateSession); response.PlayerId = player.Id; reply(); }
protected override async ETTask Run(Scene scene, R2G_CreateAccount request, G2R_CreateAccount response, Action reply) { // 1 首次创建Gamer对象 Gamer gamer = GamerHelper.InitGamer(scene.Domain, request.Account); // 2 存出Gamer对象到DB DBComponent db = scene.GetComponent <DBComponent>(); await GamerDBHelper.AddGamerToDB(db, gamer); // 3 创建Player对象 DPlayer player = PlayerHelper.InitPlayer(request.Account, request.Password, gamer.Id); await PlayerDBHelper.AddPlayerToDB(db, player); reply(); }
protected override async ETTask Run(Session session, C2R_DLogin request, R2C_DLogin response, Action reply) { // 随机分配一个Gate StartSceneConfig config = DRealmGateAddressHelper.GetGate(session.DomainZone()); // 账号验证 DBComponent db = session.Domain.GetComponent <DBComponent>(); DPlayer player = await PlayerDBHelper.GetPlayerFromDB(db, request.Account); if (player == null) { // DB无Player对象,创建对象 await ActorMessageSenderComponent.Instance.Call( config.SceneId, new R2G_CreateAccount() { Account = request.Account, Password = request.Password }); } else if (!player.PassWord.Equals(request.Password)) { response.Error = ErrorCode.ERR_ConnectPasswordError; response.Message = "Password Error!"; reply(); return; } // 向gate请求一个key,客户端可以拿着这个key连接gate G2R_DGetLoginKey g2RGetLoginKey = (G2R_DGetLoginKey)await ActorMessageSenderComponent.Instance.Call( config.SceneId, new R2G_DGetLoginKey() { Account = request.Account }); response.Address = config.OuterIPPort.ToString(); response.Key = g2RGetLoginKey.Key; response.GateId = g2RGetLoginKey.GateId; reply(); }