コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        protected override async ETTask Run(Session session, C2G_EnterLobby request, G2C_EnterLobby response, Action reply)
        {
            DPlayer player = session.GetComponent <DSessionPlayerComponent>().Player;

            // 在随机选择的map服务器上创建Gamer
            long mapInstanceId = GateMapAddressHelper.GetMapID(session.DomainZone());

            M2G_CreateGamer createGamer = (M2G_CreateGamer)await ActorMessageSenderComponent.Instance.Call(
                mapInstanceId, new G2M_CreateGamer()
            {
                GamerId = player.GamerId, GateSessionId = session.InstanceId
            });

            // 返回信息
            response.SelfGamer = createGamer.SelfGamer;

            reply();
        }
コード例 #4
0
ファイル: C2R_DLoginHandler.cs プロジェクト: chengxu-yh/ET
        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();
        }
コード例 #5
0
        public static async ETTask AddPlayerToDB(DBComponent db, DPlayer player)
        {
            await db.Save(player);

            Log.Info($"ÐÂÔöÕ˺ţº{player.Account}£¬ÃÜÂ룺{player.PassWord}¡£");
        }
コード例 #6
0
ファイル: DPlayerComponent.cs プロジェクト: chengxu-yh/ET
 public void Add(DPlayer player)
 {
     this.idPlayers.Add(player.Id, player);
 }