Пример #1
0
        public override void JoinServer(string server, string nickName, string userName, string realName, string password)
        {
            ServerInfo.Server = server;
            ServerInfo.NickName = nickName;
            ServerInfo.UserName = userName;
            ServerInfo.RealName = realName;
            ServerInfo.Password = password;

            Client = new StandardIrcClient();
            Client.Connected += Client_Connected;
            Client.Disconnected += Client_Disconnected;
            Client.Registered += Client_Registered;
            Client.RawMessageReceived += Client_RawMessageReceived;

            var ri = new IrcUserRegistrationInfo();
            ri.NickName = nickName;
            ri.UserName = userName;
            ri.RealName = realName;
            ri.Password = password;

            using (var connectedEvent = new ManualResetEventSlim(false))
            {
                Client.Connected += (sender2, e2) => connectedEvent.Set();
                Client.Connect(server, false, ri);
                if (!connectedEvent.Wait(10000))
                {
                    Client.Dispose();
                    return;
                }
            }
        }
Пример #2
0
        protected void Connect(string server, IrcRegistrationInfo registrationInfo)
        {
            // Create new IRC client and connect to given server.
            var client = new StandardIrcClient();

            client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            client.Connected     += IrcClient_Connected;
            client.Disconnected  += IrcClient_Disconnected;
            client.Registered    += IrcClient_Registered;

            // Wait until connection has succeeded or timed out.
            using (var connectedEvent = new ManualResetEventSlim(false))
            {
                client.Connected += (sender2, e2) => connectedEvent.Set();
                client.Connect(server, false, registrationInfo);
                if (!connectedEvent.Wait(10000))
                {
                    client.Dispose();
                    ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server);
                    return;
                }
            }

            // Add new client to collection.
            this.allClients.Add(client);

            Console.Out.WriteLine("Now connected to '{0}'.", server);
        }
Пример #3
0
        public MainWindow()
        {
            InitializeComponent();
            this.messageField.KeyDown += textBoxEnter;

            //Instantiate an IRC client session
            irc = new StandardIrcClient();
            IrcRegistrationInfo info = new IrcUserRegistrationInfo()
            {
                NickName = Environment.UserName, // "NerdChat",
                UserName = Environment.UserName + "NerdChat",
                RealName = "NerdChat"
            };

            //Open IRC client connection
            irc.Connect("irc.freenode.net", false, info);
            irc.RawMessageReceived += IrcClient_Receive;

            // Add server to treeview
            TreeViewItem serverTreeItem = new TreeViewItem();
            serverTreeItem.Header = "irc.freenode.net";
            channelTree.Items.Add(serverTreeItem);

            // Add some dummy channels for testing
            for (int i = 0; i < 10; i++) {
                TreeViewItem dummyItem = new TreeViewItem();
                dummyItem.Header = "#dummy" + i;
                serverTreeItem.Items.Add(dummyItem);
            }
        }
Пример #4
0
        public MainWindow()
        {
            // Set the current directory to wherever the executable is located.
            // The current directory is sometimes C:\Windows\System32 when the application starts on windows startup
            string executableDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            Directory.SetCurrentDirectory(executableDir);

            InitializeComponent();

            try {
                ShowCollection.LoadFromFile(Directory.GetCurrentDirectory() + @"\shows");
            }
            catch (Exception e)
            {
                // The file doesn't exist, so this is our first time running. That's fine.
            }

            // Sort the shows by date
            ShowCollection = new SerializableCollection <Show>(ShowCollection.OrderBy(show => show.AirsOn));

            // Connect the ListView to the list of shows we're tracking
            Shows_LV.Items.Clear();
            Shows_LV.ItemsSource = ShowCollection;

            // When the user selects a show in the list, bring up an edit dialog.
            Shows_LV.PreviewMouseLeftButtonUp += LV_Item_Clicked;

            // Update the status of the shows if they've become available.
            foreach (Show s in ShowCollection)
            {
                UpdateShowStatus(s);
            }

            // Instantiate the IRC clients
            client = new StandardIrcClient();
            ctcp   = new IrcDotNet.Ctcp.CtcpClient(client);

            // Hookup error handlers
            client.ConnectFailed += (sender, args) => { MessageBox.Show("Connection failed. Check the server setting and your internet connection."); };
            client.Error         += (sender, args) => { MessageBox.Show("Generic error thrown: " + args.Error.Message); };

            // If the "Download On Startup" option is selected, go ahead and do it.
            if (settings.DownloadOnStartup)
            {
                Download_Button_Click(null, null);
            }
        }
Пример #5
0
        protected void Connect(string server, IrcRegistrationInfo registrationInfo)
        {
            // Create new IRC client and connect to given server.
            var client = new StandardIrcClient();
            client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            client.Connected += IrcClient_Connected;
            client.Disconnected += IrcClient_Disconnected;
            client.Registered += IrcClient_Registered;

            // Wait until connection has succeeded or timed out.
            using (var connectedEvent = new ManualResetEventSlim(false))
            {
                client.Connected += (sender2, e2) => connectedEvent.Set();
                client.Connect(server, false, registrationInfo);
                if (!connectedEvent.Wait(10000))
                {
                    client.Dispose();
                    ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server);
                    return;
                }
            }

            // Add new client to collection.
            this.allClients.Add(client);

            Console.Out.WriteLine("Now connected to '{0}'.", server);
        }
Пример #6
0
        public IrcAdapter(ChatServer chatServerConfig)
        {
            serverConfig = chatServerConfig;
            client = new StandardIrcClient { FloodPreventer = new IrcStandardFloodPreventer(5, 2000) };

            Messages = Observable.FromEvent<EventHandler<IrcRawMessageEventArgs>, ChatMessage>(handler =>
            {
                EventHandler<IrcRawMessageEventArgs> converter = (sender, ircMessageArgs) =>
                {
                    try
                    {
                        if (client == null)
                        {
                            return;
                        }

                        // If it's not an actual user message, ignore it
                        if (!ircMessageArgs.Message.Command.Equals("PRIVMSG", StringComparison.OrdinalIgnoreCase))
                        {
                            return;
                        }

                        string messageSender = ircMessageArgs.Message.Source.Name;
                        string message = ircMessageArgs.Message.Parameters[1];
                        string roomName = ircMessageArgs.Message.Parameters[0];
                        if (roomName != null && roomName.StartsWith("#"))
                        {
                            roomName = roomName.Substring(1);
                        }

                        // Don't relay our own messages
                        if (messageSender.Equals(serverConfig.UserName, StringComparison.OrdinalIgnoreCase))
                        {
                            return;
                        }

                        // Check for emotes, ignore for now
                        if (message.StartsWith("\u0001" + "ACTION", StringComparison.OrdinalIgnoreCase))
                        {
                            return;
                        }

                        var chatMessage = new ChatMessage
                        {
                            ServerId = serverConfig.ServerId,
                            Room = roomName,
                            User = messageSender,
                            Text = message,
                            TimeStamp = DateTimeOffset.Now // IRC Doesn't hand us the timestamp
                        };

                        handler(chatMessage);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"{serverConfig.ServerId}|EXCEPTION: {ex}");
                    }
                };

                return converter;
            },
                converter => client.RawMessageReceived += converter,
                converter => client.RawMessageReceived -= converter
            );

            client.Connected += Client_Connected;
            client.Disconnected += Client_Disconnected;

            // Debugging
            client.ConnectFailed += Client_ConnectFailed;
            client.ErrorMessageReceived += Client_ErrorMessageReceived;
        }
Пример #7
0
        static void Main()
        {
            Logger.Init();

              var server = "irc.rizon.sexy";
              var username = "******";

              using (var client = new StandardIrcClient()) {
            //client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            client.Disconnected += IrcClient_Disconnected;
            client.Registered += IrcClient_Registered;
            // Wait until connection has succeeded or timed out.
            using (var registeredEvent = new ManualResetEventSlim(false)) {
              using (var connectedEvent = new ManualResetEventSlim(false)) {
            client.Connected += (sender2, e2) => connectedEvent.Set();
            client.Registered += (sender2, e2) => registeredEvent.Set();
            client.Connect(server, 6667, false,
                new IrcUserRegistrationInfo() {
                  NickName = username,
                  UserName = username,
                  RealName = username,
                  Password = PrivateConstants.IrcFloodBypassPassword,
                });
            if (!connectedEvent.Wait(10000)) {
              Console.WriteLine($"Connection to '{server}' timed out.");
              return;
            }
              }
              client.LocalUser.NoticeReceived += IrcClient_LocalUser_NoticeReceived;

              Console.Out.WriteLine($"Now connected to '{server}'.");
              if (!registeredEvent.Wait(10000)) {
            Console.WriteLine($"Could not register to '{server}'.");
            return;
              }
            }

            Console.Out.WriteLine($"Now registered to '{server}' as '{username}'.");
            client.Channels.Join(EchoChannel);

            HandleEventLoop(client);
              }
        }
Пример #8
0
 public void Disconnect()
 {
     client.Disconnect();
     client.Dispose();
     client = null;
 }
Пример #9
0
        public async void Connect()
        {
            client = new StandardIrcClient();

            client.ChannelListReceived += Client_ChannelListReceived;
            client.Connected += Client_Connected;
            client.ConnectFailed += Client_ConnectFailed;
            client.Disconnected += Client_Disconnected;
            client.Error += Client_Error;
            client.ErrorMessageReceived += Client_ErrorMessageReceived;
            client.MotdReceived += Client_MotdReceived;
            client.ProtocolError += Client_ProtocolError;
            client.RawMessageReceived += Client_RawMessageReceived;
            client.Registered += Client_Registered;
            client.ServerBounce += Client_ServerBounce;
            client.ServerLinksListReceived += Client_ServerLinksListReceived;
            client.ServerStatsReceived += Client_ServerStatsReceived;
            client.ServerTimeReceived += Client_ServerTimeReceived;
            client.ServerVersionInfoReceived += Client_ServerVersionInfoReceived;
            client.WhoIsReplyReceived += Client_WhoIsReplyReceived;
            client.WhoReplyReceived += Client_WhoReplyReceived;
            client.WhoWasReplyReceived += Client_WhoWasReplyReceived;

            connection.AddHistory(HtmlWriter.Write(string.Format(MainPage.GetInfoString("TryToConnect"),
                connection.Name, connection.Port == null ? IrcClient.DefaultPort : (int)connection.Port)));
            if (string.IsNullOrWhiteSpace(connection.Nickname))
                connection.Nickname = App.APPNAME + new Random().Next(int.MinValue, int.MaxValue);
            if (string.IsNullOrWhiteSpace(connection.RealName))
                connection.RealName = connection.Nickname;
            client.Connect(connection.Name, connection.Port == null ? IrcClient.DefaultPort : (int)connection.Port,
                false, new IrcUserRegistrationInfo()
                {
                    NickName = connection.Nickname,
                    Password = string.IsNullOrWhiteSpace(connection.Password) ? null : await Encryption.UnProtect(connection.Password),
                    RealName = connection.RealName,
                    UserModes = connection.UserModes,
                    UserName = App.APPNAME
                });
        }