(d2accb97f) Restrict server name length to 60 characters, prevent long server names from overflowing in the "host server" menu & server lobby

This commit is contained in:
Joonas Rikkonen
2019-06-12 16:42:33 +03:00
parent e38c896d42
commit cd5f8735e7
4 changed files with 17 additions and 3 deletions

View File

@@ -948,7 +948,11 @@ namespace Barotrauma
new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("HostServerButton"), textAlignment: Alignment.Center, font: GUI.LargeFont) { ForceUpperCase = true };
var label = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("ServerName"), textAlignment: textAlignment);
serverNameBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment);
serverNameBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment)
{
MaxTextLength = NetConfig.ServerNameMaxLength,
OverflowClip = true
};
label = new GUITextBlock(new RectTransform(textLabelSize, parent.RectTransform), TextManager.Get("ServerPort"), textAlignment: textAlignment);
portBox = new GUITextBox(new RectTransform(textFieldSize, label.RectTransform, Anchor.CenterRight), textAlignment: textAlignment)

View File

@@ -335,8 +335,12 @@ namespace Barotrauma
new GUIFrame(new RectTransform(new Vector2(1.0f, 0.03f), rightInfoColumn.RectTransform), style: null);
//server info ------------------------------------------------------------------
ServerName = new GUITextBox(new RectTransform(new Vector2(0.3f, 0.05f), infoFrameContent.RectTransform));
ServerName = new GUITextBox(new RectTransform(new Vector2(infoColumnContainer.RectTransform.RelativeSize.X, 0.05f), infoFrameContent.RectTransform))
{
MaxTextLength = NetConfig.ServerNameMaxLength,
OverflowClip = true
};
ServerName.OnDeselected += (textBox, key) =>
{
GameMain.Client.ServerSettings.ClientAdminWrite(ServerSettings.NetFlags.Name);

View File

@@ -93,6 +93,10 @@ namespace Barotrauma.Networking
{
name = name.Replace(":", "");
name = name.Replace(";", "");
if (name.Length > NetConfig.ServerNameMaxLength)
{
name = name.Substring(0, NetConfig.ServerNameMaxLength);
}
this.name = name;

View File

@@ -10,6 +10,8 @@ namespace Barotrauma.Networking
public const int MaxPlayers = 16;
public const int ServerNameMaxLength = 60;
public static string MasterServerUrl = GameMain.Config.MasterServerUrl;
//if a Character is further than this from the sub and the players, the server will disable it