Beispiel #1
0
        /// <summary>
        /// Reads the config file and initializes tracing and logging
        /// </summary>
        public static void LoadConfiguration()
        {
            if (_config == null)
            {
                // Try to read the configuration
                try
                {
                    _config = (TagConfig)ConfigurationSettings.GetConfig("TagConfig");

                    if (_config == null)
                    {
                        throw new ConfigurationException("Error parsing TagConfig section of config file");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error loading Config file: {0}", e.Message);
                    Console.WriteLine("Exiting...");
                    return;
                }

                // Make the configuration available to the CallsignHelper for ServerAdmin tags
                CallsignHelper.SetServerAdmins(_config.ServerAdmins);

                // Initialize tracing
                TagTrace.Initialize(_config.TraceLevel, _config.TracePath, _config.TraceArchiveDir, _config.TraceConsole, null);

                TagTrace.WriteLine(TraceLevel.Info, "TAG Build {0} is starting...", Build.ToString());

                // Initialize reconnect timer
                ReconnectTimer.Initialize(_config.ReconnectInterval, _config.MaxRetries);
                ReconnectTimer.ShutdownTagEvent += new AsyncCallback(ReconnectShutdown);

                // Configure ASGS as necessary
                if (_config.AsgsUrl != null)
                {
                    AsgsConnector.Initialize(_config.AsgsUrl, _config.PostTimeout);
                }

                if (_config.CssUrl != null)
                {
                    CssConnector.Initialize(_config.CssUrl, _config.PostTimeout, _config.UseCss);
                }

                TagTrace.WriteLine(TraceLevel.Verbose, "Initializing logging...");
                GameLogger.Initialize(_config.XmlPath);

                TagTrace.WriteLine(TraceLevel.Info, "Configuration Loaded.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Posts the specified game to ASGS, and logs it
        /// </summary>
        /// <param name="data">The data to post</param>
        public static void PostGame(object data)
        {
            // Unpackage and prepare data
            GameData    Data          = (GameData)data;
            GameDataset Set           = Data.GetDataset();
            string      Xml           = Set.GetXml();
            string      CompressedXml = Compression.Compress(Xml);

            TagTrace.WriteLine(TraceLevel.Verbose, "Game data ready to post. Sending to stats server...");
            TagTrace.WriteLine(TraceLevel.Verbose, "Use CSS: " + CssConnector.UseCss + ", CSS Url: " + CssConnector.CssUrl);

            // Post game to ASGS
            string PostMessage;
            int    GameID;

            if (CssConnector.UseCss == true)
            {
                GameID = CssConnector.PostGame(CompressedXml, out PostMessage);
            }
            else
            {
                GameID = AsgsConnector.PostGame(CompressedXml, out PostMessage);
            }

            TagTrace.WriteLine(TraceLevel.Info, "Game #{0} Posted: {1}", GameID, PostMessage);

            // Post message to all servers
            GameServer.SendChat(PostMessage);

            // Log games as configured
            XmlLogger.LogGame(Data, GameID);

            // Get rid of this GameData since we no longer need it
            Data.Dispose();
            TagTrace.WriteLine(TraceLevel.Verbose, "Game data disposed");

            // If no games are in progress...
            if (TagUpdate.IsAbleToUpdate())
            {
                TagTrace.WriteLine(TraceLevel.Verbose, "TAG is able to update. No games are in progress");
                // And an update is available...
                if (TagUpdate.UpdateAvailable())
                {
                    TagUpdate.InitiateUpdate();                         // Update!
                }
            }
        }