示例#1
0
        public ClientBehaviour()
        {
            connection = new FakeConnection(line => clientLines.Enqueue(line));
            client = new Client(connection, new ClientConfig() { Nickname = nickname, Username = username, UserMode = usermode, Password = password });
            client.Message += (sender, message) => serverLines.Enqueue(message.Line);

            clientThread = new Thread((ParameterizedThreadStart)((object delay) => client.Run((Action)delay)));
            clientThread.IsBackground = true;
            clientThread.Start((Action)(() => Thread.Sleep(100)));
        }
示例#2
0
文件: Program.cs 项目: Banane9/Iris
        private static void Main(string[] args)
        {
            var ircConnection = new IrcConnection(new ServerDetails() { Port = 6667, Address = "irc.esper.net", Name = "Esper.net" });
            var client = new Client(ircConnection, new ClientConfig() { Nickname = "Iris", Password = "******", UserMode = 0, Username = "******" });
            client.Message += (sender, message) =>
                {
                    if (message is PrivateMessage)
                    {
                        var privmsg = (PrivateMessage)message;
                        Console.WriteLine(privmsg.User + ": " + privmsg.Message);
                    }
                    else
                        Console.WriteLine(message.Line.Remove(0, message.Line.IndexOf(':', 2) + 1));
                };

            var clientThread = new Thread((ParameterizedThreadStart)((object delay) => client.Run((Action)delay)))
            {
                Name = "Client - Esper.net",
                IsBackground = true
            };
            clientThread.Start((Action)(() => Thread.Sleep(100))); //Needs the delay action passed in because Portable Class Libraries don't support Threads ...

            Console.WriteLine("Write exit to ... well ... exit.");

            var readLine = "";
            while (true)
            {
                readLine = Console.ReadLine();

                if (readLine.ToLower() == "exit")
                    break;

                ircConnection.SendLine(readLine);
            }

            client.Stop();

            Console.WriteLine("Threads should be stopping.");
            Console.ReadLine();
        }
示例#3
0
文件: Program.cs 项目: nishtown/Iris
        private static void Main(string[] args)
        {
            IrcConnection ircConnection = new IrcConnection(new ServerDetails() { Port = 6667, Address = "irc.esper.net", Name = "Esper.net" });

            Client client = new Client(ircConnection, new ClientConfig() { Nickname = "Nish|Iris", Password = "", UserMode = 0, Username = "******" });
            client.Message += (sender, line) => Console.WriteLine(line);
            client.PrivateMessage += client_PrivateMessage;
            client.Connected += client_Connected;

            Thread clientThread = new Thread((ParameterizedThreadStart)((object delay) => client.Run((Action)delay)));
            clientThread.Name = "Client - Esper.net";
            clientThread.IsBackground = true;
            clientThread.Start((Action)(() => Thread.Sleep(100))); //Needs the delay action passed in because Portable Class Libraries don't support Threads ...

            Console.WriteLine("Press enter to stop threads.");
            Console.ReadLine();

            client.Stop();

            Console.WriteLine("Threads should be stopping.");
            Console.ReadLine();
        }
示例#4
0
        static void processCommand(string msg)
        {
            if (msg.Length > 0)
            {
                switch (msg.Substring(0, 1).ToLower())
                {
                    case "a":
                        if (msg.Contains(' '))
                        {
                            string[] settings = msg.Split(' ');
                            if (settings.Length >= 3)
                            {
                                Client c = ircClient[settings[1]];
                                ircSettings i = iSettings[c];

                                i.auth.Add(settings[2]);
                                iSettings[c] = i;
                            }
                        }
                        break;
                    case "j":
                        if (msg.Contains(' '))
                        {
                            string[] settings = msg.Split(' ');
                            if (settings.Length >= 3)
                            {
                                Client c = ircClient[settings[1]];

                                c.Join(settings[2]);

                                Console.WriteLine("Joining channel " + settings[2] + " on " + settings[1]);
                            }
                            else
                            {
                                Console.WriteLine("Invalid parameters! eg: 'j client channel'");
                            }
                        }
                        break;

                    case "l":
                        if (msg.Contains(' '))
                        {
                            string[] settings = msg.Split(' ');
                            if (settings.Length >= 3)
                            {
                                Client c = ircClient[settings[1]];

                                c.Leave(settings[2]);

                                Console.WriteLine("Leaving channel " + settings[2] + " on " + settings[1]);
                            }
                            else
                            {
                                Console.WriteLine("Invalid parameters! eg: 'l client channel'");
                            }
                        }
                        break;
                    case "c":
                        if (msg.Contains(' '))
                        {
                            string server = msg.Split(' ')[1];
                            IrcConnection irc = new IrcConnection(new ServerDetails() { Port = 6667, Address = server, Name = server.Split('.')[1] });
                            Client c = new Client(irc, new ClientConfig() { Nickname = "Nish", Password = "", UserMode = 0, Username = "******" });
                            c.Message += c_Message;
                            c.PrivateMessage += c_PrivateMessage;
                            c.Connected += c_Connected;

                            ircSettings i = new ircSettings();
                            i.auth = new List<string>();
                            i.auth.Add("Nishtown");
                            i.server = irc.Server.Address;
                            i.log = false;
                            i.greet = false;

                            ircClient.Add(irc.Server.Name, c);
                            iSettings.Add(c, i);

                            Thread clientThread = new Thread((ParameterizedThreadStart)((object delay) => c.Run((Action)delay)));
                            clientThread.Name = irc.Server.Name;
                            clientThread.IsBackground = true;
                            clientThread.Start((Action)(() => Thread.Sleep(100)));
                        }
                        break;

                    case "d":
                        if (msg.Contains(' '))
                        {
                            string[] settings = msg.Split(' ');
                            Client c = ircClient[settings[1]];
                            c.Stop();
                        }
                        break;

                    default:
                        Console.WriteLine("Invalid chat command");
                        break;
                }
            }
        }