コード例 #1
0
        //连接成功
        private void ConnectSuccessEvent(G2C_GateLogin g2CGateLogin)
        {
            UIComponent.GetUiView <LoadingIconPanelComponent>().Hide();
            User user = g2CGateLogin.User;

            Game.Scene.GetComponent <UserComponent>().SetSelfUser(user);;
            Game.Scene.GetComponent <ToyGameComponent>().StartGame(ToyGameId.Lobby);
            SessionComponent.Instance.Session.AddComponent <HeartbeatComponent>();//添加心跳组件
        }
コード例 #2
0
        //连接网关
        public async ETTask <G2C_GateLogin> ConnectGate(string gateAddress, long key, int loginType)
        {
            try
            {
                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(gateAddress); //连接网关
                ETModel.Game.Scene.GetComponent <ETModel.SessionComponent>().Session = gateSession;
                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.GetComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);
                gateSession.GetComponent <SessionCallbackComponent>().DisposeCallback += GateSessionDisposeCallback;
                G2C_GateLogin g2CLoginGate = (G2C_GateLogin)await SessionComponent.Instance.Session.Call(new C2G_GateLogin()
                {
                    Key = key
                });

                Log.Debug(SessionComponent.Instance.Session.Id.ToString());
                return(g2CLoginGate);
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
        }
コード例 #3
0
 //重连成功
 public void AgainConnectSuccess(G2C_GateLogin g2CGateLogin)
 {
     Log.Debug("重连成功");
     pKCPNetWorkState = KCPNetWorkState.Connect;
     pAgainConnectSuccessCall?.Invoke(g2CGateLogin);
 }
コード例 #4
0
 //重连成功
 private void AgainConnectSuccessEvent(G2C_GateLogin g2CGateLogin)
 {
     UIComponent.GetUiView <LoadingIconPanelComponent>().Hide();
     SessionComponent.Instance.Session.AddComponent <HeartbeatComponent>();//添加心跳组件
 }
コード例 #5
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;
            }
        }