Exemple #1
0
        public void Disconnect()
        {
            client.Connected            -= Client_Connected;
            client.Disconnected         -= Client_Disconnected;
            client.Disconnected         -= OnConnectedCallback;
            client.ConnectFailed        -= Client_ConnectFailed;
            client.ConnectFailed        -= OnConnectFailedCallback;
            client.ErrorMessageReceived -= Client_ErrorMessageReceived;

            Messages = null;
            client?.Disconnect();

            Console.WriteLine($"Disconnected from {serverConfig.ServerId}.");
        }
Exemple #2
0
 static bool HandlerRoutine(int CtrlType)
 {
     Console.WriteLine("Exiting...");
     switch (CtrlType)
     {
     case 0:
     case 2:
         PingThread.Abort();
         if (IRCClient != null)
         {
             IRCClient.SendRawMessage("QUIT");
             IRCClient.Disconnect();
         }
         Environment.Exit(0);
         break;
     }
     return(false);
 }
Exemple #3
0
 private void ConnectBtn_Click(object sender, EventArgs e)
 {
     if (client.IsConnected)
     {
         client.Disconnect();
         ConnectBtn.Text = "Connect";
     }
     else
     {
         Uri uri = new Uri(AddressTxb.Text);
         ConnectBtn.Text = "Connecting...";
         IrcUserRegistrationInfo info = new IrcUserRegistrationInfo();
         string username = UsernameTxb.Text;
         if (username.Length < 1)
         {
             username = "******" + RandomNumberGenerator.Create().ToString();
         }
         info.NickName = username;
         info.RealName = username;
         info.UserName = username;
         info.Password = PasswordTxb.Text;
         client.Connect(uri, info);
     }
 }
Exemple #4
0
        public bool Connect(BotType target)
        {
            switch (target)
            {
            case BotType.Osu:
            {
                IrcUserRegistrationInfo reg = new IrcUserRegistrationInfo()
                {
                    NickName = m_credentials.OsuCredentials.Username,
                    UserName = m_credentials.OsuCredentials.Username,
                    RealName = m_credentials.OsuCredentials.Username,
                    Password = m_credentials.OsuCredentials.Password,
                };

                try
                {
                    m_osuClient = new StandardIrcClient();

                    m_osuClient.Connected += (o, e) =>
                    {
                        Console.WriteLine("Connected to irc.ppy.sh");
                    };

                    m_osuClient.ConnectFailed += (o, e) =>
                    {
                        Console.WriteLine("Failed connecting to irc.ppy.sh");
                    };

                    Console.WriteLine("Connecting to irc.ppy.sh...");

                    m_osuClient.RawMessageReceived += m_osuClient_RawMessageReceived;
                    m_osuClient.Disconnected       += (o, e) =>
                    {
                        m_osuClient.Disconnect();
                        Console.WriteLine("Got disconnected from irc.ppy.sh, reconnecting...");
                        m_osuClient.Connect("irc.ppy.sh", 6667, false, reg);
                    };

                    m_osuClient.Connect("irc.ppy.sh", 6667, false, reg);
                    m_osuClient.SendRawMessage($"PASS {m_credentials.OsuCredentials.Password}\r\n");
                    m_osuClient.SendRawMessage($"NICK {m_credentials.OsuCredentials.Username}\r\n");

                    return(true);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Something happened while trying to connect to irc.ppy.sh, {e.Message}");
                    return(false);
                }
            }

            case BotType.Twitch:
            {
                {
                    IrcUserRegistrationInfo reg = new IrcUserRegistrationInfo()
                    {
                        NickName = m_credentials.TwitchCredentials.Username,
                        UserName = m_credentials.TwitchCredentials.Username,
                        RealName = m_credentials.TwitchCredentials.Username,
                        Password = m_credentials.TwitchCredentials.Password
                    };

                    try
                    {
                        m_twitchClient = new TwitchIrcClient();

                        m_twitchClient.Connected += (o, e) =>
                        {
                            Console.WriteLine("Connected to irc.twitch.tv");
                        };

                        m_twitchClient.ConnectFailed += (o, e) =>
                        {
                            Console.WriteLine("Failed connecting to irc.twitch.tv");
                        };

                        Console.WriteLine("Connecting to irc.twitch.tv...");

                        m_twitchClient.RawMessageReceived += m_twitchClient_RawMessageReceived;
                        m_twitchClient.Disconnected       += (o, e) =>
                        {
                            Console.WriteLine("Got disconnected from irc.twitch.tv, reconnecting...");
                            m_twitchClient.Connect("irc.twitch.tv", 6667, false, reg);
                        };

                        m_twitchClient.Connect("irc.twitch.tv", 6667, false, reg);

                        return(true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Something happened while trying to connect to irc.twitch.tv, {e.Message}");

                        return(false);
                    }
                }
            }

            default:
                return(false);    // wat
            }
        }
Exemple #5
0
        void Run()
        {
            Client = new StandardIrcClient();
            DrawCommandLine();

            var Info = new IrcUserRegistrationInfo();

            Info.NickName = Settings.Default.Name;
            Info.RealName = Settings.Default.Realname;
            Info.UserName = Settings.Default.Realname + "Bot";

            using (var connectedEvent = new ManualResetEventSlim(false))
            {
                Client.Connected += (sender2, e2) => connectedEvent.Set();

                Client.Connect(new Uri(Settings.Default.Server), Info);

                if (!connectedEvent.Wait(10000))
                {
                    Client.Dispose();
                    PrintLine(string.Format("Connection to {0} timed out.", Settings.Default.Server), ConsoleColor.Red);
                    return;
                }

                PrintLine(string.Format("Connected to {0}", Settings.Default.Server));

                // *** POST-INIT
                Client.MotdReceived += delegate(Object Sender, EventArgs E)
                {
                    PrintLine("Joining Channels...");
                    Client.Channels.Join(Settings.Default.Channel);
                };

                // *** DEBUG OUTPUT
                Client.RawMessageReceived += delegate(Object Sender, IrcRawMessageEventArgs Event)
                {
                    PrintLine(Event.RawContent);
                };

                // *** PING
                Client.PingReceived += delegate(Object Sender, IrcPingOrPongReceivedEventArgs Event)
                {
                    Client.Ping(Event.Server);
                };

                // *** CHANNEL JOINING
                Client.LocalUser.JoinedChannel += delegate(Object Sender, IrcChannelEventArgs Event)
                {
                    Event.Channel.MessageReceived += Channel_MessageReceived;
                    SayInChannel(OnJoinActions);
                };

                // *** REJOIN AFTER KICK
                Client.LocalUser.LeftChannel += delegate(Object Sender, IrcChannelEventArgs Event)
                {
                    Client.Channels.Join(Event.Channel.Name);
                };

                Int32 Counter = 0;
                while (Client.IsConnected)
                {
                    Thread.Sleep(5);
                    if (DCTimer > 0)
                    {
                        DCTimer--;
                        if (DCTimer == 0)
                        {
                            Client.Disconnect();
                        }
                    }
                    if (++Counter == 12000)
                    {
                        PrintLine("Manual Ping");
                        Client.Ping();
                        Counter = 0;
                    }
                    while (Console.KeyAvailable)
                    {
                        Console.SetCursorPosition(0, 0);
                        ConsoleKeyInfo Key = Console.ReadKey(true);
                        switch (Key.Key)
                        {
                        case ConsoleKey.Enter:
                            ConsoleCommand();
                            CommandLine = "";
                            break;

                        case ConsoleKey.Backspace:
                            if (CommandLine.Length > 0)
                            {
                                CommandLine = CommandLine.Substring(0, CommandLine.Length - 1);
                            }
                            break;

                        default:
                            CommandLine = CommandLine + Key.KeyChar;
                            break;
                        }
                        DrawCommandLine();
                    }
                }
            }
            DrawCommandLine();
        }