bool Connect() { if (m_twitch != null) { m_twitch.InformChatClear -= ClearChatHandler; m_twitch.MessageReceived -= ChatMessageReceived; m_twitch.ActionReceived -= ChatActionReceived; m_twitch.UserSubscribed -= SubscribeHandler; m_twitch.StatusUpdate -= StatusUpdate; } string channel = m_channel.ToLower(); m_users = new TwitchUsers(channel); m_twitch = new TwitchClient(m_users); m_twitch.InformChatClear += ClearChatHandler; m_twitch.MessageReceived += ChatMessageReceived; m_twitch.ActionReceived += ChatActionReceived; m_twitch.UserSubscribed += SubscribeHandler; m_twitch.StatusUpdate += StatusUpdate; bool first = true; ConnectResult result; const int sleepTime = 5000; do { if (!NativeMethods.IsConnectedToInternet()) { WriteStatus("Not connected to the internet."); do { Thread.Sleep(sleepTime); } while (!NativeMethods.IsConnectedToInternet()); WriteStatus("Re-connected to the internet."); } if (!first) Thread.Sleep(sleepTime); first = false; result = m_twitch.Connect(channel, m_options.User, m_options.Pass); if (result == ConnectResult.LoginFailed) { WriteStatus("Failed to login, please change options.ini and restart the application."); return false; } else if (result != ConnectResult.Success) { WriteStatus("Failed to connect: {0}", result == ConnectResult.NetworkFailed ? "network failed" : "failed"); } } while (result != ConnectResult.Success); WriteStatus("Connected to channel {0}.", channel); return true; }
void Connect() { if (m_twitch != null) { m_twitch.InformChatClear -= ClearChatHandler; m_twitch.MessageReceived -= ChatMessageReceived; m_twitch.ActionReceived -= ChatActionReceived; m_twitch.UserSubscribed -= SubscribeHandler; m_twitch.InformModerator -= InformModerator; m_twitch.StatusUpdate -= IrcStatusHandler; } m_twitch = new TwitchClient(m_data); m_twitch.TimeoutDelay = 250; m_twitch.InformChatClear += ClearChatHandler; m_twitch.MessageReceived += ChatMessageReceived; m_twitch.ActionReceived += ChatActionReceived; m_twitch.UserSubscribed += SubscribeHandler; m_twitch.InformModerator += InformModerator; m_twitch.StatusUpdate += IrcStatusHandler; bool first = true; ConnectResult result; const int sleepTime = 5000; do { if (!NativeMethods.IsConnectedToInternet()) { WriteDiagnostic(DiagnosticFacility.Network, "Not connected to the internet."); do { Thread.Sleep(sleepTime); } while (!NativeMethods.IsConnectedToInternet()); WriteDiagnostic(DiagnosticFacility.Network, "Re-connected to the internet."); } if (!first) Thread.Sleep(sleepTime); first = false; result = m_twitch.Connect(m_channel, m_options.Username, m_options.Password); if (result == ConnectResult.LoginFailed) throw new TwitchLoginException(m_options.Username); } while (result != ConnectResult.Success); OnConnected(); }