コード例 #1
0
        /// <summary>
        /// 注册按钮事件
        /// </summary>
        public async void OnRegister()
        {
            if (isRegistering || this.IsDisposed)
            {
                return;
            }

            //设置登录中状态
            isRegistering = true;
            Session sessionWrap = null;

            prompt.text = "";
            try
            {
                //创建登录服务器连接
                IPEndPoint      connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                ETModel.Session session        = Game.Scene.ModelScene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);

                //发送注册请求
                prompt.text = "正在注册中....";
                R2C_Register_Ack r2C_Register_Ack = await sessionWrap.Call(new C2R_Register_Req()
                {
                    Account = account.text, Password = password.text
                }) as R2C_Register_Ack;

                prompt.text = "";

                if (this.IsDisposed)
                {
                    return;
                }

                if (r2C_Register_Ack.Error == ErrorCode.ERR_AccountAlreadyRegister)
                {
                    prompt.text   = "注册失败,账号已被注册";
                    account.text  = "";
                    password.text = "";
                    return;
                }

                //注册成功自动登录
                OnLogin();
            }
            catch (Exception e)
            {
                prompt.text = "注册异常";
                Log.Error(e.ToStr());
            }
            finally
            {
                //断开验证服务器的连接
                sessionWrap?.Dispose();
                //设置注册处理完成状态
                isRegistering = false;
            }
        }
コード例 #2
0
 private static void FinalRun()
 {
     Log.Info("注册按钮重新显示");
     //设置注册处理完成状态
     isRegistering = false;
     ((FUILogin)Game.Scene.GetComponent <FUIComponent>().Get(FUILogin.UIPackageName)).Btn_Registe.self
     .visible =
         true;
     //释放realmSession
     realmSession?.Dispose();
 }
コード例 #3
0
        public async void onClickGetPhoneCode()
        {
            if (inputField_Phone.text.CompareTo("") == 0)
            {
                ToastScript.createToast("请输入手机号");
                return;
            }

            if (!VerifyRuleUtil.CheckPhone(inputField_Phone.text))
            {
                ToastScript.createToast("请输入正确的手机号");
                return;
            }

            btn_yanzhengma.transform.localScale          = Vector3.zero;
            text_yanzhengmadaojishi.transform.localScale = new Vector3(1, 1, 1);

            UINetLoadingComponent.showNetLoading();

            Session sessionWrap = null;

            try
            {
                //IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                IPEndPoint      connetEndPoint = ToIPEndPointWithYuMing(NetConfig.getInstance().getServerPort());
                ETModel.Session session        = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);

                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);

                R2C_SendSms r2CData = (R2C_SendSms)await sessionWrap.Call(new C2R_SendSms()
                {
                    Phone = inputField_Phone.text
                });

                UINetLoadingComponent.closeNetLoading();

                if (r2CData.Error != ErrorCode.ERR_Success)
                {
                    ToastScript.createToast(r2CData.Message);
                }

                sessionWrap.Dispose();

                startPhoneCodeTimer();
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error(e);
            }
        }
コード例 #4
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();

            IsRun = false;

            _session?.Dispose();

            _session = null;
        }
コード例 #5
0
ファイル: UILoginComponent.cs プロジェクト: zcourage/ET
        public async ETVoid OnLoginAsync()
        {
            try
            {
                string text = this.account.GetComponent <InputField>().text;

                // 创建一个ETModel层的Session
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session   realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);
                R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = text, Password = "******"
                });

                realmSession.Dispose();

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);

                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                Log.Info("登陆gate成功!");

                // 创建Player
                Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();
                playerComponent.MyPlayer = player;

                Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);

                // 测试消息有成员是class类型
                G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #6
0
        protected override async void Run(Session session, C2R_Login message, Action <R2C_Login> reply)
        {
            R2C_Login response = new R2C_Login();

            Log.Info($"请求realmsession");
            try
            {
                if (message.Account == "admin" && message.Password == "jinyou123")
                {
                    response.Message = Game.Scene.GetComponent <NetOuterComponent>().sessions.Count + "";
                    reply(response);
                }
                else
                {
                    response.Message = "账号错误";
                    reply(response);
                }
//			    DBProxyComponent proxyComponent = Game.Scene.GetComponent<DBProxyComponent>();
//			    List<AccountInfo> accountInfos = await proxyComponent.QueryJson<AccountInfo>($"{{Account:'{message.Account}',Password:'******'}}");
//			    if (accountInfos.Count == 0)
//			    {
//			        response.Message = "账号或密码错误";
//			        response.Error = ErrorCode.ERR_AccountOrPasswordError;
//			        reply(response);
//			        return;
//			    }
//
//                AccountInfo accountInfo = accountInfos[0];
//
//			    // 随机分配一个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() {UserId = accountInfo.Id});
//
//				string outerAddress = config.GetComponent<OuterConfig>().IPEndPoint2.ToString();
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }

            session.Dispose();
        }
コード例 #7
0
        public static async ETVoid OnLoginAsync(string account, string password)
        {
            try
            {
                // 创建一个ETModel层的Session
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session   realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);
                R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = account, Password = password
                });

                realmSession.Dispose();

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);

                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                Log.Info("登陆gate成功!");

                // 创建Player
                Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();
                playerComponent.MyPlayer = player;

                Game.EventSystem.Run(EventIdType.LoginFinish);
                Game.EventSystem.Run(EventIdType.Init_UI_Lobby);

                // 测试消息有成员是class类型
                G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #8
0
        public static async void onClickChangeAccount()
        {
            Session sessionWrap = null;

            try
            {
                //IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);

                IPEndPoint      connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing();
                ETModel.Session session        = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);
                R2C_ChangeAccount r2CData = (R2C_ChangeAccount)await SessionComponent.Instance.Session.Call(new C2R_ChangeAccount()
                {
                    Uid = PlayerInfoComponent.Instance.uid
                });

                sessionWrap.Dispose();

                PlayerPrefs.SetString("Phone", "");
                PlayerPrefs.SetString("Token", "");

                Game.Scene.GetComponent <UIComponent>().RemoveAll();
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UILogin);
                //给android发送切换账号回调
                if ("qihoo360".Equals(PlatformHelper.GetChannelName()))
                {
                    PlatformHelper.setLogoutCallback("", "", "");
                }

                HeartBeat.getInstance().stopHeartBeat();
            }
            catch (Exception e)
            {
                PlayerPrefs.SetString("Phone", "");
                PlayerPrefs.SetString("Token", "");

                Game.Scene.GetComponent <UIComponent>().RemoveAll();
                Game.Scene.GetComponent <UIComponent>().Create(UIType.UILogin);

                HeartBeat.getInstance().stopHeartBeat();

                sessionWrap?.Dispose();
                Log.Error(e);
            }
        }
コード例 #9
0
        protected override async void Run(Session session, C2R_Register message, Action <R2C_Register> reply)
        {
            Log.Info(JsonHelper.ToJson(message));
            R2C_Register response = new R2C_Register();

            try
            {
                DBProxyComponent   proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <AccountInfo> accountInfos   = await proxyComponent.QueryJson <AccountInfo>($"{{Account:'{message.Account}'}}");

                if (accountInfos.Count > 0)
                {
                    response.Error   = ErrorCode.AccountExist;
                    response.Message = "用户名存在";
                    reply(response);
                    return;
                }
                AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                accountInfo.Account  = message.Account;
                accountInfo.Password = message.Password;
                await proxyComponent.Save(accountInfo);

                Stopwatch sw = new Stopwatch();
                sw.Start();
                List <AccountInfo> infos = await proxyComponent.QueryJsonCurrentDay <AccountInfo>();

                AccountInfo info = await proxyComponent.Query <AccountInfo>(accountInfo.Id);

                Log.Info($"根据id查询:{info.Account}");
                sw.Stop();
                Log.Info($"查询时间:{sw.ElapsedMilliseconds}");
                Log.Info($"当天的注册有:{infos.Count}");

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }

            session.Dispose();
        }
コード例 #10
0
ファイル: LogicHelper.cs プロジェクト: aoehuge/ET
        public static async ETVoid Login(string account)
        {
            // 创建一个ETModel层的Session
            ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);

            // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
            Session   realmSession = EntityFactory.Create <Session, ETModel.Session>(Game.Scene, session);
            R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
            {
                Account = account, Password = "******"
            });

            realmSession.Dispose();

            // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
            ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
            ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

            // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
            Game.Scene.AddComponent <SessionComponent>().Session = EntityFactory.Create <Session, ETModel.Session>(Game.Scene, gateSession);

            G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
            {
                Key = r2CLogin.Key
            });

            Log.Info("登陆gate成功!");

            // 创建Player
            Player          player          = ETModel.EntityFactory.CreateWithId <Player>(ETModel.Game.Scene, g2CLoginGate.PlayerId);
            PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();

            playerComponent.MyPlayer = player;

            // 测试消息有成员是class类型
            G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());

            // 逻辑层不应该去调用UI,逻辑层只关心逻辑并且抛出事件,由UI层自己去订阅事件,而且注意事件名字
            // 很多人容易把这个事件取名成LoginFinishiCreateLobbyUI,这是不对的,事件抛出去不可能知道谁订阅了这个事件,
            // 也不会知道别人订阅这个事件是干什么的,这里只知道我Login Finish
            Game.EventSystem.Run(EventIdType.LoginFinish);
        }
コード例 #11
0
        //不懂TODO
        public static async ETVoid OnTestCall()
        {
            try
            {
                // 创建一个ETModel层的Session
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session      realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);
                R2C_TestCall r2CTestCall  = (R2C_TestCall)await realmSession.Call(new C2R_TestCall());

                realmSession.Dispose();

                //处理回调
                Log.Debug($"Error={r2CTestCall.Error},消息是={r2CTestCall.Message}");
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #12
0
ファイル: Actor_LoginHelper.cs プロジェクト: 510264505/ETCow
        /// <summary>
        /// 登陆
        /// </summary>
        public static async ETVoid OnLoginAsync(string account, string password)
        {
            ETModel.Session session       = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
            Session         realm_session = ComponentFactory.Create <Session, ETModel.Session>(session);
            //给登陆服务器发送登陆
            R2C_CowCowLogin r2cLogin = (R2C_CowCowLogin)await realm_session.Call(new C2R_CowCowLogin()
            {
                Account = account, Password = password
            });

            realm_session.Dispose();
            //将与消息服务器的链接session加入到SessionComponent组件
            if (r2cLogin.Error == ErrorCode.ERR_LoginError)
            {
                Log.Debug($"登录错误:{r2cLogin.Message}");
                PopupsHelper.ShowPopups($"登录错误:{r2cLogin.Message}");
                return;
            }
            Log.Debug("地址" + r2cLogin.Address);
            await LoginAsync(r2cLogin.Address, r2cLogin.Key);
        }
コード例 #13
0
        private async void OnClickPressTest()
        {
            Session sessionWrap = null;

            try
            {
                //IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                IPEndPoint      connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.4.158:10006");
                ETModel.Session session        = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);

                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);

                G2C_PressTest g2C_PressTest = (G2C_PressTest)await sessionWrap.Call(new C2G_PressTest());

                UINetLoadingComponent.closeNetLoading();

                sessionWrap.Dispose();
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error(e);
            }
        }
コード例 #14
0
        public static async ETVoid OnLoginAsync(string account, string password)
        {
            try
            {
                // 显示加载UI
                ETModel.Game.EventSystem.Run(ETModel.EventIdType.ShowLoadingUI);
                // 如果正在登录,就驳回登录请求,为了双重保险,点下登录按钮后,收到服务端响应之前将不能再点击
                if (isLogining)
                {
                    FinalRun();
                    return;
                }

                isLogining = true;

                if (account == "" || password == "")
                {
                    Game.EventSystem.Run(EventIdType.ShowLoginInfo, "账号或密码不能为空");
                    FinalRun();
                    return;
                }

                // 创建一个ETModel层的Session
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>()
                                          .Create(GlobalConfigComponent.Instance.GlobalProto.Address);
                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);

                Game.EventSystem.Run(EventIdType.ShowLoginInfo, "登陆中。。。");
                // 发送登录请求,账号,密码均为传来的参数
                R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = account, Password = password
                });

                if (r2CLogin.Error == ErrorCode.ERR_LoginError)
                {
                    Game.EventSystem.Run(EventIdType.ShowLoginInfo, "登录失败,账号或密码错误");
                    FinalRun();
                    return;
                }

                //释放realmSession
                realmSession.Dispose();

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);

                // 增加客户端断线处理组件
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <SessionOfflineComponent>();

                // 增加心跳组件
                ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session.AddComponent <HeartBeatComponent>();

                await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                Game.EventSystem.Run(EventIdType.ShowLoginInfo, "登录成功");

                // 创建Player(抽象化的玩家),这里的id是数据库里的账号id
                Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(r2CLogin.PlayerId);
                PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();
                playerComponent.MyPlayer = player;

                // 登录完成
                Game.EventSystem.Run(EventIdType.LoginFinish);

                // 测试消息有成员是class类型
                // G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo) await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());
                // Debug.Log("测试玩家信息为" + g2CPlayerInfo.Message);
                FinalRun();
            }
            catch (Exception e)
            {
                Log.Error(e);
                FinalRun();
            }
        }
コード例 #15
0
        public async void OnLogin()
        {
            try
            {
                //
                IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);


                // 创建一个ETModel层的Session
                ETModel.Session session      = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                Session         realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);

                /*
                 * 请求登录
                 */
                R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account  = this.account.GetComponent <InputField>().text,
                    Password = this.password.GetComponent <InputField>().text
                }
                                                                        );

                realmSession.Dispose();

                /*
                 * 处理登录结果
                 */
                if (r2CLogin.Error == ErrorCode.ERR_Success)
                {
                    connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
                    // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中"111.230.133.20:10002"
                    ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                    ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                    // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                    Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);

                    G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                    {
                        Key = r2CLogin.Key
                    });

                    Log.Info("登陆gate成功!");

                    // 创建Player
                    Player          player          = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId);
                    PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();
                    playerComponent.MyPlayer = player;

                    Game.Scene.GetComponent <UIComponent>().Create(UIType.UILobby);
                    Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
                }
                else if (r2CLogin.Error == ErrorCode.ERR_AccountInvaild)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("账号中有不法字符~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_PasswordInvaild)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("密码中有不法字符~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_PasswordIncorrect)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("密码不正确~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_AccountNotExist)
                {
                    UIAlertsGrayComponent l = Game.Scene.GetComponent <UIAlertsGrayComponent>();
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("账号不存在~", onAlertCbLoginFail, "好的~");
                }
                else if (r2CLogin.Error == ErrorCode.ERR_DataBaseRead)
                {
                    Game.Scene.GetComponent <UIAlertsGrayComponent>().CreateAlertWin("网络异常~", onAlertCbLoginFail, "好的~");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #16
0
        public async Task OnThirdLogin(string third_id, string name, string head)
        {
            //加锁
            if (isLogining)
            {
                return;
            }
            isLogining = true;

            Session sessionWrap = null;

            try
            {
                UINetLoadingComponent.showNetLoading();

                // IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                IPEndPoint connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing();
#if Localhost
                connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.5.74:10002");
#endif
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);

                name = name.Replace("'", "*");
                R2C_ThirdLogin r2CLogin = (R2C_ThirdLogin)await sessionWrap.Call(new C2R_ThirdLogin()
                {
                    Third_Id = third_id, MachineId = PlatformHelper.GetMacId(), ChannelName = PlatformHelper.GetChannelName(), ClientVersion = PlatformHelper.GetVersionName(), Name = name, Head = head
                });

                sessionWrap.Dispose();

                UINetLoadingComponent.closeNetLoading();

                if (r2CLogin.Error != ErrorCode.ERR_Success)
                {
                    ToastScript.createToast(r2CLogin.Message);
                    return;
                }

                UINetLoadingComponent.showNetLoading();

                // connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
//                connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing();
                string[] temp = r2CLogin.Address.Split(':');
                connetEndPoint = ToIPEndPointWithYuMing(Convert.ToInt32(temp[1]));

                // connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);

#if Localhost
                connetEndPoint = NetworkHelper.ToIPEndPoint("10.224.5.74:10002");
#endif

                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                Game.Scene.GetComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(session);
                ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session = gateSession;

                // Log.Info("gateSession:"+ connetEndPoint.ToString());
                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                ToastScript.createToast("登录成功");
                //挂心跳包
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <HeartBeatComponent>();
                UINetLoadingComponent.closeNetLoading();

                await getAllData();

                isLoginSuccess = true;

                Game.Scene.GetComponent <PlayerInfoComponent>().uid = g2CLoginGate.Uid;

                PlayerInfoComponent.Instance.SetShopInfoList(g2CLoginGate.ShopInfoList);
                PlayerInfoComponent.Instance.SetBagInfoList(g2CLoginGate.BagList);
                PlayerInfoComponent.Instance.ownIcon = g2CLoginGate.ownIcon;

                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIMain);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
                isLogining = false;
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error("OnThirdLogin:" + e);
                isLogining = false;
            }
        }
コード例 #17
0
        public async Task OnLoginPhone(string phone, string code, string token)
        {
            Session sessionWrap = null;

            try
            {
                UINetLoadingComponent.showNetLoading();

                //IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);

                IPEndPoint      connetEndPoint = ToIPEndPointWithYuMing(NetConfig.getInstance().getServerPort());
                ETModel.Session session        = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);
                R2C_PhoneLogin r2CLogin = (R2C_PhoneLogin)await sessionWrap.Call(new C2R_PhoneLogin()
                {
                    Phone = phone, Code = code, Token = token, MachineId = PlatformHelper.GetMacId(), ChannelName = PlatformHelper.GetChannelName(), ClientVersion = PlatformHelper.GetVersionName()
                });

                //R2C_PhoneLogin r2CLogin = (R2C_PhoneLogin)await sessionWrap.Call(new C2R_PhoneLogin() { Phone = phone, Code = code, Token = token, MachineId = "1234", ChannelName = "jav", ClientVersion = "1.1.0" });
                sessionWrap.Dispose();

                UINetLoadingComponent.closeNetLoading();

                if (r2CLogin.Error != ErrorCode.ERR_Success)
                {
                    ToastScript.createToast(r2CLogin.Message);

                    if (r2CLogin.Error == ErrorCode.ERR_TokenError)
                    {
                        PlayerPrefs.SetString("Phone", "");
                        PlayerPrefs.SetString("Token", "");

                        panel_phoneLogin.transform.localScale = new Vector3(1, 1, 1);
                    }

                    if (r2CLogin.Message.CompareTo("用户不存在") == 0)
                    {
                        panel_phoneLogin.transform.localScale = new Vector3(1, 1, 1);
                    }

                    return;
                }

                UINetLoadingComponent.showNetLoading();


                //connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address);
                //connetEndPoint = NetConfig.getInstance().ToIPEndPointWithYuMing();
                string[] temp = r2CLogin.Address.Split(':');
                connetEndPoint = ToIPEndPointWithYuMing(Convert.ToInt32(temp[1]));
                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint);
                Game.Scene.GetComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(session);
                ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session = gateSession;

                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key
                });

                UINetLoadingComponent.closeNetLoading();

                ToastScript.createToast("登录成功");
                //挂心跳包
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <HeartBeatComponent>();
                UINetLoadingComponent.closeNetLoading();
                await getAllData();

                isLoginSuccess = true;

                {
                    // 保存Phone
                    PlayerPrefs.SetString("Phone", phone);

                    // 保存Token
                    PlayerPrefs.SetString("Token", r2CLogin.Token);
                }

                Game.Scene.GetComponent <PlayerInfoComponent>().uid = g2CLoginGate.Uid;

                PlayerInfoComponent.Instance.SetShopInfoList(g2CLoginGate.ShopInfoList);
                PlayerInfoComponent.Instance.SetBagInfoList(g2CLoginGate.BagList);
                PlayerInfoComponent.Instance.ownIcon = g2CLoginGate.ownIcon;

                ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
                await resourcesComponent.LoadBundleAsync($"UIMain.unity3d");

                await resourcesComponent.LoadBundleAsync($"Image_Main.unity3d");

                Game.Scene.GetComponent <UIComponent>().Create(UIType.UIMain);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.UILogin);
            }
            catch (Exception e)
            {
                sessionWrap?.Dispose();
                Log.Error(e);
            }
        }
コード例 #18
0
        protected override async void Run(Session session, C2R_PhoneLogin message, Action <R2C_PhoneLogin> reply)
        {
            Log.Info(JsonHelper.ToJson(message));
            R2C_PhoneLogin response = new R2C_PhoneLogin();

            try
            {
                DBProxyComponent   proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <AccountInfo> accountInfos   = await proxyComponent.QueryJson <AccountInfo>($"{{Phone:'{message.Phone}'}}");

                // 用验证码登录
                if (message.Code.CompareTo("") != 0)
                {
                    // 先校验验证码
                    {
                        string str = HttpUtil.CheckSms("0", message.Phone, message.Code);
                        if (!CommonUtil.checkSmsCode(str))
                        {
                            response.Message = "验证码错误";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }
                    }
                    // 用户已存在,走登录流程
                    if (accountInfos.Count > 0)
                    {
                        AccountInfo accountInfo = accountInfos[0];

                        // 黑名单检测
                        if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                        {
                            response.Message = "您的账号存在异常,请联系客服处理。";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }

                        // 更新Token
                        accountInfo.Token = CommonUtil.getToken(message.Phone);
                        await proxyComponent.Save(accountInfo);

                        // 随机分配一个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 = accountInfo.Id
                        });

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

                        response.Address = outerAddress;
                        response.Key     = g2RGetLoginKey.Key;
                        response.Token   = accountInfo.Token;
                        reply(response);
                        // 登录日志
                        await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                    }
                    // 用户不存在,走注册流程
                    else
                    {
                        AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                        accountInfo.Phone         = message.Phone;
                        accountInfo.Token         = CommonUtil.getToken(message.Phone);
                        accountInfo.MachineId     = message.MachineId;
                        accountInfo.ChannelName   = message.ChannelName;
                        accountInfo.ClientVersion = message.ClientVersion;

                        await proxyComponent.Save(accountInfo);

                        // 添加用户信息
                        PlayerBaseInfo playerBaseInfo = await DBCommonUtil.addPlayerBaseInfo(accountInfo.Id, accountInfo.Phone, "", "");

                        // 随机分配一个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 = accountInfo.Id
                        });

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

                        response.Address = outerAddress;
                        response.Key     = g2RGetLoginKey.Key;
                        response.Token   = accountInfo.Token;
                        reply(response);
                        // 登录日志
                        await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                    }
                }
                // 用Token登录
                else if (message.Token.CompareTo("") != 0)
                {
                    if (accountInfos.Count > 0)
                    {
                        AccountInfo accountInfo = accountInfos[0];

                        // 黑名单检测
                        if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                        {
                            response.Message = "您的账号存在异常,请联系客服处理。";
                            response.Error   = ErrorCode.ERR_PhoneCodeError;
                            reply(response);
                            return;
                        }

                        if (accountInfo?.Token?.CompareTo(message.Token) == 0)
                        {
                            // 随机分配一个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 = accountInfo.Id
                            });

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

                            response.Address = outerAddress;
                            response.Key     = g2RGetLoginKey.Key;
                            response.Token   = accountInfo.Token;
                            reply(response);

                            // 登录日志
                            await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                        }
                        else
                        {
                            response.Message = "Token失效,请重新验证登录";
                            response.Error   = ErrorCode.ERR_TokenError;
                            reply(response);
                            return;
                        }
                    }
                    else
                    {
                        response.Message = "用户不存在";
                        response.Error   = ErrorCode.ERR_AccountNoExist;
                        reply(response);
                        return;
                    }
                }
                // 传的数据错误
                else
                {
                    response.Message = "请求参数缺失";
                    response.Error   = ErrorCode.ERR_ParamError;
                    reply(response);
                    return;
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
            session.Dispose();
        }
コード例 #19
0
        /// <summary>
        /// 普通账号游客登录
        /// </summary>
        /// <param name="account"></param>
        /// <param name="pwd"></param>
        /// <param name="isGuest"></param>
        /// <returns></returns>
        public static async Task <int> OnLoginAsync(string account, string pwd, bool isGuest = false)
        {
            int errcode = -1;

            try
            {
                // 创建一个ETModel层的Session
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);

                //向服务器申请了一个Key
                R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = account, Password = pwd
                });

                errcode = r2CLogin.Error;
                realmSession.Dispose();

                if (r2CLogin.Error != 0)
                {
                    if (isGuest && r2CLogin.Error == ErrorCode.ERR_AccountDoesnExist)
                    {
                        return(r2CLogin.Error);
                    }
                    Game.PopupComponent.ShowMessageBox(r2CLogin.Message);
                    return(r2CLogin.Error);
                }

                GamePrefs.SetUserId(r2CLogin.UserId);

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);

                //增加客户端断线处理组件
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <SessionOfflineComponent>();


                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
                {
                    Key = r2CLogin.Key, UserId = r2CLogin.UserId
                });

                errcode = g2CLoginGate.Error;
                if (g2CLoginGate.Error != 0)
                {
                    Game.PopupComponent.ShowMessageBox(g2CLoginGate.Message);

                    Game.Scene.GetComponent <SessionComponent>().Session.Dispose();
                    return(g2CLoginGate.Error);
                }

                if (Game.Scene.GetComponent <PingComponent>() == null)
                {
                    Game.Scene.AddComponent <PingComponent, long, Session, Action>(3000, Game.Scene.GetComponent <SessionComponent>().Session, null);
                }

                return(g2CLoginGate.Error);
            }
            catch (Exception e)
            {
                //                if (e.Message.Equals("ERR_AccountDoesnExist")) throw;
                Game.PopupComponent.ShowMessageBox(DataCenterComponent.Instance.tipInfo.NotConnectGateTip);
                Log.Error("无法连接到网关服务器: " + e.Message);
                return(errcode);
            }
        }
コード例 #20
0
        public async void Dispatch(Session session, ushort opcode, object message)
        {
            try
            {
                SessionHeartbeatComponent sessionHeartbeatComponent = session.GetComponent <SessionHeartbeatComponent>();
                SessionUserComponent      sessionUserComponent      = session.GetComponent <SessionUserComponent>();
                if (sessionHeartbeatComponent == null)
                {
                    session.Dispose();//心跳组件 没有 直接销毁
                    return;
                }
                sessionHeartbeatComponent.UpReceiveMessageDistance = 0;//重置上次收到消息的时间
                //如果没有挂载SessionUserComponent组件 需要判断一下是不是登陆消息
                if (sessionUserComponent == null)
                {
                    if (message.GetType() != typeof(C2G_GateLogin) && message.GetType() != typeof(C2R_CommonLogin))
                    {
                        session.Dispose();            //发其他 消息 却没有 SessionUserComponent 组件 绝对不走正常
                        return;
                    }
                }
                //如果收到 一秒收到的消息 大于规定的消息 就认定是DOSS攻击 直接销毁
                if (++sessionHeartbeatComponent.SecondTotalMessageNum >=
                    SessionHeartbeatComponent.DestroySeesiontSecondTotalNum)
                {
                    //断开连接
                    sessionHeartbeatComponent.DisposeSession();
                    //直接封号
                    //  UserHelp.StopSealOrRelieve(sessionUserComponent.UserId,true,"DOSS攻击封号"); //不要封号容易误封
                    return;
                }
                switch (message)
                {
                case IActorMessage irActorMessage:
                {
                    long sessionActorId = sessionUserComponent.GamerSessionActorId;
                    if (sessionActorId == 0)
                    {
                        return;
                    }
                    ActorMessageSender actorLocationSender = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(sessionActorId);
                    actorLocationSender.Send(irActorMessage);
                    return;
                }

                case IUserRequest iUserRequest:
                {
                    if (iUserRequest is IUserActorRequest userActorRequest)
                    {
                        userActorRequest.SessionActorId = session.Id;
                        userActorRequest.User           = sessionUserComponent.user;
                    }
                    if (iUserRequest is IAdministratorRequest administratorRequest)
                    {
                        if (!AdministratorHelp.VerifyAdministrator(administratorRequest))
                        {
                            //如果账号密码错误 直接返回 不如直接封号
                            return;
                        }
                    }
                    iUserRequest.UserId = sessionUserComponent.UserId;
                    AppType   appType       = (AppType)(1 << ((opcode - 10000) / 1000));
                    Session   serverSession = Game.Scene.GetComponent <NetInnerSessionComponent>().Get(appType);
                    int       rpcId         = iUserRequest.RpcId; // 这里要保存客户端的rpcId
                    IResponse response      = await serverSession.Call(iUserRequest);

                    response.RpcId = rpcId;
                    session.Reply(response);
                    return;
                }

                case C2G_Heartbeat c2GHeartbeat:
                    return;
                }
                Game.Scene.GetComponent <MessageDispatherComponent>().Handle(session, new MessageInfo(opcode, message));
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #21
0
        protected override async void Run(Session session, C2R_ThirdLogin message, Action <R2C_ThirdLogin> reply)
        {
            Log.Info("收到第三方登录");

            R2C_ThirdLogin response = new R2C_ThirdLogin();

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

                bool any = (await proxyComponent.Query <AccountInfo>(a => a.Third_Id == message.Third_Id && a.Token == "")).Any();

                List <AccountInfo> accountInfos = await proxyComponent.QueryJson <AccountInfo>($"{{Third_Id:'{message.Third_Id}'}}");

                // 用户已存在,走登录流程
                if (accountInfos.Count > 0)
                {
                    AccountInfo accountInfo = accountInfos[0];
                    // 黑名单检测
                    if (await DBCommonUtil.CheckIsInBlackList(accountInfo.Id, session))
                    {
                        response.Message = "您的账号存在异常,请联系客服处理。";
                        response.Error   = ErrorCode.ERR_PhoneCodeError;
                        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 = accountInfo.Id
                    });

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

//                    Log.Warning("Gate的ip:" + outerAddress);

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                    reply(response);

                    // 登录日志
                    await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                }
                // 用户不存在,走注册流程
                else
                {
                    AccountInfo accountInfo = ComponentFactory.CreateWithId <AccountInfo>(UidUtil.createUID());
                    accountInfo.Third_Id      = message.Third_Id;
                    accountInfo.MachineId     = message.MachineId;
                    accountInfo.ChannelName   = message.ChannelName;
                    accountInfo.ClientVersion = message.ClientVersion;

                    await proxyComponent.Save(accountInfo);

                    // 添加用户信息
                    PlayerBaseInfo playerBaseInfo = await DBCommonUtil.addPlayerBaseInfo(accountInfo.Id, "", message.Name, message.Head);

                    // 随机分配一个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 = accountInfo.Id
                    });

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

                    response.Address = outerAddress;
                    response.Key     = g2RGetLoginKey.Key;
                    reply(response);

                    // 登录日志
                    await DBCommonUtil.Log_Login(accountInfo.Id, session, message.ClientVersion);
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
            session.Dispose();
        }
コード例 #22
0
        protected override async void Run(Session session, C2G_PlayerInfo message, Action <G2C_PlayerInfo> reply)
        {
//            Log.Info(JsonHelper.ToJson(message));
            G2C_PlayerInfo response = new G2C_PlayerInfo();

            try
            {
                User user = session.GetComponent <SessionUserComponent>()?.User;

                if (user == null)
                {
                    response.Error = ErrorCode.ERR_Common;
                    reply(response);
                    session.Dispose();
                    return;
                }
                DBProxyComponent      proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                List <PlayerBaseInfo> playerInfo     = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{user.UserID}}}");

                List <OtherData> otherDatas = await proxyComponent.QueryJson <OtherData>($"{{UId:{user.UserID}}}");

                response.PlayerInfo = new PlayerInfo();
                int fKeyCount = await DBCommonUtil.GetUserFriendKeyNum(user.UserID);

                if (playerInfo != null)
                {
                    response.Message               = "数据库里已存在玩家的基本信息,返回玩家信息";
                    response.PlayerInfo.Name       = playerInfo[0].Name;
                    response.PlayerInfo.GoldNum    = playerInfo[0].GoldNum;
                    response.PlayerInfo.WingNum    = playerInfo[0].WingNum;
                    response.PlayerInfo.HuaFeiNum  = playerInfo[0].HuaFeiNum;
                    response.PlayerInfo.Icon       = playerInfo[0].Icon;
                    response.PlayerInfo.IsRealName = playerInfo[0].IsRealName;
                    AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(user.UserID);

                    response.PlayerInfo.Phone               = accountInfo.Phone;
                    response.PlayerInfo.PlayerSound         = playerInfo[0].PlayerSound;
                    response.PlayerInfo.RestChangeNameCount = playerInfo[0].RestChangeNameCount;
                    response.PlayerInfo.VipTime             = playerInfo[0].VipTime;
                    response.PlayerInfo.EmogiTime           = playerInfo[0].EmogiTime;
                    response.PlayerInfo.MaxHua              = playerInfo[0].MaxHua;
                    response.PlayerInfo.WinGameCount        = playerInfo[0].WinGameCount;
                    response.PlayerInfo.IsGiveFriendKey     = playerInfo[0].IsGiveFriendKey;
                    response.PlayerInfo.FriendKeyCount      = fKeyCount;
                    response.PlayerInfo.Score               = playerInfo[0].Score;
                    List <ChengjiuInfo> infos =
                        await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{user.UserID},TaskId:{102}}}");

                    if (infos.Count > 0)
                    {
                        response.PlayerInfo.TotalGameCount = infos[0].CurProgress;
                    }
                    if (otherDatas.Count > 0)
                    {
                        response.OwnIcon = otherDatas[0].OwnIcon;
                    }

                    // 今天是否签到过
                    {
                        List <DailySign> dailySigns = await proxyComponent.QueryJson <DailySign>($"{{CreateTime:/^{DateTime.Now.GetCurrentDay()}/,Uid:{user.UserID}}}");

                        if (dailySigns.Count == 0)
                        {
                            response.PlayerInfo.IsSign = false;
                        }
                        else
                        {
                            response.PlayerInfo.IsSign = true;
                        }
                    }

                    {
                        //端午节活动是否结束
//                        List<DuanwuDataBase> duanwuDataBases = await proxyComponent.QueryJson<DuanwuDataBase>($"{{UId:{user.UserID}}}");
//                        string curTime = CommonUtil.getCurTimeNormalFormat();
//                        if (string.CompareOrdinal(curTime, duanwuDataBases[0].EndTime) >= 0)
//                        {
//                            long goldNum = 0;
//                            if (duanwuDataBases[0].ZongziCount > 0)
//                            {
//                                goldNum = duanwuDataBases[0].ZongziCount * 100;
//                                duanwuDataBases[0].ZongziCount = 0;
//                                //添加邮件
//                                await DBCommonUtil.SendMail(user.UserID, "端午粽香", $"端午活动已结束,剩余粽子已转换为金币存入您的账号,兑换比例:一个粽子=100金币,您获得{goldNum}金币", $"1:{goldNum}");
//                                await proxyComponent.Save(duanwuDataBases[0]);
//                            }
//                        }
                    }

                    reply(response);
                    return;
                }

                response.Message    = "Account数据库里不存在该用户";
                response.PlayerInfo = null;
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
コード例 #23
0
        /// <summary>
        /// 登录按钮事件
        /// </summary>
        public async void OnLogin()
        {
            if (isLogining || this.IsDisposed)
            {
                return;
            }
            NetOuterComponent netOuterComponent = Game.Scene.ModelScene.GetComponent <NetOuterComponent>();

            //设置登录中状态
            isLogining = true;
            Session sessionWrap = null;

            try
            {
                //创建登录服务器连接
                IPEndPoint      connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address);
                ETModel.Session session        = netOuterComponent.Create(connetEndPoint);
                sessionWrap = ComponentFactory.Create <Session, ETModel.Session>(session);
                sessionWrap.session.GetComponent <SessionCallbackComponent>().DisposeCallback += s =>
                {
                    if (Game.Scene.GetComponent <UIComponent>()?.Get(UIType.LandlordsLogin) != null)
                    {
                        prompt.text = "连接失败";
                        isLogining  = false;
                    }
                };

                //发送登录请求
                prompt.text = "正在登录中....";
                R2C_Login_Ack r2C_Login_Ack = await sessionWrap.Call(new C2R_Login_Req()
                {
                    Account = account.text, Password = password.text
                }) as R2C_Login_Ack;

                prompt.text = "";

                if (this.IsDisposed)
                {
                    return;
                }

                if (r2C_Login_Ack.Error == ErrorCode.ERR_LoginError)
                {
                    prompt.text   = "登录失败,账号或密码错误";
                    password.text = "";
                    return;
                }

                //创建Gate服务器连接
                connetEndPoint = NetworkHelper.ToIPEndPoint(r2C_Login_Ack.Address);
                ETModel.Session gateSession = netOuterComponent.Create(connetEndPoint);
                Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);
                //SessionWeap添加连接断开组件,用于处理客户端连接断开
                Game.Scene.GetComponent <SessionComponent>().Session.AddComponent <SessionOfflineComponent>();
                Game.Scene.ModelScene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

                //登录Gate服务器
                G2C_LoginGate_Ack g2C_LoginGate_Ack = await SessionComponent.Instance.Session.Call(new C2G_LoginGate_Req()
                {
                    Key = r2C_Login_Ack.Key
                }) as G2C_LoginGate_Ack;

                if (g2C_LoginGate_Ack.Error == ErrorCode.ERR_ConnectGateKeyError)
                {
                    prompt.text   = "连接网关服务器超时";
                    password.text = "";
                    Game.Scene.GetComponent <SessionComponent>().Session.Dispose();
                    return;
                }

                Log.Info("登录成功");

                //保存本地玩家
                User user = ETModel.ComponentFactory.CreateWithId <User, long>(g2C_LoginGate_Ack.PlayerID, g2C_LoginGate_Ack.UserID);
                ClientComponent.Instance.LocalPlayer = user;

                //跳转到大厅界面
                Game.Scene.GetComponent <UIComponent>().Create(UIType.LandlordsLobby);
                Game.Scene.GetComponent <UIComponent>().Remove(UIType.LandlordsLogin);
            }
            catch (Exception e)
            {
                prompt.text = "登录异常";
                Log.Error(e.ToStr());
            }
            finally
            {
                //断开验证服务器的连接
                sessionWrap.Dispose();
                //设置登录处理完成状态
                isLogining = false;
            }
        }
コード例 #24
0
        //登陆并连接
        public async void LoginAndConnect(int loginType, string dataStr, bool isReconnection = false)
        {
            _UpLoginType    = loginType;
            _UpLoginDataStr = dataStr;
            if (_mStateManage.pKCPNetWorkState == KCPNetWorkState.BebeingConnect || _mStateManage.pKCPNetWorkState == KCPNetWorkState.Connect)
            {
                Log.Warning("正在连接 请不要重复连接 或已经成功连接");
            }
            try
            {
                _mStateManage.StartConnect();
                //根据是否重连 注册 连接成功 是连接失败的事件
                mSocketCantConnectCall = _mStateManage.ConnectFailure;                     //连接失败
                Action <G2C_GateLogin> connectSuccesAction = _mStateManage.ConnectSuccess; //连接成功
                //如果是重连 更改一下回调
                if (isReconnection)
                {
                    mSocketCantConnectCall = _mStateManage.AgainConnectFailure;
                    connectSuccesAction    = _mStateManage.AgainConnectSuccess;
                }
                Log.Debug("验证服地址:" + GameVersionsConfigMgr.Ins.ServerAddress);
                // 创建一个ETModel层的Session
                ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GameVersionsConfigMgr.Ins.ServerAddress);
                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);
                realmSession.session.GetComponent <SessionCallbackComponent>().DisposeCallback += RealmSessionDisposeCallback;
                //登陆验证服务器
                R2C_CommonLogin r2CLogin = (R2C_CommonLogin)await realmSession.Call(new C2R_CommonLogin()
                {
                    LoginType    = loginType,
                    PlatformType = HardwareInfos.pCurrentPlatform,
                    DataStr      = dataStr,
                });

                realmSession.Dispose();
                if (!string.IsNullOrEmpty(r2CLogin.Message))
                {
                    if (PlayerPrefs.HasKey(GlobalConstant.LoginVoucher))
                    {
                        PlayerPrefs.DeleteKey(GlobalConstant.LoginVoucher);                                                           //登陆失败的话 如果有凭证 就删除凭证
                    }
                    UIComponent.GetUiView <PopUpHintPanelComponent>().ShowOptionWindow(r2CLogin.Message, null, PopOptionType.Single); //显示提示
                    UIComponent.GetUiView <LoadingIconPanelComponent>().Hide();                                                       //隐藏圈圈
                    _mStateManage.pKCPNetWorkState = KCPNetWorkState.Disconnectl;                                                     //状态改为断开连接
                    Game.Scene.GetComponent <ToyGameComponent>().StartGame(ToyGameId.Login);                                          //进入登陆界面
                    return;
                }
                PlayerPrefs.SetString(GlobalConstant.LoginVoucher, r2CLogin.LoginVoucher);//记录登陆凭证
                //登陆网关服务器
                G2C_GateLogin g2CLoginGate = await ConnectGate(r2CLogin.Address, r2CLogin.Key, loginType);

                if (!string.IsNullOrEmpty(g2CLoginGate.Message))
                {
                    UIComponent.GetUiView <PopUpHintPanelComponent>().ShowOptionWindow(g2CLoginGate.Message, null, PopOptionType.Single);
                    UIComponent.GetUiView <LoadingIconPanelComponent>().Hide();   //隐藏圈圈
                    _mStateManage.pKCPNetWorkState = KCPNetWorkState.Disconnectl; //状态改为断开连接
                    return;
                }
                //发起连接成功事件
                connectSuccesAction(g2CLoginGate);
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }