From 89f2a479bfd17b46360290d1c175aacca076243b Mon Sep 17 00:00:00 2001 From: Kevin Azzam Date: Wed, 16 Sep 2015 13:08:23 +0200 Subject: [PATCH 1/2] 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); } From f4461b292e2ceed530e6985ab2a9f3534a810087 Mon Sep 17 00:00:00 2001 From: Kevin Azzam Date: Thu, 17 Sep 2015 20:03:05 +0200 Subject: [PATCH 2/2] Generalize error message when creating a server fails --- .../Widgets/Logic/ServerCreationLogic.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs index eae2636590..df24a42fb5 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs @@ -119,13 +119,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic { Game.CreateServer(settings); } - catch (System.Net.Sockets.SocketException) + catch (System.Net.Sockets.SocketException e) { - 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"); + var err_msg = "Could not listen on port {0}.".F(Game.Settings.Server.ListenPort); + if (e.ErrorCode == 10048) { // AddressAlreadyInUse (WSAEADDRINUSE) + err_msg += "\n\nCheck if the port is already being used."; + } else { + err_msg += "\n\nError is: \"{0}\" ({1})".F(e.Message, e.ErrorCode); + } + ConfirmationDialogs.CancelPrompt("Server Creation Failed", err_msg, cancelText: "OK"); return; }