Beispiel #1
0
        public void WriteMessage(string _nick, string _msg)
        {
            if (_msg.Contains(ContextCollection.Server.Client.Nickname))
            {
                _msg = RTF.ColourString(_msg, IrcColor.Black, IrcColor.Yellow);
            }

            if (_msg.Length > 5 && _msg.Substring(0, 7) == "\u0001ACTION")
            {
                content += DateTime.Now.ToString("[HH:mm:ss] ") + RTF.ColourString(" * " + _nick + _msg.Substring(7), IrcColor.LightRed) + @"\line";
            }
            else
            {
                IrcColor c = (_nick == ContextCollection.Server.Client.Nickname) ? IrcColor.LightRed : IrcColor.Blue;

                content += DateTime.Now.ToString("[HH:mm:ss] ") + "<" + RTF.ColourString(_nick, c) + "> " + _msg + @"\line";
            }

            if (ContextCollection.Current == this)
            {
                Program.MainWindow.UpdateContent();
            }
            else
            {
                ContextCollection.ActiveContexts.Add(this.name);
                Program.MainWindow.UpdateChannelsList();
            }
        }
Beispiel #2
0
        private async void HandleInput()
        {
            string input;

            while (true)
            {
                input = await Reader.ReadLineAsync();

                if (input != null)
                {
                    try
                    {
                        Message message = new Message(input);

                        MethodInfo oMethodInfo = MessageProcessing.GetMethod(message.Command);

                        if (oMethodInfo != null)
                        {
                            oMethodInfo.Invoke(new MessageProcessingMethods(), new object[] { message });
                        }
                        else
                        {
                            WriteLine(RTF.ColourString(message.Command, IrcColor.LightRed) + ": " + message.Text + "(" + RTF.ColourString(message.Params.Trim(), IrcColor.Orange) + ")");
                        }
                    }
                    catch (Exception e)
                    {
                        WriteLine("Unhandled exception on " + input + ": " + e.Message);
                    }
                }
            }
        }
        static public void WhoisIdleAction(Message message)
        {
            int      secs        = int.Parse(message.ParamsArray[3]);
            TimeSpan idle        = TimeSpan.FromSeconds(secs);
            string   idle_string = string.Format("{0:D2}:{1:D2}:{2:D2}", idle.Hours, idle.Minutes, idle.Seconds);

            ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + " idle: " + RTF.ColourString(idle_string, IrcColor.Orange));
        }
        static public void TopicInfoAction(Message message)
        {
            var ctx = ContextCollection.GetByName(message.ParamsArray[2]);

            var timeSpan = TimeSpan.FromSeconds(double.Parse(message.ParamsArray[4]));
            var epoch    = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var dateTime = epoch.Add(timeSpan).ToLocalTime();

            ctx.WriteLine(RTF.ColourString("Topic set by " + message.ParamsArray[3] + " on " + dateTime, IrcColor.Green));
        }
        static public void TopicAction(Message message)
        {
            var ctx = ContextCollection.GetByName(message.ParamsArray[2]);

            ctx.Topic = message.Text;
            ctx.WriteLine(RTF.ColourString("Topic for " + message.ParamsArray[2] + ": " + message.Text, IrcColor.Green));

            if (ctx == ContextCollection.Current)
            {
                Program.MainWindow.UpdateTopic();
            }
        }
        static public void TopicChangeAction(Message message)
        {
            var ctx = ContextCollection.GetByName(message.ParamsArray[1]);

            ctx.WriteLine(RTF.ColourString(message.Nick + " changed topic to: " + message.Text, IrcColor.Green));
            ctx.Topic = message.Text;

            if (ctx == ContextCollection.Current)
            {
                Program.MainWindow.UpdateTopic();
            }
        }
        static public void ModeAction(Message message)
        {
            var ctx = ContextCollection.GetByName(message.ParamsArray[1]);

            if (ctx != null)
            {
                ctx.WriteLine(RTF.ColourString(message.Nick + " sets mode" + message.Params, IrcColor.Green));
                ContextCollection.Server.SendQuery("NAMES " + message.ParamsArray[1]);
            }
            else
            {
                ContextCollection.Server.WriteLine(RTF.ColourString(message.Nick + " sets mode " + message.Text, IrcColor.Green));
            }
        }
        static public void KickAction(Message message)
        {
            var ctx = ContextCollection.GetByName(message.ParamsArray[1]);

            if (ContextCollection.Server.Client.Nickname == message.ParamsArray[2])
            {
                ContextCollection.Server.WriteLine(string.Format("You were kicked from {0} by {1} ({2})", message.ParamsArray[1], message.Nick, message.Text));
                ContextCollection.Remove(ctx);
            }
            else
            {
                ctx.WriteLine(RTF.ColourString(string.Format("{0} has been kicked by {1} ({2})", message.ParamsArray[2], message.Nick, message.Text), IrcColor.Orange));
                ctx.UsersList.Remove(message.ParamsArray[2]);
                Program.MainWindow.UpdateUsersList();
            }
        }
        static public void JoinAction(Message message)
        {
            if (message.Nick == ContextCollection.Server.Client.Nickname)
            {
                ContextCollection.Add(new IrcChannel(message.ParamsArray[1]));
            }
            else
            {
                var ctx = ContextCollection.GetByName(message.ParamsArray[1]);

                if (ctx != null)
                {
                    ((IrcChannel)ctx).Users.Add(message.Nick);
                    ctx.WriteLine(RTF.ColourString(message.Nick + " (" + message.Ident + "@" + message.Host + ") has joined.", IrcColor.Orange));

                    Program.MainWindow.UpdateUsersList();
                }
            }
        }
        static public void PartAction(Message message)
        {
            if (message.Nick == ContextCollection.Server.Client.Nickname)
            {
                ContextCollection.Remove(ContextCollection.GetByName(message.ParamsArray[1]));
            }
            else
            {
                var ctx = ContextCollection.GetByName(message.ParamsArray[1]);

                if (ctx != null)
                {
                    ((IrcChannel)ctx).Users.Remove(message.Nick);
                    ctx.WriteLine(RTF.ColourString(message.Nick + " has left.", IrcColor.Orange));


                    Program.MainWindow.UpdateUsersList();
                }
            }
        }
Beispiel #11
0
        private void eButtonSend_Click(object sender, EventArgs e)
        {
            if (eTextInput.Text.Length > 0)
            {
                string input = RTF.Escape(eTextInput.Text);

                history.Add(input);
                history_i = history.Count - 1;

                if (input.StartsWith("/"))
                {
                    try
                    {
                        Match m = Regex.Match(input, @"^\/([A-Za-z]+) ?(.*)?$");

                        MethodInfo oMethodInfo = CommandProcessing.GetMethod(m.Groups[1].Value.ToLower());

                        if (oMethodInfo != null)
                        {
                            oMethodInfo.Invoke(new CommandProcessingMethods(), new object[] { (m.Groups[2] != null) ? m.Groups[2].Value : null });
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                    catch (Exception)
                    {
                        ContextCollection.Current.WriteLine("Command not found.");
                    }
                }
                else
                {
                    ContextCollection.Server.SendQuery("PRIVMSG " + ContextCollection.Current.Name + " :" + eTextInput.Text);
                    ContextCollection.Current.WriteMessage(ContextCollection.Server.Client.Nickname, input);
                }

                eTextInput.Clear();
            }
        }
Beispiel #12
0
        public void Connect()
        {
            WriteLine("Connecting to " + RTF.ColourString(hostname, IrcColor.LightRed) + " on port " + RTF.ColourString(port.ToString(), IrcColor.LightRed) + "...");

            try
            {
                IRC = new TcpClient(hostname, port);
            }
            catch (Exception)
            {
                WriteLine("Cannot connect to " + RTF.ColourString(hostname, IrcColor.LightRed) + " on port " + RTF.ColourString(port.ToString(), IrcColor.LightRed) + "!");
                return;
            }


            Stream = IRC.GetStream();
            Writer = new StreamWriter(Stream);
            Reader = new StreamReader(Stream);

            SendQuery(string.Format("USER {0} {1} {2} {3} :{4}", Client.Username, Client.Username, Client.Username, Client.Username, Client.Realname));
            SendQuery(string.Format("NICK {0}", Client.Nickname));

            HandleInput();
        }
 static public void ChanOPrivsNeededAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + ": " + message.Text);
 }
 static public void AwayAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[1], IrcColor.Pink) + " is away (" + message.Text + ")");
 }
 static public void WelcomeAction(Message message)
 {
     ContextCollection.Server.WriteLine(RTF.ColourString(message.Text, IrcColor.Blue));
 }
 static public void LUserChannelsAction(Message message)
 {
     ContextCollection.Server.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.LightRed) + " " + message.Text);
 }
 static public void WhoisUserAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + " (" + RTF.ColourString(message.ParamsArray[3], IrcColor.Orange) + "@" + RTF.ColourString(message.ParamsArray[4], IrcColor.Orange) + "): " + message.Text);
 }
 static public void WhoisServerAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + " is connected with " + RTF.ColourString(message.ParamsArray[3], IrcColor.Orange) + " (" + message.Text + ")");
 }
 static public void ErroneusNickAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + ": " + message.Text);
 }
 static public void AlreadyOnChannelAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + ": " + message.Text);
 }
 static public void WhoisSecuredAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + " " + message.Text);
 }