public override void Reconnect(FrontendManager fm) { Trace.Call(fm); fm.SetStatus(_("Reconnecting...")); try { string msg; if (_IrcClient != null) { if (_IrcClient.IsConnected) { Session.AddTextToChat( _NetworkChat, String.Format( "-!- " + _("Reconnecting to {0}..."), _IrcClient.Address ) ); ApplyConfig(Session.UserConfig, _ServerModel); _IrcClient.Reconnect(true); msg = String.Format(_("Connection to {0} established"), _IrcClient.Address); fm.SetStatus(msg); Session.AddTextToChat(_NetworkChat, "-!- " + msg); } else { Connect(fm); } } else { msg = _("Reconnect Error"); fm.SetStatus(msg); Session.AddTextToChat(_NetworkChat, "-!- " + msg); } } catch (ConnectionException) { fm.SetStatus(String.Empty); fm.AddTextToChat(_NetworkChat, "-!- " + _("Not connected")); } fm.UpdateNetworkStatus(); }
public override void Disconnect(FrontendManager fm) { Trace.Call(fm); fm.SetStatus(_("Disconnecting...")); if (IsConnected) { Session.AddTextToChat(_NetworkChat, "-!- " + String.Format(_("Disconnecting from {0}..."), _IrcClient.Address)); // else the Listen() thread would try to connect again _Listening = false; _IrcClient.Disconnect(); fm.SetStatus(String.Format(_("Disconnected from {0}"), _IrcClient.Address)); Session.AddTextToChat(_NetworkChat, "-!- " + _("Connection closed")); // TODO: set someone else as current network manager? } else { fm.SetStatus(String.Empty); fm.AddTextToChat(_NetworkChat, "-!- " + _("Not connected")); } if (_RunThread != null && _RunThread.IsAlive) { try { _RunThread.Abort(); } catch (Exception ex) { #if LOG4NET _Logger.Error("_RunThread.Abort() failed:", ex); #endif } } if (_LagWatcherThread != null && _LagWatcherThread.IsAlive) { try { _LagWatcherThread.Abort(); } catch (Exception ex) { #if LOG4NET _Logger.Error("_LagWatcherThread.Abort() failed:", ex); #endif } } fm.UpdateNetworkStatus(); }
public void Connect(FrontendManager fm) { Trace.Call(fm); try { string msg; msg = String.Format(_("Connecting to {0} port {1}..."), _Host, _Port); fm.SetStatus(msg); Session.AddTextToChat(_NetworkChat, "-!- " + msg); // TODO: add SSL support _IrcClient.Connect(_Host, _Port); fm.UpdateNetworkStatus(); msg = String.Format(_("Connection to {0} established"), _Host); fm.SetStatus(msg); Session.AddTextToChat(_NetworkChat, "-!- " + msg); Session.AddTextToChat(_NetworkChat, "-!- " + _("Logging in...")); string realname = (string) Session.UserConfig["Connection/Realname"]; if (realname.Trim().Length == 0) { realname = "unset"; } _IrcClient.Login(_Nicknames, realname, 0, _Username, _Password); foreach (string command in (string[]) Session.UserConfig["Connection/OnConnectCommands"]) { if (command.Length == 0) { continue; } CommandModel cd = new CommandModel(_FrontendManager, _NetworkChat, (string) Session.UserConfig["Interface/Entry/CommandCharacter"], command); bool handled; handled = Session.Command(cd); if (!handled) { Command(cd); } } _Listening = true; } catch (CouldNotConnectException ex) { fm.SetStatus(_("Connection failed!")); Session.AddTextToChat(_NetworkChat, "-!- " + _("Connection failed! Reason: ") + ex.Message); throw; } }
public void Connect(FrontendManager fm) { Trace.Call(fm); try { MessageBuilder builder; if (!String.IsNullOrEmpty(_IrcClient.ProxyHost)) { builder = CreateMessageBuilder(); builder.AppendEventPrefix(); builder.AppendText(_("Using proxy: {0}:{1}"), _IrcClient.ProxyHost, _IrcClient.ProxyPort); Session.AddMessageToChat(Chat, builder.ToMessage()); } string msg; msg = String.Format(_("Connecting to {0} port {1}..."), _Host, _Port); fm.SetStatus(msg); Session.AddTextToChat(_NetworkChat, "-!- " + msg); // TODO: add SSL support _IrcClient.Connect(_Host, _Port); fm.UpdateNetworkStatus(); msg = String.Format(_("Connection to {0} established"), _Host); fm.SetStatus(msg); Session.AddTextToChat(_NetworkChat, "-!- " + msg); Session.AddTextToChat(_NetworkChat, "-!- " + _("Logging in...")); string realname = (string) Session.UserConfig["Connection/Realname"]; if (realname.Trim().Length == 0) { realname = "unset"; } if (!Regex.IsMatch(_Username, "^[a-z0-9]+$", RegexOptions.IgnoreCase)) { builder = CreateMessageBuilder(); builder.AppendEventPrefix(); builder.AppendWarningText( "Warning: Your username (ident) contains special " + "characters which the IRC server might refuse. " + "If this happens please change your username in the " + "server settings." ); Session.AddMessageToChat(_NetworkChat, builder.ToMessage()); } _IrcClient.Login(_Nicknames, realname, 0, _Username, _Password); foreach (string command in (string[]) Session.UserConfig["Connection/OnConnectCommands"]) { if (command.Length == 0) { continue; } CommandModel cd = new CommandModel(_FrontendManager, _NetworkChat, (string) Session.UserConfig["Interface/Entry/CommandCharacter"], command); bool handled; handled = Session.Command(cd); if (!handled) { Command(cd); } } _Listening = true; } catch (CouldNotConnectException ex) { fm.SetStatus(_("Connection failed!")); Session.AddTextToChat(_NetworkChat, "-!- " + _("Connection failed! Reason: ") + ex.Message); throw; } }
public override void Connect(FrontendManager fm, string host, int port, string username, string password) { Trace.Call(fm, host, port, username, "XXX"); f_Username = username; var proxyType = (string) Session.UserConfig["Connection/ProxyType"]; if (proxyType.ToLower() == "http") { var uriBuilder = new UriBuilder(); uriBuilder.Scheme = "http"; uriBuilder.Host = (string) Session.UserConfig["Connection/ProxyHostname"]; uriBuilder.Port = (int) Session.UserConfig["Connection/ProxyPort"]; uriBuilder.UserName = (string) Session.UserConfig["Connection/ProxyUsername"]; uriBuilder.Password = (string) Session.UserConfig["Connection/ProxyPassword"]; var proxyUri = uriBuilder.ToString(); f_WebProxy = new WebProxy(proxyUri); } f_OptionalProperties = new OptionalProperties(); if (f_WebProxy != null) { f_OptionalProperties.Proxy = f_WebProxy; } f_ProtocolChat = new ProtocolChatModel(NetworkID, "Twitter " + username, this); Session.AddChat(f_ProtocolChat); Session.SyncChat(f_ProtocolChat); string msg; msg = String.Format(_("Connecting to Twitter...")); fm.SetStatus(msg); Session.AddTextToChat(f_ProtocolChat, "-!- " + msg); try { var key = GetApiKey(); f_OAuthTokens = new OAuthTokens(); f_OAuthTokens.ConsumerKey = key[0]; f_OAuthTokens.ConsumerSecret = key[1]; MessageBuilder builder; var servers = new ServerListController(Session.UserConfig); var server = servers.GetServer(Protocol, username); if (server != null) { if (password == null) { // no password passed, use server password password = server.Password; } } password = password ?? String.Empty; var access = password.Split('|'); if (password.Length == 0 || access.Length == 1) { // new account or basic auth user that needs to be migrated var reqToken = OAuthUtility.GetRequestToken(key[0], key[1], "oob", f_WebProxy); f_RequestToken = reqToken.Token; var authUri = OAuthUtility.BuildAuthorizationUri(f_RequestToken); builder = CreateMessageBuilder(); builder.AppendEventPrefix(); builder.AppendText(_("Twitter authorization required.")); Session.AddMessageToChat(f_ProtocolChat, builder.ToMessage()); /* _("Twitter authorization required, please open the " + "following URL and enter the returned PIN using the " + "/pin command: {0}"), String.Empty ); */ builder = CreateMessageBuilder(); builder.AppendEventPrefix(); // TRANSLATOR: do NOT change the position of {0}! builder.AppendText( _("Please open the following URL and click " + "\"Allow\" to allow Smuxi to connect to your " + "Twitter account: {0}"), String.Empty ); Session.AddMessageToChat(f_ProtocolChat, builder.ToMessage()); builder = CreateMessageBuilder(); builder.AppendEventPrefix(); builder.AppendText(" "); builder.AppendUrl(authUri.AbsoluteUri); Session.AddMessageToChat(f_ProtocolChat, builder.ToMessage()); builder = CreateMessageBuilder(); builder.AppendEventPrefix(); builder.AppendText( _("Once you have allowed Smuxi to access your " + "Twitter account, Twitter will provide a PIN.") ); Session.AddMessageToChat(f_ProtocolChat, builder.ToMessage()); builder = CreateMessageBuilder(); builder.AppendEventPrefix(); builder.AppendText(_("Please type: /pin PIN_FROM_TWITTER")); Session.AddMessageToChat(f_ProtocolChat, builder.ToMessage()); } else { f_OAuthTokens.AccessToken = access[0]; f_OAuthTokens.AccessTokenSecret = access[1]; } } catch (Exception ex) { #if LOG4NET f_Logger.Error("Connect(): Exception", ex); #endif fm.SetStatus(_("Connection failed!")); Session.AddTextToChat(f_ProtocolChat, "-!- " + _("Connection failed! Reason: ") + ex.Message ); return; } // twitter is sometimes pretty slow, so fetch this in the background ThreadPool.QueueUserWorkItem(delegate { try { // FIXME: replace with AutoResetEvent while (!HasTokens) { Thread.Sleep(1000); } var message = _("Fetching user details from Twitter, please wait..."); Session.AddTextToChat(f_ProtocolChat, "-!- " + message); UpdateUser(); message = _("Finished fetching user details."); Session.AddTextToChat(f_ProtocolChat, "-!- " + message); f_IsConnected = true; fm.UpdateNetworkStatus(); msg =_("Successfully connected to Twitter."); fm.SetStatus(msg); Session.AddTextToChat(f_ProtocolChat, "-!- " + msg); f_Listening = true; f_FriendsTimelineChat.PersonCount = f_RepliesChat.PersonCount = f_DirectMessagesChat.PersonCount = (int) f_TwitterUser.NumberOfFriends; } catch (Exception ex) { var message = _("Failed to fetch user details from Twitter. Reason: "); #if LOG4NET f_Logger.Error("Connect(): " + message, ex); #endif Session.AddTextToChat(f_ProtocolChat, "-!- " + message + ex.Message); fm.SetStatus(_("Connection failed!")); Session.AddTextToChat(f_ProtocolChat, "-!- " + _("Connection failed! Reason: ") + ex.Message ); } }); ThreadPool.QueueUserWorkItem(delegate { try { // FIXME: replace with AutoResetEvent // f_TwitterUser needed for proper self detection in the // CreatePerson() method while (!HasTokens || f_TwitterUser == null) { Thread.Sleep(1000); } var message = _("Fetching friends from Twitter, please wait..."); Session.AddTextToChat(f_ProtocolChat, "-!- " + message); UpdateFriends(); message = _("Finished fetching friends."); Session.AddTextToChat(f_ProtocolChat, "-!- " + message); } catch (Exception ex) { var message = _("Failed to fetch friends from Twitter. Reason: "); #if LOG4NET f_Logger.Error("Connect(): " + message, ex); #endif Session.AddTextToChat(f_ProtocolChat, "-!- " + message + ex.Message); } }); OpenFriendsTimelineChat(); OpenRepliesChat(); OpenDirectMessagesChat(); }
public override void Reconnect(FrontendManager fm) { Trace.Call(fm); fm.SetStatus("Reconnecting..."); try { string msg; if (_IrcClient != null) { if (_IrcClient.IsConnected) { Session.AddTextToChat(_NetworkChat, "-!- Reconnecting to " + _IrcClient.Address + "..."); _IrcClient.Reconnect(true); msg = "Connection to " + _IrcClient.Address + " established"; fm.SetStatus(msg); Session.AddTextToChat(_NetworkChat, "-!- "+msg); } else { Connect(fm); } } else { fm.SetStatus("Reconnect Error"); Session.AddTextToChat(_NetworkChat, "-!- Reconnect Error"); } } catch (ConnectionException) { fm.SetStatus("Not connected!"); fm.AddTextToChat(_NetworkChat, "-!- Not connected"); } fm.UpdateNetworkStatus(); }