Json starting fresh.
This commit is contained in:
parent
7f65697bc2
commit
45a8cf09ce
7 changed files with 82 additions and 55 deletions
23
TShockAPI/ConfigFile.cs
Normal file
23
TShockAPI/ConfigFile.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
class ConfigFile
|
||||
{
|
||||
public ConfigFile() { }
|
||||
public int InvasionMultiplier = 1;
|
||||
public int DefaultMaximumSpawns = 4;
|
||||
public int DefaultSpawnRate = 700;
|
||||
public int ServerPort = 7777;
|
||||
public bool EnableWhitelist = false;
|
||||
public bool InfiniteInvasion = false;
|
||||
public bool AlwaysPvP = false;
|
||||
public bool KickSaveEditors = true;
|
||||
public bool BanSaveEditors = true;
|
||||
public bool BanKillTileAbusers = false;
|
||||
public bool KickKillTileAbusers = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -29,5 +31,54 @@ namespace TShockAPI
|
|||
EYE = 1,
|
||||
SKELETRON = 2
|
||||
}
|
||||
|
||||
public static void ReadJsonConfiguration()
|
||||
{
|
||||
TextReader tr = new StreamReader(FileTools.saveDir + "config.json");
|
||||
ConfigFile cfg = JsonConvert.DeserializeObject<ConfigFile>(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.KickSaveEditors;
|
||||
banCheater = cfg.BanSaveEditors;
|
||||
banTnt = cfg.BanKillTileAbusers;
|
||||
kickTnt = cfg.KickKillTileAbusers;
|
||||
}
|
||||
|
||||
public static void WriteJsonConfiguration()
|
||||
{
|
||||
if (System.IO.File.Exists(FileTools.saveDir + "config.json"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
FileTools.CreateFile(FileTools.saveDir + "config.json");
|
||||
}
|
||||
|
||||
ConfigFile cfg = new ConfigFile();
|
||||
cfg.InvasionMultiplier = 50;
|
||||
cfg.DefaultMaximumSpawns = 4;
|
||||
cfg.DefaultSpawnRate = 700;
|
||||
cfg.ServerPort = 7777;
|
||||
cfg.EnableWhitelist = false;
|
||||
cfg.InfiniteInvasion = false;
|
||||
cfg.AlwaysPvP = false;
|
||||
cfg.KickSaveEditors = false;
|
||||
cfg.BanSaveEditors = false;
|
||||
cfg.BanKillTileAbusers = true;
|
||||
cfg.KickKillTileAbusers = true;
|
||||
|
||||
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
|
||||
TextWriter tr = new StreamWriter(FileTools.saveDir + "config.json");
|
||||
tr.Write(json);
|
||||
tr.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Terraria;
|
||||
using System.Web;
|
||||
|
||||
namespace TShockAPI
|
||||
{
|
||||
|
|
@ -77,10 +75,6 @@ namespace TShockAPI
|
|||
public static void SetupConfig()
|
||||
{
|
||||
if (!System.IO.Directory.Exists(saveDir)) { System.IO.Directory.CreateDirectory(saveDir); }
|
||||
if (System.IO.File.Exists(saveDir + "tiles.txt"))
|
||||
{
|
||||
System.IO.File.Delete(saveDir + "tiles.txt");
|
||||
}
|
||||
if (!System.IO.File.Exists(saveDir + "motd.txt"))
|
||||
{
|
||||
FileTools.CreateFile(saveDir + "motd.txt");
|
||||
|
|
@ -95,41 +89,8 @@ namespace TShockAPI
|
|||
if (!System.IO.File.Exists(saveDir + "admins.txt")) { FileTools.CreateFile(saveDir + "admins.txt"); }
|
||||
if (!System.IO.File.Exists(saveDir + "grief.txt")) { FileTools.CreateFile(saveDir + "grief.txt"); }
|
||||
if (!System.IO.File.Exists(saveDir + "whitelist.txt")) { FileTools.CreateFile(saveDir + "whitelist.txt"); }
|
||||
if (!System.IO.File.Exists(saveDir + "config.txt"))
|
||||
{
|
||||
FileTools.CreateFile(saveDir + "config.txt");
|
||||
TextWriter tw = new StreamWriter(saveDir + "config.txt");
|
||||
tw.WriteLine("true,50,4,700,true,true,7777,false,false,false,false,false");
|
||||
tw.Close();
|
||||
}
|
||||
TextReader tr = new StreamReader(saveDir + "config.txt");
|
||||
string config = tr.ReadToEnd();
|
||||
config = config.Replace("\n", "");
|
||||
config = config.Replace("\r", "");
|
||||
config = config.Replace(" ", "");
|
||||
tr.Close();
|
||||
string[] configuration = config.Split(',');
|
||||
try
|
||||
{
|
||||
ConfigurationManager.invasionMultiplier = Convert.ToInt32(configuration[1]);
|
||||
ConfigurationManager.defaultMaxSpawns = Convert.ToInt32(configuration[2]);
|
||||
ConfigurationManager.defaultSpawnRate = Convert.ToInt32(configuration[3]);
|
||||
ConfigurationManager.kickCheater = Convert.ToBoolean(configuration[4]);
|
||||
ConfigurationManager.banCheater = Convert.ToBoolean(configuration[5]);
|
||||
ConfigurationManager.serverPort = Convert.ToInt32(configuration[6]);
|
||||
ConfigurationManager.enableWhitelist = Convert.ToBoolean(configuration[7]);
|
||||
ConfigurationManager.infiniteInvasion = Convert.ToBoolean(configuration[8]);
|
||||
ConfigurationManager.permaPvp = Convert.ToBoolean(configuration[9]);
|
||||
ConfigurationManager.kickTnt = Convert.ToBoolean(configuration[10]);
|
||||
ConfigurationManager.banTnt = Convert.ToBoolean(configuration[11]);
|
||||
NPC.defaultMaxSpawns = ConfigurationManager.defaultMaxSpawns;
|
||||
NPC.defaultSpawnRate = ConfigurationManager.defaultSpawnRate;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FileTools.WriteError(e.Message);
|
||||
}
|
||||
|
||||
ConfigurationManager.WriteJsonConfiguration();
|
||||
ConfigurationManager.ReadJsonConfiguration();
|
||||
Netplay.serverPort = ConfigurationManager.serverPort;
|
||||
}
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace TShockAPI
|
|||
|
||||
public static string saveDir = "./tshock/";
|
||||
|
||||
public static Version VersionNum = new Version(1, 3, 0, 0);
|
||||
public static Version VersionNum = new Version(1, 3, 0, 1);
|
||||
|
||||
public static bool shownVersion = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@
|
|||
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
|
||||
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
|
||||
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>.\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
|
|
@ -50,6 +53,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Commands.cs" />
|
||||
<Compile Include="ConfigFile.cs" />
|
||||
<Compile Include="ConfigurationManager.cs" />
|
||||
<Compile Include="FileTools.cs" />
|
||||
<Compile Include="Tools.cs" />
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue