예제 #1
0
        protected override async ETTask Run(Session session, C2G_GetOtherPlayer message)
        {
            //获取内网发送组件
            IPEndPoint mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
            Session    mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

            M2G_GetAllMapUnitExcept m2GGetAllMapUnitExcept = (M2G_GetAllMapUnitExcept)await mapSession.Call(new G2M_GetAllMapUnitExcept()
            {
                Account = message.Account
            });

            if (m2GGetAllMapUnitExcept.Accounts.Count > 0)
            {
                PlayerComponent             playerComponent      = Game.Scene.GetComponent <PlayerComponent>();
                ActorMessageSenderComponent actorSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();

                for (int i = 0; i < m2GGetAllMapUnitExcept.Accounts.Count; i++)
                {
                    if (playerComponent.AccountHaveBeCreated(m2GGetAllMapUnitExcept.Accounts[i]))
                    {
                        Player player = playerComponent.getPlayerByAccount(m2GGetAllMapUnitExcept.Accounts[i]);

                        ActorMessageSender actorMessageSender = actorSenderComponent.Get(player.MapInstanceId);
                        Actor_PlayerInitPositionResponse actor_PlayerInitPositionResponse = (Actor_PlayerInitPositionResponse)await actorMessageSender.Call(new Actor_PlayerInitPositionRequest());

                        session.Send(new G2C_OtherPlayerEnterMap()
                        {
                            Account   = player.Account,
                            PositionX = actor_PlayerInitPositionResponse.PositionX,
                            PositionY = actor_PlayerInitPositionResponse.PositionY,
                            PositionZ = actor_PlayerInitPositionResponse.PositionZ
                        });
                    }
                }
            }

            await ETTask.CompletedTask;
        }
예제 #2
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;
        }
        protected override async ETTask Run(Session session, C2G_RequestEnterMap request, G2C_RequestEnterMap response, Action reply)
        {
            Log.Info("玩家:" + request.Account + "请求进入Map");

            //获取玩家
            PlayerComponent playerComponent = Game.Scene.GetComponent <PlayerComponent>();
            Player          player          = playerComponent.getPlayerByAccount(request.Account);

            if (player != null)
            {
                //获取内网发送组件
                IPEndPoint mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session    mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

                M2G_EnterWorld m2GEnterWorld = (M2G_EnterWorld)await mapSession.Call(new G2M_EnterWorld()
                {
                    Account = request.Account, PlayerGateInstanceId = player.InstanceId
                });

                player.MapInstanceId = m2GEnterWorld.PlayerMapInstanceId;

                //获取角色出生位置
                ActorMessageSenderComponent actorSenderComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>();
                ActorMessageSender          actorMessageSender   = actorSenderComponent.Get(player.MapInstanceId);

                Actor_PlayerInitPositionResponse actor_PlayerInitPositionResponse = (Actor_PlayerInitPositionResponse)await actorMessageSender.Call(new Actor_PlayerInitPositionRequest());

                Log.Info("获取角色初始位置:" + actor_PlayerInitPositionResponse.PositionX + " || " +
                         actor_PlayerInitPositionResponse.PositionY + " || " + actor_PlayerInitPositionResponse.PositionZ);

                response.PositionX = actor_PlayerInitPositionResponse.PositionX;
                response.PositionY = actor_PlayerInitPositionResponse.PositionY;
                response.PositionZ = actor_PlayerInitPositionResponse.PositionZ;

                reply();

                Log.Info("同意进入Map");

                //向其它玩家发送自己登录的信息
                List <Player> players = playerComponent.getOtherPlayerIgnoreAccount(request.Account);
                if (players != null)
                {
                    for (int i = 0; i < players.Count; i++)
                    {
                        players[i].session.Send(new G2C_OtherPlayerEnterMap()
                        {
                            Account   = request.Account,
                            PositionX = actor_PlayerInitPositionResponse.PositionX,
                            PositionY = actor_PlayerInitPositionResponse.PositionY,
                            PositionZ = actor_PlayerInitPositionResponse.PositionZ
                        });
                    }
                }
            }
            else
            {
                Log.Info("玩家超时:" + request.Account);
                session.Send(new G2C_PlayerBackLogin()
                {
                    NetMessage = "游戏超时: " + request.Account
                });
            }

            await ETTask.CompletedTask;
        }