internal static List <EffectSpawner> ReadAll(string json) { List <EffectSpawner> spawners = new List <EffectSpawner>(); if (elems == null) { elems = ConfigElement.GetAll(typeof(EffectSpawner)); } JsonContext ctx = new JsonContext(); ctx.Val = json; JsonArray array = (JsonArray)Json.ParseStream(ctx); if (array == null) { return(spawners); } foreach (object raw in array) { JsonObject obj = (JsonObject)raw; if (obj == null) { continue; } EffectSpawner data = new EffectSpawner(); obj.Deserialise(elems, data); spawners.Add(data); } return(spawners); }
public static void Save(bool global, Level lvl) { if (elems == null) { elems = ConfigElement.GetAll(typeof(BlockDefinition)); } string path = global ? GlobalPath : Paths.MapBlockDefs(lvl.MapName); BlockDefinition[] defs = global ? GlobalDefs : lvl.CustomBlockDefs; using (StreamWriter w = new StreamWriter(path)) { w.WriteLine("["); string separator = null; for (int i = 0; i < defs.Length; i++) { BlockDefinition def = defs[i]; // don't want to save global blocks in the level's custom blocks list if (!global && def == GlobalDefs[i]) { def = null; } if (def == null) { continue; } w.Write(separator); Json.Serialise(w, elems, def); separator = ",\r\n"; } w.WriteLine("]"); } }
public void Load(string effectName) { if (cfg == null) { cfg = ConfigElement.GetAll(typeof(EffectConfig)); } ConfigElement.ParseFile(cfg, "effects/" + effectName + ".properties", this); }
public void Save(string effectName) { if (cfg == null) { cfg = ConfigElement.GetAll(typeof(EffectConfig)); } ConfigElement.SerialiseSimple(cfg, "effects/" + effectName + ".properties", this); }
public static void Start() { serverConfig = ConfigElement.GetAll(typeof(ServerConfig)); levelConfig = ConfigElement.GetAll(typeof(LevelConfig)); zoneConfig = ConfigElement.GetAll(typeof(ZoneConfig)); #pragma warning disable 0618 Player.players = PlayerInfo.Online.list; Server.levels = LevelInfo.Loaded.list; #pragma warning restore 0618 StartTime = DateTime.UtcNow; shuttingDown = false; Logger.Log(LogType.SystemActivity, "Starting Server"); ServicePointManager.Expect100Continue = false; CheckFile("MySql.Data.dll"); CheckFile("sqlite3_x32.dll"); CheckFile("sqlite3_x64.dll"); CheckFile("LibNoise.dll"); EnsureFilesExist(); MoveSqliteDll(); MoveOutdatedFiles(); LoadAllSettings(); SrvProperties.GenerateSalt(); InitDatabase(); Economy.LoadDatabase(); Background.QueueOnce(UpgradeTasks.CombineEnvFiles); Background.QueueOnce(LoadMainLevel); Plugin.LoadAll(); Background.QueueOnce(LoadAutoloadMaps); Background.QueueOnce(UpgradeTasks.MovePreviousLevelFiles); Background.QueueOnce(UpgradeTasks.UpgradeOldTempranks); Background.QueueOnce(UpgradeTasks.UpgradeDBTimeSpent); Background.QueueOnce(InitPlayerLists); Background.QueueOnce(UpgradeTasks.UpgradeBots); Background.QueueOnce(SetupSocket); Background.QueueOnce(InitTimers); Background.QueueOnce(InitRest); Background.QueueOnce(InitHeartbeat); Devs.Clear(); Mods.Clear(); Background.QueueOnce(InitTasks.UpdateStaffList); ServerTasks.QueueTasks(); Background.QueueRepeat(ThreadSafeCache.DBCache.CleanupTask, null, TimeSpan.FromMinutes(5)); }
public static BlockDefinition[] Load(string path) { BlockDefinition[] defs = new BlockDefinition[Block.ExtendedCount]; if (!File.Exists(path)) { return(defs); } if (elems == null) { elems = ConfigElement.GetAll(typeof(BlockDefinition)); } try { JsonContext ctx = new JsonContext(); ctx.Val = File.ReadAllText(path); JsonArray array = (JsonArray)Json.ParseStream(ctx); if (array == null) { return(defs); } foreach (object raw in array) { JsonObject obj = (JsonObject)raw; if (obj == null) { continue; } BlockDefinition def = new BlockDefinition(); obj.Deserialise(elems, def); if (String.IsNullOrEmpty(def.Name)) { continue; } BlockID block = def.GetBlock(); if (block >= defs.Length) { Logger.Log(LogType.Warning, "Invalid block ID: " + def.RawID); } else { defs[block] = def; } // In case user manually edited fallback in the json file def.FallBack = Math.Min(def.FallBack, Block.CpeMaxBlock); } } catch (Exception ex) { Logger.LogError("Error Loading block defs from " + path, ex); } return(defs); }
public static void SaveGroups(List <Group> givenList) { if (cfg == null) { cfg = ConfigElement.GetAll(typeof(Group)); } using (StreamWriter w = new StreamWriter(Paths.RankPropsFile)) { w.WriteLine("#Version 3"); w.WriteLine("#RankName = string"); w.WriteLine("#\tThe name of the rank, use capitalization."); w.WriteLine("#"); w.WriteLine("#Permission = num"); w.WriteLine("#\tThe \"permission\" of the rank. It's a number."); w.WriteLine("#\tThere are pre-defined permissions already set. (for the old ranks)"); w.WriteLine("#\t\tBanned = -20, Guest = 0, Builder = 30, AdvBuilder = 50, Operator = 80"); w.WriteLine("#\t\tSuperOP = 100, Nobody = 120"); w.WriteLine("#\tMust be greater than -50 and less than 120"); w.WriteLine("#\tThe higher the number, the more commands do (such as undo allowing more seconds)"); w.WriteLine("#Limit = num"); w.WriteLine("#\tThe command limit for the rank (can be changed in-game with /limit)"); w.WriteLine("#\tMust be greater than 0"); w.WriteLine("#MaxUndo = num"); w.WriteLine("#\tThe undo limit for the rank, only applies when undoing others."); w.WriteLine("#\tMust be greater than 0"); w.WriteLine("#Color = char"); w.WriteLine("#\tA single letter (a-f) or number (0-9) denoting the color of the rank"); w.WriteLine("#MOTD = string"); w.WriteLine("#\tAlternate MOTD players of the rank will see when joining the server."); w.WriteLine("#\tLeave blank to use the server MOTD."); w.WriteLine("#OSMaps = num"); w.WriteLine("#\tThe number of maps the players will have in /os"); w.WriteLine("#Prefix = string"); w.WriteLine("#\tCharacters that appear directly before a player's name in chat."); w.WriteLine("#\tLeave blank to have no characters before the names of players."); w.WriteLine("#GenVolume = num"); w.WriteLine("#\tThe maximum volume of a map that can be generated by players of this rank."); w.WriteLine("#AfkKickMinutes = num"); w.WriteLine("#\tNumber of minutes a player can be AFK for, before they can be AFK kicked."); w.WriteLine(); w.WriteLine(); foreach (Group group in givenList) { w.WriteLine("RankName = " + group.Name); foreach (ConfigElement elem in cfg) { w.WriteLine(elem.Format(group)); } w.WriteLine(); } } }
public static BlockDefinition[] Load(bool global, string mapName) { BlockDefinition[] defs = new BlockDefinition[Block.ExtendedCount]; string path = global ? GlobalPath : "blockdefs/lvl_" + mapName + ".json"; if (!File.Exists(path)) { return(defs); } if (elems == null) { elems = ConfigElement.GetAll(typeof(BlockDefinition)); } try { JsonContext ctx = new JsonContext(); ctx.Val = File.ReadAllText(path); JsonArray array = (JsonArray)Json.ParseStream(ctx); if (array == null) { return(defs); } foreach (object raw in array) { JsonObject obj = (JsonObject)raw; if (obj == null) { continue; } BlockDefinition def = new BlockDefinition(); obj.Deserialise(elems, def); if (String.IsNullOrEmpty(def.Name)) { continue; } BlockID block = def.GetBlock(); if (block >= defs.Length) { Logger.Log(LogType.Warning, "Invalid block ID: " + def.RawID); } else { defs[block] = def; } } } catch (Exception ex) { Logger.LogError("Error Loading block defs from " + path, ex); } return(defs); }
static void SaveGroups(List <Group> givenList) { if (cfg == null) { cfg = ConfigElement.GetAll(typeof(Group)); } using (StreamWriter w = new StreamWriter(Paths.RankPropsFile)) { w.WriteLine("#Version 3"); w.WriteLine("#RankName = string"); w.WriteLine("#\tThe name of the rank (e.g. Guest)"); w.WriteLine("#Permission = number"); w.WriteLine("#\tThe \"permission\" level number of the rank."); w.WriteLine("#\tPermission level numbers must be between -20 and 120"); w.WriteLine("#\tThe higher the number, the more commands and blocks are available"); w.WriteLine("#"); w.WriteLine("#\tFor example, the default ranks use the following permission levels:"); w.WriteLine("#\t\tBanned = -20, Guest = 0, Builder = 30, AdvBuilder = 50"); w.WriteLine("#\t\tOperator = 80, Admin = 100, Owner = 120"); w.WriteLine("#Limit = number"); w.WriteLine("#\tThe draw command limit for the rank (can be changed in-game with /limit)"); w.WriteLine("#\tMust be greater than 0"); w.WriteLine("#MaxUndo = number of seconds"); w.WriteLine("#\tThe undo limit for players of the rank when undoing others. (/undoplayer)"); w.WriteLine("#Color = color"); w.WriteLine("#\tThe default color shown in tab and chat for players of the rank (e.g. &f)"); w.WriteLine("#MOTD = string"); w.WriteLine("#\tThe default MOTD players of the rank will see when joining levels."); w.WriteLine("#\tLeave blank to use the server MOTD."); w.WriteLine("#OSMaps = number"); w.WriteLine("#\tThe maximum number of maps players of the rank can have in /os"); w.WriteLine("#Prefix = string"); w.WriteLine("#\tCharacters that always appear before names of players of the rank in chat."); w.WriteLine("#\tLeave blank to have no characters before the names of players."); w.WriteLine("#GenVolume = number"); w.WriteLine("#\tThe maximum volume of a map that can be generated by players of the rank."); w.WriteLine("#\t(e.g. 512 x 256 x 512 map = 67108864 volume)"); w.WriteLine("#AfkKickMinutes = number of minutes"); w.WriteLine("#\tNumber of minutes a player of the rank can be AFK for before they are automatically AFK kicked."); w.WriteLine(); w.WriteLine(); foreach (Group group in givenList) { w.WriteLine("RankName = " + group.Name); ConfigElement.SerialiseElements(cfg, w, group); w.WriteLine(); } } }
public void LoadConfig() { if (cfg == null) { cfg = ConfigElement.GetAll(typeof(DiscordConfig)); } PropertiesFile.Read(ConfigFile, LineProcessor); SaveConfig(); if (config.DiscordPrefix != "") { config.DiscordPrefix += " "; // add space after prefix, trim removes it } }
public static void SaveGroups(List <Group> givenList) { if (cfg == null) { cfg = ConfigElement.GetAll(typeof(Group)); } using (StreamWriter w = new StreamWriter(Paths.RankPropsFile)) { w.WriteLine("#Version 3"); w.WriteLine("#RankName = string"); w.WriteLine("#\tThe name of the rank (e.g. Guest)"); w.WriteLine("#Permission = num"); w.WriteLine("#\tThe \"permission\" of the rank. It's a number."); w.WriteLine("#\tThere are pre-defined permissions already set. (for the old ranks)"); w.WriteLine("#\t\tBanned = -20, Guest = 0, Builder = 30, AdvBuilder = 50, Operator = 80"); w.WriteLine("#\t\tSuperOP = 100, Nobody = 120"); w.WriteLine("#\tMust be greater than -50 and less than 120"); w.WriteLine("#\tThe higher the number, the more commands do (such as undo allowing more seconds)"); w.WriteLine("#Limit = num"); w.WriteLine("#\tThe draw command limit for the rank (can be changed in-game with /limit)"); w.WriteLine("#\tMust be greater than 0"); w.WriteLine("#MaxUndo = num"); w.WriteLine("#\tThe undo limit for the rank, only applies when undoing others."); w.WriteLine("#\tMust be greater than 0"); w.WriteLine("#Color = color"); w.WriteLine("#\tThe default color shown in tab and chat for players of the rank (e.g. &f)"); w.WriteLine("#MOTD = string"); w.WriteLine("#\tAlternate MOTD players of the rank will see when joining the server."); w.WriteLine("#\tLeave blank to use the server MOTD."); w.WriteLine("#OSMaps = num"); w.WriteLine("#\tThe number of maps the players will have in /os"); w.WriteLine("#Prefix = string"); w.WriteLine("#\tCharacters that always appear before names of players of the rank in chat."); w.WriteLine("#\tLeave blank to have no characters before the names of players."); w.WriteLine("#GenVolume = num"); w.WriteLine("#\tThe maximum volume of a map that can be generated by players of the rank."); w.WriteLine("#AfkKickMinutes = num"); w.WriteLine("#\tNumber of minutes a player of the rank can be AFK for before they are automatically AFK kicked."); w.WriteLine(); w.WriteLine(); foreach (Group group in givenList) { w.WriteLine("RankName = " + group.Name); ConfigElement.SerialiseElements(cfg, w, group); w.WriteLine(); } } }
public void SaveConfig() { if (cfg == null) { cfg = ConfigElement.GetAll(typeof(DiscordConfig)); } try { lock (saveLock) { using (StreamWriter w = new StreamWriter(ConfigFile)) SaveProps(w); } } catch (Exception ex) { Logger.LogError("Error saving " + ConfigFile, ex); } }
public static void InitAll() { Group temp = null; if (cfg == null) { cfg = ConfigElement.GetAll(typeof(Group)); } PropertiesFile.Read(Paths.RankPropsFile, ref temp, ParseProperty, '=', false); if (temp != null) { AddGroup(ref temp); } }
internal static void WriteAll(StreamWriter w, List <EffectSpawner> props) { w.WriteLine("["); if (elems == null) { elems = ConfigElement.GetAll(typeof(EffectSpawner)); } string separator = null; for (int i = 0; i < props.Count; i++) { w.Write(separator); Json.Serialise(w, elems, props[i]); separator = ",\r\n"; } w.WriteLine("]"); }
public static BlockDefinition[] Load(string path) { BlockDefinition[] defs = new BlockDefinition[Block.ExtendedCount]; if (!File.Exists(path)) { return(defs); } if (elems == null) { elems = ConfigElement.GetAll(typeof(BlockDefinition)); } try { string json = File.ReadAllText(path); JsonReader reader = new JsonReader(json); reader.OnMember = (obj, key, value) => { if (obj.Meta == null) { obj.Meta = new BlockDefinition(); } ConfigElement.Parse(elems, obj.Meta, key, (string)value); }; JsonArray array = (JsonArray)reader.Parse(); if (array == null) { return(defs); } foreach (object raw in array) { JsonObject obj = (JsonObject)raw; if (obj == null || obj.Meta == null) { continue; } BlockDefinition def = (BlockDefinition)obj.Meta; if (String.IsNullOrEmpty(def.Name)) { continue; } BlockID block = def.GetBlock(); if (block >= defs.Length) { Logger.Log(LogType.Warning, "Invalid block ID: " + def.RawID); } else { defs[block] = def; } // In case user manually edited fallback in the json file def.FallBack = Math.Min(def.FallBack, Block.CpeMaxBlock); } } catch (Exception ex) { Logger.LogError("Error Loading block defs from " + path, ex); } return(defs); }
public void Start() { serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGameProps)); levelConfig = ConfigElement.GetAll(typeof(Level)); #pragma warning disable 0618 Player.players = PlayerInfo.Online.list; PlayerInfo.players = PlayerInfo.Online.list; Server.levels = LevelInfo.Loaded.list; PlayerBot.playerbots = PlayerBot.Bots.list; #pragma warning restore 0618 StartTime = DateTime.UtcNow; StartTimeLocal = StartTime.ToLocalTime(); shuttingDown = false; Log("Starting Server"); try { if (File.Exists("Restarter.exe")) { File.Delete("Restarter.exe"); } } catch { } try { if (File.Exists("Restarter.pdb")) { File.Delete("Restarter.pdb"); } } catch { } CheckFile("MySql.Data.dll"); CheckFile("System.Data.SQLite.dll"); CheckFile("sqlite3.dll"); CheckFile("Newtonsoft.Json.dll"); CheckFile("LibNoise.dll"); EnsureFilesExist(); MoveOutdatedFiles(); lava = new LavaSurvival(); zombie = new ZombieGame(); Countdown = new CountdownGame(); LoadAllSettings(); InitDatabase(); Economy.LoadDatabase(); Server.zombie.CheckTableExists(); Level[] loaded = LevelInfo.Loaded.Items; foreach (Level l in loaded) { l.Unload(); } Background.QueueOnce(UpgradeTasks.CombineEnvFiles); Background.QueueOnce(LoadMainLevel); Plugin.Load(); Background.QueueOnce(UpgradeTasks.UpgradeOldBlacklist); Background.QueueOnce(LoadPlayerLists); Background.QueueOnce(LoadAutoloadCommands); Background.QueueOnce(UpgradeTasks.MovePreviousLevelFiles); Background.QueueOnce(UpgradeTasks.UpgradeOldLockdown); Background.QueueOnce(SetupSocket); Background.QueueOnce(InitTimers); Background.QueueOnce(InitRest); Background.QueueOnce(InitHeartbeat); Devs.Clear(); Mods.Clear(); Background.QueueOnce(InitTasks.UpdateStaffList); MainScheduler.QueueRepeat(ServerTasks.TemprankExpiry, null, TimeSpan.FromMinutes(1)); Background.QueueRepeat(ServerTasks.AutoSave, 1, TimeSpan.FromSeconds(Server.backupInterval)); Background.QueueRepeat(ServerTasks.BlockUpdates, null, TimeSpan.FromSeconds(Server.blockInterval)); Background.QueueRepeat(ThreadSafeCache.DBCache.CleanupTask, null, TimeSpan.FromMinutes(5)); }
public void Start() { serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGame)); PlayerInfo.players = PlayerInfo.Online.list; Player.players = PlayerInfo.Online.list; Server.levels = LevelInfo.Loaded.list; PlayerBot.playerbots = PlayerBot.Bots.list; StartTime = DateTime.UtcNow; StartTimeLocal = StartTime.ToLocalTime(); shuttingDown = false; Log("Starting Server"); try { if (File.Exists("Restarter.exe")) { File.Delete("Restarter.exe"); } } catch { } try { if (File.Exists("Restarter.pdb")) { File.Delete("Restarter.pdb"); } } catch { } CheckFile("MySql.Data.dll"); CheckFile("System.Data.SQLite.dll"); CheckFile("sqlite3.dll"); CheckFile("Newtonsoft.Json.dll"); CheckFile("LibNoise.dll"); EnsureFilesExist(); MoveOutdatedFiles(); Chat.LoadCustomTokens(); if (File.Exists("text/emotelist.txt")) { foreach (string s in File.ReadAllLines("text/emotelist.txt")) { Player.emoteList.Add(s); } } else { File.Create("text/emotelist.txt").Dispose(); } lava = new LavaSurvival(); zombie = new ZombieGame(); Countdown = new CountdownGame(); LoadAllSettings(); InitDatabase(); Economy.LoadDatabase(); Server.zombie.CheckTableExists(); Level[] loaded = LevelInfo.Loaded.Items; foreach (Level l in loaded) { l.Unload(); } ml.Queue(LoadMainLevel); Plugin.Load(); ml.Queue(LoadPlayerLists); ml.Queue(LoadAutoloadCommands); ml.Queue(LoadGCAccepted); ml.Queue(InitTimers); ml.Queue(InitRest); ml.Queue(InitHeartbeat); UpdateStaffList(); }