public void DisplayChannelKick( User from, string target, string message ) { // TODO: Fix this with LINQ // userlist.Remove ( ); IrcReply.FormatMessage ( string.Format ( "{0} has kicked {1} from {2} {{ {3} }}", from.name, target, this.channel, message ), ConsoleColor.Red ); }
/// <summary> /// Issues a piped command /// </summary> /// <param name="caller">The channel it was sent from</param> /// <param name="responsible"></param> /// <param name="command"></param> /// <param name="args"></param> public void IssuePipeCommand( Channel caller, User responsible, string command, params object[] args ) { run ( command, args, caller.Name, responsible.name, true, false ); }
private void Irc_OnPrivateNotice( User from, Channel c, string to, string message ) { Format ( "<{0}> => {1} ", ConsoleColor.DarkCyan, from.name, message ); }
private void Irc_OnServerQuit( User from, Channel channel, string target, string message ) { channel.DisplayQuit ( from, target, message ); }
private void Irc_OnChannelPart( User from, Channel channel, string target, string message ) { channel.DisplayChannelPart ( from, target, message ); }
private void Irc_OnPrivateAction( User from, Channel c, string to, string message ) { message = message.Substring ( " ACTION ".Length ); IrcReply.FormatMessage ( string.Format ( "* {0} {1}", from.name, message.Trim ( Constants.CtcpChar ), ConsoleColor.DarkCyan ) ); }
public void DisplayQuit( User from, string target, string message ) { userlist.Remove ( from ); IrcReply.FormatMessage ( string.Format ( "{0} {1}@{2} has disconnected {{ {3} }}", from.Nick, from.Username, from.Host, message ), ConsoleColor.DarkRed ); }
private void Irc_OnChannelJoin( User from, Channel channel, string target, string message ) { try { channel.DisplayChannelJoin ( from, target, message ); } catch ( Exception ) { // Assuming AutoJoin // TODO: Fix Bug for AutoJoin Channel c = new Channel ( this, message, "" ); // Format ( "Adding {0} to {1}", ConsoleColor.Yellow, c.Name, c.ToString ( ) ); Channels.Add ( c ); } }
public void DisplayChannelMode( User from, string target, string message ) { IrcReply.FormatMessage ( string.Format ( "{0} sets mode {1} in {2}", from.Nick, message, this.channel ), ConsoleColor.Gray ); }
public void DisplayChannelPart( User from, string target, string message ) { userlist.Remove ( from ); IrcReply.FormatMessage ( string.Format ( "{0} has left {1} {{ {2} }}", from.Nick, this.channel, message ), ConsoleColor.DarkRed ); }
private void Irc_OnPublicAction( User from, string to, string message ) { GetChannel ( to ).RecievePublicAction ( from, to, message ); }
// Strip code from this file and move back to Irc.cs public void DisplayChannelJoin( User from, string target, string message ) { userlist.Add ( from ); IrcReply.FormatMessage ( string.Format ( "{0} has joined {1}",from.name, this.channel ), ConsoleColor.Cyan ); }
public void DisplayQuit( User from, string target, string message ) { userlist.Remove ( from ); IrcReply.FormatMessage ( string.Format ( "{0} has disconnected", from.name ), ConsoleColor.DarkRed ); }
/// <summary> /// Issues a private command /// </summary> /// <param name="responsible"></param> /// <param name="command"></param> /// <param name="args"></param> public void IssuePrivateCommand( User responsible, string command, params object[] args ) { run ( command, args, string.Empty, responsible.name, false, true ); }
public void RecievePublicAction( User from, string to, string message ) { message = message.Substring ( " ACTION ".Length ); IrcReply.FormatMessage ( string.Format ( "[{0}] * {1} {2}", this.channel, from.Nick, message.Trim ( Constants.CtcpChar ), ConsoleColor.DarkCyan ) ); }
/// <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 ( ); }
public void RecievePublicMessage( User from, string to, string message ) { string[] msg = message.Split ( ' ' ); // Parse as a command if ( msg[ 0 ].StartsWith ( "-" ) ) { // -ExternalCommand Params IrcReply.FormatMessage ( string.Format ( "[{0}] <{1}> {2}", this.channel, from.Nick, message ), ConsoleColor.Magenta ); string command = msg[ 0 ].Substring ( 1 ); object[] arguments = msg.Length > 1 ? string.Join ( " ", msg, 1, msg.Length - 1 ).Split ( ' ' ) : new object[] { }; parent.IssueCommand ( this, from, command, arguments ); } else if ( msg[ 0 ].StartsWith ( "+" ) ) { IrcReply.FormatMessage ( string.Format ( "[{0}] <{1}> {2}", this.channel, from.Nick, message ), ConsoleColor.Yellow ); string command = msg[ 0 ].Substring ( 1 ); object[] arguments = msg.Length > 0 ? string.Join ( " ", msg, 1, msg.Length - 1 ).Split ( ' ' ) : new object[] { }; CoreCommands.Execute ( command, this.parent, this, from.Nick, arguments ); } else // Just display the message in a specified colour IrcReply.FormatMessage ( string.Format ( "[{0}] <{1}> {2}", this.channel, from.Nick, message ), ConsoleColor.Green ); }
private void Irc_OnChannelMode( User from, Channel channel, string target, string message ) { try { channel.DisplayChannelMode ( from, target, message ); } catch ( Exception ) { } }
public void RecievePublicNotice( User from, string to, string message ) { IrcReply.FormatMessage ( string.Format ( "[{0}] :: [{1}] -> {2} ", this.channel, from.Nick, message ), ConsoleColor.DarkMagenta ); }
private void Irc_OnNickChange( User from, string newnick ) { IrcReply.FormatMessage ( string.Format ( "{0} is now known as {1}", from.name, newnick ), ConsoleColor.DarkGray ); }
public void ChangeTopic( User from, string newtopic ) { topic = newtopic; IrcReply.FormatMessage ( string.Format ( "{0} has changed topic in {1} :: {2}", from.Nick, this.channel, newtopic ), ConsoleColor.DarkCyan ); }
private void Irc_OnPrivateMessage( User from, Channel c, string to, string message ) { string[] msg = message.Split ( ' ' ); if ( msg[ 0 ].StartsWith ( "." ) ) { // This is a private command, We won't display messages here string command = msg[ 0 ].Substring ( 1 ); object[] arguments = msg.Length > 1 ? string.Join ( " ", msg, 1, msg.Length - 1 ).Split ( ' ' ) : new object[] { }; CoreCommands.Execute ( command, this, null, from.name, arguments ); } else Format ( "<{0}> {1}", ConsoleColor.DarkRed, from.name, message ); }
// Strip code from this file and move back to Irc.cs public void DisplayChannelJoin( User from, string target, string message ) { userlist.Add ( from ); IrcReply.FormatMessage ( string.Format ( "{0} {1}@{2} has joined {3}", from.Nick, from.Username, from.Host, this.channel ), ConsoleColor.Cyan ); parent.Raw ( IrcCommands.Notice ( from.Nick, string.Format ( "Welcome to {0}, {1}! Enjoy your stay! :3", this.channel, from.Nick ) ) ); }
private void Irc_OnPublicNotice( User from, Channel c, string to, string message ) { GetChannel ( to ).RecievePublicNotice ( from, to, message ); }
public void DisplayChannelKick( User from, string target, string message ) { userlist.Remove ( new User ( target ) ); IrcReply.FormatMessage ( string.Format ( "{0} has kicked {1} from {2} {{ {3} }}", from.Nick, target, this.channel, message ), ConsoleColor.Red ); }
private void Irc_OnTopicChange( User from, Channel channel, string newtopic ) { channel.ChangeTopic ( from, newtopic ); }
private static void createProfile( string name, bool staff, bool defaultUser = false ) { //Irc.Format ( "<Accounts> Formatting and adding {0}", ConsoleColor.Green, name ); string streamDir = string.Empty; if ( staff ) { Console.WriteLine ( "Using Staff Directory" ); streamDir = string.Format ( "Streamers\\Staff\\{0}", name ); } else { Console.WriteLine ( "Using Normal Directory" ); streamDir = string.Format ( "Streamers\\Normal\\{0}", name ); } if ( !defaultUser && StreamerExists ( name ) ) { Console.WriteLine ( "User {0} has already been registered!", name ); return; } Directory.CreateDirectory ( streamDir ); XAttribute xName = new XAttribute ( "name", name ); XAttribute xToken = new XAttribute ( "token", string.Empty ); XAttribute xBanned = new XAttribute ( "banned", false ); XAttribute xConfig = new XAttribute ( "config", streamDir ); XElement xUser = new XElement ( "Streamer" ); xUser.Add ( xName, xToken, xBanned, xConfig ); XElement xUsers = xDoc.Element ( "Streamers" ); xUsers.Add ( xUser ); XDocument xUsersDB = new XDocument ( new XDeclaration ( "1.0", "utf-8", "yes" ) ); XElement xUserDB = new XElement ( "User" ); User sUser = new User ( ) { name = name, banned = false, permission = Permissions.Administrator.ToString ( ) }; xUserDB.SetAttributeValue ( "name", sUser.name ); xUserDB.SetAttributeValue ( "banned", sUser.banned.ToString ( ) ); xUserDB.SetAttributeValue ( "permission", sUser.permission ); xUsersDB.Add ( xUserDB ); xUsersDB.Save ( string.Format ( "{0}\\users.xml", streamDir ) ); }