Esempio n. 1
0
        private static void HandleRoot(WebAPIContext context)
        {
            if (!CSOptions.WebServer)
            {
                context.Response.Status = HttpStatusCode.ServiceUnavailable;
                return;
            }

            var root = IOUtility.EnsureDirectory(Core.BaseDirectory + "/web");
            var path = IOUtility.GetSafeFilePath(root + "/" + context.Uri, true);

            if (Path.HasExtension(path))
            {
                var file = new FileInfo(path);

                context.Response.FileName = file.Name;
                context.Response.Data     = file.Directory;
            }
            else if (Directory.Exists(path))
            {
                context.Response.Data = new DirectoryInfo(path);
            }
            else
            {
                context.Response.Status = HttpStatusCode.BadRequest;
            }
        }
Esempio n. 2
0
        private static bool Backup(bool restore)
        {
            if (restore)
            {
                return(VitaNexCore.TryCatchGet(
                           () =>
                {
                    World.Save(false, false);
                    //World.WaitForWriteCompletion();

                    return true;
                },
                           CSOptions.ToConsole));
            }

            return(VitaNexCore.TryCatchGet(
                       () =>
            {
                DirectoryInfo target = IOUtility.EnsureDirectory(BackupTarget + "/" + _Stamp.ToSimpleString("D d M y - t@h-m@"));

                Parallel.ForEach(
                    GetFiles(BackupSource),
                    file =>
                    VitaNexCore.TryCatch(
                        () =>
                        file.CopyTo(IOUtility.EnsureFile(file.FullName.Replace(BackupSource.FullName, target.FullName)).FullName, true),
                        CSOptions.ToConsole));

                return true;
            },
                       CSOptions.ToConsole));
        }
Esempio n. 3
0
        private static void Backup()
        {
            VitaNexCore.TryCatch(
                () =>
            {
                DateTime expire = DateTime.UtcNow.Subtract(_BackupExpire);

                Parallel.ForEach(
                    BackupTarget.EnumerateDirectories(),
                    dir => VitaNexCore.TryCatch(
                        () =>
                {
                    if (dir.CreationTimeUtc < expire)
                    {
                        dir.Delete(true);
                    }
                }));
            });

            VitaNexCore.TryCatch(
                () =>
            {
                DirectoryInfo target =
                    IOUtility.EnsureDirectory(BackupTarget + "/" + DateTime.Now.ToSimpleString("D d M y - t@h-m@"));

                Parallel.ForEach(
                    BackupSource.EnumerateDirectories(),
                    dir =>
                    VitaNexCore.TryCatch(
                        () => dir.CopyDirectory(IOUtility.EnsureDirectory(dir.FullName.Replace(BackupSource.FullName, target.FullName)))));
            });
        }
Esempio n. 4
0
        static VitaNexCore()
        {
            _INITQueue    = new Queue <Tuple <string, string> >();
            _INITHandlers = new Dictionary <string, Action <string> >();

            _INITVersion = "2.2.0.0";

            Version = null;

            if (!Directory.Exists(IOUtility.GetSafeDirectoryPath(Core.BaseDirectory + "/VitaNexCore")))
            {
                FirstBoot = true;
            }

            BaseDirectory = IOUtility.EnsureDirectory(Core.BaseDirectory + "/VitaNexCore");

            if (!File.Exists(BaseDirectory + "/FirstBoot.vnc"))
            {
                FirstBoot = true;

                IOUtility.EnsureFile(BaseDirectory + "/FirstBoot.vnc")
                .AppendText(
                    true,
                    "This file serves no other purpose than to identify if",
                    "the software has been initialized for the first time. ",
                    "To re-initialize 'First-Boot' mode, simply delete this",
                    "file before starting the application.");
            }

            // HACK: See FindRootDirectory summary.
            var root = FindRootDirectory(Core.BaseDirectory + "/Scripts/VitaNex");

            if (root == null || !root.Exists)
            {
                return;
            }

            RootDirectory = root;

            ParseVersion();
            ParseINIT();

            RegisterINITHandler(
                "ROOT_DIR",
                path =>
            {
                root = FindRootDirectory(path);

                if (root == null || !root.Exists)
                {
                    return;
                }

                RootDirectory = root;

                ParseVersion();
            });
        }
Esempio n. 5
0
        /// <summary>
        ///     Performs a global backup action, copying all files in the SavesDirectory to the BackupDirectory.
        /// </summary>
        public static void Backup()
        {
            if (Busy)
            {
                ToConsole("Could not perform backup action, the service is busy.");
                return;
            }

            Busy = true;

            DateTime now = DateTime.UtcNow;

            ToConsole(String.Empty);
            ToConsole("Backup action started...");

            TryCatch(
                () =>
            {
                DateTime expire = DateTime.UtcNow.Subtract(TimeSpan.FromDays(3.0));

                Parallel.ForEach(
                    BackupDirectory.EnumerateDirectories(),
                    dir => TryCatch(
                        () =>
                {
                    if (dir.CreationTimeUtc < expire)
                    {
                        dir.Delete(true);
                    }
                }));
            });

            TryCatch(
                () =>
            {
                var target = IOUtility.EnsureDirectory(
                    BackupDirectory + "/" + DateTime.Now.ToSimpleString("D d M y - t@h-m@"), true);

                Parallel.ForEach(
                    SavesDirectory.EnumerateDirectories(),
                    dir =>
                    TryCatch(
                        () =>
                        dir.CopyDirectory(IOUtility.EnsureDirectory(dir.FullName.Replace(SavesDirectory.FullName, target.FullName)))));
            });

            if (OnBackup != null)
            {
                TryCatch(OnBackup, ToConsole);
            }

            Busy = false;

            double time = (DateTime.UtcNow - now).TotalSeconds;

            ToConsole("Backup action completed in {0:F2} second{1}", time, (time != 1) ? "s" : String.Empty);
        }
Esempio n. 6
0
 public CSharpCompiler(
     string inputPath, string outputPath, string outputFileName, Action <CompilerResults> onCompiled = null)
     : this(
         new DirectoryInfo(IOUtility.GetSafeDirectoryPath(inputPath)),
         IOUtility.EnsureDirectory(outputPath, true),
         outputFileName,
         onCompiled)
 {
 }
Esempio n. 7
0
        static AutoSave()
        {
            Instance = new AutoSave();

            SavesEnabled = true;

            BackupSource = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Saves/");
            BackupTarget = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Backups/Automatic/");
        }
Esempio n. 8
0
        private static void CSConfig()
        {
            Core.CrashedHandler = OnServerCrashed;

            EventSink.Crashed += e =>
            {
                if (!World.Loading && !World.Saving)
                {
                    NotifyPlayers();
                }
            };

            BackupSource = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Saves/");
            BackupTarget = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Backups/Crashed/");
            ReportTarget = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Reports/");

            _CrashState = IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/CrashState.bin");

            _LastOnline = new List <PlayerMobile>();
            _CrashNotes = new List <CrashNote>();

            CommandUtility.Register(
                "CrashGuard",
                Access,
                e =>
            {
                if (e.Mobile is PlayerMobile)
                {
                    SuperGump.Send(new CrashNoteListGump((PlayerMobile)e.Mobile));
                }
            });

            CommandUtility.Register(
                "Crash",
                AccessLevel.Administrator,
                e =>
            {
                if (e.Mobile is PlayerMobile)
                {
                    SuperGump.Send(
                        new ConfirmDialogGump((PlayerMobile)e.Mobile)
                    {
                        Title         = "Force Crash",
                        Html          = "Click OK to force the server to crash.",
                        AcceptHandler = b => { throw new Exception("Forced Crash Exception"); }
                    });
                }
            });
        }
Esempio n. 9
0
        /// <summary>
        ///     Performs a global backup action, copying all files in the SavesDirectory to the BackupDirectory.
        /// </summary>
        public static void Backup()
        {
            if (Busy)
            {
                ToConsole("Could not perform backup action, the service is busy.");
                return;
            }

            Busy = true;

            var now = DateTime.UtcNow;

            try
            {
                ToConsole(String.Empty);
                ToConsole("Backup action started...");

                if (BackupExpireAge > TimeSpan.Zero)
                {
                    ToConsole("Backup Expire Age: {0}", BackupExpireAge);

                    lock (IOLock)
                    {
                        BackupDirectory.EmptyDirectory(BackupExpireAge);
                    }
                }

                lock (IOLock)
                {
                    SavesDirectory.CopyDirectory(
                        IOUtility.EnsureDirectory(BackupDirectory + "/" + DateTime.Now.ToSimpleString("D d M y"), true));
                }

                InvokeByPriority(OnBackup);
            }
            finally
            {
                Busy = false;
            }

            var time = (DateTime.UtcNow - now).TotalSeconds;

            ToConsole("Backup action completed in {0:F2} second{1}", time, (time != 1) ? "s" : String.Empty);
        }
Esempio n. 10
0
        /// <summary>
        ///     Performs a global backup action, copying all files in the SavesDirectory to the BackupDirectory.
        /// </summary>
        public static void Backup()
        {
            if (Busy)
            {
                ToConsole("Could not perform backup action, the service is busy.");
                return;
            }

            Busy = true;

            DateTime now = DateTime.UtcNow;

            ToConsole(String.Empty);
            ToConsole("Backup action started...");

            SavesDirectory.CopyDirectory(
                IOUtility.EnsureDirectory(BackupDirectory + "/" + DateTime.Now.ToSimpleString("D d M y"), true));

            if (_ExpireThread != null)
            {
                TryCatch(_ExpireThread.Abort);
                _ExpireThread = null;
            }

            _ExpireThread = new Thread(FlushExpired)
            {
                Name     = "Backup Expire Flush",
                Priority = ThreadPriority.BelowNormal
            };
            _ExpireThread.Start();

            if (OnBackup != null)
            {
                TryCatch(OnBackup, ToConsole);
            }

            Busy = false;

            double time = (DateTime.UtcNow - now).TotalSeconds;

            ToConsole("Backup action completed in {0:F2} second{1}", time, (time != 1) ? "s" : String.Empty);
        }
Esempio n. 11
0
        static VitaNexCore()
        {
            _INITVersion = "5.2.0.0";

            _INITQueue    = new Queue <Tuple <string, string> >();
            _INITHandlers = new Dictionary <string, Action <string> >();

            var basePath = IOUtility.GetSafeDirectoryPath(Core.BaseDirectory + "/VitaNexCore");

            if (!Directory.Exists(basePath))
            {
                FirstBoot = true;
            }

            BaseDirectory = IOUtility.EnsureDirectory(basePath);

            var first = IOUtility.GetSafeFilePath(BaseDirectory + "/FirstBoot.vnc", true);

            if (!File.Exists(first))
            {
                FirstBoot = true;

                IOUtility.EnsureFile(first)
                .AppendText(
                    true,
                    "This file serves no other purpose than to identify if",
                    "the software has been initialized for the first time. ",
                    "To re-initialize 'First-Boot' mode, simply delete this",
                    "file before starting the application.");
            }

            var root = FindRootDirectory(Core.BaseDirectory + "/Scripts/VitaNex");

            if (root != null && root.Exists)
            {
                RootDirectory = root;

                ParseVersion();
                ParseINIT();

                RegisterINITHandler(
                    "ROOT_DIR",
                    path =>
                {
                    root = FindRootDirectory(path);

                    if (root == null || !root.Exists)
                    {
                        return;
                    }

                    RootDirectory = root;

                    ParseVersion();
                });
            }

            BackupExpireAge = TimeSpan.FromDays(7);

            RegisterINITHandler(
                "BACKUP_EXPIRE",
                time =>
            {
                TimeSpan ts;

                if (TimeSpan.TryParse(time, out ts))
                {
                    BackupExpireAge = ts;
                }
            });

            Core.Slice += Slice;
        }
Esempio n. 12
0
        static VitaNexCore()
        {
            _INITVersion = "2.2.0.0";

                        #if MONO
            Version = _INITVersion;
                        #endif

            _INITQueue    = new Queue <Tuple <string, string> >();
            _INITHandlers = new Dictionary <string, Action <string> >();

            //ensuring simply "VitaNexCore" exists causes Mono to look in system root folder "/", so we
            // concatenate to give path relative to Server.  --sith
            if (!Directory.Exists(Core.BaseDirectory + "/VitaNexCore"))
            {
                FirstBoot = true;
            }

            BaseDirectory = IOUtility.EnsureDirectory(Core.BaseDirectory + "/VitaNexCore");

            if (!File.Exists(BaseDirectory + "/FirstBoot.vnc"))
            {
                FirstBoot = true;

                IOUtility.EnsureFile(BaseDirectory + "/FirstBoot.vnc")
                .AppendText(
                    true,
                    "This file serves no other purpose than to identify if",
                    "the software has been initialized for the first time. ",
                    "To re-initialize 'First-Boot' mode, simply delete this",
                    "file before starting the application.");
            }


                        #if MONO
            // Someone moved VitaNex from Scripts/VitaNex to Scripts/Custom Systems/VitaNex/Core
            //  but this path was not updated... does this cause problems on Windows?  --Sith
            var root = FindRootDirectory("Scripts/VitaNex");
                        #else
            var root = new DirectoryInfo(Core.BaseDirectory + @"\Scripts\Custom Systems\VitaNex\Core");
                        #endif

            if (root == null || !root.Exists)
            {
                return;
            }

            RootDirectory = root;

            ParseVersion();
            ParseINIT();

            RegisterINITHandler(
                "ROOT_DIR",
                path =>
            {
                root = FindRootDirectory(path);

                if (root == null || !root.Exists)
                {
                    return;
                }

                RootDirectory = root;

                ParseVersion();
            });
        }