Changes region allow to use IP addresses rather than names. Cancels out name spoofing.
This commit is contained in:
parent
640382d898
commit
c45696efb2
4 changed files with 49 additions and 24 deletions
|
|
@ -1087,7 +1087,6 @@ namespace TShockAPI
|
|||
args.Player.TempArea.Width, args.Player.TempArea.Height,
|
||||
regionName, Main.worldName))
|
||||
{
|
||||
RegionManager.WriteSettings();
|
||||
args.Player.TempArea = Rectangle.Empty;
|
||||
args.Player.SendMessage("Set region " + regionName, Color.Yellow);
|
||||
}
|
||||
|
|
@ -1155,6 +1154,7 @@ namespace TShockAPI
|
|||
{
|
||||
string playerName = args.Parameters[1];
|
||||
string regionName = "";
|
||||
string playerIP = null;
|
||||
|
||||
for (int i = 2; i < args.Parameters.Count; i++)
|
||||
{
|
||||
|
|
@ -1167,14 +1167,20 @@ namespace TShockAPI
|
|||
regionName = regionName + " " + args.Parameters[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (RegionManager.AddNewUser(regionName, playerName))
|
||||
if ((playerIP = Tools.GetPlayerIP(playerName)) != null)
|
||||
{
|
||||
args.Player.SendMessage("Added user " + playerName + " to " + regionName, Color.Yellow);
|
||||
RegionManager.WriteSettings();
|
||||
if (RegionManager.AddNewUser(regionName, playerIP))
|
||||
{
|
||||
args.Player.SendMessage("Added user " + playerName + " to " + regionName, Color.Yellow);
|
||||
RegionManager.WriteSettings();
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Region " + regionName + " not found", Color.Red);
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Region " + regionName + " not found", Color.Red);
|
||||
{
|
||||
args.Player.SendMessage("Player " + playerName + " not found", Color.Red);
|
||||
}
|
||||
}
|
||||
else
|
||||
args.Player.SendMessage("Invalid syntax! Proper syntax: /region allow [name] [region]", Color.Red);
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ namespace TShockAPI
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if (!args.Player.Group.HasPermission("editspawn") && RegionManager.InProtectedArea(x, y, args.Player.Name))
|
||||
if (!args.Player.Group.HasPermission("editspawn") && RegionManager.InProtectedArea(x, y, Tools.GetPlayerIP(args.Player.Name)))
|
||||
{
|
||||
args.Player.SendMessage("Region protected from changes.", Color.Red);
|
||||
args.Player.SendTileSquare(x, y);
|
||||
|
|
|
|||
|
|
@ -12,27 +12,27 @@ namespace TShockAPI
|
|||
{
|
||||
public static List<Region> Regions = new List<Region>();
|
||||
|
||||
public static bool AddRegion(int tx, int ty, int width, int height, string name, string worldname)
|
||||
public static bool AddRegion(int tx, int ty, int width, int height, string regionname, string worldname)
|
||||
{
|
||||
foreach (Region nametest in Regions)
|
||||
{
|
||||
if (name.ToLower() == nametest.RegionName.ToLower())
|
||||
if (regionname.ToLower() == nametest.RegionName.ToLower())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Regions.Add(new Region(new Rectangle(tx, ty, width, height), name, true, worldname));
|
||||
Regions.Add(new Region(new Rectangle(tx, ty, width, height), regionname, true, worldname));
|
||||
WriteSettings();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool AddNewUser(string regionName, string name)
|
||||
public static bool AddNewUser(string regionName, string IP)
|
||||
{
|
||||
foreach (Region nametest in Regions)
|
||||
{
|
||||
if (regionName.ToLower() == nametest.RegionName.ToLower())
|
||||
{
|
||||
nametest.RegionAllowedUsers.Add(name.ToLower());
|
||||
Console.WriteLine(nametest.RegionName);
|
||||
nametest.RegionAllowedIPs.Add(IP.ToLower());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -67,11 +67,11 @@ namespace TShockAPI
|
|||
return false;
|
||||
}
|
||||
|
||||
public static bool InProtectedArea(int X, int Y, string name)
|
||||
public static bool InProtectedArea(int X, int Y, string IP)
|
||||
{
|
||||
foreach(Region region in Regions)
|
||||
{
|
||||
if (X >= region.RegionArea.Left && X <= region.RegionArea.Right && Y >= region.RegionArea.Top && Y <= region.RegionArea.Bottom && region.DisableBuild && Main.worldName == region.WorldRegionName && (!AllowedUser(region.RegionName, name.ToLower()) || region.RegionAllowedUsers.Count == 0))
|
||||
if (X >= region.RegionArea.Left && X <= region.RegionArea.Right && Y >= region.RegionArea.Top && Y <= region.RegionArea.Bottom && region.DisableBuild && Main.worldName == region.WorldRegionName && (!AllowedUser(region.RegionName, IP.ToLower()) || region.RegionAllowedIPs.Count == 0))
|
||||
{
|
||||
Console.WriteLine(region.RegionName);
|
||||
return true;
|
||||
|
|
@ -90,14 +90,14 @@ namespace TShockAPI
|
|||
return -1;
|
||||
}
|
||||
|
||||
public static bool AllowedUser(string regionName, string playerName)
|
||||
public static bool AllowedUser(string regionName, string playerIP)
|
||||
{
|
||||
int ID = -1;
|
||||
if ((ID = GetRegionIndex(regionName)) != -1)
|
||||
{
|
||||
for (int i = 0; i < Regions[ID].RegionAllowedUsers.Count; i++)
|
||||
for (int i = 0; i < Regions[ID].RegionAllowedIPs.Count; i++)
|
||||
{
|
||||
if (Regions[ID].RegionAllowedUsers[i].ToLower() == playerName.ToLower())
|
||||
if (Regions[ID].RegionAllowedIPs[i].ToLower() == playerIP.ToLower())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -129,10 +129,10 @@ namespace TShockAPI
|
|||
settingsw.WriteElementString("Point2Y", region.RegionArea.Height.ToString());
|
||||
settingsw.WriteElementString("Protected", region.DisableBuild.ToString());
|
||||
settingsw.WriteElementString("WorldName", region.WorldRegionName);
|
||||
settingsw.WriteElementString("AllowedUserCount", region.RegionAllowedUsers.Count.ToString());
|
||||
for (int i = 0; i < region.RegionAllowedUsers.Count; i++)
|
||||
settingsw.WriteElementString("AllowedUserCount", region.RegionAllowedIPs.Count.ToString());
|
||||
for (int i = 0; i < region.RegionAllowedIPs.Count; i++)
|
||||
{
|
||||
settingsw.WriteElementString("User", region.RegionAllowedUsers[i]);
|
||||
settingsw.WriteElementString("IP", region.RegionAllowedIPs[i]);
|
||||
}
|
||||
settingsw.WriteEndElement();
|
||||
}
|
||||
|
|
@ -257,10 +257,10 @@ namespace TShockAPI
|
|||
if (settingr.Value != "" || settingr.Value != null)
|
||||
{
|
||||
int ID = RegionManager.GetRegionIndex(name);
|
||||
Regions[ID].RegionAllowedUsers.Add(settingr.Value);
|
||||
Regions[ID].RegionAllowedIPs.Add(settingr.Value);
|
||||
}
|
||||
else
|
||||
Log.Warn("Playername " + i + " for region " + name + " is empty");
|
||||
Log.Warn("PlayerIP " + i + " for region " + name + " is empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -286,7 +286,7 @@ namespace TShockAPI
|
|||
public string RegionName { get; set; }
|
||||
public bool DisableBuild { get; set; }
|
||||
public string WorldRegionName { get; set; }
|
||||
public List<string> RegionAllowedUsers = new List<string>();
|
||||
public List<string> RegionAllowedIPs = new List<string>();
|
||||
|
||||
public Region(Rectangle region, string name, bool disablebuild, string worldname)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,6 +60,25 @@ namespace TShockAPI
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds a player and gets IP as string
|
||||
/// </summary>
|
||||
/// <param name="msg">Player name</param>
|
||||
public static string GetPlayerIP(string playername)
|
||||
{
|
||||
foreach (TSPlayer player in TShock.Players)
|
||||
{
|
||||
if (player != null && player.Active)
|
||||
{
|
||||
if (playername.ToLower() == player.Name.ToLower())
|
||||
{
|
||||
return player.IP;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// It's a clamp function
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue