Attempting a work around for DNS host resolution. There will now be a configuration parameter that will enable the check. This is expensive, and not recommended, but a better reserved slot system will be done in the future.
Closes #254
This commit is contained in:
parent
d6c1f44219
commit
407d327236
3 changed files with 41 additions and 4 deletions
|
|
@ -93,7 +93,9 @@ namespace TShockAPI
|
|||
public string TileKillAbuseReason = "Tile Kill abuse ({0})";
|
||||
public string HardcoreBanReason = "Death results in a ban";
|
||||
public string HardcoreKickReason = "Death results in a kick";
|
||||
|
||||
|
||||
public bool EnableDNSHostResolution = false;
|
||||
|
||||
public static ConfigFile Read(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
|
|
|
|||
|
|
@ -222,6 +222,36 @@ namespace TShockAPI.DB
|
|||
}
|
||||
return Tools.GetGroup("default");
|
||||
}
|
||||
|
||||
public Group GetGroupForIPExpensive(string ip)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var com = database.CreateCommand())
|
||||
{
|
||||
com.CommandText = "SELECT * FROM Users";
|
||||
|
||||
using (var reader = com.ExecuteReader())
|
||||
{
|
||||
while(reader.Read())
|
||||
{
|
||||
if (Tools.GetIPv4Address(reader.Get<string>("IP")) == ip)
|
||||
{
|
||||
string group = reader.Get<string>("UserGroup");
|
||||
return Tools.GetGroup(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.ConsoleError("GetGroupForIP SQL returned an error: " + ex.ToString());
|
||||
}
|
||||
return Tools.GetGroup("default");
|
||||
}
|
||||
|
||||
|
||||
public User GetUserByName(string name)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace TShockAPI
|
|||
public class TShock : TerrariaPlugin
|
||||
{
|
||||
public static readonly Version VersionNum = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
public static readonly string VersionCodename = "The Deathly Database Part 2";
|
||||
public static readonly string VersionCodename = "Codename: Re";
|
||||
|
||||
public static string SavePath = "tshock";
|
||||
|
||||
|
|
@ -376,8 +376,13 @@ namespace TShockAPI
|
|||
private void OnJoin(int ply, HandledEventArgs handler)
|
||||
{
|
||||
var player = new TSPlayer(ply);
|
||||
|
||||
player.Group = TShock.Users.GetGroupForIP(player.IP);
|
||||
if (Config.EnableDNSHostResolution)
|
||||
{
|
||||
player.Group = TShock.Users.GetGroupForIPExpensive(player.IP);
|
||||
} else
|
||||
{
|
||||
player.Group = TShock.Users.GetGroupForIP(player.IP);
|
||||
}
|
||||
|
||||
if (Tools.ActivePlayers() + 1 > TShock.Config.MaxSlots && !player.Group.HasPermission("reservedslot"))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue