Пример #1
0
        protected override async ETTask Run(Session session, C2G_Reg request, G2C_Reg response, Action reply)
        {
            Log.Info("玩家请求注册:" + request.Account + "玩家输入密码:" + request.Password);

            DBProxyComponent dBProxy = Game.Scene.GetComponent <DBProxyComponent>();

            List <ComponentWithId> count = await dBProxy.Query <PlayerInfoDB>(PlayerInfoDB => PlayerInfoDB.account == request.Account);

            if (count.Count == 0)
            {
                //如果运行到这里说明是注册的新账号
                PlayerInfoDB playerData = ComponentFactory.Create <PlayerInfoDB>();
                playerData.account = request.Account;
                playerData.pwd     = request.Password;
                await dBProxy.Save(playerData);

                response.RegFail = true;

                Log.Info("注册新账号成功");
            }
            else
            {
                response.RegFail = false;
                Log.Info("注册新账号失败");

                if (count.Count != 1)
                {
                    Log.Error("账号:" + request.Account + " 数量异常:" + count.Count);
                }
            }


            reply();
            await ETTask.CompletedTask;
        }
Пример #2
0
        protected override async ETTask Run(Session session, C2G_GetPlayerInfo request, G2C_GetPlayerInfo response, Action reply)
        {
            DBProxyComponent dBProxy = Game.Scene.GetComponent <DBProxyComponent>();

            List <ComponentWithId> count = await dBProxy.Query <PlayerInfoDB>(PlayerInfoDB => PlayerInfoDB.account == request.Account);

            if (count.Count == 1)
            {
                PlayerInfoDB playerInfoDB = count[0] as PlayerInfoDB;

                Log.Info("查询玩家:" + request.Account);

                response.KillCount  = playerInfoDB.KillCount;
                response.DeathCount = playerInfoDB.DeathCount;
                response.MoneyCount = playerInfoDB.MoneyCount;
            }
            else
            {
                Log.Error("查找数据不正确:" + request.Account);

                response.KillCount  = 0;
                response.DeathCount = 0;
                response.MoneyCount = 0;
            }

            reply();
            await ETTask.CompletedTask;
        }
        protected override async ETTask Run(Session session, M2G_RecordKillData message)
        {
            DBProxyComponent dBProxy = Game.Scene.GetComponent <DBProxyComponent>();

            {
                List <ComponentWithId> count = await dBProxy.Query <PlayerInfoDB>(PlayerInfoDB => PlayerInfoDB.account == message.KillerAccount);

                if (count.Count == 1)
                {
                    PlayerInfoDB playerInfoDB = count[0] as PlayerInfoDB;

                    Log.Info("查询击杀者:" + message.KillerAccount);

                    playerInfoDB.KillCount++;
                    playerInfoDB.MoneyCount += 20;

                    await dBProxy.Save(playerInfoDB);
                }
                else
                {
                    Log.Error("查找数据不正确:" + message.KillerAccount);
                }
            }
            {
                List <ComponentWithId> count = await dBProxy.Query <PlayerInfoDB>(PlayerInfoDB => PlayerInfoDB.account == message.DeathAccount);

                if (count.Count == 1)
                {
                    PlayerInfoDB playerInfoDB = count[0] as PlayerInfoDB;

                    Log.Info("查询被杀者:" + message.DeathAccount);

                    playerInfoDB.DeathCount++;

                    await dBProxy.Save(playerInfoDB);
                }
                else
                {
                    Log.Error("查找数据不正确:" + message.KillerAccount);
                }
            }

            await ETTask.CompletedTask;
        }
Пример #4
0
        protected override async ETTask Run(Session session, C2G_Login request, G2C_Login response, Action reply)
        {
            Log.Info("玩家请求登录:" + request.Account + "玩家输入密码:" + request.Password);

            DBProxyComponent dBProxy = Game.Scene.GetComponent <DBProxyComponent>();

            List <ComponentWithId> count = await dBProxy.Query <PlayerInfoDB>(PlayerInfoDB => PlayerInfoDB.account == request.Account);

            if (count.Count > 0)
            {
                if (count.Count == 1)
                {
                    //取得该条数据
                    PlayerInfoDB info = await dBProxy.Query <PlayerInfoDB>(count[0].Id);

                    //验证密码
                    if (info.pwd == request.Password)
                    {
                        Log.Info("密码正确,允许登录");

                        response.LoginFail = true;

                        PlayerComponent playerComponent = Game.Scene.GetComponent <PlayerComponent>();

                        Player loginPlayer;
                        //查看玩家是否已经登录创建过
                        if (playerComponent.AccountHaveBeCreated(request.Account))
                        {
                            Log.Info("玩家被顶号: " + request.Account);

                            //获取之前已经创建好的Player实体
                            loginPlayer = playerComponent.getPlayerByAccount(request.Account);

                            try
                            {
                                //给被顶号的人发送被顶号的信息
                                loginPlayer.session.Send(new G2C_PlayerBackLogin()
                                {
                                    NetMessage = "此账号在其它地方被登录"
                                });
                            }
                            catch
                            {
                                Log.Info("发送顶号信息失败:" + request.Account);
                            }

                            //给其它玩家广播这个玩家掉线的信息
                            playerComponent.PlayerBackLogin(request.Account).Coroutine();
                        }
                        else
                        {
                            //创建登录玩家的实体
                            loginPlayer = PlayerFactory.Create(request.Account);
                            //向玩家管理组件里添加玩家的信息
                            playerComponent.addPlayerToDict(request.Account, loginPlayer);
                        }

                        //对玩家的session进行记录
                        loginPlayer.session = session;
                        session.AddComponent <SessionPlayerComponent>().Player = loginPlayer;
                    }
                    else
                    {
                        Log.Info("密码错误");

                        response.LoginFail = false;
                    }
                }
                else
                {
                    Log.Error("账号重复了: " + count.Count);
                    response.LoginFail = false;
                }
            }
            else
            {
                response.LoginFail = false;
            }


            reply();
            await ETTask.CompletedTask;
        }