2021-05-27 02:00:26 +01:00
|
|
|
using System;
|
2021-08-01 19:37:13 +01:00
|
|
|
using System.IO;
|
2021-08-14 02:26:48 +01:00
|
|
|
using System.Text;
|
2021-05-27 02:00:26 +01:00
|
|
|
|
|
|
|
namespace CLre_server.API.Config
|
|
|
|
{
|
|
|
|
[Serializable]
|
|
|
|
public struct CLreConfig
|
|
|
|
{
|
|
|
|
public bool clre_clients_only;
|
|
|
|
public bool web_server;
|
2021-08-01 19:37:13 +01:00
|
|
|
public bool terrain_exclusion_zone;
|
2021-08-14 02:26:48 +01:00
|
|
|
public bool chat_commands;
|
|
|
|
public string email_address;
|
|
|
|
public string password;
|
|
|
|
public string[] bans;
|
|
|
|
public string[] moderators;
|
2021-05-27 02:00:26 +01:00
|
|
|
|
|
|
|
public static CLreConfig Default()
|
|
|
|
{
|
|
|
|
return new CLreConfig
|
|
|
|
{
|
|
|
|
clre_clients_only = false,
|
|
|
|
web_server = false,
|
2021-08-01 19:37:13 +01:00
|
|
|
terrain_exclusion_zone = false,
|
2021-08-14 02:26:48 +01:00
|
|
|
chat_commands = false,
|
|
|
|
email_address = "email@address.com",
|
|
|
|
password = "s3cur3-password",
|
|
|
|
bans = new string[0],
|
|
|
|
moderators = new []{ "NGuiness", "NGnius", "Zhang"},
|
2021-05-27 02:00:26 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CLreConfig FromString(string s)
|
|
|
|
{
|
|
|
|
return UnityEngine.JsonUtility.FromJson<CLreConfig>(s);
|
|
|
|
}
|
|
|
|
|
2021-08-01 19:37:13 +01:00
|
|
|
public static CLreConfig FromFile(string path)
|
|
|
|
{
|
|
|
|
string s = File.ReadAllText(path);
|
|
|
|
return FromString(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CLreConfig FromFileSafely(string path)
|
|
|
|
{
|
|
|
|
// try to load config file
|
|
|
|
CLreConfig conf = Default();
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string s = File.ReadAllText(path);
|
|
|
|
conf = FromString(s);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Utility.Logging.LogWarning($"Failed to load {path}: {e}\n{e.StackTrace}");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
File.WriteAllText(path, conf.ToString());
|
|
|
|
}
|
|
|
|
catch (Exception e2)
|
|
|
|
{
|
|
|
|
Utility.Logging.LogWarning($"Failed to write {path}: {e2}\n{e2.StackTrace}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
2021-05-27 02:00:26 +01:00
|
|
|
public override string ToString()
|
|
|
|
{
|
|
|
|
return UnityEngine.JsonUtility.ToJson(this, true);
|
|
|
|
}
|
2021-08-14 02:26:48 +01:00
|
|
|
|
|
|
|
public void ToFile(string path)
|
|
|
|
{
|
|
|
|
File.WriteAllText(path, this.ToString());
|
|
|
|
}
|
2021-05-27 02:00:26 +01:00
|
|
|
}
|
|
|
|
}
|