diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index b38718fdc418..2d0f117e81f8 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -130,6 +130,9 @@ public Server(IPEndPoint endpoint, ServerSettings settings, ModData modData) Port = localEndpoint.Port; Settings = settings; + + Settings.Name = OpenRA.Settings.SanitizedServerName(Settings.Name); + ModData = modData; randomSeed = (int)DateTime.Now.ToBinary(); diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 0b3d87274992..54c53041c123 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -321,6 +321,14 @@ static string SanitizedName(string dirty) return clean; } + public static string SanitizedServerName(string dirty) + { + if (string.IsNullOrWhiteSpace(dirty)) + return new ServerSettings().Name; + else + return SanitizedName(dirty); + } + public static string SanitizedPlayerName(string dirty) { var forbiddenNames = new string[] { "Open", "Closed" }; diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs index 0a13a5aba845..bcc0d5128381 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs @@ -54,8 +54,17 @@ public ServerCreationLogic(Widget widget, Action onExit, Action openLobby) panel.Get("MAP_NAME").GetText = () => preview.Title; } - panel.Get("SERVER_NAME").Text = settings.Server.Name ?? ""; + var serverName = panel.Get("SERVER_NAME"); + serverName.Text = Settings.SanitizedServerName(settings.Server.Name); + serverName.OnEnterKey = () => { serverName.YieldKeyboardFocus(); return true; }; + serverName.OnLoseFocus = () => + { + serverName.Text = Settings.SanitizedServerName(serverName.Text); + settings.Server.Name = serverName.Text; + }; + panel.Get("LISTEN_PORT").Text = settings.Server.ListenPort.ToString(); + advertiseOnline = Game.Settings.Server.AdvertiseOnline; var externalPort = panel.Get("EXTERNAL_PORT"); @@ -79,7 +88,7 @@ public ServerCreationLogic(Widget widget, Action onExit, Action openLobby) void CreateAndJoin() { - var name = panel.Get("SERVER_NAME").Text; + var name = Settings.SanitizedServerName(panel.Get("SERVER_NAME").Text); int listenPort, externalPort; if (!Exts.TryParseIntegerInvariant(panel.Get("LISTEN_PORT").Text, out listenPort)) listenPort = 1234;