Esempio n. 1
0
        /// <summary>
        /// Start server with given port
        /// </summary>
        /// <param name="port"></param>
        public virtual void StartServer(int port)
        {
            socket.Listen(port);
            IsRunning = true;

            OnServerStartedEvent?.Invoke();

            if (lookForModules)
            {
                // Find modules
                var modules = lookInChildrenOnly ? GetComponentsInChildren <BaseServerModule>() : FindObjectsOfType <BaseServerModule>();

                // Add modules
                foreach (var module in modules)
                {
                    AddModule(module);
                }

                // Initialize modules
                InitializeModules();

                // Check and notify if some modules are not uninitialized
                var uninitializedModules = GetUninitializedModules();

                if (uninitializedModules.Count > 0)
                {
                    logger.Warn($"Some of the {GetType().Name} modules failed to initialize: \n{string.Join(" \n", uninitializedModules.Select(m => m.GetType().ToString()).ToArray())}");
                }
            }

            OnStartedServer();
        }
        /// <summary>
        /// When mirror server is started
        /// </summary>
        public override void OnStartServer()
        {
            base.OnStartServer();

            // Register handler to listen to player creation message
            NetworkServer.RegisterHandler <CreatePlayerMessage>(CreatePlayerRequestHandler, false);
            OnServerStartedEvent?.Invoke();
        }
 /// <summary>
 /// Start server with given port and ip
 /// </summary>
 /// <param name="listenToIp">IP который слшаем</param>
 /// <param name="listenToPort"></param>
 public virtual void StartServer(string listenToIp, int listenToPort)
 {
     socket.Listen(listenToIp, listenToPort);
     LookForModules();
     IsRunning = true;
     OnServerStartedEvent?.Invoke();
     OnStartedServer();
 }
Esempio n. 4
0
        /// <summary>
        /// Start server with given port and ip
        /// </summary>
        /// <param name="listenToIp">IP который слшаем</param>
        /// <param name="listenToPort"></param>
        public virtual void StartServer(string listenToIp, int listenToPort)
        {
            if (IsRunning)
            {
                return;
            }

            MstProperties startInfo = new MstProperties();

            startInfo.Add("\tFPS is", Application.targetFrameRate);
            startInfo.Add("\tApp key", socket.ApplicationKey);
            startInfo.Add("\tSecure", socket.UseSecure);
            startInfo.Add("\tCertificate Path", !socket.UseSecure ? "Undefined" : socket.CertificatePath);
            startInfo.Add("\tCertificate Pass", string.IsNullOrEmpty(socket.CertificatePath) || !socket.UseSecure ? "Undefined" : "********");

            logger.Info($"Starting Server...\n{startInfo.ToReadableString(";\n", " ")}");

            socket.Listen(listenToIp, listenToPort);
            LookForModules();
            IsRunning = true;
            OnServerStartedEvent?.Invoke();
            OnStartedServer();
        }
Esempio n. 5
0
        /// <summary>
        /// Start server with given port and ip
        /// </summary>
        /// <param name="listenToIp"></param>
        /// <param name="listenToPort"></param>
        public virtual void StartServer(string listenToIp, int listenToPort)
        {
            if (usePublicIp)
            {
                logger.Info("Trying to get public IP...");

                Msf.Helper.GetPublicIp((publicIp) =>
                {
                    socket.Listen(publicIp, listenToPort);
                    IsRunning = true;
                    OnServerStartedEvent?.Invoke();
                    LookForModules();
                    OnStartedServer();
                });
            }
            else
            {
                socket.Listen(listenToIp, listenToPort);
                IsRunning = true;
                OnServerStartedEvent?.Invoke();
                LookForModules();
                OnStartedServer();
            }
        }