Example #1
0
    void StartCreat()
    {
        if (bIsLinkServer)
        {
            bIsLinkServer = false;
            if (FreeModeCtrl.IsServer)
            {
                FreeModeCtrl.CheckIsHavePlayerIp();
                //ScreenLog.Log("start create to server...");
                string passwordStr = "Movie";
                if (Application.loadedLevelName != GameLeve.Movie.ToString())
                {
                    passwordStr = "LinkGame";
                }

                NetworkConnectionError error = NetworkConnectionError.CreateSocketOrThreadFailure;
                if (NetCtrlScript == null || (NetCtrlScript != null && NetCtrlScript.IsServerPort))
                {
                    error = Network.InitializeServer(30, port, true);
                    Network.incomingPassword = passwordStr;
                }

                ScreenLog.Log("NetworkServerNet -> current level is " + Application.loadedLevelName
                              + ", password " + passwordStr);
                //ScreenLog.Log("creat server: info is " + error);
                if (error.ToString() != "NoError")
                {
                    bIsLinkServer = true;
                }
            }
            else if (!FreeModeCtrl.IsServer)
            {
                if (Application.loadedLevel < (int)GameLeve.Leve3)
                {
                    TimeLinkServer += Time.deltaTime;
                    if (TimeLinkServer < 3.0f)
                    {
                        bIsLinkServer = true;
                        return;
                    }
                    TimeLinkServer = 0.0f;
                }
                FreeModeCtrl.CheckIsHavePlayerIp();

                if (NetCtrlScript == null || (NetCtrlScript != null && NetCtrlScript.GetIsConnectServer()))
                {
                    string passwordStr = "Movie";
                    if (Application.loadedLevelName != GameLeve.Movie.ToString())
                    {
                        passwordStr = "LinkGame";
                    }
                    ScreenLog.Log("start connect to server -> current level is " + Application.loadedLevelName
                                  + ", password " + passwordStr + ", connectIp " + ip);
                    Network.Connect(ip, port, passwordStr);
                }
            }
        }
    }