c# - IRC Bot GUI crash? -
ok so, bot connects fine, when create bot, form crashes. bot stays connected !about commands doesnt work. if use same exact code console application works fine. problem ui form
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.io; using system.net.sockets; namespace circbot { public partial class bsetup : form { public bsetup() { initializecomponent(); } private void createbotbtn_click(object sender, eventargs e) { string buf, nick, owner, server, chan; int port; tcpclient sock = new tcpclient(); textreader input; textwriter output; //get nick, owner, server, port, , channel user nick = botnick.text; owner = botname.text; server = servername.text; bool isnumber = int.tryparse(portnum.text, out port); chan = channelname.text; if (isnumber == false) { messagebox.show("failed connect. make sure server address , port number correct.", "connection failed", messageboxbuttons.ok, messageboxicon.error); return; } //connect irc server , input , output text streams tcpclient. sock.connect(server, port); if (!sock.connected) { //console.writeline("failed connect!"); return; } else { this.close(); input = new streamreader(sock.getstream()); output = new streamwriter(sock.getstream()); //starting user , nick login commands output.write( "user " + nick + " 0 * :" + owner + "\r\n" + "nick " + nick + "\r\n" ); output.flush(); //process each line received irc server (buf = input.readline(); ; buf = input.readline()) { //display received irc message //console.writeline(buf); //send pong reply ping messages if (buf.startswith("ping ")) { output.write(buf.replace("ping", "pong") + "\r\n"); output.flush(); } if (buf[0] != ':') continue; /* irc commands come in 1 of these formats: * :nick!user@host command args ... :data\r\n * :server comand args ... :data\r\n */ //after server sends 001 command, can set mode bot , join channel if (buf.split(' ')[1] == "001") { output.write("mode " + nick + " +b\r\n" + "join " + chan + "\r\n"); output.flush(); if (buf.contains("!about")) { output.writeline("privmsg {0} :" + "i'm shitty little bot coded " + botname, channelname); output.flush(); } } } } } } }
this main window, have other form use setup
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace circbot { public partial class mwin : form { public mwin() { initializecomponent(); } private void newbottoolstripmenuitem_click(object sender, eventargs e) { bsetup bsetup = new bsetup(); bsetup.show(); } private void quittoolstripmenuitem1_click(object sender, eventargs e) { application.exit(); } } }
this setup window
i suspect causes problem fact you're doing this.close()
, gets disposed. after calling close()
go for()
, try operate on possibly disposed resources.
Comments
Post a Comment