Removed per-user password from whitelist
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -57,7 +57,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
private void CheckAuthentication(NetIncomingMessage inc)
|
||||
{
|
||||
string whitelistPw = "";
|
||||
var unauthenticatedClient = unauthenticatedClients.Find(uc => uc.Connection == inc.SenderConnection);
|
||||
if (unauthenticatedClient != null)
|
||||
{
|
||||
@@ -70,26 +69,10 @@ namespace Barotrauma.Networking
|
||||
inc.Decrypt(algo);
|
||||
|
||||
string rdPw = inc.ReadString();
|
||||
if (!whitelist.enabled)
|
||||
if (rdPw != saltedPw)
|
||||
{
|
||||
if (rdPw != saltedPw)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("Wrong password!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WhiteListedPlayer wlp = whitelist.WhiteListedPlayers.Find(x => x.GetHashedPassword(unauthenticatedClient.Nonce) == saltedPw);
|
||||
if (wlp==null)
|
||||
{
|
||||
inc.SenderConnection.Disconnect("Wrong password or name!");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
whitelistPw = wlp.Password;
|
||||
}
|
||||
inc.SenderConnection.Disconnect("Wrong password!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -160,9 +143,15 @@ namespace Barotrauma.Networking
|
||||
inc.SenderConnection.Disconnect("The name ''" + name + "'' is already in use. Please choose another name.");
|
||||
DebugConsole.NewMessage(name + " couldn't join the server (name already in use)", Color.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
if (!whitelist.IsWhiteListed(name, inc.SenderConnection.RemoteEndPoint.Address.ToString()))
|
||||
{
|
||||
inc.SenderConnection.Disconnect("You're not in this server's whitelist.");
|
||||
DebugConsole.NewMessage(name + " couldn't join the server (not in whitelist)", Color.Red);
|
||||
return;
|
||||
}
|
||||
|
||||
//existing user re-joining
|
||||
if (userID > 0)
|
||||
|
||||
@@ -4,33 +4,23 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
class WhiteListedPlayer
|
||||
{
|
||||
public string Name;
|
||||
public string Password;
|
||||
public string IP;
|
||||
|
||||
public WhiteListedPlayer(string name,string password,string ip)
|
||||
{
|
||||
Name = name;
|
||||
Password = password;
|
||||
IP = ip;
|
||||
}
|
||||
|
||||
public string GetHashedPassword(int nonce)
|
||||
{
|
||||
string saltedPw = Password;
|
||||
saltedPw = saltedPw + Convert.ToString(nonce);
|
||||
saltedPw = Encoding.UTF8.GetString(Lidgren.Network.NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(saltedPw)));
|
||||
return saltedPw;
|
||||
}
|
||||
}
|
||||
|
||||
class WhiteList
|
||||
{
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
class WhiteListedPlayer
|
||||
{
|
||||
public string Name;
|
||||
public string IP;
|
||||
|
||||
public WhiteListedPlayer(string name,string ip)
|
||||
{
|
||||
Name = name;
|
||||
IP = ip;
|
||||
}
|
||||
}
|
||||
|
||||
class WhiteList
|
||||
{
|
||||
private List<WhiteListedPlayer> whitelistedPlayers;
|
||||
public List<WhiteListedPlayer> WhiteListedPlayers
|
||||
{
|
||||
@@ -42,7 +32,6 @@ namespace Barotrauma.Networking
|
||||
|
||||
private GUITextBox nameBox;
|
||||
private GUITextBox ipBox;
|
||||
private GUITextBox pwBox;
|
||||
|
||||
public bool enabled;
|
||||
|
||||
@@ -54,27 +43,26 @@ namespace Barotrauma.Networking
|
||||
public WhiteList()
|
||||
{
|
||||
enabled = false;
|
||||
whitelistedPlayers = new List<WhiteListedPlayer>();
|
||||
}
|
||||
|
||||
public bool IsWhiteListed(string name, string password, string ip)
|
||||
{
|
||||
if (!enabled) return true;
|
||||
WhiteListedPlayer wlp = whitelistedPlayers.Find(p => p.Name == name);
|
||||
if (wlp == null) return false;
|
||||
if (wlp.Password != password && !string.IsNullOrWhiteSpace(wlp.Password)) return false;
|
||||
if (wlp.IP != ip && !string.IsNullOrWhiteSpace(wlp.IP)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
whitelistedPlayers = new List<WhiteListedPlayer>();
|
||||
}
|
||||
|
||||
public bool IsWhiteListed(string name, string ip)
|
||||
{
|
||||
if (!enabled) return true;
|
||||
WhiteListedPlayer wlp = whitelistedPlayers.Find(p => p.Name == name);
|
||||
if (wlp == null) return false;
|
||||
if (wlp.IP != ip && !string.IsNullOrWhiteSpace(wlp.IP)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public GUIComponent CreateWhiteListFrame()
|
||||
{
|
||||
whitelistFrame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.5f);
|
||||
|
||||
GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 500, 460), null, Alignment.Center, GUI.Style, whitelistFrame);
|
||||
innerFrame.Padding = new Vector4(20.0f, 50.0f, 20.0f, 130.0f);
|
||||
GUIFrame innerFrame = new GUIFrame(new Rectangle(0, 0, 500, 430), null, Alignment.Center, GUI.Style, whitelistFrame);
|
||||
innerFrame.Padding = new Vector4(20.0f, 50.0f, 20.0f, 100.0f);
|
||||
|
||||
var closeButton = new GUIButton(new Rectangle(0, 115, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
|
||||
var closeButton = new GUIButton(new Rectangle(0, 85, 100, 20), "Close", Alignment.BottomRight, GUI.Style, innerFrame);
|
||||
closeButton.OnClicked = GameMain.Server.ToggleWhiteListFrame;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, -35, 200, 20), "Whitelist", GUI.Style, innerFrame, GUI.LargeFont);
|
||||
@@ -90,15 +78,11 @@ namespace Barotrauma.Networking
|
||||
nameBox = new GUITextBox(new Rectangle(100, 30, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
|
||||
nameBox.Font = GUI.Font;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 65, 90, 25), "Password:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, innerFrame, false, GUI.Font);
|
||||
pwBox = new GUITextBox(new Rectangle(100, 60, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
|
||||
pwBox.Font = GUI.Font;
|
||||
|
||||
new GUITextBlock(new Rectangle(0, 95, 90, 25), "IP Address:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, innerFrame, false, GUI.Font);
|
||||
ipBox = new GUITextBox(new Rectangle(100, 90, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
|
||||
new GUITextBlock(new Rectangle(0, 65, 90, 25), "IP Address:", GUI.Style, Alignment.BottomLeft, Alignment.TopLeft, innerFrame, false, GUI.Font);
|
||||
ipBox = new GUITextBox(new Rectangle(100, 60, 170, 25), Alignment.BottomLeft, GUI.Style, innerFrame);
|
||||
ipBox.Font = GUI.Font;
|
||||
|
||||
var addnewButton = new GUIButton(new Rectangle(300, 55, 150, 20), "Add to whitelist", Alignment.BottomLeft, GUI.Style, innerFrame);
|
||||
var addnewButton = new GUIButton(new Rectangle(300, 45, 150, 20), "Add to whitelist", Alignment.BottomLeft, GUI.Style, innerFrame);
|
||||
addnewButton.OnClicked = AddToWhiteList;
|
||||
|
||||
innerlistFrame = new GUIListBox(new Rectangle(0, 0, 0, 0), GUI.Style, innerFrame);
|
||||
@@ -137,12 +121,12 @@ namespace Barotrauma.Networking
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool AddToWhiteList(GUIButton button, object obj)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(nameBox.Text) || whitelistedPlayers.Find(x => x.Name.ToLower() == nameBox.Text.ToLower()) != null) return false;
|
||||
whitelistedPlayers.Add(new WhiteListedPlayer(nameBox.Text,pwBox.Text,ipBox.Text));
|
||||
CloseFrame(); CreateWhiteListFrame();
|
||||
return true;
|
||||
private bool AddToWhiteList(GUIButton button, object obj)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(nameBox.Text) || whitelistedPlayers.Find(x => x.Name.ToLower() == nameBox.Text.ToLower()) != null) return false;
|
||||
whitelistedPlayers.Add(new WhiteListedPlayer(nameBox.Text,ipBox.Text));
|
||||
CloseFrame(); CreateWhiteListFrame();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CloseFrame(GUIButton button=null, object obj=null)
|
||||
@@ -150,6 +134,6 @@ namespace Barotrauma.Networking
|
||||
whitelistFrame = null;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user