static void Main(string[] args) { IRCConfig conf = new IRCConfig(); conf.name = "ShadowBot"; conf.nick = "ShadowBot"; conf.port = 6667; conf.server = "irc.darkmyst.org"; new IRCBot(conf); Console.WriteLine("Bot quit/crashed"); Console.ReadLine(); }
public IRCBot(IRCConfig config) { bool stayConnected = true; while (stayConnected) { this.config = config; try { IRCConnection = new TcpClient(config.server, config.port); } catch { Console.WriteLine("Connection Error"); } try { ns = IRCConnection.GetStream(); ns.ReadTimeout = 10; sr = new StreamReader(ns); sw = new StreamWriter(ns); sendData("USER", config.nick + " Japa " + " Japa" + " :" + config.name); sendData("NICK", config.nick); stayConnected = !IRCWork(); } catch { Console.WriteLine("Communication error"); } finally { if (sr != null) { sr.Close(); } if (sw != null) { sw.Close(); } if (ns != null) { ns.Close(); } if (IRCConnection != null) { IRCConnection.Close(); } } } }
public IRCBot(IRCConfig config) { bool stayConnected = true; while (stayConnected) { this.config = config; try { IRCConnection = new TcpClient(config.server, config.port); } catch { Console.WriteLine("Connection Error"); } try { ns = IRCConnection.GetStream(); ns.ReadTimeout = 10; sr = new StreamReader(ns); sw = new StreamWriter(ns); sendData("USER", config.nick + " Japa " + " Japa" + " :" + config.name); sendData("NICK", config.nick); stayConnected = !IRCWork(); } catch { Console.WriteLine("Communication error"); } finally { if (sr != null) sr.Close(); if (sw != null) sw.Close(); if (ns != null) ns.Close(); if (IRCConnection != null) IRCConnection.Close(); } } }