Server setting for selecting which symbols are allowed in client names. The default setting includes symbols from the character ranges Basic Latin, Latin-1 Supplement, Latin Extended A & B and Cyrillic. Closes #534

This commit is contained in:
Joonas Rikkonen
2018-08-08 17:07:08 +03:00
parent 2f0236d99b
commit 92f3ac5469
4 changed files with 53 additions and 17 deletions
@@ -281,6 +281,15 @@ namespace Barotrauma.Networking
private set;
}
/// <summary>
/// A list of int pairs that represent the ranges of UTF-16 codes allowed in client names
/// </summary>
public List<Pair<int, int>> AllowedClientNameChars
{
get;
private set;
} = new List<Pair<int, int>>();
private void SaveSettings()
{
XDocument doc = new XDocument(new XElement("serversettings"));
@@ -302,6 +311,8 @@ namespace Barotrauma.Networking
doc.Root.SetAttributeValue("AllowedRandomMissionTypes", string.Join(",", AllowedRandomMissionTypes));
doc.Root.SetAttributeValue("AllowedClientNameChars", string.Join(",", AllowedClientNameChars.Select(c => c.First + "-" + c.Second)));
#if SERVER
doc.Root.SetAttributeValue("password", password);
#endif
@@ -361,6 +372,36 @@ namespace Barotrauma.Networking
TraitorsEnabled = traitorsEnabled;
GameMain.NetLobbyScreen.SetTraitorsEnabled(traitorsEnabled);
//"65-90", "97-122", "48-59" = upper and lower case english alphabet and numbers
string[] allowedClientNameCharsStr = doc.Root.GetAttributeStringArray("AllowedClientNameChars", new string[] { "65-90", "97-122", "48-59" });
foreach (string allowedClientNameCharRange in allowedClientNameCharsStr)
{
string[] splitRange = allowedClientNameCharRange.Split('-');
if (splitRange.Length == 0 || splitRange.Length > 2)
{
DebugConsole.ThrowError("Error in server settings - "+ allowedClientNameCharRange+" is not a valid range for characters allowed in client names.");
continue;
}
int min = -1;
if (!int.TryParse(splitRange[0], out min))
{
DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
continue;
}
int max = min;
if (splitRange.Length == 2)
{
if (!int.TryParse(splitRange[1], out max))
{
DebugConsole.ThrowError("Error in server settings - " + allowedClientNameCharRange + " is not a valid range for characters allowed in client names.");
continue;
}
}
if (min > -1 && max > -1) AllowedClientNameChars.Add(Pair<int, int>.Create(min, max));
}
AllowedRandomMissionTypes = doc.Root.GetAttributeStringArray(
"AllowedRandomMissionTypes",
MissionPrefab.MissionTypes.ToArray()).ToList();