/// <summary> /// Parse irc:// this function will connect you using currently active protocol or to services /// </summary> /// <param name="text">Link to be parsed</param> /// <param name="services"></param> public static void ParseLink(string text, ProtocolSv services = null) { DebugLog("Parsing " + text); if (text.StartsWith("irc://", StringComparison.Ordinal)) { text = text.Substring("irc://".Length); string network = text; string channel = null; bool ssl = false; int PORT = 6667; if (network.StartsWith("$", StringComparison.Ordinal)) { network = network.Substring(1); ssl = true; } if (network.Contains("/")) { channel = network.Substring(network.IndexOf("/", StringComparison.Ordinal) + 1); if (!channel.StartsWith("#", StringComparison.Ordinal)) { channel = "#" + channel; } network = network.Substring(0, network.IndexOf("/", StringComparison.Ordinal)); } if (network.Contains("#")) { channel = network.Substring(network.IndexOf("#", StringComparison.Ordinal)); network = network.Substring(0, network.IndexOf("#", StringComparison.Ordinal)); } if (network.Contains(":")) { string port = network.Substring(network.IndexOf(":", StringComparison.Ordinal) + 1); network = network.Substring(0, network.IndexOf(port, StringComparison.Ordinal)); if (port.Contains("/")) { port = port.Substring(0, port.IndexOf("/", StringComparison.Ordinal)); } if (port.Contains("#")) { port = port.Substring(0, port.IndexOf("#", StringComparison.Ordinal)); } if (!int.TryParse(port, out PORT)) { PORT = 6667; } } while (network.Contains("/")) { network = network.Substring(0, network.Length - 1); } if (services != null) { lock (services.NetworkList) { foreach (Network sv in services.NetworkList) { if (sv.ServerName == network) { sv.Join(channel); return; } } } services.ConnectTo(network, PORT); lock (services.NetworkList) { foreach (Network sv in services.NetworkList) { if (sv.ServerName == network) { sv.Join(channel); return; } } } return; } ProtocolIrc server = null; foreach (Protocol protocol in Connections) { if (typeof(ProtocolIrc) == protocol.GetType() && protocol.Server == network) { server = (ProtocolIrc)protocol; break; } } if (server == null) { server = ConnectIRC(network, PORT, "", ssl); } if (channel != null) { server._IRCNetwork.Join(channel); } } }