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