added 'none' and extra m16 variants to weapon list
moved killstreak/deathstreak messages into configuration file cleaned up configuration manager fixed misc startup issue and threading added more importing stuff network id is a ulong now ip str is now ip added time played (per server)
This commit is contained in:
@ -53,5 +53,10 @@ namespace SharedLibrary.Helpers
|
||||
RunAverage = RunAverage + ((DateTime.Now - StartTime).TotalMilliseconds - RunAverage - UpdateFrequency) / TimesRun;
|
||||
StartTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public void Abort()
|
||||
{
|
||||
RequestedTask = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,65 +6,32 @@ namespace SharedLibrary.Helpers
|
||||
{
|
||||
public class ConfigurationManager
|
||||
{
|
||||
ConcurrentDictionary<string, Dictionary<string, object>> ConfigurationSet;
|
||||
ConcurrentDictionary<string, object> ConfigSet;
|
||||
Type PluginType;
|
||||
ConcurrentDictionary<string, dynamic> ConfigSet;
|
||||
Server ServerInstance;
|
||||
|
||||
public ConfigurationManager(Type PluginType)
|
||||
{
|
||||
ConfigurationSet = new ConcurrentDictionary<string, Dictionary<string, object>>();
|
||||
this.PluginType = PluginType;
|
||||
}
|
||||
|
||||
public ConfigurationManager(Server S)
|
||||
{
|
||||
try
|
||||
{
|
||||
ConfigSet = Interfaces.Serialize<ConcurrentDictionary<string, object>>.Read($"config/Plugins_{S}.cfg");
|
||||
ConfigSet = Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Read($"config/plugins_{S.ToString()}.cfg");
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
S.Logger.WriteInfo("ConfigurationManager could not deserialize configuration file, so initializing default config set");
|
||||
ConfigSet = new ConcurrentDictionary<string, object>();
|
||||
ConfigSet = new ConcurrentDictionary<string, dynamic>();
|
||||
}
|
||||
|
||||
ServerInstance = S;
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
private void SaveChanges()
|
||||
{
|
||||
Interfaces.Serialize<ConcurrentDictionary<string, object>>.Write($"config/Plugins_{ServerInstance}.cfg", ConfigSet);
|
||||
Interfaces.Serialize<ConcurrentDictionary<string, dynamic>>.Write($"config/plugins_{ServerInstance.ToString()}.cfg", ConfigSet);
|
||||
}
|
||||
|
||||
public void AddConfiguration(Server S)
|
||||
{
|
||||
/* if (ConfigurationSet.ContainsKey(S.ToString()))
|
||||
{
|
||||
S.Logger.WriteWarning($"not adding server configuration for {S} as it already exists");
|
||||
return;
|
||||
}*/
|
||||
|
||||
try
|
||||
{
|
||||
var Config = Interfaces.Serialize<Dictionary<string, object>>.Read($"config/{PluginType.ToString()}_{S.ToString()}.cfg");
|
||||
ConfigurationSet.TryAdd(S.ToString(), Config);
|
||||
}
|
||||
|
||||
catch (Exceptions.SerializeException)
|
||||
{
|
||||
ConfigurationSet.TryAdd(S.ToString(), new Dictionary<string, object>());
|
||||
}
|
||||
}
|
||||
|
||||
public void AddProperty(Server S, KeyValuePair<string, object> Property)
|
||||
{
|
||||
ConfigurationSet[S.ToString()].Add(Property.Key, Property.Value);
|
||||
Interfaces.Serialize<Dictionary<string, object>>.Write($"config/{PluginType.ToString()}_{S.ToString()}.cfg", ConfigurationSet[S.ToString()]);
|
||||
}
|
||||
|
||||
public void AddProperty(KeyValuePair<string, object> prop)
|
||||
public void AddProperty(KeyValuePair<string, dynamic> prop)
|
||||
{
|
||||
if (!ConfigSet.ContainsKey(prop.Key))
|
||||
ConfigSet.TryAdd(prop.Key, prop.Value);
|
||||
@ -72,13 +39,7 @@ namespace SharedLibrary.Helpers
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
public void UpdateProperty(Server S, KeyValuePair<string, object> Property)
|
||||
{
|
||||
ConfigurationSet[S.ToString()][Property.Key] = Property.Value;
|
||||
Interfaces.Serialize<Dictionary<string, object>>.Write($"config/{PluginType.ToString()}_{S.ToString()}.cfg", ConfigurationSet[S.ToString()]);
|
||||
}
|
||||
|
||||
public void UpdateProperty(KeyValuePair<string, object> prop)
|
||||
public void UpdateProperty(KeyValuePair<string, dynamic> prop)
|
||||
{
|
||||
if (ConfigSet.ContainsKey(prop.Key))
|
||||
ConfigSet[prop.Key] = prop.Value;
|
||||
@ -86,21 +47,16 @@ namespace SharedLibrary.Helpers
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
public IDictionary<string, object> GetConfiguration(Server S)
|
||||
{
|
||||
return ConfigurationSet[S.ToString()];
|
||||
}
|
||||
|
||||
public object GetProperty(string prop)
|
||||
public T GetProperty<T>(string prop)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ConfigSet[prop];
|
||||
return ConfigSet[prop].ToObject<T>();
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user