/// <summary> /// Listen on an infinite loop /// </summary> public void Listen( ) { this.worker = new Thread(new ThreadStart(delegate { this.writer.SendMessage(IrcCommands.Nick(nick)); this.writer.SendMessage(IrcCommands.User(username, 8, realname)); OnPrivateMessage += Irc_OnPrivateMessage; OnPrivateNotice += Irc_OnPrivateNotice; OnPrivateAction += Irc_OnPrivateAction; OnChannelJoin += Irc_OnChannelJoin; OnChannelKick += Irc_OnChannelKick; OnChannelMode += Irc_OnChannelMode; OnChannelMode += Irc_OnChannelMode; OnChannelPart += Irc_OnChannelPart; OnChannelUserList += Irc_OnChannelUserList; OnNickChange += Irc_OnNickChange; OnPublicAction += Irc_OnPublicAction; OnPublicMessage += Irc_OnPublicMessage; OnPublicNotice += Irc_OnPublicNotice; OnSendToChannel += Irc_OnSendToChannel; OnServerQuit += Irc_OnServerQuit; OnTopicChange += Irc_OnTopicChange; while (this.client.Connected) { try { string s = string.Empty; while ((s = this.reader.ReadLine( )) != null) { this.message = s; string prefix, command; string[] parameters; this.messagearray = this.message.Split(' '); if (this.messagearray[0].StartsWith(":")) { this.messagearray[0] = this.messagearray[0].Remove(0, 1); } IrcCommands.ParseReply(this.message, out prefix, out command, out parameters); IrcMessage message = new IrcMessage(prefix, command, parameters); if (string.IsNullOrEmpty(this.server)) { this.server = this.messagearray[0]; } dbwl("Server Reply: {0}", s); /* * at System.String.Join(String separator, String[] value, Int32 startIndex, Int32 count) * at BlizzetaZero.Kernel.Extensions.NonZero(String[] arr) in g:\BreakerDev Suite 2012\Blizzeta Zero rev2\Blizzeta Zero rev2\Kernel\Extensions.cs:line 34 * at BlizzetaZero.Kernel.Irc.<Listen>b__3() in g:\BreakerDev Suite 2012\Blizzeta Zero rev2\Blizzeta Zero rev2\Kernel\Irc.cs:line 277 */ string paramsmsg = string.Join(" ", parameters.NonZero( )); string[] parr = paramsmsg.Split(' '); User u = null; Channel c = null; try { u = ((!string.IsNullOrEmpty(prefix)) ? new User(prefix) : null); c = ((parameters[0].StartsWith("#")) ? GetChannel(parameters[0]) : null); if (u != null) { dbwl("User Reply: {0}", u.Nick); } if (c != null) { dbwl("Channel Reply: {0}", c.Name); } } catch (Exception) { } if (prefix == this.server) { if (Enum.TryParse <ReplyCode> (command, out code)) { dbwl("Prefix is {0}, Command is {1}, Code is {2}", prefix, command, code); switch (code) { case ReplyCode.RPL_TOPIC: Console.WriteLine( "Topic for {0}: {1}", parr[0], paramsmsg.Substring(parr[0].Length + 2)); break; case ( ReplyCode )333: IrcReply.FormatMessage( string.Format("Topic in {0} set by {1} on {2:ddd MMM dd, yyyy HH:mm:ss}", parr[0], parr[1], Global.UnixTimeStampToDateTime(double.Parse(parr[2]))), ConsoleColor.Gray); break; // Topic Who time? case ReplyCode.RPL_NAMESREPLY: IrcReply.FormatMessage(message, ConsoleColor.DarkMagenta); break; case ReplyCode.RPL_ENDOFNAMES: IrcReply.FormatMessage(message, ConsoleColor.DarkCyan); break; case ReplyCode.RPL_MOTD: if (OnMotd != null) { string ms = string.Join(" ", messagearray, 4, messagearray.Length - 4); if (ms.Length > 1) { motd += string.Format("{0}\r\n", ms); } OnMotd(ms); } break; case ReplyCode.RPL_MOTDSTART: motd = string.Empty; break; case ReplyCode.RPL_ENDOFMOTD: hasMOTD = true; Raw(IrcCommands.Mode(nick, "+B")); Raw(IrcCommands.Umode("+B")); Raw(IrcCommands.Umode2("+B")); if (!string.IsNullOrEmpty(startchan)) { c = new Channel(this, startchan, startkey); c.Join( ); Channels.Add(c); } break; case ReplyCode.RPL_WHOISUSER: Format(this.message, ConsoleColor.Magenta); break; case ReplyCode.RPL_ENDOFWHOIS: Format(this.message, ConsoleColor.DarkMagenta); break; } } else { Console.WriteLine(this.message); } } else if (command == "PING") { dbg.WriteLine(message.ToString( )); string send = (IrcCommands.Pong(message.Parameters[0])); dbg.WriteLine(send); writer.SendMessage(send); } else { dbwl("Command is {0}, Parameters are {1}", command, paramsmsg); switch (command) { // :Prefix Command :Params // :[email protected] JOIN :#Channel case "JOIN": if (OnChannelJoin != null) { OnChannelJoin(u, c, "", paramsmsg); } break; case "PART": if (OnChannelPart != null) { OnChannelPart(u, c, "", paramsmsg); } break; case "MODE": if (OnChannelMode != null) { OnChannelMode(u, c, "", paramsmsg); } break; case "KICK": if (OnChannelKick != null) { OnChannelKick(u, c, "", paramsmsg); } break; case "NICK": if (OnNickChange != null) { OnNickChange(u, paramsmsg); } break; case "QUIT": if (OnServerQuit != null) { OnServerQuit(u, c, "", paramsmsg); } break; case "PRIVMSG": if (parameters[0].StartsWith("#")) { //Lucifer.GeekShed.net PRIVMSG #chris :ACTION peeks in if (parameters[1].StartsWith( string.Format("{0}ACTION", Constants.CtcpChar)) && parameters.Last( ).EndsWith(Constants.CtcpChar.ToString( ))) { if (OnPublicAction != null) { OnPublicAction(u, c.Name, paramsmsg); } } else if (OnPublicMessage != null) { OnPublicMessage(u, c.Name, paramsmsg); } } else if (OnPrivateMessage != null) { OnPrivateMessage(u, parameters[0], paramsmsg); } break; case "NOTICE": if (parameters[0].StartsWith("#")) { if (OnPublicNotice != null) { OnPublicNotice(u, c.Name, paramsmsg); } } else if (OnPrivateNotice != null) { if (parameters.Length > 0) { OnPrivateNotice(u != null ? u : new User("null!null@null"), parameters[0], paramsmsg); } else { OnPrivateNotice(u != null ? u : new User("null!null@null"), this.nick, "Notice returned 0"); } } break; } } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0}", ex); Console.ResetColor( ); } } })) { Name = string.Format("{0}_thread", this.server), IsBackground = false }; this.worker.Start( ); }
/// <summary> /// Listen on an infinite loop /// </summary> public void Listen( ) { this.worker = new Thread ( new ThreadStart ( delegate { this.writer.SendMessage ( IrcCommands.Pass ( _srvPass ) ); this.writer.SendMessage ( IrcCommands.Nick ( nick ) ); this.writer.SendMessage ( IrcCommands.User ( username, 8, realname ) ); OnPrivateMessage += Irc_OnPrivateMessage; OnPrivateNotice += Irc_OnPrivateNotice; OnPrivateAction += Irc_OnPrivateAction; OnChannelJoin += Irc_OnChannelJoin; OnChannelKick += Irc_OnChannelKick; OnChannelMode += Irc_OnChannelMode; OnChannelMode += Irc_OnChannelMode; OnChannelPart += Irc_OnChannelPart; OnChannelUserList += Irc_OnChannelUserList; OnNickChange += Irc_OnNickChange; OnPublicAction += Irc_OnPublicAction; OnPublicMessage += Irc_OnPublicMessage; OnPublicNotice += Irc_OnPublicNotice; OnSendToChannel += Irc_OnSendToChannel; OnServerQuit += Irc_OnServerQuit; OnTopicChange += Irc_OnTopicChange; while ( this.client.Connected ) { try { string s = string.Empty; while ( ( s = this.reader.ReadLine ( ) ) != null ) { this.message = s; string prefix, command; string[] parameters; this.messagearray = this.message.Split ( ' ' ); if ( this.messagearray[ 0 ].StartsWith ( ":" ) ) this.messagearray[ 0 ] = this.messagearray[ 0 ].Remove ( 0, 1 ); IrcCommands.ParseReply ( this.message, out prefix, out command, out parameters ); IrcMessage message = new IrcMessage ( prefix, command, parameters ); if ( string.IsNullOrEmpty ( this.server ) ) this.server = this.messagearray[ 0 ]; dbwl ( "Server Reply: {0}", s ); string paramsmsg = string.Join ( " ", parameters.NonZero ( ) ); string[] parr = paramsmsg.Split ( ' ' ); User u = new User(); Channel c = null; try { c = ( ( parameters[ 0 ].StartsWith ( "#" ) ) ? GetChannel ( parameters[ 0 ] ) : null ); if ( ( !string.IsNullOrEmpty ( u.name ) ) ) dbwl ( "User Reply: {0}", u.name ); if ( c != null ) dbwl ( "Channel Reply: {0}", c.Name ); } catch ( Exception ) { } if ( prefix == this.server ) { if ( Enum.TryParse<ReplyCode> ( command, out code ) ) { dbwl ( "Prefix is {0}, Command is {1}, Code is {2}", prefix, command, code ); switch ( code ) { case ReplyCode.RPL_TOPIC: Console.WriteLine ( "Topic for {0}: {1}", parr[ 0 ], paramsmsg.Substring ( parr[ 0 ].Length + 2 ) ); break; case ( ReplyCode ) 333: IrcReply.FormatMessage ( string.Format ( "Topic in {0} set by {1} on {2:ddd MMM dd, yyyy HH:mm:ss}", parr[ 0 ], parr[ 1 ], Global.UnixTimeStampToDateTime ( double.Parse ( parr[ 2 ] ) ) ), ConsoleColor.Gray ); break; // Topic Who time? case ReplyCode.RPL_NAMESREPLY: IrcReply.FormatMessage ( message, ConsoleColor.DarkMagenta ); break; case ReplyCode.RPL_ENDOFNAMES: IrcReply.FormatMessage ( message, ConsoleColor.DarkCyan ); break; case ReplyCode.RPL_MOTD: if ( OnMotd != null ) { string ms = string.Join ( " ", messagearray, 4, messagearray.Length - 4 ); if ( ms.Length > 1 ) motd += string.Format ( "{0}\r\n", ms ); OnMotd ( ms ); } break; case ReplyCode.RPL_MOTDSTART: motd = string.Empty; break; case ReplyCode.RPL_ENDOFMOTD: hasMOTD = true; // NOT USED BY TWITCH [5/18/2014 Blizzardo1] // Raw ( IrcCommands.Mode ( nick, "+B" ) ); // Raw ( IrcCommands.Umode ( "+B" ) ); // Raw ( IrcCommands.Umode2 ( "+B" ) ); // SendMessage ( "NickServ", string.Format("IDENTIFY {0}") ); // Add nickserv if ( !string.IsNullOrEmpty ( startchan ) ) { c = new Channel ( this, startchan, startkey ); c.Join ( ); Channels.Add ( c ); } break; case ReplyCode.RPL_WHOISUSER: Format ( this.message, ConsoleColor.Magenta ); break; case ReplyCode.RPL_ENDOFWHOIS: Format ( this.message, ConsoleColor.DarkMagenta ); break; } } else { Console.WriteLine ( this.message ); } } else if ( command == "PING" ) { dbg.WriteLine ( message.ToString ( ) ); string send = ( IrcCommands.Pong ( message.Parameters[ 0 ] ) ); dbg.WriteLine ( send ); writer.SendMessage ( send ); } else { dbwl ( "Command is {0}, Parameters are {1}", command, paramsmsg ); switch ( command ) { case "PASS": if ( string.IsNullOrEmpty ( _srvPass ) ) { Format ( "No Server Password! Disconnecting prematurely", ConsoleColor.Red ); Disconnect ( string.Format ( "Failed to login to {0} with no Password!", server ) ); } else { Raw ( "PASS", _srvPass ); } break; // :Prefix Command :Params // :[email protected] JOIN :#Channel case "JOIN": if ( OnChannelJoin != null ) OnChannelJoin ( u, c, "", paramsmsg ); break; case "PART": if ( OnChannelPart != null ) OnChannelPart ( u, c, "", paramsmsg ); break; case "MODE": if ( OnChannelMode != null ) OnChannelMode ( u, c, "", paramsmsg ); break; case "KICK": if ( OnChannelKick != null ) OnChannelKick ( u, c, "", paramsmsg ); break; case "NICK": if ( OnNickChange != null ) OnNickChange ( u, paramsmsg ); break; case "QUIT": if ( OnServerQuit != null ) OnServerQuit ( u, c, "", paramsmsg ); break; case "PRIVMSG": if ( parameters[ 0 ].StartsWith ( "#" ) ) { //Lucifer.GeekShed.net PRIVMSG #chris :ACTION peeks in if ( parameters[ 1 ].StartsWith ( string.Format ( "{0}ACTION", Constants.CtcpChar ) ) && parameters.Last ( ).EndsWith ( Constants.CtcpChar.ToString ( ) ) ) { if ( OnPublicAction != null ) OnPublicAction ( u, c, c.Name, paramsmsg ); } else if ( OnPublicMessage != null ) OnPublicMessage ( u, c, c.Name, paramsmsg ); } else if ( OnPrivateMessage != null ) OnPrivateMessage ( u, c, parameters[ 0 ], paramsmsg ); break; case "NOTICE": /* Define later if ( parameters[ 0 ].StartsWith ( "#" ) ) { if ( OnPublicNotice != null ) OnPublicNotice ( u, c, c.Name, paramsmsg ); } else if ( OnPrivateNotice != null ) { if ( parameters.Length > 0 ) OnPrivateNotice ( u != null ? u : new User ( "null!null@null" ), c, parameters[ 0 ], paramsmsg ); else OnPrivateNotice ( u != null ? u : new User ( "null!null@null" ), c, this.nick, "Notice returned 0" ); }*/ break; } } } } catch ( Exception ex ) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine ( "{0}", ex ); Console.ResetColor ( ); } } } ) ) { Name = string.Format ( "{0}_thread", this.server ), IsBackground = false }; this.worker.Start ( ); }
/// <summary> /// Listen on an infinite loop /// </summary> public void Listen( ) { this.worker = new Thread(new ThreadStart(delegate { this.writer.SendMessage(IrcCommands.Pass(_srvPass)); this.writer.SendMessage(IrcCommands.Nick(nick)); this.writer.SendMessage(IrcCommands.User(username, 8, realname)); OnPrivateMessage += Irc_OnPrivateMessage; OnPrivateNotice += Irc_OnPrivateNotice; OnPrivateAction += Irc_OnPrivateAction; OnChannelJoin += Irc_OnChannelJoin; OnChannelKick += Irc_OnChannelKick; OnChannelMode += Irc_OnChannelMode; OnChannelMode += Irc_OnChannelMode; OnChannelPart += Irc_OnChannelPart; OnChannelUserList += Irc_OnChannelUserList; OnNickChange += Irc_OnNickChange; OnPublicAction += Irc_OnPublicAction; OnPublicMessage += Irc_OnPublicMessage; OnPublicNotice += Irc_OnPublicNotice; OnSendToChannel += Irc_OnSendToChannel; OnServerQuit += Irc_OnServerQuit; OnTopicChange += Irc_OnTopicChange; while (this.client.Connected) { try { string s = string.Empty; while ((s = this.reader.ReadLine( )) != null) { this.message = s; string prefix, command; string[] parameters; this.messagearray = this.message.Split(' '); if (this.messagearray[0].StartsWith(":")) { this.messagearray[0] = this.messagearray[0].Remove(0, 1); } IrcCommands.ParseReply(this.message, out prefix, out command, out parameters); IrcMessage message = new IrcMessage(prefix, command, parameters); if (string.IsNullOrEmpty(this.server)) { this.server = this.messagearray[0]; } dbwl("Server Reply: {0}", s); string paramsmsg = string.Join(" ", parameters.NonZero( )); string[] parr = paramsmsg.Split(' '); User u = new User(); Channel c = null; try { c = ((parameters[0].StartsWith("#")) ? GetChannel(parameters[0]) : null); if ((!string.IsNullOrEmpty(u.name))) { dbwl("User Reply: {0}", u.name); } if (c != null) { dbwl("Channel Reply: {0}", c.Name); } } catch (Exception) { } if (prefix == this.server) { if (Enum.TryParse <ReplyCode> (command, out code)) { dbwl("Prefix is {0}, Command is {1}, Code is {2}", prefix, command, code); switch (code) { case ReplyCode.RPL_TOPIC: Console.WriteLine( "Topic for {0}: {1}", parr[0], paramsmsg.Substring(parr[0].Length + 2)); break; case ( ReplyCode )333: IrcReply.FormatMessage( string.Format("Topic in {0} set by {1} on {2:ddd MMM dd, yyyy HH:mm:ss}", parr[0], parr[1], Global.UnixTimeStampToDateTime(double.Parse(parr[2]))), ConsoleColor.Gray); break; // Topic Who time? case ReplyCode.RPL_NAMESREPLY: IrcReply.FormatMessage(message, ConsoleColor.DarkMagenta); break; case ReplyCode.RPL_ENDOFNAMES: IrcReply.FormatMessage(message, ConsoleColor.DarkCyan); break; case ReplyCode.RPL_MOTD: if (OnMotd != null) { string ms = string.Join(" ", messagearray, 4, messagearray.Length - 4); if (ms.Length > 1) { motd += string.Format("{0}\r\n", ms); } OnMotd(ms); } break; case ReplyCode.RPL_MOTDSTART: motd = string.Empty; break; case ReplyCode.RPL_ENDOFMOTD: hasMOTD = true; // NOT USED BY TWITCH [5/18/2014 Blizzardo1] // Raw ( IrcCommands.Mode ( nick, "+B" ) ); // Raw ( IrcCommands.Umode ( "+B" ) ); // Raw ( IrcCommands.Umode2 ( "+B" ) ); // SendMessage ( "NickServ", string.Format("IDENTIFY {0}") ); // Add nickserv if (!string.IsNullOrEmpty(startchan)) { c = new Channel(this, startchan, startkey); c.Join( ); Channels.Add(c); } break; case ReplyCode.RPL_WHOISUSER: Format(this.message, ConsoleColor.Magenta); break; case ReplyCode.RPL_ENDOFWHOIS: Format(this.message, ConsoleColor.DarkMagenta); break; } } else { Console.WriteLine(this.message); } } else if (command == "PING") { dbg.WriteLine(message.ToString( )); string send = (IrcCommands.Pong(message.Parameters[0])); dbg.WriteLine(send); writer.SendMessage(send); } else { dbwl("Command is {0}, Parameters are {1}", command, paramsmsg); switch (command) { case "PASS": if (string.IsNullOrEmpty(_srvPass)) { Format("No Server Password! Disconnecting prematurely", ConsoleColor.Red); Disconnect(string.Format("Failed to login to {0} with no Password!", server)); } else { Raw("PASS", _srvPass); } break; // :Prefix Command :Params // :[email protected] JOIN :#Channel case "JOIN": if (OnChannelJoin != null) { OnChannelJoin(u, c, "", paramsmsg); } break; case "PART": if (OnChannelPart != null) { OnChannelPart(u, c, "", paramsmsg); } break; case "MODE": if (OnChannelMode != null) { OnChannelMode(u, c, "", paramsmsg); } break; case "KICK": if (OnChannelKick != null) { OnChannelKick(u, c, "", paramsmsg); } break; case "NICK": if (OnNickChange != null) { OnNickChange(u, paramsmsg); } break; case "QUIT": if (OnServerQuit != null) { OnServerQuit(u, c, "", paramsmsg); } break; case "PRIVMSG": if (parameters[0].StartsWith("#")) { //Lucifer.GeekShed.net PRIVMSG #chris :ACTION peeks in if (parameters[1].StartsWith( string.Format("{0}ACTION", Constants.CtcpChar)) && parameters.Last( ).EndsWith(Constants.CtcpChar.ToString( ))) { if (OnPublicAction != null) { OnPublicAction(u, c, c.Name, paramsmsg); } } else if (OnPublicMessage != null) { OnPublicMessage(u, c, c.Name, paramsmsg); } } else if (OnPrivateMessage != null) { OnPrivateMessage(u, c, parameters[0], paramsmsg); } break; case "NOTICE": /* Define later * if ( parameters[ 0 ].StartsWith ( "#" ) ) * { * if ( OnPublicNotice != null ) * OnPublicNotice ( u, c, c.Name, paramsmsg ); * } * else * if ( OnPrivateNotice != null ) * { * if ( parameters.Length > 0 ) * OnPrivateNotice ( u != null ? u : new User ( "null!null@null" ), * c, * parameters[ 0 ], * paramsmsg ); * else * OnPrivateNotice ( u != null ? u : new User ( "null!null@null" ), * c, * this.nick, * "Notice returned 0" ); * }*/ break; } } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0}", ex); Console.ResetColor( ); } } })) { Name = string.Format("{0}_thread", this.server), IsBackground = false }; this.worker.Start( ); }