Forgot to handle disconnect messages.

Fixed GetIPv4Address throwing socket exception
This commit is contained in:
high 2011-08-18 20:04:16 -04:00
parent dcadec30de
commit fc03e72c77
2 changed files with 12 additions and 4 deletions

View file

@ -719,6 +719,7 @@ namespace TShockAPI
senddisconnect(Netplay.serverSock[i], e.text); senddisconnect(Netplay.serverSock[i], e.text);
} }
} }
e.Handled = true;
} }
} }

View file

@ -482,12 +482,19 @@ namespace TShockAPI
/// </summary> /// </summary>
/// <param name="hostname">string ip</param> /// <param name="hostname">string ip</param>
public static string GetIPv4Address(string hostname) public static string GetIPv4Address(string hostname)
{
try
{ {
//Get the ipv4 address from GetHostAddresses, if an ip is passed it will return that ip //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); 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 //if the dns query was successful then return it, otherwise return an empty string
return ip != null ? ip.ToString() : ""; return ip != null ? ip.ToString() : "";
} }
catch (SocketException)
{
}
return "";
}
public static string HashAlgo = "md5"; public static string HashAlgo = "md5";