Inheritance: UnityEngine.MonoBehaviour
コード例 #1
0
        public void StartServer()
        {
            m_log.Info("Start Server");
            // Where should this be checked?
            string controllerPath = "/" + m_options.controllerFilename;
            if (!HFTWebFileDB.GetInstance().FileExists(controllerPath))
            {
                throw new System.ArgumentException(
                    "\"Assets/WebPlayerTemplates/HappyFunTimes" + controllerPath + "\" does not exist. Did you forget to set \"controllerFilename\" in your \"PlayerSpawner\" or \"PlayerConnector\"?");
            }

            #if UNITY_STANDALONE_OSX
                // TODO make 2 classes, one for running internal server, one for external?
                if (m_options.startExternalServer)
                {
                    StartExternalServer(true);
                    return;
                }
            #endif

            List<string> addresses = new List<string>();
            addresses.Add("http://[::0]:18679");
            //            addresses.Add("http://0.0.0.0:18679");

            if (m_options.installationMode)
            {
                addresses.Add("http://[::0]:80");
            //                addresses.Add("http://0.0.0.0:80");
            }
            else
            {
                var hftOptions = new HFTSite.Options();
                //hftOptions.port = ??
                HFTUtil.SetIfNotNullOrEmpty(m_options.rendezvousUrl, ref hftOptions.rendezvousUrl);
                HFTUtil.SetIfNotNullOrEmpty(m_options.serverPort, ref hftOptions.port);
                m_hftSite = m_gameObject.AddComponent<HFTSite>();
                m_hftSite.Init(hftOptions);
            }

            string ipv4Address = String.IsNullOrEmpty(m_options.ipv4DnsAddress) ? HFTIpUtils.GetLocalIPv4Address() : m_options.ipv4DnsAddress;
            string ipv6Address = String.IsNullOrEmpty(m_options.ipv6DnsAddress) ? HFTIpUtils.GetLocalIPv6Address() : m_options.ipv6DnsAddress;

            m_webServer = new HFTWebServer(m_options, addresses.ToArray());
            m_webServer.Start();

            if (m_options.dns || m_options.installationMode)
            {
                m_dnsRunner = new HFTDnsRunner();
                m_dnsRunner.Start(ipv4Address, ipv6Address, 53);
            }
        }
コード例 #2
0
 public void StopServer()
 {
     CleanupCheck();
     if (m_webServerProcess != null)
     {
         m_webServerProcess.Kill();
     }
     if (m_hftSite != null)
     {
         m_hftSite.Stop();
         Component.Destroy(m_hftSite);
         m_hftSite = null;
     }
     if (m_webServer != null)
     {
         m_webServer.Stop();
         m_webServer = null;
     }
     if (m_dnsRunner != null)
     {
         m_dnsRunner.Stop();
         m_dnsRunner = null;
     }
 }