Esempio n. 1
0
        /// <summary>
        /// Signal a stop request.
        /// </summary>
        protected override void OnStop()
        {
            //
            // Mark stop requested (in case stop is requested before the
            // service has completed initialization).
            //

            Logger.Log(LogLevel.Normal, "ServiceController.OnStop(): Service stop requested.");

            StopRequested = true;

            //
            // If the server object exists, then inform it that it should begin
            // to shut down.
            //

            NWMasterServer ServerObject = Server;

            if (ServerObject != null)
            {
                ServerObject.Stop();
            }

            if (ServiceMainThread != null)
            {
                ServiceMainThread.Join();
                ServiceMainThread = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Execute the server program.
        /// </summary>
        /// <param name="args">Supplies arguments from the SCM.</param>
        protected override void OnStart(string[] args)
        {
            //
            // Spin up the server object.  Once the constructor has finished,
            // the object is ready to receive stop requests at any time.
            //

            try
            {
                NWMasterServer ServerObject = new NWMasterServer(this);

                Thread.MemoryBarrier();

                Server = ServerObject;

                if (StopRequested)
                {
                    Server.Stop();
                }

                ServiceMainThread = new Thread(ServiceMain);
                ServiceMainThread.Start();
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, "ServiceController.OnStart(): Exception: {0}", e);
            }
        }
Esempio n. 3
0
        public NWGameServer(NWMasterServer MasterServer, IPEndPoint ServerAddress)
        {
            Timer HbTimer;

            this.MasterServer     = MasterServer;
            this.Address          = ServerAddress;
            this.InitialHeartbeat = false;

            HbTimer = new Timer(HEARTBEAT_INTERVAL + (Rng.Next() % HEARTBEAT_JITTER));

            HbTimer.AutoReset = false;
            HbTimer.Elapsed  += new ElapsedEventHandler(HeartbeatTimer_Elapsed);

            this.HeartbeatTimer = HbTimer;
        }
Esempio n. 4
0
        /// <summary>
        /// Instantiate a server tracker instance.  The list of currently
        /// known servers is retrieved from the database, but heartbeats are
        /// not yet enabled as the I/O subsystem is not yet online.
        /// </summary>
        /// <param name="MasterServer">Supplies the underlying associated
        /// master server instance.</param>
        public NWServerTracker(NWMasterServer MasterServer)
        {
            this.MasterServer = MasterServer;

            PendingGameServersSweepTimer           = new System.Timers.Timer(PENDING_GAME_SERVER_SWEEP_INTERVAL);
            PendingGameServersSweepTimer.AutoReset = false;
            PendingGameServersSweepTimer.Elapsed  += new System.Timers.ElapsedEventHandler(PendingGameServersSweepTimer_Elapsed);

            ScavengerSweepTimer           = new System.Timers.Timer(SCAVENGE_SWEEP_INTERVAL);
            ScavengerSweepTimer.AutoReset = false;
            ScavengerSweepTimer.Elapsed  += new System.Timers.ElapsedEventHandler(ScavengerSweepTimer_Elapsed);

            BlacklistSweepTimer           = new System.Timers.Timer(BLACKLIST_SWEEP_INTERVAL);
            BlacklistSweepTimer.AutoReset = false;
            BlacklistSweepTimer.Elapsed  += new System.Timers.ElapsedEventHandler(BlacklistSweepTimer_Elapsed);

            InitializeDatabase();
        }
Esempio n. 5
0
        /// <summary>
        /// Execute the program.
        /// </summary>
        /// <param name="args">Supplies arguments.  The only valid argument is
        /// the -service argument, which directs the program to attempt to
        /// connect to the SCM for service-mode startup; otherwise, the program
        /// executes as a console application.</param>
        static void Main(string[] args)
        {
            //
            // Scan and process arguments.
            //

            for (int i = 0; i < args.Length; i += 1)
            {
                string Arg = args[i];

                if (Arg == "-service")
                {
                    //
                    // Execute the server in service mode.  This method returns
                    // once service stop has been requested and the server has
                    // shut down.
                    //

                    string ServiceName = "NWMasterServerSvc";

                    if ((i + 1) < args.Length)
                    {
                        i          += 1;
                        ServiceName = args[i];
                    }

                    ServiceController.ExecuteService(ServiceName);
                    return;
                }
            }

            //
            // Execute the server as an interactive, console application.
            //

            NWMasterServer ServerObject = new NWMasterServer(null);

            ServerObject.Run();
        }