More code tidying.

This commit is contained in:
high 2011-06-14 18:13:46 -04:00
parent fff6e1bcbc
commit 966735ec2e
6 changed files with 97 additions and 136 deletions

View file

@ -603,7 +603,7 @@ namespace TShockAPI
int givenCode = Convert.ToInt32(args.Parameters[0]); int givenCode = Convert.ToInt32(args.Parameters[0]);
if (givenCode == ConfigurationManager.authToken) if (givenCode == ConfigurationManager.authToken)
{ {
TextWriter tw = new StreamWriter(FileTools.SaveDir + "users.txt", true); TextWriter tw = new StreamWriter(FileTools.UsersPath, true);
tw.Write("\n" + tw.Write("\n" +
Tools.GetRealIP( Tools.GetRealIP(
Convert.ToString(Netplay.serverSock[args.PlayerID].tcpClient.Client.RemoteEndPoint)) + Convert.ToString(Netplay.serverSock[args.PlayerID].tcpClient.Client.RemoteEndPoint)) +
@ -912,7 +912,7 @@ namespace TShockAPI
List<Command> cmdlist = new List<Command>(); List<Command> cmdlist = new List<Command>();
for (int j = 0; j < commands.Count; j++) for (int j = 0; j < commands.Count; j++)
{ {
if (commands[j].CanRun(TShock.players[ply])) if (commands[j].CanRun(TShock.Players[ply]))
{ {
cmdlist.Add(commands[j]); cmdlist.Add(commands[j]);
} }

View file

@ -64,7 +64,7 @@ namespace TShockAPI
public static void ReadJsonConfiguration() public static void ReadJsonConfiguration()
{ {
TextReader tr = new StreamReader(FileTools.SaveDir + "config.json"); TextReader tr = new StreamReader(FileTools.ConfigPath);
ConfigFile cfg = JsonConvert.DeserializeObject<ConfigFile>(tr.ReadToEnd()); ConfigFile cfg = JsonConvert.DeserializeObject<ConfigFile>(tr.ReadToEnd());
tr.Close(); tr.Close();
@ -98,11 +98,6 @@ namespace TShockAPI
public static void WriteJsonConfiguration() public static void WriteJsonConfiguration()
{ {
if (System.IO.File.Exists(FileTools.SaveDir + "config.json"))
{
System.IO.File.Delete(FileTools.SaveDir + "config.json");
}
FileTools.CreateFile(FileTools.SaveDir + "config.json");
ConfigFile cfg = new ConfigFile(); ConfigFile cfg = new ConfigFile();
cfg.InvasionMultiplier = invasionMultiplier; cfg.InvasionMultiplier = invasionMultiplier;
cfg.DefaultMaximumSpawns = defaultMaxSpawns; cfg.DefaultMaximumSpawns = defaultMaxSpawns;
@ -128,7 +123,7 @@ namespace TShockAPI
cfg.AdminChatRGB = adminChatRGB; cfg.AdminChatRGB = adminChatRGB;
cfg.AdminChatPrefix = adminChatPrefix; cfg.AdminChatPrefix = adminChatPrefix;
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.ConfigPath);
tr.Write(json); tr.Write(json);
tr.Close(); tr.Close();
} }

View file

@ -22,12 +22,24 @@ namespace TShockAPI
{ {
internal class FileTools internal class FileTools
{ {
public static string SaveDir = "./tshock/"; public static readonly string ErrorsPath = Path.Combine(TShock.SavePath, "errors.txt");
public static readonly string RulesPath = Path.Combine(TShock.SavePath, "rules.txt");
public static readonly string MotdPath = Path.Combine(TShock.SavePath, "motd.txt");
public static readonly string BansPath = Path.Combine(TShock.SavePath, "bans.txt");
public static readonly string WhitelistPath = Path.Combine(TShock.SavePath, "whitelist.txt");
public static readonly string GroupsPath = Path.Combine(TShock.SavePath, "groups.txt");
public static readonly string UsersPath = Path.Combine(TShock.SavePath, "users.txt");
public static readonly string ConfigPath = Path.Combine(TShock.SavePath, "config.json");
public static void CreateFile(string file) public static void CreateFile(string file)
{ {
using (FileStream fs = File.Create(file)) File.Create(file).Close();
}
public static void CreateIfNot(string file, string data = "")
{
if (!File.Exists(file))
{ {
File.WriteAllText(file, data);
} }
} }
@ -37,19 +49,9 @@ 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 (File.Exists(SaveDir + "errors.txt")) TextWriter tw = new StreamWriter(ErrorsPath, true);
{ tw.WriteLine(err);
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true); tw.Close();
tw.WriteLine(err);
tw.Close();
}
else
{
CreateFile(SaveDir + "errors.txt");
TextWriter tw = new StreamWriter(SaveDir + "errors.txt", true);
tw.WriteLine(err);
tw.Close();
}
} }
/// <summary> /// <summary>
@ -57,53 +59,23 @@ namespace TShockAPI
/// </summary> /// </summary>
public static void SetupConfig() public static void SetupConfig()
{ {
if (!Directory.Exists(SaveDir)) if (!Directory.Exists(TShock.SavePath))
{ {
Directory.CreateDirectory(SaveDir); Directory.CreateDirectory(TShock.SavePath);
} }
if (!File.Exists(SaveDir + "rules.txt"))
{ CreateIfNot(RulesPath, "Respect the admins!\nDon't use TNT!");
CreateFile(SaveDir + "rules.txt"); CreateIfNot(MotdPath, "This server is running TShock. Type /help for a list of commands.\n%255,000,000%Current map: %map%\nCurrent players: %players%");
TextWriter tw = new StreamWriter(SaveDir + "rules.txt"); CreateIfNot(BansPath);
tw.WriteLine("Respect the admins!"); CreateIfNot(WhitelistPath);
tw.WriteLine("Don't use TNT!"); CreateIfNot(GroupsPath, Resources.groups);
tw.Close(); CreateIfNot(UsersPath, Resources.users);
}
if (!File.Exists(SaveDir + "motd.txt")) if (File.Exists(ConfigPath))
{
CreateFile(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("%255,000,000%Current map: %map%");
tw.WriteLine("Current players: %players%");
tw.Close();
}
if (!File.Exists(SaveDir + "bans.txt"))
{
CreateFile(SaveDir + "bans.txt");
}
if (!File.Exists(SaveDir + "whitelist.txt"))
{
CreateFile(SaveDir + "whitelist.txt");
}
if (!File.Exists(SaveDir + "groups.txt"))
{
CreateFile(SaveDir + "groups.txt");
StreamWriter sw = new StreamWriter(SaveDir + "groups.txt");
sw.Write(Resources.groups);
sw.Close();
}
if (!File.Exists(SaveDir + "users.txt"))
{
CreateFile(SaveDir + "users.txt");
StreamWriter sw = new StreamWriter(SaveDir + "users.txt");
sw.Write(Resources.users);
sw.Close();
}
if (File.Exists(FileTools.SaveDir + "config.json"))
{ {
ConfigurationManager.ReadJsonConfiguration(); ConfigurationManager.ReadJsonConfiguration();
} else }
else
{ {
ConfigurationManager.WriteJsonConfiguration(); ConfigurationManager.WriteJsonConfiguration();
ConfigurationManager.ReadJsonConfiguration(); ConfigurationManager.ReadJsonConfiguration();
@ -123,14 +95,8 @@ namespace TShockAPI
{ {
return true; return true;
} }
if (!File.Exists(SaveDir + "whitelist.txt")) CreateIfNot(WhitelistPath, "127.0.0.1");
{ TextReader tr = new StreamReader(WhitelistPath);
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");
string whitelist = tr.ReadToEnd(); string whitelist = tr.ReadToEnd();
ip = Tools.GetRealIP(ip); ip = Tools.GetRealIP(ip);
return whitelist.Contains(ip); return whitelist.Contains(ip);

View file

@ -33,17 +33,17 @@ namespace TShockAPI
[APIVersion(1, 3)] [APIVersion(1, 3)]
public class TShock : TerrariaPlugin public class TShock : TerrariaPlugin
{ {
public static TSPlayer[] players = new TSPlayer[Main.maxPlayers]; public static TSPlayer[] Players = new TSPlayer[Main.maxPlayers];
public static string saveDir = "./tshock/"; public static readonly string SavePath = "./tshock/";
public static Version VersionNum = new Version(2, 1, 0, 3); public static readonly Version VersionNum = new Version(2, 1, 0, 3);
public static string VersionCodename = "Forgot to increase the version."; public static readonly string VersionCodename = "Forgot to increase the version.";
private static bool[] BlacklistTiles; private static bool[] BlacklistTiles;
public static BanManager Bans = new BanManager(Path.Combine(saveDir, "bans.txt")); public static BanManager Bans = new BanManager(Path.Combine(SavePath, "bans.txt"));
delegate bool HandleGetDataD(MemoryStream data, GetDataEventArgs e); delegate bool HandleGetDataD(MemoryStream data, GetDataEventArgs e);
Dictionary<byte, HandleGetDataD> GetDataFuncs; Dictionary<byte, HandleGetDataD> GetDataFuncs;
@ -122,18 +122,18 @@ namespace TShockAPI
GetDataFuncs = new Dictionary<byte, HandleGetDataD> GetDataFuncs = new Dictionary<byte, HandleGetDataD>
{ {
{0x4, HandlePlayerInfo}, {(byte)PacketTypes.PlayerInfo, HandlePlayerInfo},
{0xA, HandleSendSection}, {(byte)PacketTypes.TileSendSection, HandleSendSection},
{0xD, HandlePlayerUpdate}, {(byte)PacketTypes.PlayerUpdate, HandlePlayerUpdate},
{0x11, HandleTile}, {(byte)PacketTypes.Tile, HandleTile},
{0x14, HandleSendTileSquare}, {(byte)PacketTypes.TileSendSquare, HandleSendTileSquare},
{0x17, HandleNpcUpdate}, {(byte)PacketTypes.NPCUpdate, HandleNpcUpdate},
{0x1A, HandlePlayerDamage}, {(byte)PacketTypes.PlayerDamage, HandlePlayerDamage},
{0x1B, HandleProjectileNew}, {(byte)PacketTypes.ProjectileNew, HandleProjectileNew},
{0x1E, HandleTogglePvp}, {(byte)PacketTypes.TogglePVP, HandleTogglePvp},
{0x22, HandleTileKill}, {(byte)PacketTypes.TileKill, HandleTileKill},
{0x2C, HandlePlayerKillMe}, {(byte)PacketTypes.PlayerKillMe, HandlePlayerKillMe},
{0x30, HandleLiquidSet}, {(byte)PacketTypes.LiquidSet, HandleLiquidSet},
}; };
} }
@ -149,7 +149,7 @@ namespace TShockAPI
} }
string version = string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename); string version = string.Format("TShock Version {0} ({1}) now running.", Version, VersionCodename);
Console.WriteLine(version); Console.WriteLine(version);
Log.Initialize(FileTools.SaveDir + "log.txt", LogLevel.All, false); Log.Initialize(Path.Combine(SavePath, "log.txt"), LogLevel.All, false);
Log.Info(version); Log.Info(version);
Log.Info("Starting..."); Log.Info("Starting...");
@ -275,17 +275,17 @@ namespace TShockAPI
Tools.ForceKick(e.Msg.whoAmI, "Empty Name."); Tools.ForceKick(e.Msg.whoAmI, "Empty Name.");
return true; return true;
} }
if (players[e.Msg.whoAmI] == null) if (Players[e.Msg.whoAmI] == null)
{ {
Tools.ForceKick(e.Msg.whoAmI, "Player doesn't exist"); Tools.ForceKick(e.Msg.whoAmI, "Player doesn't exist");
return true; return true;
} }
if (players[e.Msg.whoAmI].ReceivedInfo) if (Players[e.Msg.whoAmI].ReceivedInfo)
{ {
return Tools.HandleGriefer(e.Msg.whoAmI, "Sent client info more than once"); return Tools.HandleGriefer(e.Msg.whoAmI, "Sent client info more than once");
} }
players[e.Msg.whoAmI].ReceivedInfo = true; Players[e.Msg.whoAmI].ReceivedInfo = true;
return false; return false;
} }
@ -341,7 +341,7 @@ namespace TShockAPI
} }
if (ConfigurationManager.disableBuild) if (ConfigurationManager.disableBuild)
{ {
if (!players[e.Msg.whoAmI].Group.HasPermission("editspawn")) if (!Players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
{ {
Tools.SendMessage(e.Msg.whoAmI, "World protected from changes.", Color.Red); Tools.SendMessage(e.Msg.whoAmI, "World protected from changes.", Color.Red);
RevertPlayerChanges(e.Msg.whoAmI, type, x, y); RevertPlayerChanges(e.Msg.whoAmI, type, x, y);
@ -350,7 +350,7 @@ namespace TShockAPI
} }
if (ConfigurationManager.spawnProtect) if (ConfigurationManager.spawnProtect)
{ {
if (!players[e.Msg.whoAmI].Group.HasPermission("editspawn")) if (!Players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
{ {
var flag = CheckSpawn(x, y); var flag = CheckSpawn(x, y);
if (flag) if (flag)
@ -364,8 +364,8 @@ namespace TShockAPI
if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active) if (type == 0 && BlacklistTiles[Main.tile[x, y].type] && Main.player[e.Msg.whoAmI].active)
{ {
players[e.Msg.whoAmI].TileThreshold++; Players[e.Msg.whoAmI].TileThreshold++;
players[e.Msg.whoAmI].TilesDestroyed.Add(new Position(x, y), Main.tile[x, y]); Players[e.Msg.whoAmI].TilesDestroyed.Add(new Position(x, y), Main.tile[x, y]);
} }
return false; return false;
@ -495,14 +495,14 @@ namespace TShockAPI
} }
} }
if (lava && !players[e.Msg.whoAmI].Group.HasPermission("canlava")) if (lava && !Players[e.Msg.whoAmI].Group.HasPermission("canlava"))
{ {
Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use lava", Color.Red); Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use lava", Color.Red);
Tools.SendLogs(string.Format("{0} tried using lava", Main.player[e.Msg.whoAmI].name), Color.Red); Tools.SendLogs(string.Format("{0} tried using lava", Main.player[e.Msg.whoAmI].name), Color.Red);
return true; return true;
} }
if (!lava && !players[e.Msg.whoAmI].Group.HasPermission("canwater")) if (!lava && !Players[e.Msg.whoAmI].Group.HasPermission("canwater"))
{ {
Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use water", Color.Red); Tools.SendMessage(e.Msg.whoAmI, "You do not have permission to use water", Color.Red);
Tools.SendLogs(string.Format("{0} tried using water", Main.player[e.Msg.whoAmI].name), Color.Red); Tools.SendLogs(string.Format("{0} tried using water", Main.player[e.Msg.whoAmI].name), Color.Red);
@ -533,7 +533,7 @@ namespace TShockAPI
if (ConfigurationManager.spawnProtect) if (ConfigurationManager.spawnProtect)
{ {
if (!players[e.Msg.whoAmI].Group.HasPermission("editspawn")) if (!Players[e.Msg.whoAmI].Group.HasPermission("editspawn"))
{ {
var flag = CheckSpawn(x, y); var flag = CheckSpawn(x, y);
if (flag) if (flag)
@ -570,7 +570,7 @@ namespace TShockAPI
if (Main.netMode != 2) if (Main.netMode != 2)
return; return;
Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), players[who].Group.Name)); Log.Info(string.Format("{0} ({1}) from '{2}' group joined.", Tools.FindPlayer(who), Tools.GetPlayerIP(who), Players[who].Group.Name));
Tools.ShowMOTD(who); Tools.ShowMOTD(who);
if (HackedHealth(who)) if (HackedHealth(who))
@ -582,7 +582,7 @@ namespace TShockAPI
Main.player[who].hostile = true; Main.player[who].hostile = true;
NetMessage.SendData(30, -1, -1, "", who); NetMessage.SendData(30, -1, -1, "", who);
} }
if (players[who].Group.HasPermission("causeevents") && ConfigurationManager.infiniteInvasion) if (Players[who].Group.HasPermission("causeevents") && ConfigurationManager.infiniteInvasion)
{ {
StartInvasion(); StartInvasion();
} }
@ -600,7 +600,7 @@ namespace TShockAPI
return; return;
} }
if (players[ply].Group.HasPermission("adminchat") && !text.StartsWith("/")) if (Players[ply].Group.HasPermission("adminchat") && !text.StartsWith("/"))
{ {
Tools.Broadcast(ConfigurationManager.adminChatPrefix + "<" + Main.player[ply].name + "> " + text, (byte)ConfigurationManager.adminChatRGB[0], (byte)ConfigurationManager.adminChatRGB[1], (byte)ConfigurationManager.adminChatRGB[2]); Tools.Broadcast(ConfigurationManager.adminChatPrefix + "<" + Main.player[ply].name + "> " + text, (byte)ConfigurationManager.adminChatRGB[0], (byte)ConfigurationManager.adminChatRGB[1], (byte)ConfigurationManager.adminChatRGB[2]);
e.Handled = true; e.Handled = true;
@ -636,7 +636,7 @@ namespace TShockAPI
} }
else else
{ {
if (!cmd.CanRun(players[ply])) if (!cmd.CanRun(Players[ply]))
{ {
Tools.SendLogs(string.Format("{0} tried to execute {1}", Tools.FindPlayer(ply), cmd.Name()), Color.Red); Tools.SendLogs(string.Format("{0} tried to execute {1}", Tools.FindPlayer(ply), cmd.Name()), Color.Red);
Tools.SendMessage(ply, "You do not have access to that command.", Color.Red); Tools.SendMessage(ply, "You do not have access to that command.", Color.Red);
@ -644,7 +644,7 @@ namespace TShockAPI
else else
{ {
Tools.SendLogs(string.Format("{0} executed: /{1}", Tools.FindPlayer(ply), text), Color.Red); Tools.SendLogs(string.Format("{0} executed: /{1}", Tools.FindPlayer(ply), text), Color.Red);
cmd.Run(text, players[ply], args); cmd.Run(text, Players[ply], args);
} }
} }
e.Handled = true; e.Handled = true;
@ -659,11 +659,11 @@ namespace TShockAPI
} }
string ip = Tools.GetPlayerIP(ply); string ip = Tools.GetPlayerIP(ply);
players[ply] = new TSPlayer(ply); Players[ply] = new TSPlayer(ply);
players[ply].Group = Tools.GetGroupForIP(ip); Players[ply].Group = Tools.GetGroupForIP(ip);
if (Tools.ActivePlayers() + 1 > ConfigurationManager.maxSlots && if (Tools.ActivePlayers() + 1 > ConfigurationManager.maxSlots &&
!players[ply].Group.HasPermission("reservedslot")) !Players[ply].Group.HasPermission("reservedslot"))
{ {
Tools.ForceKick(ply, "Server is full"); Tools.ForceKick(ply, "Server is full");
handler.Handled = true; handler.Handled = true;
@ -688,14 +688,14 @@ namespace TShockAPI
private void OnPostInit() private void OnPostInit()
{ {
if (!File.Exists(FileTools.SaveDir + "auth.lck")) if (!File.Exists(Path.Combine(SavePath, "auth.lck")))
{ {
Random r = new Random((int)DateTime.Now.ToBinary()); var r = new Random((int)DateTime.Now.ToBinary());
ConfigurationManager.authToken = r.Next(100000, 10000000); ConfigurationManager.authToken = r.Next(100000, 10000000);
Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " + Console.WriteLine("TShock Notice: To become SuperAdmin, join the game and type /auth " +
ConfigurationManager.authToken); ConfigurationManager.authToken);
Console.WriteLine("This token will only display ONCE. This only works ONCE. If you don't use it and the server goes down, delete auth.lck."); Console.WriteLine("This token will only display ONCE. This only works ONCE. If you don't use it and the server goes down, delete auth.lck.");
FileTools.CreateFile(FileTools.SaveDir + "auth.lck"); FileTools.CreateFile(Path.Combine(SavePath, "auth.lck"));
} }
} }
@ -726,24 +726,24 @@ namespace TShockAPI
{ {
if (Main.player[i].active == false) if (Main.player[i].active == false)
continue; continue;
if (players[i].TileThreshold >= 20) if (Players[i].TileThreshold >= 20)
{ {
if (Tools.HandleTntUser(i, "Kill tile abuse detected.")) if (Tools.HandleTntUser(i, "Kill tile abuse detected."))
{ {
RevertKillTile(i); RevertKillTile(i);
players[i].TileThreshold = 0; Players[i].TileThreshold = 0;
players[i].TilesDestroyed.Clear(); Players[i].TilesDestroyed.Clear();
} }
else if (players[i].TileThreshold > 0) else if (Players[i].TileThreshold > 0)
{ {
players[i].TileThreshold = 0; Players[i].TileThreshold = 0;
players[i].TilesDestroyed.Clear(); Players[i].TilesDestroyed.Clear();
} }
} }
else if (players[i].TileThreshold > 0) else if (Players[i].TileThreshold > 0)
{ {
players[i].TileThreshold = 0; Players[i].TileThreshold = 0;
} }
} }
} }
@ -913,11 +913,11 @@ namespace TShockAPI
public static void RevertKillTile(int ply) public static void RevertKillTile(int ply)
{ {
Tile[] tiles = new Tile[players[ply].TilesDestroyed.Count]; Tile[] tiles = new Tile[Players[ply].TilesDestroyed.Count];
players[ply].TilesDestroyed.Values.CopyTo(tiles, 0); Players[ply].TilesDestroyed.Values.CopyTo(tiles, 0);
Position[] positions = new Position[players[ply].TilesDestroyed.Count]; Position[] positions = new Position[Players[ply].TilesDestroyed.Count];
players[ply].TilesDestroyed.Keys.CopyTo(positions, 0); Players[ply].TilesDestroyed.Keys.CopyTo(positions, 0);
for (int i = (players[ply].TilesDestroyed.Count - 1); i >= 0; i--) for (int i = (Players[ply].TilesDestroyed.Count - 1); i >= 0; i--)
{ {
Main.tile[(int)positions[i].X, (int)positions[i].Y] = tiles[i]; Main.tile[(int)positions[i].X, (int)positions[i].Y] = tiles[i];
NetMessage.SendData(17, -1, -1, "", 1, positions[i].X, positions[i].Y, (float)0); NetMessage.SendData(17, -1, -1, "", 1, positions[i].X, positions[i].Y, (float)0);

View file

@ -139,9 +139,9 @@ namespace TShockAPI
Log.Info(log); Log.Info(log);
for (int i = 0; i < Main.maxPlayers; i++) for (int i = 0; i < Main.maxPlayers; i++)
{ {
if (TShock.players[i] == null) if (TShock.Players[i] == null)
continue; continue;
if (!TShock.players[i].Group.HasPermission("logs")) if (!TShock.Players[i].Group.HasPermission("logs"))
continue; continue;
SendMessage(i, log, color); SendMessage(i, log, color);
@ -265,7 +265,7 @@ namespace TShockAPI
{ {
if (!Netplay.serverSock[ply].active || Netplay.serverSock[ply].kill) if (!Netplay.serverSock[ply].active || Netplay.serverSock[ply].kill)
return true; return true;
if (!TShock.players[ply].Group.HasPermission("immunetokick")) if (!TShock.Players[ply].Group.HasPermission("immunetokick"))
{ {
string playerName = Main.player[ply].name; string playerName = Main.player[ply].name;
NetMessage.SendData(0x2, ply, -1, string.Format("Kicked: {0}", reason), 0x0, 0f, 0f, 0f); NetMessage.SendData(0x2, ply, -1, string.Format("Kicked: {0}", reason), 0x0, 0f, 0f, 0f);
@ -288,7 +288,7 @@ namespace TShockAPI
{ {
if (!Netplay.serverSock[plr].active || Netplay.serverSock[plr].kill) if (!Netplay.serverSock[plr].active || Netplay.serverSock[plr].kill)
return true; return true;
if (!TShock.players[plr].Group.HasPermission("immunetoban")) if (!TShock.Players[plr].Group.HasPermission("immunetoban"))
{ {
string ip = GetPlayerIP(plr); string ip = GetPlayerIP(plr);
string playerName = Main.player[plr].name; string playerName = Main.player[plr].name;
@ -326,7 +326,7 @@ namespace TShockAPI
private static bool HandleBadPlayer(int ply, string overridePermission, bool ban, bool kick, string reason) private static bool HandleBadPlayer(int ply, string overridePermission, bool ban, bool kick, string reason)
{ {
if (!TShock.players[ply].Group.HasPermission(overridePermission)) if (!TShock.Players[ply].Group.HasPermission(overridePermission))
{ {
if (ban) if (ban)
{ {
@ -353,7 +353,7 @@ namespace TShockAPI
public static void ShowFileToUser(int ply, string file) public static void ShowFileToUser(int ply, string file)
{ {
string foo = ""; string foo = "";
TextReader tr = new StreamReader(FileTools.SaveDir + file); TextReader tr = new StreamReader(Path.Combine(TShock.SavePath + file));
while ((foo = tr.ReadLine()) != null) while ((foo = tr.ReadLine()) != null)
{ {
foo = foo.Replace("%map%", Main.worldName); foo = foo.Replace("%map%", Main.worldName);
@ -388,7 +388,7 @@ namespace TShockAPI
groups = new List<Group>(); groups = new List<Group>();
groups.Add(new SuperAdminGroup("superadmin")); groups.Add(new SuperAdminGroup("superadmin"));
StreamReader sr = new StreamReader(FileTools.SaveDir + "groups.txt"); StreamReader sr = new StreamReader(FileTools.GroupsPath);
string data = sr.ReadToEnd(); string data = sr.ReadToEnd();
data = data.Replace("\r", ""); data = data.Replace("\r", "");
string[] lines = data.Split('\n'); string[] lines = data.Split('\n');
@ -483,7 +483,7 @@ namespace TShockAPI
{ {
ip = GetRealIP(ip); ip = GetRealIP(ip);
StreamReader sr = new StreamReader(FileTools.SaveDir + "users.txt"); StreamReader sr = new StreamReader(FileTools.UsersPath);
string data = sr.ReadToEnd(); string data = sr.ReadToEnd();
data = data.Replace("\r", ""); data = data.Replace("\r", "");
string[] lines = data.Split('\n'); string[] lines = data.Split('\n');

View file

@ -77,7 +77,7 @@ namespace TShockAPI
{ {
if (Main.player[i].active) if (Main.player[i].active)
{ {
if (!TShock.players[i].Group.HasPermission("maintenance")) if (!TShock.Players[i].Group.HasPermission("maintenance"))
return; return;
Tools.SendMessage(i, "The server is out of date. To update, type /updatenow."); Tools.SendMessage(i, "The server is out of date. To update, type /updatenow.");
for (int j = 4; j < changes.Length; j++) for (int j = 4; j < changes.Length; j++)