private void OnPlayerSleepEnded(BasePlayer player) { bool isOnline = false; foreach (BasePlayer p in BasePlayer.activePlayerList) { if (p.UserIDString == player.UserIDString) { isOnline = true; } } if (!OnlinePlayers.Contains(player.UserIDString) && isOnline) { OnlinePlayers.Add(player.UserIDString); if (dataFile[player.UserIDString] != null) { Broadcast(player, "OnJoin", player.displayName); } else { Broadcast(player, "OnWelcome", player.displayName); dataFile[player.UserIDString] = player.displayName; dataFile.Save(); } } }
private void OnServerInitialized() { RustNetwork = Convert.ToInt32(Protocol.network); RustSave = Convert.ToInt32(Protocol.save); RustWorldSize = ConVar.Server.worldsize; RustSeed = ConVar.Server.seed; Puts($"Game Version: {RustNetwork}.{RustSave}, size: {RustWorldSize}, seed: {RustSeed}"); DynamicConfigFile settingsData = Interface.Oxide.DataFileSystem.GetDatafile(nameof(ZLevelsRemasteredMySQL)); if (settingsData["RustNetwork"] == null) { settingsData["RustNetwork"] = RustNetwork; settingsData["RustSave"] = RustSave; settingsData["RustWorldSize"] = RustWorldSize; settingsData["RustSeed"] = RustSeed; settingsData.Save(); } if (conf.Options.TurncateDataOnMonthlyWipe == true) { if (Convert.ToInt32(settingsData["RustNetwork"]) != Convert.ToInt32(Protocol.network)) { Puts("Detected monthly rust update. Turncating data."); settingsData["RustNetwork"] = RustNetwork; settingsData["RustSave"] = RustSave; settingsData["RustWorldSize"] = RustWorldSize; settingsData["RustSeed"] = RustSeed; settingsData.Save(); TurncateData(); } } if (conf.Options.TurncateDataOnMapWipe == true) { if (Convert.ToInt32(settingsData["RustSeed"]) != Convert.ToInt32(ConVar.Server.seed)) { Puts("Detected map change. Turncating data."); settingsData["RustNetwork"] = RustNetwork; settingsData["RustSave"] = RustSave; settingsData["RustWorldSize"] = RustWorldSize; settingsData["RustSeed"] = RustSeed; settingsData.Save(); TurncateData(); } } if (conf.Options.UpdateAtStart) { UpdateStatsData(); } timer.Repeat((float)conf.Options.SaveTimer, 0, () => { UpdateStatsData(); }); }
private void setCornSpawn(BasePlayer player, string command, string[] args) { if (player.IsAdmin) { spawns["cornX"] = player.transform.position.x; spawns["cornY"] = player.transform.position.y; spawns["cornZ"] = player.transform.position.z; spawns.Save(); PrintToChat(player, "Corn Spawnpoint saved!"); } }
public static void LoadConfig() { config.Load(); config["Список доступных символов в нике"] = abc = GetConfig("Список доступных символов в нике", " _-()[]=+!abcdefghijklmnopqrstuvwxyzабвгдеёжзийклмнопрстуфхцчшщъыьэюя0123456789"); config["Список начальных букв нецензурных слов или слова целиком | список исключений"] = swearWords = GetConfig("Список начальных букв нецензурных слов или слова целиком | список исключений", new Dictionary <string, object>()).ToDictionary(p => p.Key, p => ((List <object>)p.Value).Cast <string>().ToList()); config.Save(); }
private void UpdateLocation() { DynamicConfigFile dataFile = Interface.Oxide.DataFileSystem.GetDatafile("MarkedForDeathData"); ulong markID = Convert.ToUInt64(dataFile["MarkedPlayerSteamID"]); BasePlayer mark = null; foreach (BasePlayer player in BasePlayer.allPlayerList) { if (player.userID == markID) { mark = player; break; } } if (mark != null) { dataFile["MarkedPlayerLocation"] = GetScrambledMapCoords(mark.ServerPosition); dataFile.Save(); ReloadInfoPanel(); } else { Interface.Oxide.LogError($"Could not find player with SteamID {markID}"); } }
public void UpdateConfigFile() { bool changed = false; changed |= DefaultValue("HelpNotifierEnabled", true); changed |= DefaultValue("HelpNotifierInverval", 300); changed |= DefaultValue("BossPositionNotifierEnabled", true); changed |= DefaultValue("BossPositionNotifierInterval", 90); changed |= DefaultValue("AutoBossPromoteDelay", 300); changed |= DefaultValue("AutoBossPromoteMinPlayers", 5); changed |= DefaultValue("HeloStrikePrice_Quantity", 25); changed |= DefaultValue("HeloStrikePrice_Item", "metal.refined"); changed |= DefaultValue("MaxHelos", 2); changed |= DefaultValue("DecoyPrice_Quantity", 5); changed |= DefaultValue("DecoyPrice_Item", "metal.refined"); changed |= DefaultValue("EvadePrice_Quantity", 100); changed |= DefaultValue("EvadePrice_Item", "leather"); changed |= DefaultValue("FallbackWorldSize", 4000); changed |= DefaultValue("AllowBossDisconnect", false); if (changed) { configFile.Save(); } }
/// <summary> /// Gets a datafile /// </summary> /// <param name="name"></param> /// <returns></returns> public DynamicConfigFile GetDatafile(string name) { // See if it already exists DynamicConfigFile datafile; if (datafiles.TryGetValue(name, out datafile)) { return(datafile); } // Generate the filename string filename = Path.Combine(Directory, string.Format("{0}.json", SanitiseName(name))); // Does it exist? if (File.Exists(filename)) { // Load it datafile = new DynamicConfigFile(); datafile.Load(filename); } else { // Just make a new one datafile = new DynamicConfigFile(); datafile.Save(filename); } // Add and return datafiles.Add(name, datafile); return(datafile); }
private void ChangeMarkedPlayer(BasePlayer nextMark) { // Update the datafile DynamicConfigFile dataFile = Interface.Oxide.DataFileSystem.GetDatafile("MarkedForDeathData"); dataFile["MarkedPlayerSteamID"] = nextMark.userID; dataFile["MarkedPlayerName"] = nextMark.displayName; dataFile["MarkedPlayerLocation"] = GetScrambledMapCoords(nextMark.ServerPosition); dataFile.Save(); }
private void Init() { config = Config.ReadObject <PluginConfig>(); dataFile = Interface.Oxide.DataFileSystem.GetDatafile("Wasdik2"); dataFile["EpicString"] = "EpicValue"; dataFile["EpicNumber"] = 42; dataFile["EpicCategory", "EpicString2"] = "EpicValue2"; dataFile.Save(); }
public DynamicConfigFile GetDatafile(string name) { DynamicConfigFile file = this.GetFile(name); if (!file.Exists(null)) { file.Save(null); } else { file.Load(null); } return(file); }
void OnServerInitialized() // Create the plugin data file if it doesn't already exist { if (!Interface.Oxide.DataFileSystem.ExistsDatafile("MarkedForDeathData")) { DynamicConfigFile newDataFile = Interface.Oxide.DataFileSystem.GetDatafile("MarkedForDeathData"); newDataFile["MarkedPlayerSteamID"] = Convert.ToUInt64(Config["DefaultMarkedPlayerID"]); newDataFile["MarkedPlayerName"] = Config["DefaultMarkedPlayerName"]; newDataFile["MarkedPlayerLocation"] = "A1"; newDataFile.Save(); } timer.Repeat(60 * LOCATION_UPDATE_INTERVAL_IN_MINUTES, 0, () => UpdateLocation()); ReloadInfoPanel(); }
private void setCustomMsg(bool firing, int ID, String input) { DynamicConfigFile dataFile = null; if (firing) { dataFile = Interface.Oxide.DataFileSystem.GetDatafile("firingMsgs"); } else { dataFile = Interface.Oxide.DataFileSystem.GetDatafile("warningMsgs"); } dataFile[ID.ToString()] = input; dataFile.Save(); }
static FilterWords() { string path = Path.Combine(Interface.Oxide.ConfigDirectory, "SwearWords.json"); config = new DynamicConfigFile(path); if (File.Exists(path)) { config.Load(); } else { config.Save(); } LoadConfig(); }
/// <summary> /// Gets a datafile /// </summary> /// <param name="name"></param> /// <returns></returns> public DynamicConfigFile GetDatafile(string name) { DynamicConfigFile datafile = GetFile(name); // Does it exist? if (datafile.Exists()) { // Load it datafile.Load(); } else { // Just make a new one datafile.Save(); } return(datafile); }
public void TestEmptyTableInConfig() { Lua lua = new Lua(); lua.LoadString("TeleportData = { AdminTP = {}, Test = 3, ABC=4 }", "test").Call(); LuaTable tdata = lua["TeleportData"] as LuaTable; DynamicConfigFile cfgfile = new DynamicConfigFile(); Utility.SetConfigFromTable(cfgfile, tdata); Assert.AreEqual(3, cfgfile["Test"], "Failed TeleportData.Test"); Assert.AreEqual(4, cfgfile["ABC"], "Failed TeleportData.ABC"); //Assert.IsInstanceOfType(cfgfile["AdminTP"], typeof(List<string, object>), "Failed TeleportData.AdminTP"); string tmp = Path.GetTempFileName(); cfgfile.Save(tmp); string text = File.ReadAllText(tmp); File.Delete(tmp); }
protected override void LoadConfig() { string path = $"{Manager.ConfigPath}/MagicPanel/{Name}.json"; DynamicConfigFile newConfig = new DynamicConfigFile(path); if (!newConfig.Exists()) { LoadDefaultConfig(); newConfig.Save(); } try { newConfig.Load(); } catch (Exception ex) { RaiseError("Failed to load config file (is the config file corrupt?) (" + ex.Message + ")"); return; } newConfig.Settings.DefaultValueHandling = DefaultValueHandling.Populate; _pluginConfig = AdditionalConfig(newConfig.ReadObject <PluginConfig>()); newConfig.WriteObject(_pluginConfig); }
public void TestEmptyTableInConfig() { Lua lua = new Lua(); lua.LoadString("TeleportData = { AdminTP = {}, Test = 3, ABC=4 }", "test").Call(); LuaTable tdata = lua["TeleportData"] as LuaTable; DynamicConfigFile cfgfile = new DynamicConfigFile(Path.GetTempFileName()); Utility.SetConfigFromTable(cfgfile, tdata); Assert.AreEqual(3, cfgfile["Test"], "Failed TeleportData.Test"); Assert.AreEqual(4, cfgfile["ABC"], "Failed TeleportData.ABC"); //Assert.IsInstanceOfType(cfgfile["AdminTP"], typeof(List<string, object>), "Failed TeleportData.AdminTP"); string tmp = Path.GetTempFileName(); cfgfile.Save(); string text = File.ReadAllText(tmp); File.Delete(tmp); }
void LoadAllContainers() { try { lootTable = getFile("LootTables"); } catch (JsonReaderException e) { PrintWarning($"JSON error in 'LootTables' > Line: {e.LineNumber} | {e.Path}"); Interface.GetMod().UnloadPlugin(this.Title); return; } lootTables = new Dictionary <string, object>(); lootTables = lootTable["LootTables"] as Dictionary <string, object>; if (lootTables == null) { lootTables = new Dictionary <string, object>(); } bool wasAdded = false; foreach (var lootPrefab in lootPrefabsToUse) { if (!lootTables.ContainsKey((string)lootPrefab)) { var loot = GameManager.server.FindPrefab((string)lootPrefab)?.GetComponent <LootContainer>(); if (loot == null) { continue; } var container = new Dictionary <string, object>(); container.Add("Enabled", ((((string)lootPrefab).Contains("bradley_crate")) || (((string)lootPrefab).Contains("heli_crate"))) ? false : true); container.Add("Scrap", loot.scrapAmount); int slots = 0; if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { slots += lootSpawnSlots[i].numberToSpawn; } } else { slots = loot.maxDefinitionsToSpawn; } container.Add("ItemsMin", slots); container.Add("ItemsMax", slots); container.Add("MaxBPs", 1); var itemList = new Dictionary <string, object>(); if (loot.lootDefinition != null) { GetLootSpawn(loot.lootDefinition, ref itemList); } else if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { LootContainer.LootSpawnSlot lootSpawnSlot = lootSpawnSlots[i]; GetLootSpawn(lootSpawnSlot.definition, ref itemList); } } container.Add("ItemList", itemList); lootTables.Add((string)lootPrefab, container); wasAdded = true; } } if (wasAdded) { lootTable.Set("LootTables", lootTables); lootTable.Save(); } wasAdded = false; bool wasRemoved = false; int activeTypes = 0; foreach (var lootTable in lootTables.ToList()) { var loot = GameManager.server.FindPrefab(lootTable.Key)?.GetComponent <LootContainer>(); if (loot == null) { lootTables.Remove(lootTable.Key); wasRemoved = true; continue; } var container = lootTable.Value as Dictionary <string, object>; if (!container.ContainsKey("Enabled")) { container.Add("Enabled", true); wasAdded = true; } if ((bool)container["Enabled"]) { activeTypes++; } if (!container.ContainsKey("Scrap")) { container.Add("Scrap", loot.scrapAmount); wasAdded = true; } int slots = 0; if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { slots += lootSpawnSlots[i].numberToSpawn; } } else { slots = loot.maxDefinitionsToSpawn; } if (!container.ContainsKey("MaxBPs")) { container.Add("MaxBPs", 1); wasAdded = true; } if (!container.ContainsKey("ItemsMin")) { container.Add("ItemsMin", slots); wasAdded = true; } if (!container.ContainsKey("ItemsMax")) { container.Add("ItemsMax", slots); wasAdded = true; } if (!container.ContainsKey("ItemsMax")) { container.Add("ItemsMax", slots); wasAdded = true; } if (!container.ContainsKey("ItemList")) { var itemList = new Dictionary <string, object>(); if (loot.lootDefinition != null) { GetLootSpawn(loot.lootDefinition, ref itemList); } else if (loot.LootSpawnSlots.Length > 0) { LootContainer.LootSpawnSlot[] lootSpawnSlots = loot.LootSpawnSlots; for (int i = 0; i < lootSpawnSlots.Length; i++) { LootContainer.LootSpawnSlot lootSpawnSlot = lootSpawnSlots[i]; GetLootSpawn(lootSpawnSlot.definition, ref itemList); } } container.Add("ItemList", itemList); wasAdded = true; } Items.Add(lootTable.Key, new List <string> [5]); Blueprints.Add(lootTable.Key, new List <string> [5]); for (var i = 0; i < 5; ++i) { Items[lootTable.Key][i] = new List <string>(); Blueprints[lootTable.Key][i] = new List <string>(); } foreach (var itemEntry in container["ItemList"] as Dictionary <string, object> ) { bool isBP = itemEntry.Key.EndsWith(".blueprint") ? true : false; var def = ItemManager.FindItemDefinition(itemEntry.Key.Replace(".blueprint", "")); if (def != null) { if (isBP && def.Blueprint != null && def.Blueprint.isResearchable) { int index = (int)def.rarity; if (!Blueprints[lootTable.Key][index].Contains(def.shortname)) { Blueprints[lootTable.Key][index].Add(def.shortname); } } else { int index = 0; object indexoverride; if (rarityItemOverride.TryGetValue(def.shortname, out indexoverride)) { index = Convert.ToInt32(indexoverride); } else { index = (int)def.rarity; } if (!Items[lootTable.Key][index].Contains(def.shortname)) { Items[lootTable.Key][index].Add(def.shortname); } } } } totalItemWeight.Add(lootTable.Key, 0); totalBlueprintWeight.Add(lootTable.Key, 0); itemWeights.Add(lootTable.Key, new int[5]); blueprintWeights.Add(lootTable.Key, new int[5]); for (var i = 0; i < 5; ++i) { totalItemWeight[lootTable.Key] += (itemWeights[lootTable.Key][i] = ItemWeight(baseItemRarity, i) * Items[lootTable.Key][i].Count); totalBlueprintWeight[lootTable.Key] += (blueprintWeights[lootTable.Key][i] = ItemWeight(baseItemRarity, i) * Blueprints[lootTable.Key][i].Count); } } if (wasAdded || wasRemoved) { lootTable.Set("LootTables", lootTables); lootTable.Save(); } lootTable.Clear(); Puts($"Using '{activeTypes}' active of '{lootTables.Count}' supported containertypes"); }
private void Unload() { timeData.Save(); }
private void TestCommand3(IPlayer player, string command, string[] args) { dataFile.Remove("EpicString"); dataFile.Save(); }
void OnServerInitialized() { #if !RUST throw new NotSupportedException("This plugin does not support this game"); #endif RustNetwork = Convert.ToInt32(Protocol.network); RustSave = Convert.ToInt32(Protocol.save); RustWorldSize = ConVar.Server.worldsize; RustSeed = ConVar.Server.seed; Puts($"Game Version: {RustNetwork}.{RustSave}, size: {RustWorldSize}, seed: {RustSeed}"); string curVersion = Version.ToString(); string[] version = curVersion.Split('.'); var majorPluginUpdate = version[0]; // Big Plugin Update var minorPluginUpdate = version[1]; // Small Plugin Update var databaseVersion = version[2]; // Database Update var pluginVersion = majorPluginUpdate + "." + minorPluginUpdate; Puts("Plugin version: " + majorPluginUpdate + "." + minorPluginUpdate + " Database version: " + databaseVersion); if (pluginVersion != getConfigVersion("plugin")) { Puts("New " + pluginVersion + " Old " + getConfigVersion("plugin")); Config["Version"] = pluginVersion + "." + databaseVersion; SaveConfig(); } if (databaseVersion != getConfigVersion("db")) { Puts("New " + databaseVersion + " Old " + getConfigVersion("db")); PrintWarning("Database base changes please drop the old!"); Config["Version"] = pluginVersion + "." + databaseVersion; SaveConfig(); } DynamicConfigFile dataFile = Interface.Oxide.DataFileSystem.GetDatafile(nameof(MStats)); if (dataFile["RustNetwork"] == null) { dataFile["RustNetwork"] = RustNetwork; dataFile["RustSave"] = RustSave; dataFile["RustWorldSize"] = RustWorldSize; dataFile["RustSeed"] = RustSeed; dataFile.Save(); } if (Convert.ToBoolean(Config["TurncateDataOnMonthlyWipe"]) == true) { if (Convert.ToInt32(dataFile["RustNetwork"]) != RustNetwork) { Puts("Detected monthly rust update. Turncating data."); dataFile["RustNetwork"] = RustNetwork; dataFile["RustSave"] = RustSave; dataFile["RustWorldSize"] = RustWorldSize; dataFile["RustSeed"] = RustSeed; dataFile.Save(); TurncateData(); } } if (Convert.ToBoolean(Config["TurncateDataOnMapWipe"]) == true) { if (Convert.ToInt32(dataFile["RustSeed"]) != RustSeed) { Puts("Detected monthly rust update. Turncating data."); dataFile["RustNetwork"] = RustNetwork; dataFile["RustSave"] = RustSave; dataFile["RustWorldSize"] = RustWorldSize; dataFile["RustSeed"] = RustSeed; dataFile.Save(); TurncateData(); } } }