Beispiel #1
0
        public override void Initialize()
        {
            Commands.ChatCommands.Add(new Command("PurgePlayers.allow", purgePlayers, "purgeplayers", "pp"));

            var path = Path.Combine(TShock.SavePath, "purgeplayers.json");
            (purgePlayersConfig = Config.Read(path)).Write(path);

            purgeBeforeDays = purgePlayersConfig.purgeBeforeDays;
            archiveFileName = purgePlayersConfig.archiveFileName;

            ServerApi.Hooks.GamePostInitialize.Register(this, OnGameInitialize);
        }
Beispiel #2
0
        private void purgePlayers(CommandArgs args)
        {
            PurgePlayersArguments arguments = new PurgePlayersArguments(args.Parameters.ToArray());
            if (arguments.Contains("-help"))
            {
                args.Player.SendMessage("Syntax: /purgeplayers [-help] ", Color.Red);
                args.Player.SendMessage("Flags: ", Color.LightSalmon);
                args.Player.SendMessage(" -purge        starts purge operation", Color.LightSalmon);
                args.Player.SendMessage(" -reload/-r    reloads options from purgeplayers.json config file", Color.LightSalmon);
                args.Player.SendMessage(" -verbose/-v   show each user purge", Color.LightSalmon);
                args.Player.SendMessage(" -!verbose/-!v don't show each user purged", Color.LightSalmon);
                args.Player.SendMessage(" -days n       purges any user not accessed in the last n days before today", Color.LightSalmon);
                args.Player.SendMessage(" -!preview/!p  negates preview, thus users will be deleted", Color.LightSalmon);
                args.Player.SendMessage(" -preview/p    performs purge action without actually purging any users", Color.LightSalmon);
                args.Player.SendMessage(" -list/l       show current purge criteria", Color.LightSalmon);
                args.Player.SendMessage(" -help         this information", Color.LightSalmon);
                return;
            }

            if (arguments.Contains("-days"))
            {
                if (args.Parameters.Count > 1)
                    purgeBeforeDays = Int32.Parse(args.Parameters[1]);
                Console.WriteLine(" {0} Days before to purge is " + purgeBeforeDays.ToString(), Name);
                return;
            }

            if (arguments.Contains("-r") || arguments.Contains("-reload"))
            {
                var path = Path.Combine(TShock.SavePath, "purgeplayers.json");
                purgePlayersConfig = Config.Read(path);
                purgeBeforeDays = purgePlayersConfig.purgeBeforeDays;

                if (purgePlayersConfig.autoPurge)
                {
                    executePurge.Stop();
                    TimeSpan now = TimeSpan.Parse(DateTime.Now.ToString("HH:mm"));     // The current time in 24 hour format
                    TimeSpan activationTime = purgePlayersConfig.autoPurgeTime;

                    TimeSpan timeLeftUntilFirstRun = activationTime - now;
                    if (timeLeftUntilFirstRun.TotalHours < 0)
                        timeLeftUntilFirstRun += new TimeSpan(24, 0, 0);    // adds a day from the schedule
                    if (purgePlayersConfig.debugPP)
                        Console.WriteLine(timeLeftUntilFirstRun);

                    executePurge.Interval = timeLeftUntilFirstRun.TotalMilliseconds;
                    executePurge.Elapsed += autoPurge;    // Event to do your tasks.
                    executePurge.AutoReset = true;
                    executePurge.Start();
                }
                Console.WriteLine(" {0} Config file reloaded.", Name);
                return;
            }

            if (arguments.Contains("-v") || arguments.Contains("-verbose"))
            {
                verbose = true;
                Console.WriteLine(" {0} Verbose is " + verbose.ToString(), Name);
                return;
            }
            if (arguments.Contains("-!v") || arguments.Contains("-!verbose"))
            {
                verbose = false;
                Console.WriteLine(" {0} Verbose is " + verbose.ToString(), Name);
                return;
            }
            if (arguments.Contains("-p") || arguments.Contains("-preview"))
            {
                preview = true;
                Console.WriteLine(" {0} Preview is " + preview.ToString(), Name);
                return;
            }
            if (arguments.Contains("-!p") || arguments.Contains("-!preview"))
            {
                preview = false;
                Console.WriteLine(" {0} Preview is " + preview.ToString(), Name);
                return;
            }

            if (arguments.Contains("-l") || arguments.Contains("-list"))
            {
                Console.WriteLine("Current options for PurgePlayers version " + Assembly.GetExecutingAssembly().GetName().Version);
                Console.WriteLine(" keepForDays=" + purgeBeforeDays);
                Console.WriteLine(" verbose is " + verbose.ToString());
                Console.WriteLine(" preview is " + preview.ToString());
                return;
            }

            if (arguments.Contains("-purge"))
            {
                processPurgeCommand();
                return;
            }
        }