Beispiel #1
0
        internal static void MovePreviousLevelFiles(SchedulerTask task)
        {
            if (!Directory.Exists("levels"))
            {
                return;
            }
            if (Directory.Exists("levels/prev"))
            {
                return;
            }

            try {
                string[] files = Directory.GetFiles("levels", "*.prev");
                if (files.Length == 0)
                {
                    return;
                }
                if (!Directory.Exists("levels/prev"))
                {
                    Directory.CreateDirectory("levels/prev");
                }

                foreach (string file in files)
                {
                    string name    = Path.GetFileName(file);
                    string newFile = "levels/prev/" + name;

                    try {
                        File.Move(file, newFile);
                    } catch (Exception ex) {
                        Logger.Log(LogType.Warning, "Error while trying to move .lvl.prev file");
                        Logger.LogError(ex);
                    }
                }
            } catch (Exception ex) {
                Logger.LogError(ex);
            }
        }
Beispiel #2
0
        internal static void UpdateStaffList(SchedulerTask task)
        {
            try {
                using (WebClient client = HttpUtil.CreateWebClient()) {
                    string   raw  = client.DownloadString(staffUrl);
                    string[] list = raw.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

                    foreach (string line in list)
                    {
                        string[]      bits  = line.Split(':');
                        List <string> group = null;
                        if (bits[0].CaselessEq("devs"))
                        {
                            group = Server.Devs;
                        }
                        if (bits[0].CaselessEq("mods"))
                        {
                            group = Server.Mods;
                        }

                        if (group == null)
                        {
                            continue;
                        }
                        foreach (string name in bits[1].SplitSpaces())
                        {
                            group.Add(name.RemoveLastPlus());
                        }
                    }
                }
            } catch (Exception e) {
                Logger.LogError(e);
                Logger.Log(LogType.Warning, "Failed to update {0} staff list.", Server.SoftwareName);
                Server.Devs.Clear();
                Server.Mods.Clear();
            }
        }
 internal static void UpdateEntityPositions(SchedulerTask task)
 {
     Entities.GlobalUpdate();
     PlayerBot.GlobalUpdatePosition();
     task.Delay = TimeSpan.FromMilliseconds(Server.Config.PositionUpdateInterval);
 }
        internal static void AutoSave(SchedulerTask task)
        {
            int count = (int)task.State;

            count--;
            Level[] levels = LevelInfo.Loaded.Items;

            foreach (Level lvl in levels)
            {
                try {
                    if (!lvl.Changed || !lvl.SaveChanges)
                    {
                        continue;
                    }

                    lvl.Save();
                    if (count == 0)
                    {
                        string backup = lvl.Backup();
                        if (backup != null)
                        {
                            lvl.Message("Backup " + backup + " saved.");
                            Logger.Log(LogType.BackgroundActivity, "Backup {0} saved for {1}", backup, lvl.name);
                        }
                    }
                } catch (Exception ex) {
                    Logger.LogError("Error auto-backing up " + lvl.MapName, ex);
                }
            }

            if (count <= 0)
            {
                count = 15;
            }
            task.State = count;
            task.Delay = Server.Config.BackupInterval;

            Player[] players = PlayerInfo.Online.Items;
            try {
                foreach (Player p in players)
                {
                    p.SaveStats();
                }
            } catch (Exception ex) {
                Logger.LogError("Error auto-saving players", ex);
            }

            players = PlayerInfo.Online.Items;
            if (players.Length <= 0)
            {
                return;
            }
            string all = players.Join(p => p.name);

            if (all.Length > 0)
            {
                Logger.Log(LogType.BackgroundActivity, "!PLAYERS ONLINE: " + all);
            }

            levels = LevelInfo.Loaded.Items;
            all    = levels.Join(l => l.name);
            if (all.Length > 0)
            {
                Logger.Log(LogType.BackgroundActivity, "!LEVELS ONLINE: " + all);
            }
        }
Beispiel #5
0
 /// <summary> Cancels a task if it is in the tasks list. </summary>
 /// <remarks> Does not cancel the task if it is currently executing. </remarks>
 public bool Cancel(SchedulerTask task)
 {
     lock (taskLock) {
         return(tasks.Remove(task));
     }
 }
Beispiel #6
0
        internal static void AutoSave(SchedulerTask task)
        {
            int count = (int)task.State;

            count--;
            Level[] levels = LevelInfo.Loaded.Items;

            foreach (Level l in levels)
            {
                try {
                    if (!l.changed || !l.ShouldSaveChanges())
                    {
                        continue;
                    }

                    l.Save();
                    if (count == 0)
                    {
                        int backupNumber = l.Backup();
                        if (backupNumber != -1)
                        {
                            l.ChatLevel("Backup " + backupNumber + " saved.");
                            Server.s.Log("Backup " + backupNumber + " saved for " + l.name);
                        }
                    }
                } catch {
                    Server.s.Log("Backup for " + l.name + " has caused an error.");
                }
            }

            if (count <= 0)
            {
                count = 15;
            }
            task.State = count;

            Player[] players = PlayerInfo.Online.Items;
            try {
                foreach (Player p in players)
                {
                    p.save();
                }
            } catch (Exception e) {
                Server.ErrorLog(e);
            }

            players = PlayerInfo.Online.Items;
            if (players.Length <= 0)
            {
                return;
            }
            string all = players.Join(p => p.name);

            if (all.Length > 0)
            {
                Server.s.Log("!PLAYERS ONLINE: " + all, true);
            }

            levels = LevelInfo.Loaded.Items;
            all    = levels.Join(l => l.name);
            if (all.Length > 0)
            {
                Server.s.Log("!LEVELS ONLINE: " + all, true);
            }
        }
Beispiel #7
0
 internal static void UpgradeZones(SchedulerTask task)
 {
 }
Beispiel #8
0
 internal static void MuteCheckTask(SchedulerTask task)
 {
     DoTask(task, Server.muted, MuteCallback);
 }
Beispiel #9
0
 internal static void FreezeCheckTask(SchedulerTask task)
 {
     DoTask(task, Server.frozen, FreezeCallback);
 }
Beispiel #10
0
 internal static void TemprankCheckTask(SchedulerTask task)
 {
     DoTask(task, Server.tempRanks, TemprankCallback);
 }
Beispiel #11
0
 static void CalcNextRun(SchedulerTask task, PlayerExtList list)
 {
     task.Delay   = NextRun(list);
     task.NextRun = DateTime.UtcNow.Add(task.Delay);
     Server.MainScheduler.Recheck();
 }
Beispiel #12
0
        internal static void AutoSave(SchedulerTask task)
        {
            int count = (int)task.State;

            count--;
            Level[] levels = LevelInfo.Loaded.Items;

            foreach (Level lvl in levels)
            {
                try {
                    if (!lvl.Changed || !lvl.ShouldSaveChanges())
                    {
                        continue;
                    }

                    lvl.Save();
                    if (count == 0)
                    {
                        int backupNumber = lvl.Backup();
                        if (backupNumber != -1)
                        {
                            lvl.ChatLevel("Backup " + backupNumber + " saved.");
                            Logger.Log(LogType.BackgroundActivity, "Backup {0} saved for {1}", backupNumber, lvl.name);
                        }
                    }
                } catch (Exception ex) {
                    Logger.Log(LogType.Warning, "Backup for {0} has caused an error.", lvl.name);
                    Logger.LogError(ex);
                }
            }

            if (count <= 0)
            {
                count = 15;
            }
            task.State = count;
            task.Delay = TimeSpan.FromSeconds(ServerConfig.BackupInterval);

            Player[] players = PlayerInfo.Online.Items;
            try {
                foreach (Player p in players)
                {
                    p.save();
                }
            } catch (Exception e) {
                Logger.LogError(e);
            }

            players = PlayerInfo.Online.Items;
            if (players.Length <= 0)
            {
                return;
            }
            string all = players.Join(p => p.name);

            if (all.Length > 0)
            {
                Logger.Log(LogType.BackgroundActivity, "!PLAYERS ONLINE: " + all);
            }

            levels = LevelInfo.Loaded.Items;
            all    = levels.Join(l => l.name);
            if (all.Length > 0)
            {
                Logger.Log(LogType.BackgroundActivity, "!LEVELS ONLINE: " + all);
            }
        }