The same name can be added more than once to whitelist
This commit is contained in:
@@ -62,19 +62,19 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
foreach (string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
if (line[0] == '#')
|
if (line[0] == '#')
|
||||||
{
|
{
|
||||||
string lineval = line.Substring(1, line.Length - 1);
|
string lineval = line.Substring(1, line.Length - 1);
|
||||||
if (lineval.ToLower()=="true" || Convert.ToInt32(lineval)!=0)
|
if (lineval.ToLower()=="true" || Convert.ToInt32(lineval)!=0)
|
||||||
{
|
{
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string[] separatedLine = line.Split(',');
|
string[] separatedLine = line.Split(',');
|
||||||
if (separatedLine.Length < 2) continue;
|
if (separatedLine.Length < 2) continue;
|
||||||
@@ -94,13 +94,13 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
lines.Add("#true");
|
lines.Add("#true");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lines.Add("#false");
|
lines.Add("#false");
|
||||||
}
|
}
|
||||||
foreach (WhiteListedPlayer wlp in whitelistedPlayers)
|
foreach (WhiteListedPlayer wlp in whitelistedPlayers)
|
||||||
{
|
{
|
||||||
@@ -115,8 +115,8 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Saving the whitelist to " + SavePath + " failed", e);
|
DebugConsole.ThrowError("Saving the whitelist to " + SavePath + " failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsWhiteListed(string name, string ip)
|
public bool IsWhiteListed(string name, string ip)
|
||||||
{
|
{
|
||||||
if (!enabled) return true;
|
if (!enabled) return true;
|
||||||
@@ -142,16 +142,16 @@ namespace Barotrauma.Networking
|
|||||||
enabledTick.OnSelected = (GUITickBox box) =>
|
enabledTick.OnSelected = (GUITickBox box) =>
|
||||||
{
|
{
|
||||||
enabled = !enabled;
|
enabled = !enabled;
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
foreach (Client c in GameMain.Server.ConnectedClients)
|
foreach (Client c in GameMain.Server.ConnectedClients)
|
||||||
{
|
{
|
||||||
if (!IsWhiteListed(c.name,c.Connection.RemoteEndPoint.Address.ToString()))
|
if (!IsWhiteListed(c.name,c.Connection.RemoteEndPoint.Address.ToString()))
|
||||||
{
|
{
|
||||||
whitelistedPlayers.Add(new WhiteListedPlayer(c.name, c.Connection.RemoteEndPoint.Address.ToString()));
|
whitelistedPlayers.Add(new WhiteListedPlayer(c.name, c.Connection.RemoteEndPoint.Address.ToString()));
|
||||||
CloseFrame(); CreateWhiteListFrame();
|
CloseFrame(); CreateWhiteListFrame();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Save();
|
Save();
|
||||||
return true;
|
return true;
|
||||||
@@ -207,7 +207,8 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private bool AddToWhiteList(GUIButton button, object obj)
|
private bool AddToWhiteList(GUIButton button, object obj)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(nameBox.Text) || whitelistedPlayers.Find(x => x.Name.ToLower() == nameBox.Text.ToLower()) != null) return false;
|
if (string.IsNullOrWhiteSpace(nameBox.Text)) return false;
|
||||||
|
if (whitelistedPlayers.Find(x => x.Name.ToLower() == nameBox.Text.ToLower() && x.IP == ipBox.Text) != null) return false;
|
||||||
whitelistedPlayers.Add(new WhiteListedPlayer(nameBox.Text,ipBox.Text));
|
whitelistedPlayers.Add(new WhiteListedPlayer(nameBox.Text,ipBox.Text));
|
||||||
Save();
|
Save();
|
||||||
CloseFrame(); CreateWhiteListFrame();
|
CloseFrame(); CreateWhiteListFrame();
|
||||||
|
|||||||
@@ -396,10 +396,10 @@ namespace Barotrauma
|
|||||||
|
|
||||||
GUIButton settingsButton = new GUIButton(new Rectangle(-100, 0, 80, 30), "Settings", Alignment.BottomRight, GUI.Style, infoFrame);
|
GUIButton settingsButton = new GUIButton(new Rectangle(-100, 0, 80, 30), "Settings", Alignment.BottomRight, GUI.Style, infoFrame);
|
||||||
settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame;
|
settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame;
|
||||||
settingsButton.UserData = "settingsButton";
|
settingsButton.UserData = "settingsButton";
|
||||||
|
|
||||||
GUIButton whitelistButton = new GUIButton(new Rectangle(-200, 0, 80, 30), "Whitelist", Alignment.BottomRight, GUI.Style, infoFrame);
|
GUIButton whitelistButton = new GUIButton(new Rectangle(-200, 0, 80, 30), "Whitelist", Alignment.BottomRight, GUI.Style, infoFrame);
|
||||||
whitelistButton.OnClicked = GameMain.Server.ToggleWhiteListFrame;
|
whitelistButton.OnClicked = GameMain.Server.ToggleWhiteListFrame;
|
||||||
whitelistButton.UserData = "whitelistButton";
|
whitelistButton.UserData = "whitelistButton";
|
||||||
|
|
||||||
if (subList.Selected == null) subList.Select(Math.Max(0, prevSelectedSub));
|
if (subList.Selected == null) subList.Select(Math.Max(0, prevSelectedSub));
|
||||||
@@ -895,8 +895,8 @@ namespace Barotrauma
|
|||||||
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Ban))
|
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Ban))
|
||||||
{
|
{
|
||||||
GameMain.Client.KickPlayer(userData.ToString(), true);
|
GameMain.Client.KickPlayer(userData.ToString(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -911,8 +911,8 @@ namespace Barotrauma
|
|||||||
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Ban))
|
else if (GameMain.Client != null && GameMain.Client.HasPermission(ClientPermissions.Ban))
|
||||||
{
|
{
|
||||||
GameMain.Client.KickPlayer(userData.ToString(), true, true);
|
GameMain.Client.KickPlayer(userData.ToString(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user