From 0ed93b3ac97d6b8e12a0814dda0fbbcd4d5f0c4b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 15 Jul 2017 16:33:03 +1000 Subject: [PATCH] CTF: No longer uses the CTF/maps directory, operates on the live server maps. --- MCGalaxy/Commands/Fun/CTF/CmdCtf.cs | 11 ++----- MCGalaxy/Games/CTF/CtfGame.cs | 46 ++++++++++------------------ MCGalaxy/Games/CTF/Setup.cs | 2 -- MCGalaxy/Server/Tasks/ServerTasks.cs | 3 +- MCGalaxy/util/App.cs | 1 + 5 files changed, 22 insertions(+), 41 deletions(-) diff --git a/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs b/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs index 989e84b18..d503cd21a 100644 --- a/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs +++ b/MCGalaxy/Commands/Fun/CTF/CmdCtf.cs @@ -53,7 +53,7 @@ namespace MCGalaxy.Commands.Fun { } if (!Server.ctf.Start(p)) return; - Chat.MessageGlobal("A CTF GAME IS STARTING AT CTF! TYPE /goto CTF to join!"); + Chat.MessageGlobal("A CTF GAME IS STARTING AT CTF! TYPE %T/goto " + Server.ctf.Map.name + " %Sto join!"); } static void HandleStop(Player p) { @@ -73,7 +73,7 @@ namespace MCGalaxy.Commands.Fun { } else { Player.Message(p, "Added {0} %Sto the list of CTF maps.", p.level.ColoredName); maps.Add(p.level.name); - UpdateCtfMaps(maps); + File.WriteAllLines("CTF/maps.config", maps.ToArray()); } } @@ -85,7 +85,7 @@ namespace MCGalaxy.Commands.Fun { Player.Message(p, "{0} %Swas not in the list of CTF maps.", p.level.ColoredName); } else { Player.Message(p, "Removed {0} %Sfrom the list of CTF maps.", p.level.ColoredName); - UpdateCtfMaps(maps); + File.WriteAllLines("CTF/maps.config", maps.ToArray()); } } @@ -94,11 +94,6 @@ namespace MCGalaxy.Commands.Fun { string[] lines = File.ReadAllLines("CTF/maps.config"); return new List(lines); } - - static void UpdateCtfMaps(List maps) { - File.WriteAllLines("CTF/maps.config", maps.ToArray()); - if (Server.ctf != null) Server.ctf.UpdateMapList(); - } void HandleSet(Player p, string property) { diff --git a/MCGalaxy/Games/CTF/CtfGame.cs b/MCGalaxy/Games/CTF/CtfGame.cs index f815848ad..67056709e 100644 --- a/MCGalaxy/Games/CTF/CtfGame.cs +++ b/MCGalaxy/Games/CTF/CtfGame.cs @@ -43,8 +43,6 @@ namespace MCGalaxy.Games { public CtfTeam2 Red, Blue; public Level Map; - - List maps = new List(); List cache = new List(); public CTFConfig Config = new CTFConfig(); @@ -72,13 +70,8 @@ namespace MCGalaxy.Games { /// Load a map into CTF public void SetMap(string mapName) { - Command.all.Find("unload").Use(null, "ctf"); - if (File.Exists("levels/ctf.lvl")) - File.Delete("levels/ctf.lvl"); - - File.Copy("CTF/maps/" + mapName + ".lvl", "levels/ctf.lvl"); - CmdLoad.LoadLevel(null, "ctf"); - Map = LevelInfo.FindExact("ctf"); + CmdLoad.LoadLevel(null, mapName); + Map = LevelInfo.FindExact(mapName); Map.SaveChanges = false; UpdateConfig(); } @@ -97,14 +90,13 @@ namespace MCGalaxy.Games { Blue.SpawnPos = new Position(cfg.BlueSpawnX, cfg.BlueSpawnY, cfg.BlueSpawnZ); } - public bool UpdateMapList() { + List GetCtfMaps() { //Load some configs if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF"); - if (!File.Exists("CTF/maps.config")) return false; + if (!File.Exists("CTF/maps.config")) return new List(); string[] lines = File.ReadAllLines("CTF/maps.config"); - maps = new List(lines); - return maps.Count > 0; + return new List(lines); } @@ -146,15 +138,12 @@ namespace MCGalaxy.Games { /// Start the CTF game public bool Start(Player p) { - if (LevelInfo.FindExact("ctf") != null) { - Command.all.Find("unload").Use(null, "ctf"); - Thread.Sleep(1000); - } - if (started) { Player.Message(p, "CTF game already running."); return false; } - if (!UpdateMapList()) { + + List maps = GetCtfMaps(); + if (maps.Count == 0) { Player.Message(p, "No CTF maps were found."); return false; } @@ -172,11 +161,8 @@ namespace MCGalaxy.Games { public void Stop() { tagging.Stop(); tagging.Dispose(); - Map = null; started = false; - if (LevelInfo.FindExact("ctf") != null) - Command.all.Find("unload").Use(null, "ctf"); } string Vote() { @@ -185,12 +171,12 @@ namespace MCGalaxy.Games { vote2 = 0; vote3 = 0; Random rand = new Random(); - List maps1 = maps; - map1 = maps1[rand.Next(maps1.Count)]; - maps1.Remove(map1); - map2 = maps1[rand.Next(maps1.Count)]; - maps1.Remove(map2); - map3 = maps1[rand.Next(maps1.Count)]; + List maps = GetCtfMaps(); + map1 = maps[rand.Next(maps.Count)]; + maps.Remove(map1); + map2 = maps[rand.Next(maps.Count)]; + maps.Remove(map2); + map3 = maps[rand.Next(maps.Count)]; Chat.MessageLevel(Map, "%2VOTE:"); Chat.MessageLevel(Map, "1. " + map1 + " 2. " + map2 + " 3. " + map3); voting = true; @@ -226,7 +212,6 @@ namespace MCGalaxy.Games { /// Ends the current round of CTF. public void EndRound() { started = false; - string nextmap = ""; if (Blue.Points >= Config.RoundPoints || Blue.Points > Red.Points) { Chat.MessageLevel(Map, Blue.ColoredName + " %Swon this round of CTF!"); } else if (Red.Points >= Config.RoundPoints || Red.Points > Blue.Points) { @@ -242,7 +227,8 @@ namespace MCGalaxy.Games { Database.Backend.UpdateRows("CTF", "Points=@1, Captures=@2, tags=@3", "WHERE Name = @0", d.p.name, d.Points, d.Captures, d.Tags); }); - nextmap = Vote(); + + string nextmap = Vote(); Chat.MessageLevel(Map, "Starting a new game!"); Blue.Members.Clear(); Red.Members.Clear(); diff --git a/MCGalaxy/Games/CTF/Setup.cs b/MCGalaxy/Games/CTF/Setup.cs index 6d1fdf47f..1fd2ffc81 100644 --- a/MCGalaxy/Games/CTF/Setup.cs +++ b/MCGalaxy/Games/CTF/Setup.cs @@ -77,8 +77,6 @@ namespace MCGalaxy.Games { using (StreamWriter w = new StreamWriter("CTF/maps.config", true)) w.WriteLine(cache[p].current.name); - if (!Directory.Exists("CTF/maps")) Directory.CreateDirectory("CTF/maps"); - File.Copy("levels/" + cache[p].current.name + ".lvl", "CTF/maps/" + cache[p].current.name + ".lvl", true); } static void WriteMapConfig(Player p, int bx, int by, int bz, int rx, int ry, int rz) { diff --git a/MCGalaxy/Server/Tasks/ServerTasks.cs b/MCGalaxy/Server/Tasks/ServerTasks.cs index c095cc3b0..46ac1e51e 100644 --- a/MCGalaxy/Server/Tasks/ServerTasks.cs +++ b/MCGalaxy/Server/Tasks/ServerTasks.cs @@ -96,7 +96,7 @@ namespace MCGalaxy.Tasks { Player[] players = PlayerInfo.Online.Items; foreach (Player p in players) { if (p.hasTwoWayPing) { - p.Send(Packet.TwoWayPing(true, p.Ping.NextTwoWayPingData())); + p.Send(Packet.TwoWayPing(true, p.Ping.NextTwoWayPingData())); } else { p.Send(Packet.Ping()); } @@ -128,6 +128,7 @@ namespace MCGalaxy.Tasks { foreach (Level lvl in loaded) { try { + if (!lvl.ShouldSaveChanges()) continue; lvl.SaveBlockDBChanges(); } catch (Exception e) { Logger.LogError(e); diff --git a/MCGalaxy/util/App.cs b/MCGalaxy/util/App.cs index 2b3569b36..dc73c1517 100644 --- a/MCGalaxy/util/App.cs +++ b/MCGalaxy/util/App.cs @@ -67,6 +67,7 @@ namespace MCGalaxy.Gui { Level[] loaded = LevelInfo.Loaded.Items; foreach (Level lvl in loaded) { if (!lvl.ShouldSaveChanges()) continue; + level = level + lvl.name + "=" + lvl.physics + Environment.NewLine; lvl.Save(false, true); lvl.SaveBlockDBChanges();