Exemplo n.º 1
0
    public override void enter()
    {
        Debug.Log("*********进入重登录状态*********");

        NetworkManager.GetInstance().onClear();

        switch (NetStateManager.GetInstance().loginState)
        {
        case LOGIN_STATE.STATE_NONE:
            break;

        case LOGIN_STATE.STATE_SAME_ACCOUNT:
            break;

        case LOGIN_STATE.STATE_SWITCH_ACCOUNT:
        {
            //Debug.LogWarning("切换帐号释放资源");
            onReset();
            GC.Collect();
        }
        break;

        case LOGIN_STATE.STATE_SWITCH_ACCOUNT_LOGIN:
        {
            NetStateManager.GetInstance().onReset();
        }
        break;
        }
        NetStateManager.GetInstance().loginState = LOGIN_STATE.STATE_NONE;
    }
Exemplo n.º 2
0
    void onReset()
    {
        TimerManager.GetInstance().StopAllTimer();

        Singleton <GameModel> .GetInstance().onClear();

        NetStateManager.GetInstance().onReset();
    }
Exemplo n.º 3
0
 void closeConnect()
 {
     if (null != timeOut)
     {
         timeOut.onDispose();
         timeOut = null;
     }
     NetworkManager.GetInstance().closeConnect();
     NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_NONE);
 }
Exemplo n.º 4
0
 void handleConnectSucc(EventObject e = null)
 {
     if (null != timeOut)
     {
         timeOut.onDispose();
         timeOut = null;
     }
     sendLogin();
     NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_RUN);
 }
Exemplo n.º 5
0
 void handleHeartBeat()
 {
     runTime += 10f;
     if (runTime >= 30)
     {
         //收到心跳时间间隔超过30S,进入断线重连状态
         NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_RECONNECT);
     }
     else
     {
         sendHeartBeat();
     }
 }
Exemplo n.º 6
0
 void onConnect()
 {
     //重连时间超出配置时间,停止重连,进入重登录状态
     if ((Time.realtimeSinceStartup - reConnectStartTime) >= reConnectTime)
     {
         NetStateManager.GetInstance().loginState = LOGIN_STATE.STATE_NONE;
         Debug.LogError("重连超时,重新登录!");
         NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_RELOGIN);
         return;
     }
     NetworkManager.GetInstance().closeConnect();
     startConnect();
 }
Exemplo n.º 7
0
    void handleToken(MemoryStream ms)
    {
        MessageResponseToken response = MessageResponseToken.Parser.ParseFrom(ms);

        if (response.ErrorId == 0)
        {
            //正常返回,进入运行状态
            NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_RUN);
        }
        else
        {
            Debug.LogError("收到错误Token,进入重登录");
            NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_CONNECT);
        }
    }
Exemplo n.º 8
0
    //发送Token校验
    void sendToken()
    {
        if (string.IsNullOrEmpty(Singleton <GameModel> .GetInstance().Token.Trim()))
        {
            Debug.LogError("Token为空,进入重登录");
            NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_RELOGIN);
            return;
        }
        MessageRequestToken token = new MessageRequestToken();

        token.Token = Singleton <GameModel> .GetInstance().Token.Trim();

        NetworkManager.GetInstance().SendMessageSync(MSG_CS.ReqTokenCheck, token);
        //这里还需要一个计时器,如果一定时间收不到token回复,则继续连接
        receiveTokenTimer = TimerManager.GetInstance().createTimer(5f, handleTokenFail);
    }
Exemplo n.º 9
0
 protected override void handleConnectFail(EventObject e)
 {
     base.handleConnectFail(e);
     NetStateManager.GetInstance().changeNetState(NET_STATE.STATE_RECONNECT);
 }