Beispiel #1
0
    //连接失败处理
    private void NotifyDisconnected(TGCP_ERROR retError)
    {
        if (m_netState == NetState.Disconnected)
        {
            return;
        }
        Log.info("notifyDisconnected", "Net");
        Log.info("net will set net state: " + NetState.Disconnected);

        if (m_timeoutOperation != null)
        {
            m_timeoutOperation.cancel();
            m_timeoutOperation = null;
        }
        //后台主动断开
        DisConnect(false);
        this.OnDisConnectError(retError);

        EventManager.Send(EventType_Net.MSDK_AUTH_FAILED_TSS);
        //Log.info("send failed info to tss");
        //Log.info("Connect Failed! Error:" + retError);
    }
Beispiel #2
0
    //断开连接
    private void OnDisConnectError(TGCP_ERROR error)
    {
        Log.infoError("**NetConnect::OnDisConnectError::Code: " + error.ToString());
        //网络断开重置,心跳,避免干扰错误提示
        m_networkHeartBeat.OnDisConnected();

        if (_timerForReconnect != null)
        {
            _timerForReconnect.cancel();
        }

        switch (error)
        {
        case TGCP_ERROR.TGCP_ERR_AUTH_FAIL:
        case TGCP_ERROR.TGCP_ERR_NO_OPENID:
        case TGCP_ERROR.TGCP_ERR_NO_TOKEN:
        case TGCP_ERROR.TGCP_ERR_AUTH_REFRESH_FAIL:
        case TGCP_ERROR.TGCP_ERR_TOKEN_INVALID:
            if (connectRetryCount > currentRetryMaxTimes)
            {
                EventManager.Send(EventType_Net.NET_AUTH_FAILED, (int)error);
            }
            else
            {
                Log.info("重连前验证token有效性");
                //AuthenticationManager.IsPayTokenExpired(this.OnReconnect);
                EventManager.Send(EventType_Net.EVENT_CHECK_PAYTOKEN);
            }
            break;

        case TGCP_ERROR.TGCP_ERR_CONNECT_FAILED:
            //可能是网络闪断引起(无网络覆盖),可以适当增加重试频率同时放宽最大重试次数
            if (connectRetryCount > currentRetryMaxTimes * 2)
            {
                EventManager.Send(EventType_Net.NETWORK_STATE_DISCONNECTED);
                return;
            }
            Log.info("网络闪断,快速重连...count:" + connectRetryCount);
            connectRetryCount++;
            this.ReConnect();
            break;

#if UNITY_EDITOR
        case TGCP_ERROR.TGCP_ERR_PEER_CLOSED_CONNECTION:
        case TGCP_ERROR.TGCP_ERR_PEER_STOPPED_SESSION:
            EventManager.Send(EventType_Net.NET_SERVER_DISCONNECTED, error);
            break;
#else
        case TGCP_ERROR.TGCP_ERR_PEER_CLOSED_CONNECTION:
        case TGCP_ERROR.TGCP_ERR_PEER_STOPPED_SESSION:
#endif
        case TGCP_ERROR.TGCP_ERR_TIMEOUT:
        case TGCP_ERROR.TGCP_ERR_NETWORK_EXCEPTION:
        case TGCP_ERROR.TGCP_EVENT_TGCP_LONG_TIME_NOT_RECEIVE_PKG:
        case TGCP_ERROR.TGCP_EVENT_SOCKET_DISCONNECT:
        case TGCP_ERROR.TGCP_ERR_SERVER_IS_FULL:
            if (connectRetryCount > currentRetryMaxTimes)
            {    //弹窗Alert确认框,手动尝试重连。
                EventManager.Send(EventType_Net.NETWORK_STATE_DISCONNECTED);
            }
            else
            {
                EventManager.Send(EventType_Net.NET_DISCONNECTED);
                if (TGCP_ERROR.TGCP_ERR_TIMEOUT == error)
                {
                    EventManager.Send(EventType_Net.TGCP_ConnectTimeout);
                }
                _timerForReconnect = OperationManager.DoVoidFuncOnMainThread(this.OnReconnect, connTimeoutInterval / 2);
            }
            break;

        case TGCP_ERROR.TGCP_EVENT_SOCKET_ON_OPENID_IS_NULL_OR_EMPTY:
            //openid为空错误不处理
            break;

        default:
            //延迟一会再连
            _timerForReconnect = OperationManager.DoVoidFuncOnMainThread(OnReconnect, connTimeoutInterval);
            break;
        } //end switch
    }     //end OnDisConnectError