Minor changes

This commit is contained in:
Shank 2011-06-02 02:54:26 -06:00
parent fe998ad677
commit b4e028e103
5 changed files with 34 additions and 41 deletions

12
.gitignore vendored
View file

@ -43,17 +43,9 @@ Thumbs.db
*.suo *.suo
*.sdf *.sdf
*.opensdf *.opensdf
<<<<<<< HEAD
*.csproj.user
=======
>>>>>>> 3ccdba9f51710ccb56e021dd10e53eea3614f21f
*.cache *.cache
*.txt *.txt
<<<<<<< HEAD
=======
*.pdb *.pdb
<<<<<<< HEAD
>>>>>>> ef60c83b40be0a7948d3cb0381cc6e4526a9b2d6
=======
*.csproj.user *.csproj.user
>>>>>>> 3ccdba9f51710ccb56e021dd10e53eea3614f21f */_ReSharper*/*
*.user

View file

@ -77,6 +77,7 @@ namespace TShockAPI
public static void Reload(CommandArgs args) public static void Reload(CommandArgs args)
{ {
FileTools.SetupConfig(); FileTools.SetupConfig();
Tools.SendMessage(args.PlayerID, "Configuration reload complete. Some changes may require server restart.");
} }
public static void DropMeteor(CommandArgs args) public static void DropMeteor(CommandArgs args)
{ {

View file

@ -34,7 +34,7 @@ namespace TShockAPI
public static void ReadJsonConfiguration() public static void ReadJsonConfiguration()
{ {
TextReader tr = new StreamReader(FileTools.saveDir + "config.json"); TextReader tr = new StreamReader(FileTools.SaveDir + "config.json");
ConfigFile cfg = JsonConvert.DeserializeObject<ConfigFile>(tr.ReadToEnd()); ConfigFile cfg = JsonConvert.DeserializeObject<ConfigFile>(tr.ReadToEnd());
tr.Close(); tr.Close();
@ -53,13 +53,13 @@ namespace TShockAPI
public static void WriteJsonConfiguration() public static void WriteJsonConfiguration()
{ {
if (System.IO.File.Exists(FileTools.saveDir + "config.json")) if (System.IO.File.Exists(FileTools.SaveDir + "config.json"))
{ {
return; return;
} }
else else
{ {
FileTools.CreateFile(FileTools.saveDir + "config.json"); FileTools.CreateFile(FileTools.SaveDir + "config.json");
} }
ConfigFile cfg = new ConfigFile(); ConfigFile cfg = new ConfigFile();
@ -76,7 +76,7 @@ namespace TShockAPI
cfg.KickKillTileAbusers = true; cfg.KickKillTileAbusers = true;
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented); string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
TextWriter tr = new StreamWriter(FileTools.saveDir + "config.json"); TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json");
tr.Write(json); tr.Write(json);
tr.Close(); tr.Close();
} }

View file

@ -7,7 +7,7 @@ namespace TShockAPI
{ {
class FileTools class FileTools
{ {
public static string saveDir = "./tshock/"; public static string SaveDir = "./tshock/";
public static void CreateFile(string file) public static void CreateFile(string file)
{ {
using (FileStream fs = File.Create(file)) { } using (FileStream fs = File.Create(file)) { }
@ -20,11 +20,11 @@ namespace TShockAPI
{ {
string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint)); string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint));
string cheaters = ""; string cheaters = "";
TextReader tr = new StreamReader(saveDir + "cheaters.txt"); TextReader tr = new StreamReader(SaveDir + "cheaters.txt");
cheaters = tr.ReadToEnd(); cheaters = tr.ReadToEnd();
tr.Close(); tr.Close();
if (cheaters.Contains(Main.player[ply].name) && cheaters.Contains(ip)) { return; } if (cheaters.Contains(Main.player[ply].name) && cheaters.Contains(ip)) { return; }
TextWriter sw = new StreamWriter(saveDir + "cheaters.txt", true); TextWriter sw = new StreamWriter(SaveDir + "cheaters.txt", true);
sw.WriteLine("[" + Main.player[ply].name + "] " + "[" + ip + "]"); sw.WriteLine("[" + Main.player[ply].name + "] " + "[" + ip + "]");
sw.Close(); sw.Close();
} }
@ -35,7 +35,7 @@ namespace TShockAPI
public static void WriteBan(int ply) public static void WriteBan(int ply)
{ {
string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint)); string ip = Tools.GetRealIP(Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint));
TextWriter tw = new StreamWriter(saveDir + "bans.txt", true); TextWriter tw = new StreamWriter(SaveDir + "bans.txt", true);
tw.WriteLine("[" + Main.player[ply].name + "] " + "[" + ip + "]"); tw.WriteLine("[" + Main.player[ply].name + "] " + "[" + ip + "]");
tw.Close(); tw.Close();
} }
@ -45,7 +45,7 @@ namespace TShockAPI
/// <param name="ply">int player</param> /// <param name="ply">int player</param>
public static void WriteGrief(int ply) public static void WriteGrief(int ply)
{ {
TextWriter tw = new StreamWriter(saveDir + "grief.txt", true); TextWriter tw = new StreamWriter(SaveDir + "grief.txt", true);
tw.WriteLine("[" + Main.player[ply].name + "] [" + Tools.GetRealIP(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint.ToString()) + "]"); tw.WriteLine("[" + Main.player[ply].name + "] [" + Tools.GetRealIP(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint.ToString()) + "]");
tw.Close(); tw.Close();
} }
@ -55,16 +55,16 @@ namespace TShockAPI
/// <param name="err">string message</param> /// <param name="err">string message</param>
public static void WriteError(string err) public static void WriteError(string err)
{ {
if (System.IO.File.Exists(saveDir + "errors.txt")) if (System.IO.File.Exists(SaveDir + "errors.txt"))
{ {
TextWriter tw = new StreamWriter(saveDir + "errors.txt", true); TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
tw.WriteLine(err); tw.WriteLine(err);
tw.Close(); tw.Close();
} }
else else
{ {
FileTools.CreateFile(saveDir + "errors.txt"); FileTools.CreateFile(SaveDir + "errors.txt");
TextWriter tw = new StreamWriter(saveDir + "errors.txt", true); TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
tw.WriteLine(err); tw.WriteLine(err);
tw.Close(); tw.Close();
} }
@ -74,21 +74,21 @@ namespace TShockAPI
/// </summary> /// </summary>
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 + "motd.txt")) if (!System.IO.File.Exists(SaveDir + "motd.txt"))
{ {
FileTools.CreateFile(saveDir + "motd.txt"); FileTools.CreateFile(SaveDir + "motd.txt");
TextWriter tw = new StreamWriter(saveDir + "motd.txt"); TextWriter tw = new StreamWriter(SaveDir + "motd.txt");
tw.WriteLine("This server is running TShock. Type /help for a list of commands."); tw.WriteLine("This server is running TShock. Type /help for a list of commands.");
tw.WriteLine("%255,000,000%Current map: %map%"); tw.WriteLine("%255,000,000%Current map: %map%");
tw.WriteLine("Current players: %players%"); tw.WriteLine("Current players: %players%");
tw.Close(); tw.Close();
} }
if (!System.IO.File.Exists(saveDir + "bans.txt")) { FileTools.CreateFile(saveDir + "bans.txt"); } if (!System.IO.File.Exists(SaveDir + "bans.txt")) { FileTools.CreateFile(SaveDir + "bans.txt"); }
if (!System.IO.File.Exists(saveDir + "cheaters.txt")) { FileTools.CreateFile(saveDir + "cheaters.txt"); } if (!System.IO.File.Exists(SaveDir + "cheaters.txt")) { FileTools.CreateFile(SaveDir + "cheaters.txt"); }
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"); }
ConfigurationManager.WriteJsonConfiguration(); ConfigurationManager.WriteJsonConfiguration();
ConfigurationManager.ReadJsonConfiguration(); ConfigurationManager.ReadJsonConfiguration();
Netplay.serverPort = ConfigurationManager.serverPort; Netplay.serverPort = ConfigurationManager.serverPort;
@ -101,7 +101,7 @@ namespace TShockAPI
public static bool CheckBanned(String p) public static bool CheckBanned(String p)
{ {
String ip = p.Split(':')[0]; String ip = p.Split(':')[0];
TextReader tr = new StreamReader(saveDir + "bans.txt"); TextReader tr = new StreamReader(SaveDir + "bans.txt");
string banlist = tr.ReadToEnd(); string banlist = tr.ReadToEnd();
tr.Close(); tr.Close();
banlist = banlist.Trim(); banlist = banlist.Trim();
@ -117,11 +117,11 @@ namespace TShockAPI
public static bool OnWhitelist(string ip) public static bool OnWhitelist(string ip)
{ {
if (!ConfigurationManager.enableWhitelist) { return true; } if (!ConfigurationManager.enableWhitelist) { return true; }
if (!System.IO.File.Exists(saveDir + "whitelist.txt")) { FileTools.CreateFile(saveDir + "whitelist.txt"); TextWriter tw = new StreamWriter(saveDir + "whitelist.txt"); tw.WriteLine("127.0.0.1"); tw.Close(); } if (!System.IO.File.Exists(SaveDir + "whitelist.txt")) { FileTools.CreateFile(SaveDir + "whitelist.txt"); TextWriter tw = new StreamWriter(SaveDir + "whitelist.txt"); tw.WriteLine("127.0.0.1"); tw.Close(); }
TextReader tr = new StreamReader(saveDir + "whitelist.txt"); TextReader tr = new StreamReader(SaveDir + "whitelist.txt");
string whitelist = tr.ReadToEnd(); string whitelist = tr.ReadToEnd();
ip = Tools.GetRealIP(ip); ip = Tools.GetRealIP(ip);
if (whitelist.Contains(ip)) { return true; } else { return false; } return whitelist.Contains(ip);
} }
/// <summary> /// <summary>
/// Tells if the user is on grief.txt /// Tells if the user is on grief.txt
@ -132,7 +132,7 @@ namespace TShockAPI
{ {
ip = Tools.GetRealIP(ip); ip = Tools.GetRealIP(ip);
if (!ConfigurationManager.banTnt) { return false; } if (!ConfigurationManager.banTnt) { return false; }
TextReader tr = new StreamReader(saveDir + "grief.txt"); TextReader tr = new StreamReader(SaveDir + "grief.txt");
string list = tr.ReadToEnd(); string list = tr.ReadToEnd();
tr.Close(); tr.Close();
@ -143,7 +143,7 @@ namespace TShockAPI
{ {
ip = Tools.GetRealIP(ip); ip = Tools.GetRealIP(ip);
if (!ConfigurationManager.banCheater) { return false; } if (!ConfigurationManager.banCheater) { return false; }
TextReader tr = new StreamReader(saveDir + "cheaters.txt"); TextReader tr = new StreamReader(SaveDir + "cheaters.txt");
string trr = tr.ReadToEnd(); string trr = tr.ReadToEnd();
tr.Close(); tr.Close();
if (trr.Contains(ip)) if (trr.Contains(ip))

View file

@ -179,7 +179,7 @@ namespace TShockAPI
{ {
string remoteEndPoint = Convert.ToString((Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint)); string remoteEndPoint = Convert.ToString((Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint));
string[] remoteEndPointIP = remoteEndPoint.Split(':'); string[] remoteEndPointIP = remoteEndPoint.Split(':');
TextReader tr = new StreamReader(FileTools.saveDir + "admins.txt"); TextReader tr = new StreamReader(FileTools.SaveDir + "admins.txt");
string adminlist = tr.ReadToEnd(); string adminlist = tr.ReadToEnd();
tr.Close(); tr.Close();
if (adminlist.Contains(remoteEndPointIP[0])) if (adminlist.Contains(remoteEndPointIP[0]))
@ -197,7 +197,7 @@ namespace TShockAPI
{ {
string remoteEndPoint = Convert.ToString((Netplay.serverSock[Tools.FindPlayer(ply)].tcpClient.Client.RemoteEndPoint)); string remoteEndPoint = Convert.ToString((Netplay.serverSock[Tools.FindPlayer(ply)].tcpClient.Client.RemoteEndPoint));
string[] remoteEndPointIP = remoteEndPoint.Split(':'); string[] remoteEndPointIP = remoteEndPoint.Split(':');
TextReader tr = new StreamReader(FileTools.saveDir + "admins.txt"); TextReader tr = new StreamReader(FileTools.SaveDir + "admins.txt");
string adminlist = tr.ReadToEnd(); string adminlist = tr.ReadToEnd();
tr.Close(); tr.Close();
if (adminlist.Contains(remoteEndPointIP[0])) if (adminlist.Contains(remoteEndPointIP[0]))
@ -242,7 +242,7 @@ namespace TShockAPI
public static void ShowMOTD(int ply) public static void ShowMOTD(int ply)
{ {
string foo = ""; string foo = "";
TextReader tr = new StreamReader(FileTools.saveDir + "motd.txt"); TextReader tr = new StreamReader(FileTools.SaveDir + "motd.txt");
while ((foo = tr.ReadLine()) != null) while ((foo = tr.ReadLine()) != null)
{ {
foo = foo.Replace("%map%", Main.worldName); foo = foo.Replace("%map%", Main.worldName);