public void CommandConnect(CommandModel cd) { FrontendManager fm = cd.FrontendManager; var server = new ServerModel(); if (cd.DataArray.Length >= 3) { server.Username = cd.DataArray[2]; } else { NotEnoughParameters(cd); return; } if (cd.DataArray.Length >= 4) { server.Password = cd.DataArray[3]; } else { NotEnoughParameters(cd); return; } Connect(fm, server); }
public override void Connect(FrontendManager fm, ServerModel server) { Trace.Call(fm, server); if (fm == null) { throw new ArgumentNullException("fm"); } if (server == null) { throw new ArgumentNullException("server"); } _FrontendManager = fm; Host = server.Hostname; Port = server.Port; // TODO: use config for single network chat or once per network manager _NetworkChat = Session.CreateChat <ProtocolChatModel>( NetworkID, "Jabber " + Host, this ); Session.AddChat(_NetworkChat); Session.SyncChat(_NetworkChat); ApplyConfig(Session.UserConfig, server); _JabberClient.Connect(); }
public override void CloseChat(FrontendManager fm, ChatModel chatInfo) { Trace.Call(fm, chatInfo); // get real chat object from session var chat = GetChat(chatInfo.ID, chatInfo.ChatType); if (chat == null) { #if LOG4NET Logger.Error("CloseChat(): Session.GetChat(" + chatInfo.ID + ", " + chatInfo.ChatType + ")" + " returned null!"); #endif return; } switch (chat.ChatType) { case ChatType.Person: Session.RemoveChat(chat); break; case ChatType.Group: Client.LeaveRoom(chat.ID); break; } }
public override void Reconnect(FrontendManager fm) { Trace.Call(fm); _JabberClient.Close(); _JabberClient.Connect(); }
public override void Connect(FrontendManager fm, ServerModel server) { Trace.Call(fm, server); if (fm == null) { throw new ArgumentNullException("fm"); } if (server == null) { throw new ArgumentNullException("server"); } _FrontendManager = fm; _UsersAddress = server.Username; Host = server.Hostname; Port = server.Port; // TODO: use config for single network chat or once per network manager _NetworkChat = new ProtocolChatModel(NetworkID, "MSN Messenger", this); Session.AddChat(_NetworkChat); Session.SyncChat(_NetworkChat); _MsnClient.Credentials.Account = server.Username; _MsnClient.Credentials.Password = server.Password; _MsnClient.Connect(); }
public override void Connect(FrontendManager fm, ServerModel server) { Trace.Call(fm, server); if (fm == null) { throw new ArgumentNullException("fm"); } if (server == null) { throw new ArgumentNullException("server"); } _FrontendManager = fm; Host = "login.oscar.aol.com"; Port = 5190; // TODO: use config for single network chat or once per network manager _NetworkChat = new ProtocolChatModel(NetworkID, NetworkID + " Messenger", this); Session.AddChat(_NetworkChat); Session.SyncChat(_NetworkChat); _OscarSession = new OscarSession(server.Username, server.Password); _OscarSession.ClientCapabilities = Capabilities.Chat | Capabilities.OscarLib; _OscarSession.LoginCompleted += new LoginCompletedHandler(_OnLoginCompleted); _OscarSession.LoginFailed += new LoginFailedHandler(_OnLoginFailed); _OscarSession.LoginStatusUpdate += new LoginStatusUpdateHandler(_OnLoginStatusUpdate); _OscarSession.ErrorMessage += new ErrorMessageHandler(_OnErrorMessage); _OscarSession.WarningMessage += new WarningMessageHandler(_OnWarningMessage); _OscarSession.StatusUpdate += new InformationMessageHandler(_OnStatusUpdate); _OscarSession.ContactListFinished += new ContactListFinishedHandler(_OnContactListFinished); _OscarSession.Messages.MessageReceived += new MessageReceivedHandler(_OnMessageReceived); _OscarSession.Logon(Host, Port); }
protected CommandModel(SerializationInfo info, StreamingContext ctx) { SerializationReader sr = SerializationReader.GetReader(info); SetObjectData(sr); _FrontendManager = (FrontendManager)info.GetValue("_FrontendManager", typeof(FrontendManager)); _Chat = (ChatModel)info.GetValue("_Chat", typeof(ChatModel)); }
public override void OpenChat(FrontendManager fm, ChatModel chat_) { Trace.Call(fm, chat_); var room = Rooms.Single(r => r.Name.Equals(chat_.Name)); Client.Post <object>(String.Format("/room/{0}/join.json", room.Id), null); room = Client.Get <RoomResponse>(String.Format("/room/{0}.json", room.Id)).Room; var chat = Session.GetChat(room.Name, ChatType.Group, this) as GroupChatModel; if (chat == null) { chat = Session.CreateChat <GroupChatModel>(room.Id.ToString(), room.Name, this); } var bld = CreateMessageBuilder(); bld.AppendMessage(room.Topic); chat.Topic = bld.ToMessage(); Session.AddChat(chat); /* Fill what we know about the users, this is only the currently-connected ones */ lock (Users) { foreach (User user in room.Users) { if (!Users.ContainsKey(user.Id)) { Users[user.Id] = CreatePerson(user); } Session.AddPersonToGroupChat(chat, Users[user.Id]); } } /* Show the recent messages, then go live. FIXME: race condition */ var recent = Client.Get <MessagesResponse>(String.Format("/room/{0}/recent.json", chat.ID)).Messages; foreach (Message message in recent) { ShowMessage(this, new MessageReceivedEventArgs(chat, message)); } Session.SyncChat(chat); chat.IsSynced = true; // Let the part and join messages take affect var stream = new CampfireEventStream(chat, BaseUri, new NetworkCredential(Key, "X")); lock (EventStreams) EventStreams.Add(chat, stream); stream.MessageReceived += ShowMessage; stream.ErrorReceived += ShowError; stream.Start(); }
public override void CloseChat(FrontendManager fm, ChatModel ChatInfo) { var chat = GetChat(ChatInfo.ID, ChatType.Group); Client.Post <object>(String.Format("/room/{0}/leave.json", chat.ID), null); Session.RemoveChat(chat); lock (EventStreams) { var stream = EventStreams[chat]; stream.Dispose(); EventStreams.Remove(chat); } }
public override void CloseChat(FrontendManager fm, ChatModel chat) { Trace.Call(fm, chat); if (chat.ChatType == ChatType.Group) { _ConferenceManager.GetRoom(chat.ID + "/" + _JabberClient.User).Leave("Closed"); } else { Session.RemoveChat(chat); } }
public CommandModel(FrontendManager fm, ChatModel chat, string cmdChar, string data) { Trace.Call(fm, chat == null ? "(null)" : chat.GetType().ToString(), cmdChar, data); _Data = data; _CommandCharacter = cmdChar; _FrontendManager = fm; _Chat = chat; try { EnhancedParse(data); } catch (FormatException) { SimpleParse(data); } }
public override void Reconnect(FrontendManager fm) { Trace.Call(fm); var msg = CreateMessageBuilder(). AppendEventPrefix(). AppendText(_("Reconnecting to {0}..."), Server.Hostname). ToMessage(); Session.AddMessageToChat(Chat, msg); try { Client.Disconnect(); Connect(); } catch (Exception ex) { #if LOG4NET Logger.Error("Reconnect(): Exception during reconnect", ex); #endif } }
public CommandModel(FrontendManager fm, ChatModel chat, string cmdChar, string data) { Trace.Call(fm, chat == null ? "(null)" : chat.GetType().ToString(), cmdChar, data); _Data = data; _DataArray = data.Split(new char[] {' '}); _Parameter = String.Join(" ", _DataArray, 1, _DataArray.Length - 1); _CommandCharacter = cmdChar; if (data.StartsWith(cmdChar) && !data.StartsWith(cmdChar + cmdChar)) { _IsCommand = true; _Command = (_DataArray[0].Length > cmdChar.Length) ? _DataArray[0].Substring(cmdChar.Length).ToLower() : String.Empty; } else if (data.StartsWith(cmdChar + cmdChar)) { _Data = data.Substring(cmdChar.Length); _DataArray[0] = _DataArray[0].Substring(cmdChar.Length); } _FrontendManager = fm; _Chat = chat; }
public override void OpenChat(FrontendManager fm, ChatModel chat) { Trace.Call(fm, chat); switch (chat.ChatType) { case ChatType.Person: var personChat = (PersonChatModel)GetChat(chat.ID, ChatType.Person); if (personChat != null) { return; } var person = CreatePerson(chat.ID); personChat = new PersonChatModel(person, chat.ID, chat.ID, this); personChat.InitMessageBuffer(MessageBufferPersistencyType.Volatile); Session.AddChat(personChat); Session.SyncChat(personChat); break; case ChatType.Group: Client.JoinRoom(chat.ID); break; } }
public CommandModel(FrontendManager fm, ChatModel chat, string cmdChar, string data) { Trace.Call(fm, chat == null ? "(null)" : chat.GetType().ToString(), cmdChar, data); _Data = data; _DataArray = data.Split(new char[] { ' ' }); _Parameter = String.Join(" ", _DataArray, 1, _DataArray.Length - 1); _CommandCharacter = cmdChar; if (data.StartsWith(cmdChar) && !data.StartsWith(cmdChar + cmdChar)) { _IsCommand = true; _Command = (_DataArray[0].Length > cmdChar.Length) ? _DataArray[0].Substring(cmdChar.Length).ToLower() : String.Empty; } else if (data.StartsWith(cmdChar + cmdChar)) { _Data = data.Substring(cmdChar.Length); _DataArray[0] = _DataArray[0].Substring(cmdChar.Length); } _FrontendManager = fm; _Chat = chat; }
public override void OpenChat(FrontendManager fm, ChatModel chat) { Trace.Call(fm, chat); throw new NotImplementedException(); }
public static void ConnectEngineToGUI() { if (IsLocalEngine) { // HACK: SessionManager.Register() is not used for local engines _LocalSession.RegisterFrontendUI(_MainWindow.UI); } SyncConfig(); _FrontendManager = _Session.GetFrontendManager(_MainWindow.UI); _FrontendManager.Sync(); // MS .NET doesn't like this with Remoting? if (Type.GetType("Mono.Runtime") != null) { // when are running on Mono, all should be good if (_UserConfig.IsCaching) { // when our UserConfig is cached, we need to invalidate the cache // DISABLED: see FrontendManager._OnConfigChanged //_FrontendManager.ConfigChangedDelegate = SyncConfig; } } _MainWindow.ShowAll(); // make sure entry got attention :-P _MainWindow.Entry.HasFocus = true; // local sessions can't have network issues :) if (_Session != _LocalSession) { _FrontendManagerCheckerQueue = new TaskQueue("FrontendManagerCheckerQueue"); _FrontendManagerCheckerQueue.AbortedEvent += delegate { #if LOG4NET _Logger.Debug("_FrontendManagerCheckerQueue.AbortedEvent(): task queue aborted!"); #endif }; _FrontendManagerCheckerQueue.ExceptionEvent += delegate(object sender, TaskQueueExceptionEventArgs e) { #if LOG4NET _Logger.Error("Exception in TaskQueue: ", e.Exception); _Logger.Error("Inner-Exception: ", e.Exception.InnerException); #endif Frontend.ShowException(e.Exception); }; _FrontendManagerCheckerQueue.Queue(delegate { // keep looping as long as the checker returns true while (CheckFrontendManagerStatus()) { // FIXME: bail out somehow when we lost the connection // without an exception in the meantime // only check once per minute Thread.Sleep(60 * 1000); } #if LOG4NET _Logger.Debug("_FrontendManagerCheckerQueue(): " + "CheckFrontendManagerStatus() returned false, "+ "time to say good bye!"); #endif }); } MainWindow.ChatViewManager.IsSensitive = true; }
public override void CloseChat(FrontendManager fm, ChatModel chat) { throw new System.NotImplementedException(); }
public override void Connect(FrontendManager fm, string host, int port, string username, string password) { Trace.Call(fm, host, port, username, password); _FrontendManager = fm; Host = "login.oscar.aol.com"; Port = 5190; // TODO: use config for single network chat or once per network manager _NetworkChat = new ProtocolChatModel(NetworkID, NetworkID + " Messenger", this); Session.AddChat(_NetworkChat); Session.SyncChat(_NetworkChat); _OscarSession = new OscarSession(username, password); _OscarSession.ClientCapabilities = Capabilities.Chat | Capabilities.OscarLib; _OscarSession.LoginCompleted += new LoginCompletedHandler(_OnLoginCompleted); _OscarSession.LoginFailed += new LoginFailedHandler(_OnLoginFailed); _OscarSession.LoginStatusUpdate += new LoginStatusUpdateHandler(_OnLoginStatusUpdate); _OscarSession.ErrorMessage += new ErrorMessageHandler(_OnErrorMessage); _OscarSession.WarningMessage += new WarningMessageHandler(_OnWarningMessage); _OscarSession.StatusUpdate += new InformationMessageHandler(_OnStatusUpdate); _OscarSession.ContactListFinished += new ContactListFinishedHandler(_OnContactListFinished); _OscarSession.Messages.MessageReceived += new MessageReceivedHandler(_OnMessageReceived); _OscarSession.Logon(Host, Port); }
public override void Connect(FrontendManager fm, ServerModel server) { Trace.Call(fm, server); Network = server.Hostname.Substring(0, server.Hostname.IndexOf('.')); Host = server.Hostname; BaseUri = new Uri(String.Format("https://{0}", Host)); NetworkChat = new ProtocolChatModel(Network, "Campfire " + Network, this); NetworkChat.InitMessageBuffer(MessageBufferPersistencyType.Volatile); NetworkChat.ApplyConfig(Session.UserConfig); Session.AddChat(NetworkChat); Session.SyncChat(NetworkChat); var msg = _("Connecting to campfire... "); if (fm != null) { fm.SetStatus(msg); } var bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg); Session.AddMessageToChat(NetworkChat, bld.ToMessage()); if (!server.ValidateServerCertificate) { var whitelist = Session.CertificateValidator.HostnameWhitelist; lock (whitelist) { // needed for favicon if (!whitelist.Contains("campfirenow.com")) { whitelist.Add("campfirenow.com"); } // needed for receiving messages if (!whitelist.Contains("streaming.campfirenow.com")) { whitelist.Add("streaming.campfirenow.com"); } if (!whitelist.Contains(Host)) { whitelist.Add(Host); } } } Client = new JsonServiceClient(BaseUri.AbsoluteUri); var creds = new NetworkCredential(server.Username, server.Password); Client.Credentials = creds; try { var me = Client.Get <UserResponse>("/users/me.json").User; Key = me.Api_Auth_Token; Me = CreatePerson(me); // The blue color is hardcoded for now Me.IdentityNameColored.ForegroundColor = new TextColor(0x0000FF); Me.IdentityNameColored.BackgroundColor = TextColor.None; Me.IdentityNameColored.Bold = true; } catch (Exception e) { FailedToConnect("Failed to connect to Campfire", e); return; } Client.Credentials = new NetworkCredential(Key, "X"); msg = _("Connected to campfire"); if (fm != null) { fm.SetStatus(msg); } bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg); Session.AddMessageToChat(NetworkChat, bld.ToMessage()); // Campfire lets us know what channels the user is currently in, so // connect to those rooms automatically Rooms = Client.Get <RoomsResponse>("/rooms.json").Rooms; RoomsUpdated = DateTime.Now; var myrooms = Client.Get <RoomsResponse>("/presence.json").Rooms; if (myrooms.Length > 0) { bld = CreateMessageBuilder(). AppendEventPrefix(). AppendText("Present in {0}", String.Join(", ", myrooms.Select(r => r.Name).ToArray()) ); Session.AddMessageToChat(NetworkChat, bld.ToMessage()); } foreach (var room in myrooms) { var chat = new GroupChatModel(room.Id.ToString(), room.Name, null); OpenChat(fm, chat); } }
public void CommandConnect(CommandModel cd) { FrontendManager fm = cd.FrontendManager; var server = new XmppServerModel(); if (cd.DataArray.Length >= 3) { server.Hostname = cd.DataArray[2]; } else { NotEnoughParameters(cd); return; } if (cd.DataArray.Length >= 4) { try { server.Port = Int32.Parse(cd.DataArray[3]); } catch (FormatException) { fm.AddTextToChat( cd.Chat, "-!- " + String.Format( _("Invalid port: {0}"), cd.DataArray[3])); return; } } else { NotEnoughParameters(cd); return; } if (cd.DataArray.Length >= 5) { server.Username = cd.DataArray[4]; } else { NotEnoughParameters(cd); return; } if (cd.DataArray.Length >= 6) { server.Password = cd.DataArray[5]; } else { NotEnoughParameters(cd); return; } if (cd.DataArray.Length >= 7) { server.Resource = cd.DataArray[6]; } Connect(fm, server); }
public override void Connect(FrontendManager fm, ServerModel server) { throw new System.NotImplementedException(); }
public override void Connect(FrontendManager fm, ServerModel server) { Trace.Call(fm, server); Server = server; Username = server.Username; var chatName = String.Format("{0} {1}", Protocol, NetworkID); ProtocolChat = new ProtocolChatModel(NetworkID, chatName, this); ProtocolChat.InitMessageBuffer(MessageBufferPersistencyType.Volatile); Session.AddChat(Chat); Session.SyncChat(Chat); try { string url; if (server.Hostname.StartsWith("http://") || server.Hostname.StartsWith("https://")) { url = server.Hostname; } else { if (server.UseEncryption && server.Port == 443) { url = String.Format("https://{0}", server.Hostname); } else if (server.UseEncryption) { url = String.Format("https://{0}:{1}", server.Hostname, server.Port); } else if (!server.UseEncryption && server.Port == 80) { url = String.Format("http://{0}", server.Hostname); } else { url = String.Format("http://{0}:{1}", server.Hostname, server.Port); } } // HACK: SignalR's ServerSentEventsTransport times out on Mono // for some reason and then fallbacks to LongPollingTransport // this takes 10 seconds though, so let's go LP directly Func <IClientTransport> transport = null; if (Type.GetType("Mono.Runtime") == null) { transport = () => new AutoTransport(new DefaultHttpClient()); } else { transport = () => new LongPollingTransport(); } var authProvider = new DefaultAuthenticationProvider(url); Client = new JabbRClient(url, authProvider, transport); Client.AutoReconnect = true; Client.MessageReceived += OnMessageReceived; Client.MeMessageReceived += OnMeMessageReceived; Client.UserLeft += OnUserLeft; Client.UserJoined += OnUserJoined; Client.JoinedRoom += OnJoinedRoom; Client.PrivateMessage += OnPrivateMessage; Me = CreatePerson(Username); Me.IdentityNameColored.ForegroundColor = new TextColor(0, 0, 255); Me.IdentityNameColored.BackgroundColor = TextColor.None; Me.IdentityNameColored.Bold = true; Connect(); } catch (Exception ex) { #if LOG4NET Logger.Error(ex); #endif var msg = CreateMessageBuilder(). AppendEventPrefix(). AppendErrorText(_("Connection failed! Reason: {0}"), ex.Message). ToMessage(); Session.AddMessageToChat(ProtocolChat, msg); } }
public override void Reconnect(FrontendManager fm) { Trace.Call(fm); }
public override void CloseChat(FrontendManager fm, ChatModel chat) { Trace.Call(fm, chat); throw new NotImplementedException(); }
public override void OpenChat(FrontendManager fm, ChatModel chat) { throw new System.NotImplementedException(); }
public override void Disconnect(FrontendManager fm) { throw new System.NotImplementedException(); }
public override void Disconnect(FrontendManager fm) { Trace.Call(fm); Client.Disconnect(); }
public override void OpenChat(FrontendManager fm, ChatModel chat) { Trace.Call(fm, chat); if (chat.ID == "Contacts") { OpenContactChat(); return; } CommandModel cmd = new CommandModel(fm, NetworkChat, chat.ID); switch (chat.ChatType) { case ChatType.Person: CommandMessageQuery(cmd); break; case ChatType.Group: CommandJoin(cmd); break; } }
public abstract void CloseChat(FrontendManager fm, ChatModel chat);
public static void ConnectEngineToGUI() { _FrontendManager = _Session.GetFrontendManager(_MainWindow.UI); _FrontendManager.Sync(); if (_UserConfig.IsCaching) { // when our UserConfig is cached, we need to invalidate the cache _FrontendManager.ConfigChangedDelegate = new SimpleDelegate(_UserConfig.ClearCache); } // make sure entry got attention :-P // BUG: MonoCurses //_MainWindow.Entry.HasFocus = true; }
public static void Init(string[] args) { System.Threading.Thread.CurrentThread.Name = "Main"; if (!(args.Length >= 1)) { Console.Error.WriteLine("Usage: smuxi-test.exe profile"); Environment.Exit(1); } #if LOG4NET _Logger.Info("smuxi-test starting"); #endif _FrontendConfig = new FrontendConfig("Test"); _FrontendConfig.Load(); string profile = args[0]; if (String.IsNullOrEmpty(profile)) { Console.Error.WriteLine("profile parameter must not be empty!"); Environment.Exit(1); } IFrontendUI ui = new TestUI(); Session session = null; if (profile == "local") { Engine.Engine.Init(); session = new Engine.Session(Engine.Engine.Config, Engine.Engine.ProtocolManagerFactory, "local"); session.RegisterFrontendUI(ui); } else { // remote engine EngineManager engineManager = new EngineManager(_FrontendConfig, ui); engineManager.Connect(profile); session = engineManager.Session; } if (session == null) { Console.Error.WriteLine("Session is null, something went wrong setting up or connecting to the engine!"); Environment.Exit(1); } _Session = session; _UserConfig = session.UserConfig; _FrontendManager = session.GetFrontendManager(ui); _FrontendManager.Sync(); if (_UserConfig.IsCaching) { // when our UserConfig is cached, we need to invalidate the cache _FrontendManager.ConfigChangedDelegate = new SimpleDelegate(_UserConfig.ClearCache); } while (true) { string line = Console.ReadLine(); // TODO: remove the entered line from output //Console.WriteLine(Escape+"M"); _ExecuteCommand(line); } }
public override void Connect(FrontendManager fm, string host, int port, string username, string password) { Trace.Call(fm, host, port, username, password); _UsersAddress = username; _FrontendManager = fm; Host = host; Port = port; // TODO: use config for single network chat or once per network manager _NetworkChat = new ProtocolChatModel(NetworkID, "MSN Messenger", this); Session.AddChat(_NetworkChat); Session.SyncChat(_NetworkChat); _MsnClient.Credentials.Account = username; _MsnClient.Credentials.Password = password; _MsnClient.Connect(); }
public CommandModel(FrontendManager fm, ChatModel chat, string parameter) : this(fm, chat, "/", "/cmd " + parameter) { }
public override void Connect(FrontendManager fm, ServerModel server) { Trace.Call(fm, server); Network = server.Hostname.Substring(0, server.Hostname.IndexOf('.')); Host = server.Hostname; BaseUri = new Uri(String.Format("https://{0}", Host)); NetworkChat = new ProtocolChatModel(Network, "Campfire " + Network, this); NetworkChat.InitMessageBuffer(MessageBufferPersistencyType.Volatile); NetworkChat.ApplyConfig(Session.UserConfig); Session.AddChat(NetworkChat); Session.SyncChat(NetworkChat); var msg = _("Connecting to campfire... "); if (fm != null) { fm.SetStatus(msg); } var bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg); Session.AddMessageToChat(NetworkChat, bld.ToMessage()); if (!server.ValidateServerCertificate) { var whitelist = Session.CertificateValidator.HostnameWhitelist; lock (whitelist) { // needed for favicon if (!whitelist.Contains("campfirenow.com")) { whitelist.Add("campfirenow.com"); } // needed for receiving messages if (!whitelist.Contains("streaming.campfirenow.com")) { whitelist.Add("streaming.campfirenow.com"); } if (!whitelist.Contains(Host)) { whitelist.Add(Host); } } } Client = new JsonServiceClient(BaseUri.AbsoluteUri); var creds = new NetworkCredential(server.Username, server.Password); Client.Credentials = creds; try { var me = Client.Get<UserResponse>("/users/me.json").User; Key = me.Api_Auth_Token; Me = CreatePerson(me); // The blue color is hardcoded for now Me.IdentityNameColored.ForegroundColor = new TextColor(0x0000FF); Me.IdentityNameColored.BackgroundColor = TextColor.None; Me.IdentityNameColored.Bold = true; } catch (Exception e) { FailedToConnect("Failed to connect to Campfire", e); return; } Client.Credentials = new NetworkCredential(Key, "X"); msg = _("Connected to campfire"); if (fm != null) { fm.SetStatus(msg); } bld = CreateMessageBuilder().AppendEventPrefix().AppendText(msg); Session.AddMessageToChat(NetworkChat, bld.ToMessage()); // Campfire lets us know what channels the user is currently in, so // connect to those rooms automatically Rooms = Client.Get<RoomsResponse>("/rooms.json").Rooms; RoomsUpdated = DateTime.Now; var myrooms = Client.Get<RoomsResponse>("/presence.json").Rooms; if (myrooms.Length > 0) { bld = CreateMessageBuilder(). AppendEventPrefix(). AppendText("Present in {0}", String.Join(", ", myrooms.Select(r => r.Name).ToArray()) ); Session.AddMessageToChat(NetworkChat, bld.ToMessage()); } foreach (var room in myrooms) { var chat = new GroupChatModel(room.Id.ToString(), room.Name, null); OpenChat(fm, chat); } }
public override void Connect(FrontendManager fm, string server, int port, string user, string pass) { Trace.Call(fm, server, port, user, pass); string[] nicks = (string[]) Session.UserConfig["Connection/Nicknames"]; Connect(fm, server, port, nicks, user, pass); }
public override void Disconnect(FrontendManager fm) { Trace.Call(fm); _OscarSession.Logoff(); }
public override void Connect(FrontendManager fm, ServerModel server) { Trace.Call(fm, server); if (fm == null) { throw new ArgumentNullException("fm"); } if (server == null) { throw new ArgumentNullException("server"); } if (server is XmppServerModel) { Server = (XmppServerModel) server; } else { Server = new XmppServerModel(); if (server.ServerID != null) { Server.Load(Session.UserConfig, server.ServerID); } // HACK: previous line overwrites any passed values with the values from config // thus we have to copy the original values: Server.Hostname = server.Hostname; Server.Network = server.Network; Server.OnConnectCommands = server.OnConnectCommands; Server.OnStartupConnect = server.OnStartupConnect; Server.Password = server.Password; Server.Port = server.Port; Server.Protocol = server.Protocol; Server.ServerID = server.ServerID; Server.UseEncryption = server.UseEncryption; Server.Username = server.Username; Server.ValidateServerCertificate = server.ValidateServerCertificate; } Host = server.Hostname; Port = server.Port; ApplyConfig(Session.UserConfig, Server); // TODO: use config for single network chat or once per network manager NetworkChat = Session.CreateChat<ProtocolChatModel>( NetworkID, "Jabber " + Host, this ); Session.AddChat(NetworkChat); Session.SyncChat(NetworkChat); OpenContactChat(); if (!String.IsNullOrEmpty(JabberClient.ProxyHost)) { var builder = CreateMessageBuilder(); builder.AppendEventPrefix(); builder.AppendText(_("Using proxy: {0}:{1}"), JabberClient.ProxyHost, JabberClient.ProxyPort); Session.AddMessageToChat(Chat, builder.ToMessage()); } JabberClient.Connect(); }
public void Connect(FrontendManager fm, string server, int port, string[] nicks, string user, string pass) { Trace.Call(fm, server, port, nicks, user, pass); _FrontendManager = fm; _Host = server; _Port = port; _Nicknames = nicks; _Username = user; _Password = pass; // add fallbacks if only one nick was specified, else we get random // number nicks when nick collisions happen if (_Nicknames.Length == 1) { _Nicknames = new string[] { _Nicknames[0], _Nicknames[0] + "_", _Nicknames[0] + "__" }; } // TODO: use config for single network chat or once per network manager var servers = new ServerListController(Session.UserConfig); var serverModel = servers.GetServer(Protocol, server); _ServerModel = serverModel; ApplyConfig(Session.UserConfig, serverModel); string network; if (serverModel != null && !String.IsNullOrEmpty(serverModel.Network)) { network = serverModel.Network; } else { network = server; } _Network = network; _NetworkChat = new ProtocolChatModel(network, "IRC " + network, this); // BUG: race condition when we use Session.AddChat() as it pushes this already // to the connected frontend and the frontend will sync and get the page 2 times! //Session.Chats.Add(_NetworkChat); // NOTABUG: the frontend manager needs to take care for that Session.AddChat(_NetworkChat); Session.SyncChat(_NetworkChat); _RunThread = new Thread(new ThreadStart(_Run)); _RunThread.IsBackground = true; _RunThread.Name = "IrcProtocolManager ("+server+":"+port+") listener"; _RunThread.Start(); _LagWatcherThread = new Thread(new ThreadStart(_LagWatcher)); _LagWatcherThread.Name = "IrcProtocolManager ("+server+":"+port+") lag watcher"; _LagWatcherThread.Start(); }
public override void Disconnect(FrontendManager fm) { Trace.Call(fm); _JabberClient.Close(false); }
public override void CloseChat(FrontendManager fm, ChatModel chat) { Trace.Call(fm, chat); if (chat == ContactChat) { Session.RemoveChat(chat); ContactChat = null; } else if (chat.ChatType == ChatType.Group) { ConferenceManager.GetRoom(chat.ID+"/"+JabberClient.User).Leave("Closed"); } else { Session.RemoveChat(chat); } }
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 override void Disconnect(FrontendManager fm) { Trace.Call(fm); JabberClient.Close(false); }
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 override void Reconnect(FrontendManager fm) { Trace.Call(fm); JabberClient.Close(); JabberClient.Connect(); }
public override void OpenChat(FrontendManager fm, ChatModel chat) { Trace.Call(fm, chat); CommandModel cmd = new CommandModel(fm, _NetworkChat, chat.ID); switch (chat.ChatType) { case ChatType.Person: CommandMessage(cmd); break; case ChatType.Group: CommandJoin(cmd); break; } }
public static void DisconnectEngineFromGUI() { _FrontendManager.IsFrontendDisconnecting = true; //_Session.DeregisterFrontendUI(_MainWindow.UI); //_MainWindow.Hide(); //_MainWindow.Notebook.RemoveAllPages(); _FrontendManager = null; _Session = null; }
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 CloseChat(FrontendManager fm, ChatModel ChatInfo) { var chat = GetChat(ChatInfo.ID, ChatType.Group); Client.Post<object>(String.Format("/room/{0}/leave.json", chat.ID), null); Session.RemoveChat(chat); lock (EventStreams) { var stream = EventStreams[chat]; stream.Dispose(); EventStreams.Remove(chat); } }
public override void CloseChat(FrontendManager fm, ChatModel chatInfo) { Trace.Call(fm, chatInfo); if (fm == null) { throw new ArgumentNullException("fm"); } if (chatInfo == null) { throw new ArgumentNullException("chatInfo"); } // get real chat object from session var chat = GetChat(chatInfo.ID, chatInfo.ChatType); if (chat == null) { #if LOG4NET _Logger.Error("CloseChat(): Session.GetChat(" + chatInfo.ID + ", " + chatInfo.ChatType + ")" + " returned null!"); #endif return; } if (!chat.IsEnabled) { Session.RemoveChat(chat); return; } switch (chat.ChatType) { case ChatType.Person: Session.RemoveChat(chat); break; case ChatType.Group: CommandModel cmd = new CommandModel(fm, _NetworkChat, chat.ID); CommandPart(cmd); break; } }
public override void OpenChat(FrontendManager fm, ChatModel chat_) { Trace.Call(fm, chat_); var room = Rooms.Single(r => r.Name.Equals(chat_.Name)); Client.Post<object>(String.Format("/room/{0}/join.json", room.Id), null); room = Client.Get<RoomResponse>(String.Format("/room/{0}.json", room.Id)).Room; var chat = Session.GetChat(room.Name, ChatType.Group, this) as GroupChatModel; if (chat == null) chat = Session.CreateChat<GroupChatModel>(room.Id.ToString(), room.Name, this); var bld = CreateMessageBuilder(); bld.AppendMessage(room.Topic); chat.Topic = bld.ToMessage(); Session.AddChat(chat); /* Fill what we know about the users, this is only the currently-connected ones */ lock (Users) { foreach (User user in room.Users) { if (!Users.ContainsKey(user.Id)) Users[user.Id] = CreatePerson(user); Session.AddPersonToGroupChat(chat, Users[user.Id]); } } /* Show the recent messages, then go live. FIXME: race condition */ var recent = Client.Get<MessagesResponse>(String.Format("/room/{0}/recent.json", chat.ID)).Messages; foreach (Message message in recent) ShowMessage(this, new MessageReceivedEventArgs(chat, message)); Session.SyncChat(chat); chat.IsSynced = true; // Let the part and join messages take affect var stream = new CampfireEventStream(chat, BaseUri, new NetworkCredential(Key, "X")); lock (EventStreams) EventStreams.Add(chat, stream); stream.MessageReceived += ShowMessage; stream.ErrorReceived += ShowError; stream.Start(); }
private void _Run() { Trace.Call(); try { Connect(_FrontendManager); while (_Listening) { try { _Listen(); #if LOG4NET _Logger.Warn("_Run(): _Listen() returned."); #endif } catch (ThreadAbortException ex) { throw; } catch (Exception ex) { #if LOG4NET _Logger.Error("_Run(): exception in _Listen() occurred!" ,ex); #endif Reconnect(_FrontendManager); } // sleep for 10 seconds, we don't want to be abusive System.Threading.Thread.Sleep(10000); } } catch (ThreadAbortException ex) { #if LOG4NET _Logger.Debug("_Run(): thread aborted"); #endif } catch (Exception ex) { #if LOG4NET _Logger.Error(ex); #endif } // don't need the FrontendManager anymore _FrontendManager = null; }
public abstract void Connect(FrontendManager fm, ServerModel server);
public abstract void Disconnect(FrontendManager fm);
public static void DisconnectEngineFromGUI(bool cleanly) { Trace.Call(cleanly); IsDisconnecting = true; MainWindow.ChatViewManager.IsSensitive = false; if (cleanly) { try { // sync tab positions if (!IsLocalEngine && !UseLowBandwidthMode) { _MainWindow.Notebook.SyncPagePositions(); } if (_FrontendManager != null) { _FrontendManager.IsFrontendDisconnecting = true; } if (_Session != null) { _Session.DeregisterFrontendUI(_MainWindow.UI); } } catch (System.Net.Sockets.SocketException) { // ignore as the connection is maybe already broken } catch (System.Runtime.Remoting.RemotingException) { // ignore as the connection is maybe already broken } } if (_FrontendManagerCheckerQueue != null) { _FrontendManagerCheckerQueue.Dispose(); } _MainWindow.ChatViewManager.Clear(); _MainWindow.UpdateProgressBar(); // make sure no stray SSH tunnel leaves behind _MainWindow.EngineManager.Disconnect(); _MainWindow.NetworkStatus = null; _MainWindow.Status = _("Disconnected from engine."); _FrontendManager = null; Session = null; IsDisconnecting = false; }
public abstract void OpenChat(FrontendManager fm, ChatModel chat);