Added a console command for changing the server password. Closes #325

This commit is contained in:
Joonas Rikkonen
2018-03-07 17:26:42 +02:00
parent b9287beed2
commit a43b8dc278
2 changed files with 13 additions and 2 deletions

View File

@@ -197,6 +197,12 @@ namespace Barotrauma
NewMessage("***************", Color.Cyan);
}));
commands.Add(new Command("setpassword|setserverpassword", "setpassword [password]: Changes the password of the server that's being hosted.", (string[] args) =>
{
if (GameMain.Server == null || args.Length == 0) return;
GameMain.Server.SetPassword(args[0]);
}));
commands.Add(new Command("createfilelist", "", (string[] args) =>
{
UpdaterUtil.SaveFileList("filelist.xml");

View File

@@ -77,9 +77,9 @@ namespace Barotrauma.Networking
this.isPublic = isPublic;
this.maxPlayers = maxPlayers;
this.password = "";
if (password.Length>0)
if (password.Length > 0)
{
this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password)));
SetPassword(password);
}
config = new NetPeerConfiguration("barotrauma");
@@ -131,6 +131,11 @@ namespace Barotrauma.Networking
CoroutineManager.StartCoroutine(StartServer(isPublic));
}
public void SetPassword(string password)
{
this.password = Encoding.UTF8.GetString(NetUtility.ComputeSHAHash(Encoding.UTF8.GetBytes(password)));
}
private IEnumerable<object> StartServer(bool isPublic)
{
bool error = false;