/// <summary> /// this method destroy thread if created /// </summary> public void Disconnect() { try { //if thread is alive abort thread creat new if (UThread.IsAlive) { MainWindow.Core.SendToIrc("/QUIT", true); // send QUIT command IRC //_output.Close(); //_input.Close(); //Ssock.Close(); Sdelegates.OnUpStatus(((MainWindow)Application.Current.MainWindow).Resources.MergedDictionaries[0]["Shamialetstart"].ToString()); ((MainWindow)Application.Current.MainWindow).Listchat.Items.Clear(); Console.Clear(); Console.WriteLine(@"disconnected by user"); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
private static void OutPCallback(string s) { Application.Current.Dispatcher.Invoke( DispatcherPriority.Normal, (Action) delegate { /* * * message body of message IRC * PART - leave channel * JOIN - enter channel * * ex: string receive server IRC * ":[email protected] JOIN #azubu.channel" * * ex: * step 1 split parts[] * part[0] -teste * */ if (s != null) { Console.WriteLine(s); } // check Part or Join if (s.Contains("PART") || s.Contains("JOIN")) { string[] part = s.Split(new string[] { ":", "!" }, StringSplitOptions.None); // nick user // auto kick check list contains user Sdelegates.OnAutoKick(part[1]); // leave channel if (s.Contains("PART")) { Sdelegates.OnPartJoinCall(Sdelegates.ParJon.Leave, part[1]); } // enter channel else if (s.Contains("JOIN")) { Sdelegates.OnPartJoinCall(Sdelegates.ParJon.Enter, part[1]); } } // if user send message to channel /* * ex: * ":[email protected] PRIVMSG #azubu.rafael_teste :dasda" * */ else if (s.Contains("PRIVMSG") && !s.Contains("CPRIVMSG")) { string[] msg = s.Split(new string[] { ":", @"\" }, StringSplitOptions.None); // msg[2] == content message // msg.count() -1 ex content messa irc remove(\u00038\u0003) /* * [email protected] PRIVMSG #azubu.henrytado.br "Henry o que você acha da história do Aruan?\u00038\u0003 * * */ for (int i = 0; i < msg.Count(); i++) { if (i > 2) { msg[2] += msg[i]; } } string[] user = s.Split(new string[] { ":", "!" }, StringSplitOptions.None); // user[1] == user nick Sdelegates.OnChatCallback(user[1] + ": ", msg[2]); //msg[2] ); } // welcome to channel else if (s.Contains("CPRIVMSG")) { /* * ":servercentral.il.us.quakenet.org 005 teste WHOX WALLCHOPS WALLVOICES USERIP CPRIVMSG CNOTICE SILENCE=15 MODES=6 MAXCHANNELS=20 MAXBANS=45 NICKLEN=15 :are supported by this server" */ string[] chan = s.Split(new string[] { " " }, StringSplitOptions.None); //Console.WriteLine(chan[1]); Application.Current.MainWindow.Resources.MergedDictionaries[0]["Welcomechat"].ToString() Sdelegates.OnUpStatus(Application.Current.MainWindow.Resources.MergedDictionaries[0]["Welcomechat"] + @" " + MainWindow.Core.Conf.Chan); // disable progress ring Application.Current.Dispatcher.Invoke( DispatcherPriority.Normal, (Action) delegate { ((MainWindow)Application.Current.MainWindow)._progressring(false); // auth for privilege(s) to channel MainWindow.Core.SendToIrc(@"/AUTH " + MainWindow.Core.Conf.Nick + " " + MainWindow.Core.Conf.Pwssl, true); }); } }); }
internal void ThreadIrc() { try { Ssock = new TcpClient(); Ssock.Connect(Conf.Server, Conf.Port); if (!Ssock.Connected) { Console.WriteLine(@"Failed to connect socket [ internal void ThreadIrc() ]"); return; } // continue : Console.Clear(); Console.WriteLine(@"continue:"); _input = new StreamReader(Ssock.GetStream()); _output = new StreamWriter(Ssock.GetStream()); // step 1 _output.Write( "USER " + Conf.Nick + " 0 * :" + Conf.Owner + "\r\n" + "NICK " + Conf.Owner + "\r\n"); _output.Flush(); // step 2 if (Conf.AuthSsl == 1) { Console.WriteLine(@"AuthSsl: true"); // auth ssl add privileged for user moderate channel LoginSsl(Conf.Nick, Conf.Pwssl); Application.Current.Dispatcher.Invoke( DispatcherPriority.Normal, (Action) delegate { Sdelegates.OnUpStatus( ((MainWindow)Application.Current.MainWindow).Resources.MergedDictionaries[0]["AuthSslEnable"].ToString()); // open page login quakenet auth //System.Diagnostics.Process.Start("https://auth.quakenet.org/webchat_ssl"); }); } else { Application.Current.Dispatcher.Invoke( DispatcherPriority.Normal, (Action) delegate { Sdelegates.OnUpStatus( ((MainWindow)Application.Current.MainWindow).Resources.MergedDictionaries[0]["AuthSslDisable"].ToString()); }); Console.WriteLine(@"AuthSsl: false"); } Console.WriteLine(); //if(Buff != null) // process each line received from irc server for (Buff = _input.ReadLine();; Buff = _input.ReadLine()) { PCallback += OutPCallback; if (Buff == null) { return; } OutPCallback(Buff); //send pong reply to any ping messages if (Buff != null && Buff.StartsWith("PING")) { _output.Write(Buff.Replace("PING", "PONG") + "\r\n"); _output.Flush(); } if (Buff != null && Buff[0] != ':') { continue; } if (Buff != null && Buff.Split(' ')[1] == "001") { var b = Buff; //_output.Write("MODE " + Conf.Nick + "+i +o +m +x +B +n \r\n" + _output.Write("MODE " + Conf.Nick + "+o \r\n" + "JOIN " + Conf.Chan + "\r\n"); _output.Flush(); } } } catch (Exception ex) { Console.Clear(); if (ex.HResult != -2146233040) { Console.WriteLine(ex.StackTrace); } } }