コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: Irc.cs プロジェクト: Blizzardo1/BlizzetaZero
        /// <summary>
        /// Connects the specified host.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        public void Connect(string host, int port = 6667)
        {
            IrcReply.FormatMessage(string.Format("FIRE UP {0}", host), ConsoleColor.Yellow, true);
            try
            {
                this.host = host;
                this.port = port;

                this.client = new TcpClient( );

                iDent       = new Ident("Zero");
                identWorker = new Thread(iDent.InitServer)
                {
                    Name = "DaQueen", IsBackground = false
                };
                identWorker.Start( );

                killerQueen = new Thread(KillItWithFire)
                {
                    Name = "KillerQueen", IsBackground = false
                };
                killerQueen.Start( );

                this.client.SendBufferSize = 4096;
                this.client.Connect(host, port);
                this.stream = this.client.GetStream( );
                this.reader = new StreamReader(this.stream);
                this.writer = new StreamWriter(this.stream);
                Listen( );
            }
            catch (Exception ex)
            {
                Format(ex.ToString( ), ConsoleColor.Red);
            }
        }
コード例 #3
0
        public void InitServer( )
        {
            try
            {
                listener.Start( );
                TcpClient client = listener.AcceptTcpClient( );
                listener.Stop( );
                StreamReader reader = new StreamReader(client.GetStream( ));
                StreamWriter writer = new StreamWriter(client.GetStream( ));
                string       s      = reader.ReadLine( );

                IrcReply.FormatMessage(string.Format("Fetched Ident! Ident is {0}. Sending a reply now...", s), ConsoleColor.Yellow);
                writer.SendMessage("{0} : USERID: UNIX : {1}", s, userID);
                IrcReply.FormatMessage("Sent!", ConsoleColor.Green);
                IrcReply.FormatMessage("Disconnecting from {{ Ident }}", ConsoleColor.Yellow);
            }
            catch (SocketException se)
            {
                IrcReply.FormatMessage(se.Message, ConsoleColor.Red, true);
            }
            catch (Exception ex)
            {
                IrcReply.FormatMessage(ex.Message, ConsoleColor.Red, true);
            }
        }
コード例 #4
0
ファイル: Irc.cs プロジェクト: Blizzardo1/BlizzetaZero
 private void Irc_OnPrivateAction(User from, string to, string message)
 {
     message = message.Substring(" ACTION ".Length);
     IrcReply.FormatMessage(string.Format("* {0} {1}",
                                          from.Nick,
                                          message.Trim(Constants.CtcpChar),
                                          ConsoleColor.DarkCyan));
 }
コード例 #5
0
ファイル: Irc.cs プロジェクト: Blizzardo1/BlizzetaZero
 private void KillItWithFire( )
 {
     Thread.Sleep(120000);
     if (identWorker.IsAlive)   // WHY IS IT ALIVE FOR MORE THAN THAT MANY MILLISECONDS... WE MUST KILL IT NOW! >,>
     {
         IrcReply.FormatMessage("Sending Queen to kill the Ident, Cause Freddie Mercury!", ConsoleColor.Magenta, true);
         identWorker.Abort( );
     }
 }
コード例 #6
0
        public static bool ActivateKey(string key, out string[] decrypted)
        {
            string[] data = KeyCipher.Decrypt(key, "blizzetazero70iamopensourcemadebyblizzardo1dontabuse(c)2014blizzardo1").Split(':');
            if (data.Length == 3)
            {
                IrcReply.FormatMessage(string.Format("Nick: {0}\r\nChannel: {1}\r\nDate: {2:dddd MMMM dd, yyyy} at {2:HH:mm:ss}", data[0], data[1], DateTime.FromBinary(long.Parse(data[2]))), ConsoleColor.DarkGray, true);
                decrypted = data;
                return(true);
            }

            decrypted = null;
            return(false);
        }
コード例 #7
0
        /// <summary>
        /// Connects the specified host.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        internal void Connect(string host, int port = 6667)
        {
            IrcReply.FormatMessage(string.Format("FIRE UP {0}", host), ConsoleColor.Yellow, true);
            try
            {
                dbg.WriteLine("Setting host and port...");
                this.host = host;
                this.port = port;

                Warning("Instantiating a new TcpClient...");
                this.client = new TcpClient( );

                Info("Instantiating a new Ident Thread");
                iDent       = new Ident("Zero");
                identWorker = new Thread(iDent.InitServer)
                {
                    Name = "DaQueen", IsBackground = false
                };
                identWorker.Start( );

                killerQueen = new Thread(KillItWithFire)
                {
                    Name = "KillerQueen", IsBackground = false
                };
                killerQueen.Start( );

                dbg.WriteLine("Setting buffer..");
                this.client.SendBufferSize = 8192;

                Info("Connecting to host, setting streams up and then preparing to PASS...");
                this.client.Connect(host, port);
                dbg.WriteLine(".");
                this.stream = this.client.GetStream( );

                dbg.WriteLine("..");
                this.reader = new StreamReader(this.stream);
                this.writer = new StreamWriter(this.stream);

                dbg.WriteLine("...");
                Info("Sending Credentials for Validation...");

                Listen( );
            }
            catch (Exception ex)
            {
                Format(ex.ToString( ), ConsoleColor.Red);
            }
        }
コード例 #8
0
        /// <summary>
        /// Parse Line data
        /// </summary>
        /// <param name="Data">The Array of an Irc Reply Message</param>
        /// <returns>A new instance of IrcReply</returns>
        public static IrcReply GetFromLine(string[] Data)
        {
            int      position = Data[0].IndexOf('!');
            IrcReply iData    = new IrcReply( );

            if (position > 1)
            {
                iData.nick     = Data[0].Substring(1, position - 1);
                iData.hostmask = Data[0].Substring(position);
            }
            else
            {
                iData.nick     = Data[0].Substring(1);
                iData.hostmask = string.Empty;
            }
            iData.command = Data[1];
            return(iData);
        }
コード例 #9
0
        public void InitServer( )
        {
            try
            {
                _listener.Start( );
                IrcReply.FormatMessage("Blizzeta Ident Server Initialized", ConsoleColor.Green);
                TcpClient client = _listener.AcceptTcpClient( );
                IrcReply.FormatMessage(string.Format("Got a connection! {0}",
                                                     client.Client.LocalEndPoint.AddressFamily), ConsoleColor.Gray);
                _listener.Stop( );

                IrcReply.FormatMessage("Ident Server Stopped... Parsing Data...", ConsoleColor.DarkMagenta);
                var    reader = new StreamReader(client.GetStream( ));
                var    writer = new StreamWriter(client.GetStream( ));
                string s      = reader.ReadLine( );
                string rplFmt = string.Format("{0} : USERID: UNIX : {1}", s, _userId);
                IrcReply.FormatMessage(string.Format("Fetched Ident! Ident is {0}. Sending a reply now...", s),
                                       ConsoleColor.Yellow);
                Console.WriteLine("Reply: {0}", rplFmt);

                writer.SendMessage(rplFmt);
                IrcReply.FormatMessage("Sent!", ConsoleColor.Magenta);
                IrcReply.FormatMessage("Disconnecting from {{ Ident }}", ConsoleColor.DarkMagenta);

                // Destroy
                client.Close( );
            }
            catch (SocketException se)
            {
                IrcReply.FormatMessage(se.Message, ConsoleColor.Red, true);
            }
            catch (Exception ex)
            {
                IrcReply.FormatMessage(ex.Message, ConsoleColor.Red, true);
            }
        }
コード例 #10
0
        /// <summary>
        /// Parse Line data
        /// </summary>
        /// <param name="Data">The Array of an Irc Reply Message</param>
        /// <returns>A new instance of IrcReply</returns>
        public static IrcReply GetFromLine( string[] Data )
        {
            int position = Data[ 0 ].IndexOf ( '!' );
            IrcReply iData = new IrcReply ( );

            if ( position > 1 )
            {
                iData.nick = Data[ 0 ].Substring ( 1, position - 1 );
                iData.hostmask = Data[ 0 ].Substring ( position );
            }
            else
            {
                iData.nick = Data[ 0 ].Substring ( 1 );
                iData.hostmask = string.Empty;
            }
            iData.command = Data[ 1 ];
            return iData;
        }
コード例 #11
0
 // 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);
 }
コード例 #12
0
 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);
 }
コード例 #13
0
 // 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)));
 }
コード例 #14
0
 public void RecievePublicNotice(User from, string to, string message)
 {
     IrcReply.FormatMessage(string.Format("[{0}] :: [{1}] -> {2} ", this.channel, from.Nick, message), ConsoleColor.DarkMagenta);
 }
コード例 #15
0
 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);
 }
コード例 #16
0
 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));
 }
コード例 #17
0
ファイル: Irc.cs プロジェクト: Blizzardo1/BlizzetaZero
 private void Irc_OnNickChange(User from, string newnick)
 {
     IrcReply.FormatMessage(string.Format("{0} is now known as {1}", from.Nick, newnick), ConsoleColor.DarkGray);
 }
コード例 #18
0
 public void DisplayQuit(User from, string target, string message)
 {
     userlist.Remove(from);
     IrcReply.FormatMessage(string.Format("{0} has disconnected", from.name), ConsoleColor.DarkRed);
 }
コード例 #19
0
 /// <summary>
 /// Formats the specified text.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="colour">The colour.</param>
 /// <param name="args">The arguments.</param>
 public static void Format(string text, ConsoleColor colour, params object[] args)
 {
     IrcReply.FormatMessage(string.Format(string.IsNullOrEmpty(text) ? "-" : text, args), colour);
 }
コード例 #20
0
 private static void irc_OnMotd(string data)
 {
     IrcReply.FormatMessage(data, ConsoleColor.Yellow);
 }
コード例 #21
0
ファイル: Irc.cs プロジェクト: Blizzardo1/BlizzetaZero
        /// <summary>
        /// Runs a command from an external script file
        /// </summary>
        /// <param name="command">The command to search for</param>
        /// <param name="commandSet">The arguments to pass to the script</param>
        /// <param name="destination">The destination, by default should be a channel, unless pm is true</param>
        /// <param name="target">the target of the nick that has called the command</param>
        /// <param name="pipe">Are we setting up a secondary command? This allows us to execute private commands in a public room</param>
        /// <param name="pm">Are we issuing a private message command?</param>
        private void run(string command, object[] commandSet, string destination, string target, bool pipe = false, bool pm = false)
        {
            string args = string.Empty;
            Guid   g    = Guid.NewGuid( );
            var    sc   = new ScriptContext( );
            var    se   = new ScriptEngine( );

            try
            {
                sc.server = this;
                var noMod = new List <object> ( );

                // TODO: Shorten this statement
                if (commandSet.Length > 0)
                {
                    for (int i = 0; i < commandSet.Length; i++)
                    {
                        args += string.Format("[{0}]; ", commandSet[i]);
                        noMod.Add(commandSet[i]);
                    }
                }

                if (destination.StartsWith("#") && pm == false)
                {
                    sc.channel = GetChannel(destination);
                }
                else
                {
                    destination = target;
                }

                sc.nick = target;

                sc.Arguments = noMod;
                args         = args.TrimEnd(' ');

                string cmdlet = string.Format("{0}\\{1}.cs", CmdPath, command);
                var    cmdi   = se.GetInterface(cmdlet);

                if (cmdi == null)
                {
                    SendMessage(destination, "Unknown Command");
                    return;
                }
                else
                {
                    //pc ( "[{0:HH:mm:ss} {1}] {2}", ConsoleColor.Green, DateTime.Now, destination, target );
                    Format("Name: {0} - Help: {1} - Usage: {2} - More: {3} - Version: {4} - Permission: {5}",
                           ConsoleColor.DarkGreen,
                           cmdi.Name,
                           cmdi.Help,
                           cmdi.Usage,
                           cmdi.More,
                           cmdi.Version,
                           cmdi.Permission);

                    if (cmdi.IsPublic)
                    {
                        if (uac.GetPermission(target, this) <= cmdi.Permission)
                        {
                            se.Run(cmdlet, ref sc);
                        }
                        else
                        {
                            SendMessage(target,
                                        string.Format("You do not have permission to execute the command {0}", command));
                        }
                    }
                    else if (pipe)
                    {
                        if (uac.GetPermission(target, this) <= cmdi.Permission)
                        {
                            se.Run(cmdlet, ref sc);
                        }
                    }
                    else if (pm)
                    {
                        if (uac.GetPermission(target, this) <= cmdi.Permission)
                        {
                            se.Run(cmdlet, ref sc);
                        }
                        else
                        {
                            SendMessage(target,
                                        string.Format("You do not have permission to execute the command {0}", command));
                        }
                    }
                    else if (pipe && pm)
                    {
                        SendMessage(target, "Pipe command cannot be used privately");
                    }
                    else
                    {
                        SendMessage(destination,
                                    string.Format("The command \"{0}\" can only be used privately!", command));
                    }
                }
            }
            catch (Exception ex)
            {
                IrcReply.FormatMessage(string.Format("{0}", ex.Message), ConsoleColor.Red);
                SendMessage(destination, string.Format("{0} -> Command \"{1}\" not found!", target, command));
                return;
            }
            SendMessage(_dbgchan,
                        string.Format("Command: {0}; Arguments: [{1}]; Callee: [{2}]; Destination: \"{3}\"; Fingerprint: [{4}]",
                                      command,
                                      (args.Length > 0 ? args : "{{ null }}"),
                                      target,
                                      destination,
                                      g));
        }
コード例 #22
0
ファイル: Irc.cs プロジェクト: Blizzardo1/BlizzetaZero
 /// <summary>
 /// Formats the specified text.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="colour">The colour.</param>
 /// <param name="args">The arguments.</param>
 public void Format(string text, ConsoleColor colour, params object[] args)
 {
     IrcReply.FormatMessage(string.Format(text, args), colour);
 }
コード例 #23
0
        /// <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( );
        }
コード例 #24
0
 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);
 }
コード例 #25
0
 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);
 }
コード例 #26
0
ファイル: Irc.cs プロジェクト: Blizzardo1/BlizzetaZero
        /// <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( );
        }
コード例 #27
0
 public static void ReleaseCommand(string command)
 {
     IrcReply.FormatMessage(string.Format("Excluding {0}", command), ConsoleColor.DarkRed);
     commands.Remove(command);
 }
コード例 #28
0
 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);
 }
コード例 #29
0
 public static void AddCommand(string command, Func <Irc, string, string, object[], int> function)
 {
     IrcReply.FormatMessage(string.Format("Including {0}", command), ConsoleColor.Green);
     commands.Add(command, function);
 }
コード例 #30
0
 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);
 }