Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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();
            }
        }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
0
        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));
            }
        }
Exemplo n.º 8
0
        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();
            }
        }
Exemplo n.º 9
0
        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();
                }
            }
        }
Exemplo n.º 10
0
        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();
                }
            }
        }
Exemplo n.º 11
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();
        }
Exemplo n.º 12
0
 static public void WhoisSecuredAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + " " + message.Text);
 }
Exemplo n.º 13
0
 static public void WelcomeAction(Message message)
 {
     ContextCollection.Server.WriteLine(RTF.ColourString(message.Text, IrcColor.Blue));
 }
Exemplo n.º 14
0
 static public void ErroneusNickAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + ": " + message.Text);
 }
Exemplo n.º 15
0
 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 + ")");
 }
Exemplo n.º 16
0
 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);
 }
Exemplo n.º 17
0
 static public void LUserChannelsAction(Message message)
 {
     ContextCollection.Server.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.LightRed) + " " + message.Text);
 }
Exemplo n.º 18
0
 static public void AlreadyOnChannelAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + ": " + message.Text);
 }
Exemplo n.º 19
0
 static public void AwayAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[1], IrcColor.Pink) + " is away (" + message.Text + ")");
 }
Exemplo n.º 20
0
 static public void ChanOPrivsNeededAction(Message message)
 {
     ContextCollection.Current.WriteLine(RTF.ColourString(message.ParamsArray[2], IrcColor.Pink) + ": " + message.Text);
 }