Пример #1
0
        public void Initialize(NetWorker networker, string masterServerHost = "", ushort masterServerPort = 15940, JSONNode masterServerRegisterData = null)
        {
            Networker = networker;
            Networker.binaryMessageReceived += ReadBinary;

            UnityObjectMapper.Instance.UseAsDefault();
            NetworkObject.Factory = new NetworkObjectFactory();

            if (Networker is IServer)
            {
                if (!string.IsNullOrEmpty(masterServerHost))
                {
                    RegisterOnMasterServer(networker.Port, networker.MaxConnections, masterServerHost, masterServerPort, masterServerRegisterData);
                }

                Networker.playerAccepted += PlayerAcceptedSceneSetup;

#if FN_WEBSERVER
                string pathToFiles = "fnwww/html";
                Dictionary <string, string> pages = new Dictionary <string, string>();
                TextAsset[] assets = Resources.LoadAll <TextAsset>(pathToFiles);
                foreach (TextAsset a in assets)
                {
                    pages.Add(a.name, a.text);
                }

                webserver = new MVCWebServer.ForgeWebServer(networker, pages);
                webserver.Start();
#endif
            }
        }
Пример #2
0
        public virtual void Initialize(NetWorker networker, string masterServerHost = "", ushort masterServerPort = 15940, JSONNode masterServerRegisterData = null)
        {
            Networker = networker;
            networker.objectCreated         += CreatePendingObjects;
            Networker.binaryMessageReceived += ReadBinary;
            SetupObjectCreatedEvent();

            UnityObjectMapper.Instance.UseAsDefault();
            NetworkObject.Factory = new NetworkObjectFactory();

            if (Networker is IServer)
            {
                if (Settings.enableSQP)
                {
                    sqpServer = new SQPServer(Settings.SQPPort);
                }

                if (!string.IsNullOrEmpty(masterServerHost))
                {
                    _masterServerHost = masterServerHost;
                    _masterServerPort = masterServerPort;

                    RegisterOnMasterServer(masterServerRegisterData);
                }

                Networker.playerAccepted += PlayerAcceptedSceneSetup;

#if FN_WEBSERVER
                string pathToFiles = "fnwww/html";
                Dictionary <string, string> pages = new Dictionary <string, string>();
                TextAsset[] assets = Resources.LoadAll <TextAsset>(pathToFiles);
                foreach (TextAsset a in assets)
                {
                    pages.Add(a.name, a.text);
                }

                webserver = new MVCWebServer.ForgeWebServer(networker, pages);
                webserver.Start();
#endif
            }

            initialized = true;
        }