Пример #1
0
        protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            //if (message.Account != "abcdef" || message.Password != "111111")
            //{
            //	response.Error = ErrorCode.ERR_AccountOrPasswordError;
            //	reply(response);
            //	return;
            //}

            // 随机分配一个Gate
            StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();

            Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
            IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
            Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

            // 向gate请求一个key,客户端可以拿着这个key连接gate
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
            {
                Account = request.Account
            });

            string outerAddress = config.GetComponent <OuterConfig>().Address2;

            response.Address = outerAddress;
            response.Key     = g2RGetLoginKey.Key;
            reply();
        }
Пример #2
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                if (message.Account != "abcdef" || message.Password != "111111")
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                string  innerAddress = $"{config.GetComponent<InnerConfig>().Host}:{config.GetComponent<InnerConfig>().Port}";
                Session gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call <R2G_GetLoginKey, G2R_GetLoginKey>(new R2G_GetLoginKey());

                string outerAddress = $"{config.GetComponent<OuterConfig>().Host}:{config.GetComponent<OuterConfig>().Port}";

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public static void Awake(this DBProxyComponent self)
        {
            StartConfig dbStartConfig = StartConfigComponent.Instance.DBConfig;

            Log.Info(dbStartConfig.GetComponent <InnerConfig>().IPEndPoint.ToString());
            self.dbAddress = dbStartConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                //if (message.Account != "hzy" || message.Password != "123")
                //{
                //    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                //    reply(response);
                //    return;
                //}
                DBProxyComponent dBProxy     = Game.Scene.GetComponent <DBProxyComponent>();
                UserInfo         newUserInfo = ComponentFactory.Create <UserInfo>();
                newUserInfo.Account  = message.Account;
                newUserInfo.PassWord = message.Password;
                await dBProxy.Save(newUserInfo);

                try
                {
                    List <ComponentWithId> users = await dBProxy.Query <UserInfo>(t => t.Account == message.Account);

                    if (users.Count > 0)
                    {
                        UserInfo user = await dBProxy.Query <UserInfo>(users[0].Id);

                        Log.Error("user的内容:" + JsonHelper.ToJson(user));
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("查库错误");
                    throw;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #5
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                Log.Info($"登录请求:{{Account:'{message.Account}',Password:'******'}}");

                List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == message.Account);

                if (result.Count == 0)
                {
                    response.Error   = ErrorCode.ERR_AccountDoesnExist;
                    response.Message = "账号不存在";
                    reply(response);
                    return;
                }
                AccountInfo accountInfo = result[0] as AccountInfo;
                if (accountInfo.Password != message.Password)
                {
                    response.Error   = ErrorCode.ERR_LoginError;
                    response.Message = "密码错误";
                    reply(response);
                    return;
                }

                AccountInfo account = result[0] as AccountInfo;

                Log.Info($"账号登录成功{MongoHelper.ToJson(account)}");

                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();

                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;

                Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    UserId = account.Id
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;

                response.Key = g2RGetLoginKey.Key;

                response.UserId = account.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        private async static ETTask RealmToGate(Session session, User user, R2C_Authentication response, bool isRefreshToken)
        {
            // 隨機分配GateServer
            StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();

            // Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
            IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
            Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);
            //Game.Scene.GetComponent<PingComponent>().RemoveSession(session.Id);

            // 向Gate請求一個Key,Client可以拿這個Key連接Gate
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
            {
                Uid = user.Id
            });

            string outerAddress = config.GetComponent <OuterConfig>().Address2;

            // 創造權杖
            if (isRefreshToken)
            {
                SignInCryptographyHelper.Token tok = new SignInCryptographyHelper.Token
                {
                    uid = user.Id,
                    lastCreateTokenAt = user.lastCreateTokenAt,
                    salt = user.salt,
                };

                string token = SignInCryptographyHelper.EncodeToken(tok);
                response.Token = token;
            }

            PlayerRideTotalInfo playerRideTotalInfo = await UserDataHelper.QueryUserRideAllRecord(user);

            response.Error   = ErrorCode.ERR_Success;
            response.Address = outerAddress;
            response.Key     = g2RGetLoginKey.Key;
            response.Data    = new PlayerBaseInfo
            {
                Uid      = user.Id,
                Name     = user.name,
                Sex      = user.gender,
                Location = user.location,
                Height   = user.height,
                Weight   = user.weight,
                Birthday = user.birthday,
                CreateAt = user.createAt,
                // 校時用
                LastOnlineAt = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
                CharSetting  = user.playerCharSetting,
                TotalInfo    = playerRideTotalInfo,
                Language     = user.language,
            };
            response.LinkTypes.Clear();
            response.LinkTypes.AddRange(await GetAllLinkType(user.Id));
        }
Пример #7
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                User user = Game.Scene.GetComponent <UserComponent>().GetByAccount(message.Account);
                if (user != null)
                {
                    if (message.Password == user.Password)
                    {
                        Console.WriteLine(" 用户名: " + user.Account + " 验证通过!");

                        // 随机分配一个Gate
                        StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                        //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                        IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                        Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                        // 向gate请求一个key,客户端可以拿着这个key连接gate
                        G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                        {
                            Account = message.Account
                        });

                        string outerAddress = config.GetComponent <OuterConfig>().Address2;

                        response.Key     = g2RGetLoginKey.Key;
                        response.Address = outerAddress;
                        reply(response);
                    }
                    else
                    {
                        Console.WriteLine(" 用户名: " + message.Account + " 密码验证错误!");

                        response.Error   = ErrorCode.ERR_AccountOrPasswordError;
                        response.Message = " 用户名: " + message.Account + " 密码验证错误!";
                        reply(response);
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("用户名:" + message.Account + "不存在!");

                    response.Error   = ErrorCode.ERR_AccountOrPasswordError;
                    response.Message = " 用户名: " + message.Account + " 不存在!";
                    reply(response);
                    return;
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #8
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                //数据库操作对象
                {
                    DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();
                    Console.WriteLine("dbProxy : " + dbProxy);

                    //查询账号是否存在  使用LINQ和Lambda表达式根据特定条件来查询
                    List <ComponentWithId> result = await dbProxy.Query <AccountInfo>(_account => _account.Account == message.Account && _account.Password == message.Password);

                    Console.WriteLine("result : " + result);

                    if (result.Count <= 0)
                    {
                        Console.WriteLine("result.Count : " + result.Count);

                        response.Error = ErrorCode.ERR_AccountOrPasswordError;
                        reply(response);
                        return;
                    }
                    Console.WriteLine("数据库查询成功");

                    //释放数据库连接
                    dbProxy.Dispose();
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #9
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                DBProxyComponent       dbproy   = Game.Scene.GetComponent <DBProxyComponent>();
                List <ComponentWithId> accounts = await dbproy.Query <Account>($"{{\'username\':\'{message.Account}\'}}");

                if (accounts.Count == 0)
                {
                    Account account = new Account();
                    Log.Debug("账号不存在,正在保存账号");
                    await dbproy.Save(account);
                }
                else
                {
                    Account account = (Account)accounts[0];
                    Log.Debug("查找到了" + accounts);
                    if (message.Password != account.password)
                    {
                        Log.Debug("密码正确");
                        return;
                    }
                }


                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                G2R_GetLoginKey g2R_GetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2R_GetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #10
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            Log.Debug(message.ToJson());
            R2C_Login response = new R2C_Login();

            try
            {
                long   roleId = 0;
                string szName = string.Empty;
                string szIcon = string.Empty;
                if (message.channel == 0)
                {
                    try
                    {
                        roleId = System.Convert.ToInt64(message.Account);
                        szName = message.Account;
                    }
                    catch
                    {
                    }
                    if (message.channel == 0)
                    {
                    }
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress(roleId);
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call <G2R_GetLoginKey>(new R2G_GetLoginKey()
                {
                    roleId = roleId, icon = szIcon, mName = szName
                });

                string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #11
0
        /// <summary>
        /// 将已在线的玩家踢下线
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static async Task KickOutPlayer(long userId)
        {
            //判断用户是否在线,在线则踢下线
            int gateAppId = Game.Scene.GetComponent <OnlineComponent>().GetGateAppId(userId);

            if (gateAppId != 0) //如果玩家在线 则返回其所在的AppID
            {
                Log.Debug($"玩家{userId}已在线 将执行踢下线操作");

                //获取此User所在Gate服务器
                StartConfig userGateConfig     = Game.Scene.GetComponent <StartConfigComponent>().Get(gateAppId);
                IPEndPoint  userGateIPEndPoint = userGateConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session     userGateSession    = Game.Scene.GetComponent <NetInnerComponent>().Get(userGateIPEndPoint);

                //获取此User其它客户端与网关连接session
                /* 这里是向此User其它客户端发送一条测试消息,                                 */
                /* 你可以在移除它处登录用户前向之前客户端发送一条通知下线的消息让其返回登录界面  */
                User    user          = Game.Scene.GetComponent <UserComponent>().Get(userId);
                Session ClientSession = Game.Scene.GetComponent <NetOuterComponent>().Get(user.GateSessionID);
                ClientSession.Send(new G2C_TestHotfixMessage()
                {
                    Info = "recv hotfix message success"
                });

                //向客户端发送玩家下线消息
                Log.Info("它处登录,原登录踢下线《====");
                //...练习,自己实现通知客户端下线

                //通知Gate服务器移除指定User将它处登录用户踢下线
                await userGateSession.Call(new A0007_KickOutPlayer_R2G()
                {
                    UserID = userId
                });
            }
        }
Пример #12
0
        public override async ETTask Actor_TransferRequestHandler(Unit unit, Actor_TransferRequest request, Actor_TransferResponse response, Action reply)
        {
            long unitId = unit.Id;

            // 先在location锁住unit的地址
            await Game.Scene.GetComponent <LocationProxyComponent>().Lock(unitId, unit.InstanceId);

            // 删除unit,让其它进程发送过来的消息找不到actor,重发
            Game.EventSystem.Remove(unitId);

            long instanceId = unit.InstanceId;

            int mapIndex = request.MapIndex;

            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

            // 传送到map
            StartConfig mapConfig = startConfigComponent.Get(mapIndex);
            var         address   = mapConfig.GetComponent <InnerConfig>().Address;
            Session     session   = Game.Scene.GetComponent <NetInnerComponent>().Get(address);

            // 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
            Game.Scene.GetComponent <UnitComponent>().RemoveNoDispose(unitId);
            M2M_TrasferUnitResponse m2m_TrasferUnitResponse = (M2M_TrasferUnitResponse)await session.Call(new M2M_TrasferUnitRequest()
            {
                Unit = unit
            });

            unit.Dispose();

            // 解锁unit的地址,并且更新unit的instanceId
            await Game.Scene.GetComponent <LocationProxyComponent>().UnLock(unitId, instanceId, m2m_TrasferUnitResponse.InstanceId);

            reply();
        }
Пример #13
0
        protected override async void Run(Session session, M2A_RegisterService message)
        {
            try
            {
                StartConfig          startConfig          = (StartConfig)message.Component;
                NetInnerComponent    netInnerComponent    = Game.Scene.GetComponent <NetInnerComponent>();
                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
                startConfigComponent.AddConfig(startConfig);

                if (startConfig.AppId == (int)IdGenerater.AppId)
                {
                    return;
                }
                InnerConfig        innerConfig        = startConfig.GetComponent <InnerConfig>();
                Session            serverSession      = netInnerComponent.Get(innerConfig.IPEndPoint);
                A2S_ConnectService a2S_ConnectService = (A2S_ConnectService)await serverSession.Call(new S2A_ConnectService());

                if (a2S_ConnectService.Error != ErrorCode.ERR_Success)
                {
                    Log.Error($"to connect service[{startConfig.AppType}:{startConfig.AppId}] is failed.");
                }
                else
                {
                    Log.Info($"to connect service[{startConfig.AppType}:{startConfig.AppId}] is successful.");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Пример #14
0
        /// <summary>
        /// 将已在线的玩家踢下线
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static async Task KickOutPlayer(long userId, bool toClient = true)
        {
            //判断用户是否在线,在线则踢下线
            int gateAppId = Game.Scene.GetComponent <OnlineComponent>().GetGateAppId(userId);

            if (gateAppId != 0) //如果玩家在线 则返回其所在的AppID
            {
                //获取此User所在Gate服务器
                StartConfig userGateConfig     = Game.Scene.GetComponent <StartConfigComponent>().Get(gateAppId);
                IPEndPoint  userGateIPEndPoint = userGateConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session     userGateSession    = Game.Scene.GetComponent <NetInnerComponent>().Get(userGateIPEndPoint);

                //获取此User其它客户端与网关连接session
                /* 这里是向此User其它客户端发送一条测试消息,                                 */
                /* 你可以在移除它处登录用户前向之前客户端发送一条通知下线的消息让其返回登录界面  */
                User user = Game.Scene.GetComponent <UserComponent>().Get(userId);

                if (toClient)
                {
                    Session cSession = Game.Scene.GetComponent <NetOuterComponent>().Get(user.GateSessionId);
                    cSession.Send(new KickOutPlayer_R2C()
                    {
                        Message = "原登录下线《===="
                    });
                }


                //通知Gate服务器移除指定User
                await userGateSession.Call(new KickOutPlayer_R2G()
                {
                    UserId = userId
                });
            }
        }
Пример #15
0
        public static void Awake(this LocationProxyComponent self)
        {
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

            StartConfig startConfig = startConfigComponent.LocationConfig;

            self.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
Пример #16
0
        public static void Awake(this LocationProxyComponent self)
        {
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

            StartConfig startConfig = startConfigComponent.LocationConfig;              //位置服务器的配置 管理各个单位所在的进程

            self.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint; //获取内网配置地址 IP:端口
        }
Пример #17
0
        public static void Awake(this LocationProxyComponent self)
        {
            StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();

            StartConfig startConfig = startConfigComponent.StartConfig;

            self.LocationAddress = startConfig.GetComponent <LocationConfig>().IPEndPoint;
        }
        public static void Awake(this CacheProxyComponent self)
        {
            StartConfig dbStartConfig = StartConfigComponent.Instance.DBConfig;

            self.dbAddress = dbStartConfig.GetComponent <InnerConfig>().IPEndPoint;
            CacheConfig cacheConfig = dbStartConfig.GetComponent <CacheConfig>();

            if (cacheConfig == null)
            {
                self.connectionString = CacheComponent.connectionString;
            }
            else
            {
                self.connectionString = cacheConfig.ConnectionString;
            }

            Log.Info($"to prepare initializing redis......");

            // to establish connection with Redis
            self.redisClient    = ConnectionMultiplexer.Connect(self.connectionString);
            self.redisSubClient = ConnectionMultiplexer.Connect(self.connectionString);
            self.redisPubClient = ConnectionMultiplexer.Connect(self.connectionString);

            Log.Info($"to connect redis is successful.");

            var startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();

            foreach (var v in DBHelper.GetCacheUseModesIter())
            {
                if (!CacheHelper.IsSyncOn(v.Key, startConfigComponent.StartConfig.AppType))
                {
                    continue;
                }
                switch (v.Value)
                {
                case CacheUseMode.MemorySyncByDB:
                    break;

                case CacheUseMode.MemorySyncByRedis:
                    var component = ComponentFactory.Create <RedisEventSolverComponent, CacheProxyComponent, Type>(self, v.Key);
                    self.redisEventSolvers.Add(v.Key, component);
                    break;
                }
            }
        }
Пример #19
0
        protected override async void Run(Session session, C2R_CommonLogin message, Action <R2C_CommonLogin> reply)
        {
            R2C_CommonLogin response = new R2C_CommonLogin();

            try
            {
                //向用户服验证(注册/登陆)并获得一个用户ID
                Session        userSession   = Game.Scene.GetComponent <NetInnerSessionComponent>().Get(AppType.User);
                U2R_VerifyUser u2RVerifyUser = (U2R_VerifyUser)await userSession.Call(new R2U_VerifyUser()
                {
                    LoginType    = message.LoginType,
                    PlatformType = message.PlatformType,
                    DataStr      = message.DataStr,
                    // IpAddress=session.RemoteAddress.Address.ToString(),
                });

                //如果Message不为空 说明 验证失败
                if (!string.IsNullOrEmpty(u2RVerifyUser.Message))
                {
                    response.Message = u2RVerifyUser.Message;
                    reply(response);
                    return;
                }
                // 随机分配一个Gate
                StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);
                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    UserId = u2RVerifyUser.UserId
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;
                response.Address      = outerAddress;
                response.Key          = g2RGetLoginKey.Key;
                response.LoginVoucher = u2RVerifyUser.UserId.ToString() + '|' + u2RVerifyUser.Password;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #20
0
        protected override async ETTask Run(Session session, C2R_Login request, R2C_Login response, Action reply)
        {
            //数据库操作对象
            DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

            //验证账号密码是否正确
            List <ComponentWithId> result =
                await dbProxy.Query <AccountInfo>(_account => _account.Account == request.Account && _account.Password == request.Password);

            if (result.Count == 0)
            {
                //给测试场景开个后门
                if (request.Account == "Test123" && request.Password == "Test123")
                {
                    C2R_RegisterHandler.CreateUser(request.Account, request.Password).Coroutine();
                    result = await dbProxy.Query <AccountInfo>(
                        _account => _account.Account == request.Account && _account.Password == request.Password);
                }
                else
                {
                    response.Error = ErrorCode.ERR_LoginError;
                    reply();
                    return;
                }
            }

            // 随机分配一个Gate(内部)
            StartConfig config       = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
            IPEndPoint  innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
            Session     gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

            // 向gate请求一个key,客户端可以拿着这个key连接gate,20秒失效
            G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
            {
                playerID = result[0].Id
            });

            string outerAddress = config.GetComponent <OuterConfig>().Address2;

            response.Address  = outerAddress;
            response.Key      = g2RGetLoginKey.Key;
            response.PlayerId = result[0].Id;
            reply();
        }
Пример #21
0
        /// <summary>
        /// 在初始化LocationProxyComponent组件时  会把位置服务器的IP地址读取出来 保存在LocationAddress中
        /// </summary>
        /// <param name="self"></param>
        public static void Awake(this LocationProxyComponent self)
        {
            //获得启动配置
            StartConfigComponent startConfigComponent = StartConfigComponent.Instance;
            //拿到里面的位置服务器地址
            StartConfig startConfig = startConfigComponent.LocationConfig;

            //保存位置服务器的IP端口
            self.LocationAddress = startConfig.GetComponent <InnerConfig>().IPEndPoint;
        }
Пример #22
0
        protected override async void Run(Session session, C2R_RBLogin message, Action <R2C_RBLogin> reply)
        {
            R2C_RBLogin response = new R2C_RBLogin();

            try
            {
                //数据库操作对象
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                Log.Info($"登录请求:{{Account:'{message.Account}',Password:'******'}}");
                //验证账号密码是否正确
                var result = await dbProxy.Query <DB_Account>((p) => p.Account == message.Account);

                //查无此账号
                if (result.Count == 0)
                {
                    response.Error = ProtocolErrorCode.ERR_LoginError;
                    reply(response);
                    return;
                }

                //密码错误
                DB_Account account = result[0] as DB_Account;
                if (account.Password != message.Password)
                {
                    response.Error = ProtocolErrorCode.ERR_LoginError;
                    reply(response);
                    return;
                }

                Log.Info($"账号登录成功{MongoHelper.ToJson(account)}");

                //将已在线玩家踢下线
                await RealmHelper.KickOutPlayer(account.Id);

                //随机分配网关服务器
                StartConfig gateConfig  = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                Session     gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(gateConfig.GetComponent <InnerConfig>().IPEndPoint);

                //请求登录Gate服务器密匙
                G2R_RBGetLoginKey getLoginKey = await gateSession.Call(new R2G_RBGetLoginKey()
                {
                    userId = account.Id
                }) as G2R_RBGetLoginKey;

                response.Key     = getLoginKey.Key;
                response.Address = gateConfig.GetComponent <OuterConfig>().IPEndPoint2.ToString();
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #23
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                Console.WriteLine("userLogin:"******"key:" + message.Password);

                /*
                 * 账户密码验证
                 */
                int result = Game.Scene.GetComponent <MySqlComponent>().CheckPassWord(message.Account, message.Password);
                if (result == ErrorCode.ERR_Success)
                {
                    // 随机分配一个Gate
                    StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                    //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                    IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                    Console.WriteLine("userLogin:" + innerAddress);
                    Session gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                    // 向gate请求一个key,客户端可以拿着这个key连接gate
                    G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                    {
                        Account = message.Account
                    });

                    string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                }
                response.Error = result;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #24
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                string query = $"{"{"}'Account':'{message.Account}','Password':'******'{"}"}";
                Log.Info($"----{query}");
                List <AccountInfo> accounts = await Game.Scene.GetComponent <DBProxyComponent>().QueryJson <AccountInfo>(query);

                if (accounts.Count == 0)
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                string outerAddress = config.GetComponent <OuterConfig>().IPEndPoint2.ToString();

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #25
0
        protected override async void Run(Session session, LoginRt message, Action <LoginRe> reply)
        {
            LoginRe response = new LoginRe();

            try
            {
                Log.Info($"Session请求登录 账号:{message.Account} 密码:{message.Password}");
                //数据库操作对象
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                //验证账号密码是否正确
                List <AccountInfo> result = await dbProxy.QueryJson <AccountInfo>($"{"{'Account':'"}{message.Account}{"','Password':'******'}"}");

                if (result.Count == 0)
                {
                    response.Error = ErrorCode.ERR_AccountOrPasswordError;
                    reply(response);
                    return;
                }

                AccountInfo account = result[0];
                //验证账号是否在线
                if (Game.Scene.GetComponent <PlayerLoginManagerComponent>().Get(account.Id) != 0)
                {
                    response.Error = ErrorCode.ErrAccountOnline;
                    reply(response);
                    return;
                }

                //随机分配网关服务器
                StartConfig gateConfig  = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                Session     gateSession = Game.Scene.GetComponent <NetInnerComponent>().Get(gateConfig.GetComponent <InnerConfig>().IPEndPoint);

                //请求登录Gate服务器密匙
                GetLoginKeyRe getLoginKeyRE = await gateSession.Call <GetLoginKeyRe>(new GetLoginKeyRt()
                {
                    UserId = account.Id
                });

                //添加账号在线标记
                Game.Scene.GetComponent <PlayerLoginManagerComponent>().Add(account.Id, gateConfig.AppId);

                response.Key     = getLoginKeyRE.Key;
                response.Address = gateConfig.GetComponent <OuterConfig>().IPEndPoint.Address.ToString();
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #26
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                Account ret = await CheckAccount(message, response);

                if (ret == null)
                {
                    reply(response);

                    return;
                }

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);

                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    PhoneNum = ret.PhoneNum
                });

                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #27
0
        protected override async ETTask Run(Unit unit, Actor_TransferRequest message, Action <Actor_TransferResponse> reply)
        {
            Actor_TransferResponse response = new Actor_TransferResponse();

            try
            {
                long unitId = unit.Id;

                // 先在location锁住unit的地址
                await Game.Scene.GetComponent <LocationProxyComponent>().Lock(unitId, unit.InstanceId);

                // 删除unit,让其它进程发送过来的消息找不到actor,重发
                Game.EventSystem.Remove(unitId);

                long instanceId = unit.InstanceId;

                int mapIndex = message.MapIndex;

                StartConfigComponent startConfigComponent = StartConfigComponent.Instance;

                // 考虑AllServer情况
                if (startConfigComponent.Count == 1)
                {
                    mapIndex = 0;
                }

                // 传送到map
                StartConfig mapConfig = startConfigComponent.MapConfigs[mapIndex];
                IPEndPoint  address   = mapConfig.GetComponent <InnerConfig>().IPEndPoint;
                Session     session   = Game.Scene.GetComponent <NetInnerComponent>().Get(address);

                // 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
                Game.Scene.GetComponent <UnitComponent>().RemoveNoDispose(unitId);
                M2M_TrasferUnitResponse m2m_TrasferUnitResponse = (M2M_TrasferUnitResponse)await session.Call(new M2M_TrasferUnitRequest()
                {
                    Unit = unit
                });

                unit.Dispose();

                // 解锁unit的地址,并且更新unit的instanceId
                await Game.Scene.GetComponent <LocationProxyComponent>().UnLock(unitId, instanceId, m2m_TrasferUnitResponse.InstanceId);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #28
0
        private async ETVoid RunAsync(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            try
            {
                //if (message.Account != "abcdef" || message.Password != "111111")
                //{
                //	response.Error = ErrorCode.ERR_AccountOrPasswordError;
                //	reply(response);
                //	return;
                //}

                // 随机分配一个Gate
                StartConfig config = Game.Scene.GetComponent <RealmGateAddressComponent>().GetAddress();
                //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
                IPEndPoint innerAddress = config.GetComponent <InnerConfig>().IPEndPoint;
                Session    gateSession  = Game.Scene.GetComponent <NetInnerComponent>().Get(innerAddress);
                Log.Warning("请求Key+ " + session.Id);
                // 向gate请求一个key,客户端可以拿着这个key连接gate
                G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey()
                {
                    Account = message.Account
                });

                Log.Warning("返回Key+ " + session.Id);
                string outerAddress = config.GetComponent <OuterConfig>().Address2;

                response.Address = outerAddress;
                response.Key     = g2RGetLoginKey.Key;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        protected override async Task Run(Unit unit, Actor_TransferRequest message, Action <Actor_TransferResponse> reply)
        {
            Actor_TransferResponse response = new Actor_TransferResponse();

            try
            {
                long unitId = unit.Id;


                // 先在location锁住unit的地址
                await Game.Scene.GetComponent <LocationProxyComponent>().Lock(unitId);

                // 删除unit actorcomponent,让其它进程发送过来的消息找不到actor,重发
                unit.RemoveComponent <ActorComponent>();

                int mapIndex = message.MapIndex;

                StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();

                // 考虑AllServer情况
                if (startConfigComponent.Count == 1)
                {
                    mapIndex = 0;
                }

                // 传送到map
                StartConfig mapConfig = startConfigComponent.MapConfigs[mapIndex];
                string      address   = mapConfig.GetComponent <InnerConfig>().Address;
                Session     session   = Game.Scene.GetComponent <NetInnerComponent>().Get(address);

                // 只删除不disponse否则M2M_TrasferUnitRequest无法序列化Unit
                Game.Scene.GetComponent <UnitComponent>().RemoveNoDispose(unitId);
                await session.Call <M2M_TrasferUnitResponse>(new M2M_TrasferUnitRequest()
                {
                    Unit = unit
                });

                unit.Dispose();

                // 解锁unit的地址,并且更新unit的地址
                await Game.Scene.GetComponent <LocationProxyComponent>().UnLock(unitId, mapConfig.AppId);

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #30
0
        protected override void Run(Session session, M2A_Reload message, Action <A2M_Reload> reply)
        {
            A2M_Reload a2MReload = new A2M_Reload();

            try
            {
                ObjectManager.Instance.Register("Controller", DllHelper.GetController());
            }
            catch (Exception e)
            {
                a2MReload.Error = ErrorCode.ERR_ReloadFail;
                StartConfig myStartConfig = Game.Scene.GetComponent <StartConfigComponent>().MyConfig;
                InnerConfig innerConfig   = myStartConfig.GetComponent <InnerConfig>();
                a2MReload.Message = $"{innerConfig.Address} reload fail, {e}";
            }
            reply(a2MReload);
        }