Whitelist saving

This commit is contained in:
juanjp600
2016-09-03 17:51:10 -03:00
parent efa8b4da51
commit d0efbe14f3
5 changed files with 129 additions and 44 deletions
+32 -32
View File
@@ -12,18 +12,18 @@ namespace Barotrauma.Networking
public string Name;
public string IP;
public bool CompareTo(string ipCompare)
{
int rangeBanIndex = IP.IndexOf(".x");
if (rangeBanIndex<=-1)
{
return ipCompare == IP;
}
else
{
if (ipCompare.Length < rangeBanIndex) return false;
return ipCompare.Substring(0, rangeBanIndex) == IP.Substring(0, rangeBanIndex);
}
public bool CompareTo(string ipCompare)
{
int rangeBanIndex = IP.IndexOf(".x");
if (rangeBanIndex<=-1)
{
return ipCompare == IP;
}
else
{
if (ipCompare.Length < rangeBanIndex) return false;
return ipCompare.Substring(0, rangeBanIndex) == IP.Substring(0, rangeBanIndex);
}
}
public BannedPlayer(string name, string ip)
@@ -108,7 +108,7 @@ namespace Barotrauma.Networking
var removeButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Remove", Alignment.Right | Alignment.CenterY, GUI.Style, textBlock);
removeButton.UserData = bannedPlayer;
removeButton.OnClicked = RemoveBan;
if (bannedPlayer.IP.IndexOf(".x") <= -1)
if (bannedPlayer.IP.IndexOf(".x") <= -1)
{
var rangeBanButton = new GUIButton(new Rectangle(-100, 0, 100, 20), "Ban range", Alignment.Right | Alignment.CenterY, GUI.Style, textBlock);
rangeBanButton.UserData = bannedPlayer;
@@ -140,30 +140,30 @@ namespace Barotrauma.Networking
return true;
}
public string ToRange(string ip)
{
for (int i = ip.Length - 1; i > 0; i--)
{
if (ip[i] == '.')
{
ip = ip.Substring(0, i) + ".x";
break;
}
}
return ip;
public string ToRange(string ip)
{
for (int i = ip.Length - 1; i > 0; i--)
{
if (ip[i] == '.')
{
ip = ip.Substring(0, i) + ".x";
break;
}
}
return ip;
}
private bool RangeBan(GUIButton button, object obj)
{
private bool RangeBan(GUIButton button, object obj)
{
BannedPlayer banned = obj as BannedPlayer;
if (banned == null) return false;
if (banned == null) return false;
banned.IP = ToRange(banned.IP);
BannedPlayer bp;
while ((bp = bannedPlayers.Find(x => banned.CompareTo(x.IP)))!=null)
{
//remove all specific bans that are now covered by the rangeban
while ((bp = bannedPlayers.Find(x => banned.CompareTo(x.IP)))!=null)
{
//remove all specific bans that are now covered by the rangeban
bannedPlayers.Remove(bp);
}
@@ -177,7 +177,7 @@ namespace Barotrauma.Networking
CreateBanFrame(banFrame.Parent);
}
return true;
return true;
}
private bool CloseFrame(GUIButton button, object obj)