From 89f2a479bfd17b46360290d1c175aacca076243b Mon Sep 17 00:00:00 2001 From: Kevin Azzam Date: Wed, 16 Sep 2015 13:08:23 +0200 Subject: [PATCH] Catch exception when hosting server on busy port Closes #9354 --- .../Widgets/Logic/ServerCreationLogic.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs index d95406dc7b..eae2636590 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs @@ -115,7 +115,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic var settings = new ServerSettings(Game.Settings.Server); // Create and join the server - Game.CreateServer(settings); + try + { + Game.CreateServer(settings); + } + catch (System.Net.Sockets.SocketException) + { + ConfirmationDialogs.CancelPrompt( + "Server Creation Failed", + "Could not listen on port {0}.\n\nCheck if the port is already being used.".F(Game.Settings.Server.ListenPort), + cancelText: "OK"); + + return; + } + Ui.CloseWindow(); ConnectionLogic.Connect(IPAddress.Loopback.ToString(), Game.Settings.Server.ListenPort, password, onCreate, onExit); }