diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs
index b23853fc..d5056e8a 100755
--- a/TShockAPI/Commands.cs
+++ b/TShockAPI/Commands.cs
@@ -156,7 +156,7 @@ namespace TShockAPI
ChatCommands.Add(new Command("cfg", Broadcast, "broadcast", "bc"));
ChatCommands.Add(new Command("whisper", Whisper, "whisper", "w", "tell"));
ChatCommands.Add(new Command("whisper", Reply, "reply", "r"));
- if (ConfigurationManager.DistributationAgent != "terraria-online")
+ if (TShock.Config.DistributationAgent != "terraria-online")
{
ChatCommands.Add(new Command("kill", Kill, "kill"));
ChatCommands.Add(new Command("butcher", Butcher, "butcher"));
@@ -285,9 +285,9 @@ namespace TShockAPI
public static void AttemptLogin(CommandArgs args)
{
- if (args.Player.LoginAttempts > ConfigurationManager.MaximumLoginAttempts && (ConfigurationManager.MaximumLoginAttempts != -1))
+ if (args.Player.LoginAttempts > TShock.Config.MaximumLoginAttempts && (TShock.Config.MaximumLoginAttempts != -1))
{
- Log.Warn(args.Player.IP + "(" + args.Player.Name + ") had " + ConfigurationManager.MaximumLoginAttempts + " or more invalid login attempts and was kicked automatically.");
+ Log.Warn(args.Player.IP + "(" + args.Player.Name + ") had " + TShock.Config.MaximumLoginAttempts + " or more invalid login attempts and was kicked automatically.");
Tools.Kick(args.Player, "Too many invalid login attempts.");
}
@@ -965,21 +965,21 @@ namespace TShockAPI
{
args.Player.SendMessage("TShock Config:");
string lineOne = string.Format("BanCheater : {0}, KickCheater : {1}, BanGriefer : {2}, KickGriefer : {3}",
- ConfigurationManager.BanCheater, ConfigurationManager.KickCheater,
- ConfigurationManager.BanGriefer, ConfigurationManager.KickGriefer);
+ TShock.Config.BanCheaters, TShock.Config.KickCheaters,
+ TShock.Config.BanGriefers, TShock.Config.KickGriefers);
args.Player.SendMessage(lineOne, Color.Yellow);
string lineTwo = string.Format("BanTnt : {0}, KickTnt : {1}, BanBoom : {2}, KickBoom : {3}",
- ConfigurationManager.BanTnt, ConfigurationManager.KickTnt,
- ConfigurationManager.BanBoom, ConfigurationManager.KickBoom);
+ TShock.Config.BanKillTileAbusers, TShock.Config.KickKillTileAbusers,
+ TShock.Config.BanExplosives, TShock.Config.KickExplosives);
args.Player.SendMessage(lineTwo, Color.Yellow);
string lineThree = string.Format("RangeChecks : {0}, DisableBuild : {1}, ProtectSpawn : {2}, ProtectRadius : {3}",
- ConfigurationManager.RangeChecks, ConfigurationManager.DisableBuild,
- ConfigurationManager.SpawnProtect, ConfigurationManager.SpawnProtectRadius);
+ TShock.Config.RangeChecks, TShock.Config.DisableBuild,
+ TShock.Config.SpawnProtection, TShock.Config.SpawnProtectionRadius);
args.Player.SendMessage(lineThree, Color.Yellow);
string lineFour = string.Format("MaxSlots : {0}, SpamChecks : {1}, InvMultiplier : {2}, DMS : {3}, SpawnRate {4}",
- ConfigurationManager.MaxSlots, ConfigurationManager.SpamChecks,
- ConfigurationManager.InvasionMultiplier, ConfigurationManager.DefaultMaxSpawns,
- ConfigurationManager.DefaultSpawnRate);
+ TShock.Config.MaxSlots, TShock.Config.SpamChecks,
+ TShock.Config.InvasionMultiplier, TShock.Config.DefaultMaximumSpawns,
+ TShock.Config.DefaultSpawnRate);
args.Player.SendMessage(lineFour, Color.Yellow);
}
@@ -1020,7 +1020,7 @@ namespace TShockAPI
int amount = Convert.ToInt32(args.Parameters[0]);
int.TryParse(args.Parameters[0], out amount);
NPC.defaultMaxSpawns = amount;
- ConfigurationManager.DefaultMaxSpawns = amount;
+ TShock.Config.DefaultMaximumSpawns = amount;
Tools.Broadcast(string.Format("{0} changed the maximum spawns to: {1}", args.Player.Name, amount));
}
@@ -1035,7 +1035,7 @@ namespace TShockAPI
int amount = Convert.ToInt32(args.Parameters[0]);
int.TryParse(args.Parameters[0], out amount);
NPC.defaultSpawnRate = amount;
- ConfigurationManager.DefaultSpawnRate = amount;
+ TShock.Config.DefaultSpawnRate = amount;
Tools.Broadcast(string.Format("{0} changed the spawn rate to: {1}", args.Player.Name, amount));
}
@@ -1127,14 +1127,14 @@ namespace TShockAPI
private static void ToggleAntiBuild(CommandArgs args)
{
- ConfigurationManager.DisableBuild = (ConfigurationManager.DisableBuild == false);
- Tools.Broadcast(string.Format("Anti-build is now {0}.", (ConfigurationManager.DisableBuild ? "on" : "off")));
+ TShock.Config.DisableBuild = (TShock.Config.DisableBuild == false);
+ Tools.Broadcast(string.Format("Anti-build is now {0}.", (TShock.Config.DisableBuild ? "on" : "off")));
}
private static void ProtectSpawn(CommandArgs args)
{
- ConfigurationManager.SpawnProtect = (ConfigurationManager.SpawnProtect == false);
- Tools.Broadcast(string.Format("Spawn is now {0}.", (ConfigurationManager.SpawnProtect ? "protected" : "open")));
+ TShock.Config.SpawnProtection = (TShock.Config.SpawnProtection == false);
+ Tools.Broadcast(string.Format("Spawn is now {0}.", (TShock.Config.SpawnProtection ? "protected" : "open")));
}
private static void Region(CommandArgs args)
@@ -1358,17 +1358,17 @@ namespace TShockAPI
private static void AuthToken(CommandArgs args)
{
- if (ConfigurationManager.AuthToken == 0)
+ if (TShock.AuthToken == 0)
{
return;
}
int givenCode = Convert.ToInt32(args.Parameters[0]);
- if (givenCode == ConfigurationManager.AuthToken)
+ if (givenCode == TShock.AuthToken)
{
TextWriter tw = new StreamWriter(FileTools.UsersPath, true);
tw.Write("\n" + args.Player.IP + " superadmin");
args.Player.SendMessage("SuperAdmin authenticated. Please re-connect using the same IP.");
- ConfigurationManager.AuthToken = 0;
+ TShock.AuthToken = 0;
tw.Close();
}
}
diff --git a/TShockAPI/ConfigFile.cs b/TShockAPI/ConfigFile.cs
index bbfc2d09..88f82be0 100644
--- a/TShockAPI/ConfigFile.cs
+++ b/TShockAPI/ConfigFile.cs
@@ -15,17 +15,21 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+using System;
+using System.IO;
+using Newtonsoft.Json;
+
namespace TShockAPI
{
- internal class ConfigFile
+ public class ConfigFile
{
public int InvasionMultiplier = 1;
public int DefaultMaximumSpawns = 4;
public int DefaultSpawnRate = 700;
public int ServerPort = 7777;
- public bool EnableWhitelist;
- public bool InfiniteInvasion;
- public bool AlwaysPvP;
+ public bool EnableWhitelist = false;
+ public bool InfiniteInvasion = false;
+ public bool AlwaysPvP = false;
public bool KickCheaters = true;
public bool BanCheaters = true;
public bool KickGriefers = true;
@@ -44,8 +48,9 @@ namespace TShockAPI
public bool DisableBuild = false;
public int TileThreshold = 20;
- public float[] AdminChatRGB = {255, 0, 0};
+ public float[] AdminChatRGB = { 255, 0, 0 };
public string AdminChatPrefix = "(Admin) ";
+ public bool AdminChatEnabled = true;
public int PvpThrottle = 0;
@@ -62,6 +67,44 @@ namespace TShockAPI
public int MaximumLoginAttempts = 3;
- public bool EnableOptionalAlwaysOnAdminChatColor = true;
+ public static ConfigFile Read(string path)
+ {
+ if (!File.Exists(path))
+ return new ConfigFile();
+ using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
+ {
+ return Read(fs);
+ }
+ }
+
+ public static ConfigFile Read(Stream stream)
+ {
+ using(var sr = new StreamReader(stream))
+ {
+ var cf = JsonConvert.DeserializeObject(sr.ReadToEnd());
+ if (ConfigRead != null)
+ ConfigRead(cf);
+ return cf;
+ }
+ }
+
+ public void Write(string path)
+ {
+ using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Write))
+ {
+ Write(fs);
+ }
+ }
+
+ public void Write(Stream stream)
+ {
+ var str = JsonConvert.SerializeObject(this, Formatting.Indented);
+ using (var sw = new StreamWriter(stream))
+ {
+ sw.Write(str);
+ }
+ }
+
+ public static Action ConfigRead;
}
}
\ No newline at end of file
diff --git a/TShockAPI/ConfigurationManager.cs b/TShockAPI/ConfigurationManager.cs
deleted file mode 100644
index cf0801c3..00000000
--- a/TShockAPI/ConfigurationManager.cs
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
-TShock, a server mod for Terraria
-Copyright (C) 2011 The TShock Team
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
-*/
-using System.IO;
-using Newtonsoft.Json;
-using Terraria;
-
-namespace TShockAPI
-{
- ///
- /// Provides all the stupid little variables a home away from home.
- ///
- internal class ConfigurationManager
- {
- //Add default values here and in ConfigFile.cs
- //Values written here will automatically be pulled into a config file on save.
- public static int InvasionMultiplier = 1;
- public static int DefaultMaxSpawns = 4;
- public static int DefaultSpawnRate = 700;
- public static int ServerPort = 7777;
- public static bool EnableWhitelist = false;
- public static bool InfiniteInvasion = false;
- public static bool PermaPvp = false;
- public static int KillCount;
- public static bool KickCheater = true;
- public static bool BanCheater = true;
- public static bool KickGriefer = true;
- public static bool BanGriefer = true;
- public static bool BanTnt = true;
- public static bool KickTnt = true;
- public static bool BanBoom = true;
- public static bool KickBoom = true;
- public static bool DisableBoom = true;
- public static bool SpawnProtect = true;
- public static bool RangeChecks = true;
- public static int SpawnProtectRadius = 5;
- public static string DistributationAgent = "facepunch";
- public static int AuthToken;
- public static int MaxSlots = 8;
- public static bool SpamChecks = false;
- public static bool DisableBuild = false;
- public static float[] AdminChatRGB = {255, 0, 0};
- public static string AdminChatPrefix = "(Admin) ";
- public static bool RememberLeavePos = false;
- public static int TileThreshold = 20;
- public static int MaximumLoginAttempts = 3;
- public static bool AdminChatOptional = true;
-
- ///
- /// Don't allow pvp changing for x seconds.
- ///
- public static int PvpThrottle = 0;
-
- ///
- /// Backup every x minutes
- ///
- public static int BackupInterval = 0;
- ///
- /// Delete backups that are older than x mintues.
- ///
- public static int BackupKeepFor = 60;
-
- public static bool HardcoreOnly = false;
- public static bool KickOnHardcoreDeath = false;
- public static bool BanOnHardcoreDeath = false;
-
- public static bool AutoSave = true;
-
- public static void ReadJsonConfiguration()
- {
- TextReader tr = new StreamReader(FileTools.ConfigPath);
- ConfigFile cfg = JsonConvert.DeserializeObject(tr.ReadToEnd());
- tr.Close();
-
- InvasionMultiplier = cfg.InvasionMultiplier;
- DefaultMaxSpawns = cfg.DefaultMaximumSpawns;
- DefaultSpawnRate = cfg.DefaultSpawnRate;
- ServerPort = cfg.ServerPort;
- EnableWhitelist = cfg.EnableWhitelist;
- InfiniteInvasion = cfg.InfiniteInvasion;
- PermaPvp = cfg.AlwaysPvP;
- KickCheater = cfg.KickCheaters;
- BanCheater = cfg.BanCheaters;
- KickGriefer = cfg.KickGriefers;
- BanGriefer = cfg.BanGriefers;
- BanTnt = cfg.BanKillTileAbusers;
- KickTnt = cfg.KickKillTileAbusers;
- BanBoom = cfg.BanExplosives;
- KickBoom = cfg.KickExplosives;
- DisableBoom = cfg.DisableExplosives;
- SpawnProtect = cfg.SpawnProtection;
- SpawnProtectRadius = cfg.SpawnProtectionRadius;
- DistributationAgent = cfg.DistributationAgent;
- MaxSlots = cfg.MaxSlots;
- RangeChecks = cfg.RangeChecks;
- SpamChecks = cfg.SpamChecks;
- DisableBuild = cfg.DisableBuild;
- TileThreshold = cfg.TileThreshold;
- NPC.maxSpawns = DefaultMaxSpawns;
- NPC.defaultSpawnRate = DefaultSpawnRate;
- AdminChatRGB = cfg.AdminChatRGB;
- AdminChatPrefix = cfg.AdminChatPrefix;
- PvpThrottle = cfg.PvpThrottle;
- BackupInterval = cfg.BackupInterval;
- BackupKeepFor = cfg.BackupKeepFor;
- RememberLeavePos = cfg.RememberLeavePos;
- HardcoreOnly = cfg.HardcoreOnly;
- KickOnHardcoreDeath = cfg.KickOnHardcoreOnlyDeath;
- BanOnHardcoreDeath = cfg.BanOnHardcoreOnlyDeath;
- AutoSave = cfg.AutoSave;
- MaximumLoginAttempts = cfg.MaximumLoginAttempts;
- AdminChatOptional = cfg.EnableOptionalAlwaysOnAdminChatColor;
- }
-
- public static void WriteJsonConfiguration()
- {
- ConfigFile cfg = new ConfigFile();
- cfg.InvasionMultiplier = InvasionMultiplier;
- cfg.DefaultMaximumSpawns = DefaultMaxSpawns;
- cfg.DefaultSpawnRate = DefaultSpawnRate;
- cfg.ServerPort = ServerPort;
- cfg.EnableWhitelist = EnableWhitelist;
- cfg.InfiniteInvasion = InfiniteInvasion;
- cfg.AlwaysPvP = PermaPvp;
- cfg.KickCheaters = KickCheater;
- cfg.BanCheaters = BanCheater;
- cfg.KickGriefers = KickGriefer;
- cfg.BanGriefers = BanGriefer;
- cfg.BanKillTileAbusers = BanTnt;
- cfg.KickKillTileAbusers = KickTnt;
- cfg.BanExplosives = BanBoom;
- cfg.KickExplosives = KickBoom;
- cfg.DisableExplosives = DisableBoom;
- cfg.SpawnProtection = SpawnProtect;
- cfg.SpawnProtectionRadius = SpawnProtectRadius;
- cfg.MaxSlots = MaxSlots;
- cfg.RangeChecks = RangeChecks;
- cfg.SpamChecks = SpamChecks;
- cfg.DisableBuild = DisableBuild;
- cfg.TileThreshold = TileThreshold;
- cfg.AdminChatRGB = AdminChatRGB;
- cfg.AdminChatPrefix = AdminChatPrefix;
- cfg.PvpThrottle = PvpThrottle;
- cfg.BackupInterval = BackupInterval;
- cfg.BackupKeepFor = BackupKeepFor;
- cfg.RememberLeavePos = RememberLeavePos;
- cfg.HardcoreOnly = HardcoreOnly;
- cfg.BanOnHardcoreOnlyDeath = BanOnHardcoreDeath;
- cfg.KickOnHardcoreOnlyDeath = KickOnHardcoreDeath;
- cfg.AutoSave = AutoSave;
- cfg.MaximumLoginAttempts = MaximumLoginAttempts;
- cfg.EnableOptionalAlwaysOnAdminChatColor = AdminChatOptional;
- string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
- TextWriter tr = new StreamWriter(FileTools.ConfigPath);
- tr.Write(json);
- tr.Close();
- }
- }
-}
\ No newline at end of file
diff --git a/TShockAPI/FileTools.cs b/TShockAPI/FileTools.cs
index 26c9d5c3..d3b3c18a 100644
--- a/TShockAPI/FileTools.cs
+++ b/TShockAPI/FileTools.cs
@@ -88,15 +88,10 @@ namespace TShockAPI
{
if (File.Exists(ConfigPath))
{
- ConfigurationManager.ReadJsonConfiguration();
+ TShock.Config = ConfigFile.Read(ConfigPath);
// Add all the missing config properties in the json file
- ConfigurationManager.WriteJsonConfiguration();
- }
- else
- {
- ConfigurationManager.WriteJsonConfiguration();
- ConfigurationManager.ReadJsonConfiguration();
}
+ TShock.Config.Write(ConfigPath);
}
catch (Exception ex)
{
@@ -105,7 +100,7 @@ namespace TShockAPI
Log.Error(ex.ToString());
}
- Netplay.serverPort = ConfigurationManager.ServerPort;
+
}
///
@@ -115,7 +110,7 @@ namespace TShockAPI
/// true/false
public static bool OnWhitelist(string ip)
{
- if (!ConfigurationManager.EnableWhitelist)
+ if (!TShock.Config.EnableWhitelist)
{
return true;
}
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 4932a15d..318f8b7a 100755
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -165,7 +165,7 @@ namespace TShockAPI
{
return Tools.HandleGriefer(args.Player, "Sent client info more than once");
}
- if (ConfigurationManager.HardcoreOnly && !hardcore)
+ if (TShock.Config.HardcoreOnly && !hardcore)
{
Tools.ForceKick(args.Player, "Server is set to hardcore characters only!");
return true;
@@ -242,7 +242,7 @@ namespace TShockAPI
int tileX = Math.Abs(x);
int tileY = Math.Abs(y);
- if (ConfigurationManager.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
+ if (TShock.Config.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
{
if (!(type == 1 && ((tiletype == 0 && args.Player.TPlayer.selectedItem == 114) || (tiletype == 53 && args.Player.TPlayer.selectedItem == 266))))
{
@@ -265,7 +265,7 @@ namespace TShockAPI
args.Player.SendTileSquare(x, y);
return true;
}
- if (ConfigurationManager.DisableBuild)
+ if (TShock.Config.DisableBuild)
{
if (!args.Player.Group.HasPermission("editspawn"))
{
@@ -274,7 +274,7 @@ namespace TShockAPI
return true;
}
}
- if (ConfigurationManager.SpawnProtect)
+ if (TShock.Config.SpawnProtection)
{
if (!args.Player.Group.HasPermission("editspawn"))
{
@@ -311,14 +311,14 @@ namespace TShockAPI
bool pvp = args.Data.ReadBoolean();
long seconds = (long)(DateTime.UtcNow - args.Player.LastPvpChange).TotalSeconds;
- if (ConfigurationManager.PvpThrottle > 0 && seconds < ConfigurationManager.PvpThrottle)
+ if (TShock.Config.PvpThrottle > 0 && seconds < TShock.Config.PvpThrottle)
{
- args.Player.SendMessage(string.Format("You cannot change pvp status for {0} seconds", ConfigurationManager.PvpThrottle - seconds), 255, 0, 0);
- args.Player.SetPvP(id != args.Player.Index || ConfigurationManager.PermaPvp ? true : args.TPlayer.hostile);
+ args.Player.SendMessage(string.Format("You cannot change pvp status for {0} seconds", TShock.Config.PvpThrottle - seconds), 255, 0, 0);
+ args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : args.TPlayer.hostile);
}
else
{
- args.Player.SetPvP(id != args.Player.Index || ConfigurationManager.PermaPvp ? true : pvp);
+ args.Player.SetPvP(id != args.Player.Index || TShock.Config.AlwaysPvP ? true : pvp);
}
return true;
}
@@ -369,7 +369,7 @@ namespace TShockAPI
if (type == 29 || type == 28 || type == 37)
{
Log.Debug(string.Format("Explosive(PlyXY:{0}_{1}, Type:{2})", args.Player.TileX, args.Player.TileY, type));
- if (ConfigurationManager.DisableBoom && (!args.Player.Group.HasPermission("useexplosives") || !args.Player.Group.HasPermission("ignoregriefdetection")))
+ if (TShock.Config.DisableExplosives && (!args.Player.Group.HasPermission("useexplosives") || !args.Player.Group.HasPermission("ignoregriefdetection")))
{
Main.projectile[ident].type = 0;
args.Player.SendData(PacketTypes.ProjectileNew, "", ident);
@@ -450,14 +450,14 @@ namespace TShockAPI
Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), liquid));
return Tools.HandleGriefer(args.Player, "Manipulating liquid without bucket."); ;
}
- if (ConfigurationManager.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
+ if (TShock.Config.RangeChecks && ((Math.Abs(plyX - tileX) > 32) || (Math.Abs(plyY - tileY) > 32)))
{
Log.Debug(string.Format("Liquid(PlyXY:{0}_{1}, TileXY:{2}_{3}, Result:{4}_{5}, Amount:{6})",
plyX, plyY, tileX, tileY, Math.Abs(plyX - tileX), Math.Abs(plyY - tileY), liquid));
return Tools.HandleGriefer(args.Player, "Placing impossible to place liquid."); ;
}
- if (ConfigurationManager.SpawnProtect)
+ if (TShock.Config.SpawnProtection)
{
if (!args.Player.Group.HasPermission("editspawn"))
{
@@ -498,16 +498,18 @@ namespace TShockAPI
if (args.Player.InitSpawn)
{
- if (ConfigurationManager.HardcoreOnly && (ConfigurationManager.KickOnHardcoreDeath || ConfigurationManager.BanOnHardcoreDeath))
+ if (TShock.Config.HardcoreOnly && (TShock.Config.KickOnHardcoreOnlyDeath || TShock.Config.BanOnHardcoreOnlyDeath))
if (args.TPlayer.selectedItem != 50)
{
- if (ConfigurationManager.BanOnHardcoreDeath)
+ if (TShock.Config.BanOnHardcoreOnlyDeath)
{
if (!Tools.Ban(args.Player, "Death results in a ban"))
Tools.ForceKick(args.Player, "Death results in a ban, but can't ban you");
}
else
+ {
Tools.ForceKick(args.Player, "Death results in a kick");
+ }
return true;
}
}
diff --git a/TShockAPI/Properties/AssemblyInfo.cs b/TShockAPI/Properties/AssemblyInfo.cs
index 8d55d6aa..19f98b1c 100644
--- a/TShockAPI/Properties/AssemblyInfo.cs
+++ b/TShockAPI/Properties/AssemblyInfo.cs
@@ -35,5 +35,5 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.3.0.0701")]
-[assembly: AssemblyFileVersion("2.3.0.0701")]
+[assembly: AssemblyVersion("2.3.2.0701")]
+[assembly: AssemblyFileVersion("2.3.2.0701")]
diff --git a/TShockAPI/Resources.Designer.cs b/TShockAPI/Resources.Designer.cs
index 69d5beef..34060646 100644
--- a/TShockAPI/Resources.Designer.cs
+++ b/TShockAPI/Resources.Designer.cs
@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
-// Runtime Version:4.0.30319.1
+// Runtime Version:4.0.30319.235
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -82,8 +82,8 @@ namespace TShockAPI {
}
///
- /// Looks up a localized string similar to #see https://github.com/TShock/TShock/wiki/Item-List for a list of groups
- ///#List each banned item below this with spaces.
+ /// Looks up a localized string similar to #see https://github.com/TShock/TShock/wiki/Item-List for a list of item ids
+ ///#List each banned item ID below this, with each on a new line.
///
internal static string itembans {
get {
diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs
index b66a231b..70a3dccd 100755
--- a/TShockAPI/TShock.cs
+++ b/TShockAPI/TShock.cs
@@ -18,6 +18,7 @@ along with this program. If not, see .
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Data;
using System.Diagnostics;
using System.IO;
using System.Net;
@@ -43,6 +44,10 @@ namespace TShockAPI
public static BanManager Bans;
public static BackupManager Backups;
+ public static ConfigFile Config { get; set; }
+
+ public static IDbConnection Sql;
+
public override Version Version
{
get { return VersionNum; }
@@ -66,6 +71,7 @@ namespace TShockAPI
public TShock(Main game)
: base(game)
{
+ Config = new ConfigFile();
Order = 0;
}
@@ -73,6 +79,8 @@ namespace TShockAPI
{
HandleCommandLine(Environment.GetCommandLineArgs());
+ ConfigFile.ConfigRead += OnConfigRead;
+
Bans = new BanManager(FileTools.BansPath);
Backups = new BackupManager(Path.Combine(SavePath, "backups"));
@@ -105,11 +113,7 @@ namespace TShockAPI
WarpsManager.ReadAllSettings();
ItemManager.LoadBans();
- Main.autoSave = ConfigurationManager.AutoSave;
- Backups.KeepFor = ConfigurationManager.BackupKeepFor;
- Backups.Interval = ConfigurationManager.BackupInterval;
-
- Log.ConsoleInfo("AutoSave " + (ConfigurationManager.AutoSave ? "Enabled" : "Disabled"));
+ Log.ConsoleInfo("AutoSave " + (TShock.Config.AutoSave ? "Enabled" : "Disabled"));
Log.ConsoleInfo("Backups " + (Backups.Interval > 0 ? "Enabled" : "Disabled"));
}
@@ -180,14 +184,14 @@ namespace TShockAPI
*
*/
+ public static int AuthToken = -1;
private void OnPostInit()
{
if (!File.Exists(Path.Combine(SavePath, "auth.lck")))
{
var r = new Random((int)DateTime.Now.ToBinary());
- ConfigurationManager.AuthToken = r.Next(100000, 10000000);
- Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " +
- ConfigurationManager.AuthToken);
+ AuthToken = r.Next(100000, 10000000);
+ Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " + AuthToken);
Console.WriteLine("This token will only display ONCE. This only works ONCE. If you don't use it and the server goes down, delete auth.lck.");
FileTools.CreateFile(Path.Combine(SavePath, "auth.lck"));
}
@@ -206,7 +210,7 @@ namespace TShockAPI
{
if (player.TilesDestroyed != null)
{
- if (player.TileThreshold >= ConfigurationManager.TileThreshold)
+ if (player.TileThreshold >= TShock.Config.TileThreshold)
{
if (Tools.HandleTntUser(player, "Kill tile abuse detected."))
{
@@ -247,7 +251,7 @@ namespace TShockAPI
var player = new TSPlayer(ply);
player.Group = Tools.GetGroupForIP(player.IP);
- if (Tools.ActivePlayers() + 1 > ConfigurationManager.MaxSlots && !player.Group.HasPermission("reservedslot"))
+ if (Tools.ActivePlayers() + 1 > TShock.Config.MaxSlots && !player.Group.HasPermission("reservedslot"))
{
Tools.ForceKick(player, "Server is full");
handler.Handled = true;
@@ -270,7 +274,7 @@ namespace TShockAPI
Players[ply] = player;
- Netplay.spamCheck = ConfigurationManager.SpamChecks;
+
}
private void OnLeave(int ply)
@@ -280,7 +284,7 @@ namespace TShockAPI
{
Log.Info(string.Format("{0} left.", tsplr.Name));
- if (ConfigurationManager.RememberLeavePos)
+ if (TShock.Config.RememberLeavePos)
{
RemeberedPosManager.RemeberedPosistions.Add(new RemeberedPos(tsplr.IP,
new Vector2(tsplr.X / 16,
@@ -307,10 +311,10 @@ namespace TShockAPI
return;
}
- if (tsplr.Group.HasPermission("adminchat") && !text.StartsWith("/") && ConfigurationManager.AdminChatOptional)
+ if (tsplr.Group.HasPermission("adminchat") && !text.StartsWith("/") && Config.AdminChatEnabled)
{
- Tools.Broadcast(ConfigurationManager.AdminChatPrefix + "<" + tsplr.Name + "> " + text,
- (byte)ConfigurationManager.AdminChatRGB[0], (byte)ConfigurationManager.AdminChatRGB[1], (byte)ConfigurationManager.AdminChatRGB[2]);
+ Tools.Broadcast(TShock.Config.AdminChatPrefix + "<" + tsplr.Name + "> " + text,
+ (byte)TShock.Config.AdminChatRGB[0], (byte)TShock.Config.AdminChatRGB[1], (byte)TShock.Config.AdminChatRGB[2]);
e.Handled = true;
return;
}
@@ -377,8 +381,8 @@ namespace TShockAPI
}
else if (text == "autosave")
{
- Main.autoSave = ConfigurationManager.AutoSave = !ConfigurationManager.AutoSave;
- Log.ConsoleInfo("AutoSave " + (ConfigurationManager.AutoSave ? "Enabled" : "Disabled"));
+ Main.autoSave = TShock.Config.AutoSave = !TShock.Config.AutoSave;
+ Log.ConsoleInfo("AutoSave " + (TShock.Config.AutoSave ? "Enabled" : "Disabled"));
e.Handled = true;
}
else if (text.StartsWith("/"))
@@ -409,7 +413,7 @@ namespace TShockAPI
Debug.WriteLine("{0:X} ({2}): {3} ({1:XX})", player.Index, (byte)type, player.TPlayer.dead ? "dead " : "alive", type.ToString());
// Stop accepting updates from player as this player is going to be kicked/banned during OnUpdate (different thread so can produce race conditions)
- if ((ConfigurationManager.BanTnt || ConfigurationManager.KickTnt) && player.TileThreshold >= ConfigurationManager.TileThreshold && !player.Group.HasPermission("ignoregriefdetection"))
+ if ((TShock.Config.BanKillTileAbusers || TShock.Config.KickKillTileAbusers) && player.TileThreshold >= TShock.Config.TileThreshold && !player.Group.HasPermission("ignoregriefdetection"))
{
Log.Debug("Rejecting " + type + " from " + player.Name + " as this player is about to be kicked");
e.Handled = true;
@@ -447,15 +451,15 @@ namespace TShockAPI
{
Tools.HandleCheater(player, "Hacked health.");
}
- if (ConfigurationManager.PermaPvp)
+ if (Config.AlwaysPvP)
{
player.SetPvP(true);
}
- if (player.Group.HasPermission("causeevents") && ConfigurationManager.InfiniteInvasion)
+ if (player.Group.HasPermission("causeevents") && Config.InfiniteInvasion)
{
StartInvasion();
}
- if (ConfigurationManager.RememberLeavePos)
+ if (Config.RememberLeavePos)
{
foreach (RemeberedPos playerIP in RemeberedPosManager.RemeberedPosistions)
{
@@ -473,7 +477,7 @@ namespace TShockAPI
private void NpcHooks_OnStrikeNpc(NpcStrikeEventArgs e)
{
- if (ConfigurationManager.InfiniteInvasion)
+ if (Config.InfiniteInvasion)
{
IncrementKills();
if (Main.invasionSize < 10)
@@ -490,13 +494,13 @@ namespace TShockAPI
public static void StartInvasion()
{
Main.invasionType = 1;
- if (ConfigurationManager.InfiniteInvasion)
+ if (TShock.Config.InfiniteInvasion)
{
Main.invasionSize = 20000000;
}
else
{
- Main.invasionSize = 100 + (ConfigurationManager.InvasionMultiplier * Tools.ActivePlayers());
+ Main.invasionSize = 100 + (TShock.Config.InvasionMultiplier * Tools.ActivePlayers());
}
Main.invasionWarn = 0;
@@ -510,32 +514,33 @@ namespace TShockAPI
}
}
+ static int KillCount = 0;
public static void IncrementKills()
{
- ConfigurationManager.KillCount++;
+ KillCount++;
Random r = new Random();
int random = r.Next(5);
- if (ConfigurationManager.KillCount % 100 == 0)
+ if (KillCount % 100 == 0)
{
switch (random)
{
case 0:
- Tools.Broadcast(string.Format("You call that a lot? {0} goblins killed!", ConfigurationManager.KillCount));
+ Tools.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount));
break;
case 1:
- Tools.Broadcast(string.Format("Fatality! {0} goblins killed!", ConfigurationManager.KillCount));
+ Tools.Broadcast(string.Format("Fatality! {0} goblins killed!", KillCount));
break;
case 2:
- Tools.Broadcast(string.Format("Number of 'noobs' killed to date: {0}", ConfigurationManager.KillCount));
+ Tools.Broadcast(string.Format("Number of 'noobs' killed to date: {0}", KillCount));
break;
case 3:
- Tools.Broadcast(string.Format("Duke Nukem would be proud. {0} goblins killed.", ConfigurationManager.KillCount));
+ Tools.Broadcast(string.Format("Duke Nukem would be proud. {0} goblins killed.", KillCount));
break;
case 4:
- Tools.Broadcast(string.Format("You call that a lot? {0} goblins killed!", ConfigurationManager.KillCount));
+ Tools.Broadcast(string.Format("You call that a lot? {0} goblins killed!", KillCount));
break;
case 5:
- Tools.Broadcast(string.Format("{0} copies of Call of Duty smashed.", ConfigurationManager.KillCount));
+ Tools.Broadcast(string.Format("{0} copies of Call of Duty smashed.", KillCount));
break;
}
}
@@ -545,7 +550,7 @@ namespace TShockAPI
{
Vector2 tile = new Vector2(x, y);
Vector2 spawn = new Vector2(Main.spawnTileX, Main.spawnTileY);
- return Vector2.Distance(spawn, tile) <= ConfigurationManager.SpawnProtectRadius;
+ return Vector2.Distance(spawn, tile) <= TShock.Config.SpawnProtectionRadius;
}
public static bool HackedHealth(TSPlayer player)
@@ -556,6 +561,20 @@ namespace TShockAPI
(player.TPlayer.statLife > 400);
}
+ public void OnConfigRead(ConfigFile file)
+ {
+ NPC.maxSpawns = file.DefaultMaximumSpawns;
+ NPC.defaultSpawnRate = file.DefaultSpawnRate;
+
+ Main.autoSave = file.AutoSave;
+ Backups.KeepFor = file.BackupKeepFor;
+ Backups.Interval = file.BackupInterval;
+
+ Netplay.serverPort = file.ServerPort;
+
+ Netplay.spamCheck = file.SpamChecks;
+ }
+
static readonly Dictionary MsgNames = new Dictionary()
{
diff --git a/TShockAPI/TShockAPI.csproj b/TShockAPI/TShockAPI.csproj
index cf1a9ec2..9a054663 100644
--- a/TShockAPI/TShockAPI.csproj
+++ b/TShockAPI/TShockAPI.csproj
@@ -78,7 +78,6 @@
-
@@ -146,7 +145,7 @@
-
+