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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -29,5 +31,54 @@ namespace TShockAPI
|
||||||
EYE = 1,
|
EYE = 1,
|
||||||
SKELETRON = 2
|
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;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
|
|
@ -77,10 +75,6 @@ namespace TShockAPI
|
||||||
public static void SetupConfig()
|
public static void SetupConfig()
|
||||||
{
|
{
|
||||||
if (!System.IO.Directory.Exists(saveDir)) { System.IO.Directory.CreateDirectory(saveDir); }
|
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"))
|
if (!System.IO.File.Exists(saveDir + "motd.txt"))
|
||||||
{
|
{
|
||||||
FileTools.CreateFile(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 + "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 + "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 + "whitelist.txt")) { FileTools.CreateFile(saveDir + "whitelist.txt"); }
|
||||||
if (!System.IO.File.Exists(saveDir + "config.txt"))
|
ConfigurationManager.WriteJsonConfiguration();
|
||||||
{
|
ConfigurationManager.ReadJsonConfiguration();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
Netplay.serverPort = ConfigurationManager.serverPort;
|
Netplay.serverPort = ConfigurationManager.serverPort;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace TShockAPI
|
||||||
|
|
||||||
public static string saveDir = "./tshock/";
|
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;
|
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, 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.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="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" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
|
@ -50,6 +53,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Commands.cs" />
|
<Compile Include="Commands.cs" />
|
||||||
|
<Compile Include="ConfigFile.cs" />
|
||||||
<Compile Include="ConfigurationManager.cs" />
|
<Compile Include="ConfigurationManager.cs" />
|
||||||
<Compile Include="FileTools.cs" />
|
<Compile Include="FileTools.cs" />
|
||||||
<Compile Include="Tools.cs" />
|
<Compile Include="Tools.cs" />
|
||||||
|
|
|
||||||
Binary file not shown.
12
Terraria.sln
12
Terraria.sln
|
|
@ -1,8 +1,6 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||||
# Visual Studio 2010
|
# Visual Studio 2010
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terraria", "Terraria.csproj", "{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockAPI", "TShockAPI\TShockAPI.csproj", "{49606449-072B-4CF5-8088-AA49DA586694}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockAPI", "TShockAPI\TShockAPI.csproj", "{49606449-072B-4CF5-8088-AA49DA586694}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
|
@ -15,16 +13,6 @@ Global
|
||||||
Release|x86 = Release|x86
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Debug|Any CPU.ActiveCfg = Debug|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Debug|x86.ActiveCfg = Debug|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Debug|x86.Build.0 = Debug|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Release|Any CPU.ActiveCfg = Release|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Release|Mixed Platforms.Build.0 = Release|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Release|x86.ActiveCfg = Release|x86
|
|
||||||
{1528EA3F-A6D2-49F6-BF75-7A842CF4D97B}.Release|x86.Build.0 = Release|x86
|
|
||||||
{49606449-072B-4CF5-8088-AA49DA586694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{49606449-072B-4CF5-8088-AA49DA586694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{49606449-072B-4CF5-8088-AA49DA586694}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{49606449-072B-4CF5-8088-AA49DA586694}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{49606449-072B-4CF5-8088-AA49DA586694}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
{49606449-072B-4CF5-8088-AA49DA586694}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue