Esempio n. 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);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Stops Allsrv, either via AGClib, stopping the service, or by manually killing the process as appropriate
 /// </summary>
 public static void StopAllsrv()
 {
     // If Allsrv service isn't stopped, stop it!
     if (TagServiceController.AllsrvService != null)
     {
         if (TagServiceController.IsAllsrvServiceStarted())
         {
             TagServiceController.StopAllsrvService();
         }
     }
     else
     {
         // TODO: Should I kill allsrv.exe process? Kinda ugly...
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Starts Allsrv in desktop or service mode as installed
        /// </summary>
        public static void StartAllsrv()
        {
            try
            {
                // If Allsrv is a stopped service, start it!
                if (TagServiceController.AllsrvService != null)
                {
                    if (TagServiceController.IsAllsrvServiceStarted() == false)
                    {
                        TagServiceController.StartAllsrvService();
                        TagTrace.WriteLine(TraceLevel.Info, "Allsrv Service started.");
                    }
                }
                else
                {
                    // Start Allsrv in console mode
                    string ServerEXEPath = null;

                    // Get registry key
                    RegistryKey ServerKey = Registry.LocalMachine.OpenSubKey(ALLEGIANCESERVERREGKEY);
                    if (ServerKey != null)
                    {
                        ServerEXEPath = ServerKey.GetValue("EXE Path").ToString();
                        ServerKey.Close();
                    }
                    else
                    {
                        throw new ApplicationException("Could not find Allsrv.exe");
                    }

                    // start executable
                    if (ServerEXEPath != null)
                    {
                        Process.Start(ServerEXEPath);
                        TagTrace.WriteLine(TraceLevel.Info, "Allsrv started in console mode.");
                    }
                }
                Thread.Sleep(1500);                     // Wait a second for Allsrv to start
            }
            catch (Exception e)
            {
                TagTrace.WriteLine(TraceLevel.Error, "Error starting Allsrv: {0}", e.Message);
            }
        }
Esempio n. 4
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();
            }
        }
Esempio n. 5
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();
        }