コード例 #1
0
 /// <summary>
 /// Checks for updates to TAG
 /// </summary>
 /// <param name="info">Additional info used by the Update timer (null)</param>
 public static void CheckForUpdates(object info)
 {
     TagTrace.WriteLine(TraceLevel.Verbose, "Checking for updates...");
     if (TagUpdate.IsAbleToUpdate())
     {
         if (TagUpdate.UpdateAvailable())
         {
             TagTrace.WriteLine(TraceLevel.Info, "An update to TAG is available. Performing update...");
             TagUpdate.InitiateUpdate();
         }
     }
     else
     {
         TagTrace.WriteLine(TraceLevel.Verbose, "TAG can't update now. Games in progress.");
     }
 }
コード例 #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!
                }
            }
        }
コード例 #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();
        }
コード例 #4
0
        /// <summary>
        /// Handles the AdminPaged AGCEvent
        /// </summary>
        /// <param name="sender">The object firing the event</param>
        /// <param name="e">The arguments of the event</param>
        public static void AdminPagedAGCEventHandler(object sender, AdminPagedAGCEventArgs e)
        {
            try
            {
                TagTrace.WriteLine(TraceLevel.Verbose, "AdminPage Event received from {0}: {1}", e.Callsign, e.Message);
                Game CurrentGame = GameServer.Games.GetGameByID(e.GameID);
                if (CurrentGame != null)
                {
                    TagTrace.WriteLine(TraceLevel.Verbose, "AdminPage Event waiting to lock GameData...");
                    lock (CurrentGame.GetSyncRoot())
                    {
                        CurrentGame.GameData.LogAdminPage(e.Time, e.Callsign, e.Message);
                        TagTrace.WriteLine(TraceLevel.Verbose, "AdminPage logged.");
                    }

                    // If it's a #command, parse it
                    if (e.Message.StartsWith("#"))
                    {
                        int    SpacePosition = e.Message.IndexOf(" ");
                        string CommandName   = (SpacePosition < 0) ? e.Message : e.Message.Substring(0, SpacePosition);
                        string Params        = (SpacePosition < 0) ? string.Empty : e.Message.Substring(SpacePosition + 1);

                        switch (CommandName)
                        {
                        case "#debugkills":                                             // Allows debugging of kill logging
                            CurrentGame.DebugKills = !CurrentGame.DebugKills;
                            CurrentGame.SendChat("Kill debugging is now " + ((CurrentGame.DebugKills) ? "on" : "off"));
                            break;

                        case "#hq":
                            if (CallsignHelper.GetAuthLevel(e.Callsign) > AuthLevel.User)
                            {
                                GameServer.SendChat(Params);
                            }
                            else
                            {
                                GameServer.SendChat(e.Callsign, "You must be logged in with administrative tokens or tags in order to broadcast across the server");
                            }
                            break;

                        case "#hqgame":
                            if (CallsignHelper.GetAuthLevel(e.Callsign) > AuthLevel.User)
                            {
                                CurrentGame.SendChat(Params);
                            }
                            else
                            {
                                GameServer.SendChat(e.Callsign, "You must be logged in with administrative tokens or tags in order to broadcast to this game");
                            }
                            break;

//							case "#smite":
//								if (CurrentGame.SmitePlayer(Params, e.Callsign))
//									GameServer.SendChat(e.Callsign, "Player smited");
//								else
//									GameServer.SendChat(e.Callsign, "Specified player not found");
//
//								break;
                        case "#tag":
                            if (CallsignHelper.GetAuthLevel(e.Callsign) > AuthLevel.User)
                            {
                                CurrentGame.GameData.TagGame(e.Time, e.Callsign, Params);
                                GameServer.SendChat(e.Callsign, "This game has been tagged " + Params + ".");
                            }
                            else
                            {
                                GameServer.SendChat(e.Callsign, "You must be logged in with administrative tokens or tags in order to #tag a game");
                            }
                            break;

                        case "#update":                                 // Forces an update-check for TAG
                            if (TagUpdate.IsAbleToUpdate() || CallsignHelper.GetAuthLevel(e.Callsign) == AuthLevel.Admin)
                            {
                                if (TagUpdate.UpdateAvailable())
                                {
                                    GameServer.SendChat(e.Callsign, "TAG update available. Installing...");
                                    TagUpdate.InitiateUpdate();
                                }
                                else
                                {
                                    GameServer.SendChat(e.Callsign, "TAG is already up to date.");
                                }
                            }
                            else
                            {
                                GameServer.SendChat(e.Callsign, "TAG can't update now. There are games in progress.");
                            }
                            break;

                        case "#version":                                                // A simple version check to see what version is running
                            Version TagVersion       = Assembly.GetEntryAssembly().GetName().Version;
                            string  TagVersionString = string.Format("TAG v{0}.{1}.{2}.{3} online", TagVersion.Major, TagVersion.Minor, TagVersion.Build, TagVersion.Revision);
                            GameServer.SendChat(e.Callsign, TagVersionString);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TagTrace.WriteLine(TraceLevel.Error, "Error handling AdminPaged event: {0}", ex.Message);
            }
        }