Refactor for new configuration

This commit is contained in:
Chris 2020-12-03 17:43:10 +10:30
parent a03647ce38
commit 9423febd0a
26 changed files with 351 additions and 433 deletions

View file

@ -107,7 +107,7 @@ namespace TShockAPI.DB
int res;
if (database.GetSqlType() == SqlType.Mysql)
{
res = database.QueryScalar<int>("SELECT COUNT(name) FROM information_schema.tables WHERE table_schema = @0 and table_name = 'Bans'", TShock.Config.MySqlDbName);
res = database.QueryScalar<int>("SELECT COUNT(name) FROM information_schema.tables WHERE table_schema = @0 and table_name = 'Bans'", TShock.Config.Settings.MySqlDbName);
}
else
{

View file

@ -126,7 +126,7 @@ namespace TShockAPI.DB
{
var inventory = new StringBuilder();
var items = new List<NetItem>(TShock.ServerSideCharacterConfig.StartingInventory);
var items = new List<NetItem>(TShock.ServerSideCharacterConfig.Settings.StartingInventory);
if (items.Count < NetItem.MaxInventory)
items.AddRange(new NetItem[NetItem.MaxInventory - items.Count]);
@ -135,10 +135,10 @@ namespace TShockAPI.DB
{
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, questsCompleted) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8);",
account.ID,
TShock.ServerSideCharacterConfig.StartingHealth,
TShock.ServerSideCharacterConfig.StartingHealth,
TShock.ServerSideCharacterConfig.StartingMana,
TShock.ServerSideCharacterConfig.StartingMana,
TShock.ServerSideCharacterConfig.Settings.StartingHealth,
TShock.ServerSideCharacterConfig.Settings.StartingHealth,
TShock.ServerSideCharacterConfig.Settings.StartingMana,
TShock.ServerSideCharacterConfig.Settings.StartingMana,
initialItems,
-1,
-1,

View file

@ -196,7 +196,7 @@ namespace TShockAPI.DB
// Load Permissions from the DB
LoadPermisions();
Group.DefaultGroup = GetGroupByName(TShock.Config.DefaultGuestGroupName);
Group.DefaultGroup = GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName);
}
private void AddDefaultGroup(string name, string parent, string permissions)
@ -271,7 +271,7 @@ namespace TShockAPI.DB
group.Parent = parent;
}
string query = (TShock.Config.StorageType.ToLower() == "sqlite")
string query = (TShock.Config.Settings.StorageType.ToLower() == "sqlite")
? "INSERT OR IGNORE INTO GroupList (GroupName, Parent, Commands, ChatColor) VALUES (@0, @1, @2, @3);"
: "INSERT IGNORE INTO GroupList SET GroupName=@0, Parent=@1, Commands=@2, ChatColor=@3";
if (database.Query(query, name, parentname, permissions, chatcolor) == 1)
@ -389,15 +389,15 @@ namespace TShockAPI.DB
}
// Read the config file to prevent the possible loss of any unsaved changes
TShock.Config = ConfigFile.Read(FileTools.ConfigPath, out bool writeConfig);
if (TShock.Config.DefaultGuestGroupName == oldGroup.Name)
TShock.Config.Read(FileTools.ConfigPath, out bool writeConfig);
if (TShock.Config.Settings.DefaultGuestGroupName == oldGroup.Name)
{
TShock.Config.DefaultGuestGroupName = newGroup.Name;
TShock.Config.Settings.DefaultGuestGroupName = newGroup.Name;
Group.DefaultGroup = newGroup;
}
if (TShock.Config.DefaultRegistrationGroupName == oldGroup.Name)
if (TShock.Config.Settings.DefaultRegistrationGroupName == oldGroup.Name)
{
TShock.Config.DefaultRegistrationGroupName = newGroup.Name;
TShock.Config.Settings.DefaultRegistrationGroupName = newGroup.Name;
}
if (writeConfig)
{

View file

@ -496,7 +496,7 @@ namespace TShockAPI.DB
return;
}
if (currentWorkFactor < TShock.Config.BCryptWorkFactor)
if (currentWorkFactor < TShock.Config.Settings.BCryptWorkFactor)
{
try
{
@ -513,13 +513,13 @@ namespace TShockAPI.DB
/// <param name="password">The plain text password to hash</param>
public void CreateBCryptHash(string password)
{
if (password.Trim().Length < Math.Max(4, TShock.Config.MinimumPasswordLength))
if (password.Trim().Length < Math.Max(4, TShock.Config.Settings.MinimumPasswordLength))
{
throw new ArgumentOutOfRangeException("password", "Password must be > " + TShock.Config.MinimumPasswordLength + " characters.");
throw new ArgumentOutOfRangeException("password", "Password must be > " + TShock.Config.Settings.MinimumPasswordLength + " characters.");
}
try
{
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), TShock.Config.BCryptWorkFactor);
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), TShock.Config.Settings.BCryptWorkFactor);
}
catch (ArgumentOutOfRangeException)
{
@ -533,9 +533,9 @@ namespace TShockAPI.DB
/// <param name="workFactor">The work factor to use in generating the password hash</param>
public void CreateBCryptHash(string password, int workFactor)
{
if (password.Trim().Length < Math.Max(4, TShock.Config.MinimumPasswordLength))
if (password.Trim().Length < Math.Max(4, TShock.Config.Settings.MinimumPasswordLength))
{
throw new ArgumentOutOfRangeException("password", "Password must be > " + TShock.Config.MinimumPasswordLength + " characters.");
throw new ArgumentOutOfRangeException("password", "Password must be > " + TShock.Config.Settings.MinimumPasswordLength + " characters.");
}
Password = BCrypt.Net.BCrypt.HashPassword(password.Trim(), workFactor);
}
@ -563,8 +563,8 @@ namespace TShockAPI.DB
if (bytes == null)
throw new NullReferenceException("bytes");
Func<HashAlgorithm> func;
if (!HashTypes.TryGetValue(TShock.Config.HashAlgorithm.ToLower(), out func))
throw new NotSupportedException("Hashing algorithm {0} is not supported".SFormat(TShock.Config.HashAlgorithm.ToLower()));
if (!HashTypes.TryGetValue(TShock.Config.Settings.HashAlgorithm.ToLower(), out func))
throw new NotSupportedException("Hashing algorithm {0} is not supported".SFormat(TShock.Config.Settings.HashAlgorithm.ToLower()));
using (var hash = func())
{