From fc03e72c77021d32b06c4e7a8bd26ea2a3d1a9cb Mon Sep 17 00:00:00 2001 From: high Date: Thu, 18 Aug 2011 20:04:16 -0400 Subject: [PATCH] Forgot to handle disconnect messages. Fixed GetIPv4Address throwing socket exception --- TShockAPI/TShock.cs | 1 + TShockAPI/Tools.cs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 9e0e258b..d246f98b 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -719,6 +719,7 @@ namespace TShockAPI senddisconnect(Netplay.serverSock[i], e.text); } } + e.Handled = true; } } diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index a79e5ce7..ad9f21de 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -483,10 +483,17 @@ namespace TShockAPI /// string ip public static string GetIPv4Address(string hostname) { - //Get the ipv4 address from GetHostAddresses, if an ip is passed it will return that ip - var ip = Dns.GetHostAddresses(hostname).FirstOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork); - //if the dns query was successful then return it, otherwise return an empty string - return ip != null ? ip.ToString() : ""; + try + { + //Get the ipv4 address from GetHostAddresses, if an ip is passed it will return that ip + var ip = Dns.GetHostAddresses(hostname).FirstOrDefault(i => i.AddressFamily == AddressFamily.InterNetwork); + //if the dns query was successful then return it, otherwise return an empty string + return ip != null ? ip.ToString() : ""; + } + catch (SocketException) + { + } + return ""; } public static string HashAlgo = "md5";