/// <summary> /// Retrieve information about a Minecraft server /// </summary> /// <param name="serverIP">Server IP to ping</param> /// <param name="serverPort">Server Port to ping</param> /// <param name="protocolversion">Will contain protocol version, if ping successful</param> /// <returns>TRUE if ping was successful</returns> public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo forgeInfo) { bool success = false; int protocolversionTmp = 0; ForgeInfo forgeInfoTmp = null; if (AutoTimeout.Perform(() => { try { if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversionTmp) || Protocol18Handler.doPing(serverIP, serverPort, ref protocolversionTmp, ref forgeInfoTmp)) { success = true; } else { Translations.WriteLineFormatted("error.unexpect_response"); } } catch (Exception e) { ConsoleIO.WriteLineFormatted(String.Format("§8{0}: {1}", e.GetType().FullName, e.Message)); } }, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30))) { if (protocolversion != 0 && protocolversion != protocolversionTmp) { Translations.WriteLineFormatted("error.version_different"); } if (protocolversion == 0 && protocolversionTmp <= 1) { Translations.WriteLineFormatted("error.no_version_report"); } if (protocolversion == 0) { protocolversion = protocolversionTmp; } forgeInfo = forgeInfoTmp; return(success); } else { Translations.WriteLineFormatted("error.connection_timeout"); return(false); } }
/// <summary> /// Retrieve information about a Minecraft server /// </summary> /// <param name="serverIP">Server IP to ping</param> /// <param name="serverPort">Server Port to ping</param> /// <param name="protocolversion">Will contain protocol version, if ping successful</param> /// <returns>TRUE if ping was successful</returns> public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo forgeInfo) { bool success = false; int protocolversionTmp = 0; ForgeInfo forgeInfoTmp = null; if (AutoTimeout.Perform(() => { try { if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversionTmp) || Protocol18Handler.doPing(serverIP, serverPort, ref protocolversionTmp, ref forgeInfoTmp)) { success = true; } else { ConsoleIO.WriteLineFormatted("§8Unexpected response from the server (is that a Minecraft server?)"); } } catch (Exception e) { ConsoleIO.WriteLineFormatted(String.Format("§8{0}: {1}", e.GetType().FullName, e.Message)); } }, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30))) { if (protocolversion != 0 && protocolversion != protocolversionTmp) { ConsoleIO.WriteLineFormatted("§8Server reports a different version than manually set. Login may not work."); } if (protocolversion == 0 && protocolversionTmp <= 1) { ConsoleIO.WriteLineFormatted("§8Server does not report its protocol version, autodetection will not work."); } if (protocolversion == 0) { protocolversion = protocolversionTmp; } forgeInfo = forgeInfoTmp; return(success); } else { ConsoleIO.WriteLineFormatted("§8A timeout occured while attempting to connect to this IP."); return(false); } }
/// <summary> /// Retrieve information about a Minecraft server /// </summary> /// <param name="serverIP">Server IP to ping</param> /// <param name="serverPort">Server Port to ping</param> /// <param name="protocolversion">Will contain protocol version, if ping successful</param> /// <returns>TRUE if ping was successful</returns> public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo forgeInfo) { bool success = false; int protocolversionTmp = 0; ForgeInfo forgeInfoTmp = null; if (AutoTimeout.Perform(() => { try { if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversionTmp) || Protocol18Handler.doPing(serverIP, serverPort, ref protocolversionTmp, ref forgeInfoTmp)) { success = true; } else { ConsoleIO.WriteLineFormatted("§c[警告]§8无法连接至非Minecraft服务器之外的服务器!"); } } catch (Exception e) { ConsoleIO.WriteLineFormatted(String.Format("§e[信息]§8{0}: {1}", e.GetType().FullName, e.Message)); } }, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30))) { if (protocolversion != 0 && protocolversion != protocolversionTmp) { ConsoleIO.WriteLineFormatted("§e[信息]§8服务器发送了不同的版本,可能无法登入,请手动输入版本."); } if (protocolversion == 0 && protocolversionTmp <= 1) { ConsoleIO.WriteLineFormatted("§e[信息]§8服务器未通知协议版本,可能会无法登入,请手动输入版本."); } if (protocolversion == 0) { protocolversion = protocolversionTmp; } forgeInfo = forgeInfoTmp; return(success); } else { ConsoleIO.WriteLineFormatted("§c[错误]§8连接超时."); return(false); } }
/// <summary> /// Retrieve information about a Minecraft server /// </summary> /// <param name="serverIP">Server IP to ping</param> /// <param name="serverPort">Server Port to ping</param> /// <param name="protocolversion">Will contain protocol version, if ping successful</param> /// <returns>TRUE if ping was successful</returns> public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo forgeInfo) { bool success = false; int protocolversionTmp = 0; ForgeInfo forgeInfoTmp = null; if (AutoTimeout.Perform(() => { try { if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversionTmp) || Protocol18Handler.doPing(serverIP, serverPort, ref protocolversionTmp, ref forgeInfoTmp)) { success = true; } else { ConsoleIO.WriteLineFormatted("§8Unexpected response from the server (is that a Minecraft server?)"); } } catch (Exception e) { //ConsoleIO.WriteLineFormatted("ProtocolHandler:82"); //ConsoleIO.WriteLineFormatted(String.Format("§8{0}: {1}", e.GetType().FullName, e.Message)); } }, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30))) { protocolversion = protocolversionTmp; forgeInfo = forgeInfoTmp; return(success); } else { //ConsoleIO.WriteLineFormatted("§8A timeout occured while attempting to connect to this IP."); return(false); } }
/// <summary> /// Retrieve information about a Minecraft server /// </summary> /// <param name="serverIP">Server IP to ping</param> /// <param name="serverPort">Server Port to ping</param> /// <param name="protocolversion">Will contain protocol version, if ping successful</param> /// <returns>TRUE if ping was successful</returns> public static bool GetServerInfo(string serverIP, short serverPort, ref int protocolversion) { try { if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversion)) { return(true); } else if (Protocol17Handler.doPing(serverIP, serverPort, ref protocolversion)) { return(true); } else { ConsoleIO.WriteLineFormatted("§8Unexpected answer from the server (is that a Minecraft server ?)"); return(false); } } catch { ConsoleIO.WriteLineFormatted("§8An error occured while attempting to connect to this IP."); return(false); } }