public void Connect() { this.connection = new Connection(); this.connection.Type = "IRC"; string server = ServerSettings.GetSetting("IRC-Server"); int port = ServerSettings.GetSettingInt("IRC-Port"); string nickname = ServerSettings.GetSetting("IRC-Nickname"); string channel = ServerSettings.GetSetting("IRC-Channel"); string opChannel = ServerSettings.GetSetting("IRC-OPChannel"); string password = ServerSettings.GetSetting("IRC-NickServ"); if (nickname == "" || server == "" || channel == "" || port == -1 || !ServerSettings.GetSettingBoolean("IRC-Enabled")) return; this.connection.Setup(server, port, nickname, channel, password, opChannel); this.connection.Run(); }
/// <summary> /// Converts the IRC line to something useable. /// </summary> /// <param name="cmd"></param> /// <param name="connection"></param> /// <returns></returns> public static List<object> Parse(string cmd, Connection connection) { char[] data = cmd.ToCharArray(); List<string> parsed = new List<string> { }; List<string> userinfo = new List<string> { }; string buffer = ""; bool inString = false; bool userStr = false; for (int i = 0; i < data.Length; i++) { if (i == 0 && data[i] == ':') { userStr = true; continue; } if ((data[i] == '!' || data[i] == '@' || data[i] == ' ') && userStr) { userinfo.Add(buffer); buffer = ""; if (data[i] == ' ') userStr = false; continue; } if (data[i] == ':' && !inString) { inString = true; continue; } if (data[i] == ' ' && !inString) { parsed.Add(buffer); buffer = ""; continue; } buffer += data[i]; } if (buffer != null) parsed.Add(buffer); List<object> ret = new List<object> { }; parsed.RemoveAll(item => String.IsNullOrEmpty(item)); ret.Add(parsed); if (userinfo.Count == 3) ret.Add(new User(userinfo[0], userinfo[1], userinfo[2], connection)); else ret.Add(new User()); return ret; }