示例#1
0
        /// <summary>
        /// Attempts a reconnection with Allsrv
        /// </summary>
        /// <param name="state">Data asynchronously passed to this method</param>
        private static void AttemptReconnect(object state)
        {
            try
            {
                _retryCount++;
                if (_retryCount > _maxRetries)
                {
                    TagTrace.WriteLine(TraceLevel.Info, "TAG has reached the maximum amount of Allsrv reconnect attempts. Shutting down...");
                    Stop();
                    if (TagServiceController.IsTagServiceStarted())
                    {
                        TagServiceController.StopTagService();
                    }
                    else
                    {
                        ShutdownTagEvent(null);
                    }

                    return;
                }

                TagTrace.WriteLine(TraceLevel.Verbose, "Attempting to reconnect to Allsrv...");
                GameServer.Initialize();

                // If it worked, kill the reconnect timer!
                TagTrace.WriteLine(TraceLevel.Info, "Allsrv reconnection successful.");
                Stop();
            }
            catch (Exception)
            {
                TagTrace.WriteLine(TraceLevel.Verbose, "Allsrv reconnection failed. Will retry in {0} seconds", _interval);
            }
        }
示例#2
0
        /// <summary>
        /// Performs the TAG update
        /// </summary>
        /// <param name="sender">The object that raised this event</param>
        /// <param name="e">The event arguments</param>
        public static void PerformUpdate(object sender, EventArgs e)
        {
            string UpdaterPath = Application.StartupPath + "\\" + UPDATERNAME;

            // Launch the updater
            Process.Start(new ProcessStartInfo(UpdaterPath));

            TagTrace.WriteLine(TraceLevel.Verbose, "Updater application launched");

            if (TagServiceController.IsTagServiceStarted())
            {
                // TAG is a service. Stop it!
                TagServiceController.StopTagService();
                TagTrace.WriteLine(TraceLevel.Verbose, "TAG Service stopped");
            }
            else
            {
                // TAG is console. Stop it!
                Tag.Stop();
            }
        }
示例#3
0
        /// <summary>
        /// Performs the startup operations necessary to make TAG log Allsrv events
        /// </summary>
        public static void DoStart()
        {
            // Load configuration if necessary
            if (_config == null)
            {
                LoadConfiguration();
            }

            if (_config.SkipUpdates == true)
            {
                TagTrace.WriteLine(TraceLevel.Verbose, "TAG Automatic updates are disabled in the configuration file with the skipUpdates setting.");
            }
            else
            {
#if !DEBUG
                TagTrace.WriteLine(TraceLevel.Verbose, "Checking for updates...");
                // Check for updates to TAG before starting
                if (TagUpdate.UpdateAvailable())
                {
                    TagTrace.WriteLine(TraceLevel.Info, "An update to TAG is available. Exiting to perform update...");
                    PerformUpdate(null, new EventArgs());

                    // Allow main thread to continue
                    _tagStartedResetEvent.Set();

                    return;
                }
                else
                {
                    TagTrace.WriteLine(TraceLevel.Verbose, "No updates are available.");
                }
#endif

                // Prepare the TAG Update timer
                TimeSpan TimeUntilNextUpdate = _config.UpdateTime.Subtract(DateTime.Now);
                _updateTimer = new System.Threading.Timer(new TimerCallback(CheckForUpdates), null, TimeUntilNextUpdate, new TimeSpan(1, 0, 0, 0));

                // Hook up the Update event for manual update requests
                TagUpdate.UpdateTriggeredEvent += new ManualUpdateDelegate(PerformUpdate);
            }

            try
            {
                // Initialize GameServer
                TagTrace.WriteLine(TraceLevel.Info, "Connecting to GameServer....");
                GameServer.Initialize();
            }
            catch (Exception e)
            {
                TagTrace.WriteLine(TraceLevel.Error, "TAG could not connect to Allsrv-: {0}", e.ToString());

                // Allow main thread to continue
                _tagStartedResetEvent.Set();

                if (TagServiceController.IsTagServiceStarted())
                {
                    TagServiceController.StopTagService();
                }
                else
                {
                    new Thread(new ThreadStart(Stop)).Start();
                }

                return;
            }

            // Create the ResetEvent used to prevent from returning
            _closeAppResetEvent = new ManualResetEvent(false);

            // Allow main thrad to continue into 'Q' loop
            if (_tagStartedResetEvent != null)
            {
                _tagStartedResetEvent.Set();
            }

            TagTrace.WriteLine(TraceLevel.Info, "TAG is ready.");

            // Block the thread from exiting until we're shutting down
            _closeAppResetEvent.WaitOne();
        }