hch
2025-11-20 ed98029a88cd89702980ac7c40b711afddc5aeb2
Main/Core/NetworkPackage/GameNetSystem.cs
@@ -6,6 +6,10 @@
public class GameNetSystem : Singleton<GameNetSystem>
{
    //限制客户端的下一个包是登录包C0101_tagCPlayerLogin,如果不是登录包不允许发送
    bool waitLogin = false; //等待发送登录包,如果有其他包直接屏蔽,避免断线重连的情况发了攻击包之类的
    //等待服务端0403的包后才能发其他的功能包,只有C0123_tagCClientPackVersion 和 C0101_tagCPlayerLogin 可以发送
    bool waitLoginMap = false;
    NetUpdateBehaviour m_NetUpdateBehaviour;
    NeverConnectState neverConnectState;
    AccountLoginState accountLoginState;
@@ -85,8 +89,8 @@
    public GameNetSystem()
    {
        var gameObject = new GameObject("NetUpdateBehaviour");
        GameObject.DontDestroyOnLoad(gameObject);
        m_NetUpdateBehaviour = gameObject.AddComponent<NetUpdateBehaviour>();
        GameObject.DontDestroyOnLoad(gameObject);
        m_NetUpdateBehaviour = gameObject.AddComponent<NetUpdateBehaviour>();
        m_NetUpdateBehaviour.RegisterUpdateCallBack(OnUpdate);
        neverConnectState = gameObject.AddComponent<NeverConnectState>();
@@ -125,8 +129,38 @@
        });
    }
    //限制客户端的下一个包是登录包C0101_tagCPlayerLogin,如果不是登录包不允许发送
    public void SetIsWaitLogin(bool _wait)
    {
        waitLogin = _wait;
    }
    //等待服务端0403的包后才能发其他的功能包,只有C0123_tagCClientPackVersion 和 C0101_tagCPlayerLogin 可以发送
    public void SetIsWaitLoginMap(bool _wait)
    {
        waitLoginMap = _wait;
    }
    public void SendInfo(GameNetPackBasic protocol)
    {
        if (waitLogin)
        {
            if (protocol is not C0101_tagCPlayerLogin)
            {
                Debug.LogWarning("等待执行登录,不允许发送其他包 " + protocol.ToString());
                return;
            }
        }
        if (waitLoginMap)
        {
            if (protocol is not C0123_tagCClientPackVersion && protocol is not C0101_tagCPlayerLogin)
            {
                Debug.LogWarning("等待0403包,不允许发送其他包 " + protocol.ToString());
                return;
            }
        }
        if (mainSocket != null)
        {
            mainSocket.SendInfo(protocol);
@@ -183,8 +217,7 @@
        finally
        {
            netState = NetState.DisConnected;
            // var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
            // loginModel.busy = false;
            LoginManager.Instance.busy = false;
        }
    }
@@ -208,21 +241,16 @@
        finally
        {
            netState = NetState.AccountLogin;
            // var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
            // loginModel.busy = false;
            // loginModel.ReAccountLogin();
            LoginManager.Instance.busy = false;
            LoginManager.Instance.ReAccountLogin();
        }
    }
    public void LoginOut()
    {
        // if (CameraController.Instance != null)
        //     CameraController.Instance.SetInGame(false);
        // DTC0102_tagCDBPlayer.isAfterPlayerDataInitialize = false;
        try
        {
            // ynmbxxjUtil.Instance.RoleLoginOut();
            SDKUtils.Instance.RoleLoginOut();
            if (mainSocket != null)
            {
@@ -238,31 +266,11 @@
        finally
        {
            netState = NetState.NerverConnect;
            // TODO YYL
            // var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
            // loginModel.busy = false;
            LoginManager.Instance.busy = false;
            // StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand()
            // {
            //     toMapId = 1,
            //     toLineId = 0,
            //     needEmpty = false,
            //     needLoadResource = true,
            //     serverType = ServerType.Main,
            //     isClientLoadMap = true
            // });
            // //CameraManager.uiCamera.clearFlags = CameraClearFlags.SolidColor;
            // //GameObject obj = GameObject.Find("NormalCanvas");
            // //int count = obj.transform.childCount;
            // //for (int i = count - 1; i >= 0; --i)
            // //{
            // //    //Debug.LogError(obj.transform.GetChild(i).name);
            // //    GameObject.Destroy(obj.transform.GetChild(i).gameObject);
            // //}
            // //SceneManager.LoadScene("Empty");
            StageManager.Instance.ReturnToLoginScene();
            NetLinkWin.Hide();
            // DTC0403_tagPlayerLoginLoadOK.neverLoginOk = true;
        }
    }
@@ -308,4 +316,6 @@
public enum ServerType
{
    Main = 1,
    B430 = 2,
    MainFight = 3,
}