From cd5f8735e7af6379f0fe4e25d2589b99499804d4 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 12 Jun 2019 16:42:33 +0300 Subject: [PATCH] (d2accb97f) Restrict server name length to 60 characters, prevent long server names from overflowing in the "host server" menu & server lobby --- .../BarotraumaClient/Source/Screens/MainMenuScreen.cs | 6 +++++- .../BarotraumaClient/Source/Screens/NetLobbyScreen.cs | 8 ++++++-- .../BarotraumaServer/Source/Networking/GameServer.cs | 4 ++++ .../BarotraumaShared/Source/Networking/NetConfig.cs | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs index d94697541..a55342ca6 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs @@ -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) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs index d050187db..d392f2bfa 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/NetLobbyScreen.cs @@ -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); diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs index 291ca50dc..586e28a2e 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs @@ -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; diff --git a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs index 5c7bfa0f0..6d47913a4 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/NetConfig.cs @@ -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