public void RequestAvatar(Jid userId, RequestAvatarCallback finished) { if (dontRequestIds.Contains(userId.ToString())) { return; } dontRequestIds.Add(userId.ToString()); PubSubIq metaiq = new PubSubIq(IqType.get, userId, Program.Jabber.conn.MyJID); metaiq.PubSub.Items = new Items("urn:xmpp:avatar:metadata"); Program.Jabber.conn.IqGrabber.SendIq(metaiq, (IqCB)((object unused_1, IQ result, object unused_2) => { if (result.Type != IqType.result) { finished(false, null); return; } Element info = result.SelectSingleElement("info", true); if (info == null || !info.HasAttribute("id") || !info.HasAttribute("type")) { finished(false, null); return; } this.DownloadAvatar(userId, info.GetAttribute("id"), info.GetAttribute("type"), finished); })); }
public override Vcard GetVCard(Jid jid) { ASCContext.SetCurrentTenant(jid.Server); jid = new Jid(jid.Bare.ToLowerInvariant()); var ui = ASCContext.UserManager.GetUserByUserName(jid.User); if (ui != null) { var vcard = (Vcard)cache.Get(jid.ToString()); if (vcard != null) { return(vcard); } vcard = new Vcard(); vcard.Name = new Name(ui.LastName, ui.FirstName, null); vcard.Fullname = UserFormatter.GetUserName(ui); vcard.Nickname = ui.UserName; vcard.Description = ui.Notes; if (ui.BirthDate != null) { vcard.Birthday = ui.BirthDate.Value; } vcard.JabberId = jid; if (ui.Sex.HasValue) { vcard.Gender = ui.Sex.Value ? Gender.MALE : Gender.FEMALE; } var index = ui.Contacts.FindIndex(c => string.Compare(c, "phone", true) == 0) + 1; if (0 < index && index < ui.Contacts.Count) { vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.Contacts[index])); } vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true)); var tenant = ASCContext.GetCurrentTenant(); var departments = string.Join(", ", CoreContext.UserManager.GetUserGroups(ui.ID).Select(d => HttpUtility.HtmlEncode(d.Name)).ToArray()); if (tenant != null) { vcard.Organization = new Organization(tenant.Name, departments); } vcard.Title = ui.Title; var image = PreparePhoto(ASCContext.UserManager.GetUserPhoto(ui.ID, Guid.Empty)); if (image != null) { vcard.Photo = new Photo(image, ImageFormat.Png); image.Dispose(); } cache.Insert(jid.ToString(), vcard, CACHE_TIMEOUT); return(vcard); } else { return(base.GetVCard(jid)); } }
/// <summary> /// Pending request can be removed. /// This is useful when a ressource for the callback is destroyed and /// we are not interested anymore at the result. /// </summary> /// <param name="id">ID of the Iq we are not interested anymore</param> public void Remove(Jid jid) { lock (m_grabbing) { if (m_grabbing.ContainsKey(jid.ToString())) m_grabbing.Remove(jid.ToString()); } }
/// <summary> /// Pending request can be removed. /// This is useful when a ressource for the callback is destroyed and /// we are not interested anymore at the result. /// </summary> /// <param name="id">ID of the Iq we are not interested anymore</param> public void Remove(Jid jid) { lock (m_grabbing) { if (m_grabbing.ContainsKey(jid.ToString())) { m_grabbing.Remove(jid.ToString()); } } }
public void ChatWtich_Group(Jid roomJid, string nick) { frmGroupChat f = null; if (GroupChatForms.ContainsKey(roomJid.ToString())) { f = (frmGroupChat)GroupChatForms[roomJid.ToString()]; } else { f = new frmGroupChat(roomJid, nick); } f.Show(); }
/// <summary> /// Se crea un formulario de chat /// Usauario A quiere chatear con usuario B /// </summary> /// <param name="fromJid">jabber id de A </param> /// <param name="nick">Nick de A</param> public void ChatWtich_User(Jid fromJid, string nick) { frmChat f = null; if (ChatForms.ContainsKey(fromJid.ToString())) { f = (frmChat)ChatForms[fromJid.ToString()]; } else { f = new frmChat(fromJid, nick); } f.Show(); }
public Form1(XmppClientConnection con) { InitializeComponent(); connection = con; Jid jid_ = new Jid(tb_login.Text, tb_ip.Text, connection.Resource); jid = jid_.ToString(); }
/// <summary> /// Fetch message history from the server. /// /// The 'start' and 'end' attributes MAY be specified to indicate a date range. /// /// If the 'with' attribute is omitted then collections with any JID are returned. /// /// If only 'start' is specified then all collections on or after that date should be returned. /// /// If only 'end' is specified then all collections prior to that date should be returned. /// </summary> /// <param name="pageRequest">Paging options</param> /// <param name="start">Optional start date range to query</param> /// <param name="end">Optional enddate range to query</param> /// <param name="with">Optional JID to filter archive results by</param> public XmppPage <ArchivedChatId> GetArchivedChatIds(XmppPageRequest pageRequest, DateTimeOffset?start = null, DateTimeOffset?end = null, Jid with = null) { pageRequest.ThrowIfNull(); var request = Xml.Element("list", xmlns); if (with != null) { request.Attr("with", with.ToString()); } if (start != null) { request.Attr("start", start.Value.ToXmppDateTimeString()); } if (end != null) { request.Attr("end", end.Value.ToXmppDateTimeString()); } var setNode = pageRequest.ToXmlElement(); request.Child(setNode); var response = IM.IqRequest(IqType.Get, null, null, request); if (response.Type == IqType.Error) { throw Util.ExceptionFromError(response, "Failed to get archived chat ids"); } return(new XmppPage <ArchivedChatId>(response.Data["list"], GetChatIdsFromStanza)); }
public IEnumerable <IXmppHandlerInvoker> GetInvokers(Type type, Jid jid) { using (locker.ReadLock()) { var byType = Enumerable.Empty <string>(); var byJid = Enumerable.Empty <string>(); while (type != null && type != typeof(object)) { byType = byType.Union(types.GetIdentifiers(type)); type = type.BaseType; } foreach (var pattern in jids.Keys) { if (Regex.IsMatch(jid.ToString(), pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline)) { byJid = byJid.Union(jids.GetIdentifiers(pattern)); } } return(byType.Reverse() .Intersect(byJid) .Select(id => handlers[id]) .ToArray()); } }
public frmSubscribe(XmppClientConnection con, Jid jid) { this.InitializeComponent(); this._connection = con; this._from = jid; this.lblFrom.Text = jid.ToString(); }
protected override void OnRegisterCore(XmppHandlerManager handlerManager, XmppServiceManager serviceManager, IServiceProvider serviceProvider) { var jid = new Jid(Jid.ToString()); jid.Resource = MessageAnnounceHandler.ANNOUNCE; handlerManager.AddXmppHandler(jid, messageAnnounceHandler); }
private bool PostPrivilegeChange(Jid room, Jid user, Affiliation affiliation, string reason, string nickname) { room.ThrowIfNull("room"); user.ThrowIfNull("user"); var item = Xml.Element("item") .Attr("affiliation", affiliation.ToString().ToLower()) .Attr("jid", user.ToString()); if (!string.IsNullOrWhiteSpace(nickname)) { item.Attr("nick", nickname); } if (!string.IsNullOrWhiteSpace(reason)) { item.Child(Xml.Element("reason").Text(reason)); } var queryElement = Xml.Element("query", MucNs.NsAdmin) .Child(item); Iq iq = im.IqRequest(IqType.Set, room, im.Jid, queryElement); return(iq.Type == IqType.Result); }
public void FullJidTestTest() { var jid1 = "[email protected]/resource"; Jid jid = jid1; Assert.Equal(jid.ToString(), jid1); Assert.Equal((string)jid, jid1); }
public void CloneJidTest() { const string JID1 = "[email protected]/resource"; const string JID2 = "[email protected]/resource2"; Jid jid1 = JID1; var jid2 = jid1.Clone(); Assert.Equal(jid1.ToString(), JID1); Assert.Equal(jid2.ToString(), JID1); jid2.Resource = "resource2"; jid2.User = "******"; Assert.Equal(jid1.ToString(), JID1); Assert.Equal(jid2.ToString(), JID2); }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public int Compare(object x, object y) { if (x is Jid && y is Jid) { Jid jidX = (Jid)x; Jid jidY = (Jid)y; if (jidX.ToString() == jidY.ToString()) { return(0); } else { return(String.Compare(jidX.ToString(), jidY.ToString())); } } throw new ArgumentException("the objects to compare must be Jids"); }
/// <summary> /// Adds the specified jid. /// </summary> /// <param name="jid">The jid.</param> /// <param name="comparer">The comparer.</param> /// <param name="cb">The callback.</param> /// <param name="cbArg">The callback Arguments.</param> public void Add(Jid jid, IComparer comparer, PresenceCB cb, object cbArg) { lock (m_grabbing) { if (m_grabbing.ContainsKey(jid.ToString())) return; } TrackerData td = new TrackerData(); td.cb = cb; td.data = cbArg; td.comparer = comparer; lock (m_grabbing) { m_grabbing.Add(jid.ToString(), td); } }
public void GetInfo(Jid entity, string node, MessageHandlerFunc callback) { Message m = new Message(entity.ToString(), MessageType.Iq, MessageSubType.Get); MessageNode queryNode = m.Node.AddChild("query", null); queryNode.SetAttribute("xmlns", Namespace.DiscoInfo); queryNode.SetAttribute("node", node); m_Account.Send(m, callback); }
public AceptSubscribe(XmppClientConnection con, Jid jid) { InitializeComponent(); _connection = con; _from = jid; lblFrom.Text = jid.ToString(); }
public override Vcard GetVCard(Jid jid, string id = "") { ASCContext.SetCurrentTenant(jid.Server); jid = new Jid(jid.Bare.ToLowerInvariant()); var ui = ASCContext.UserManager.GetUserByUserName(jid.User); if (ui != null) { var vcard = (Vcard)cache.Get(jid.ToString()); if (vcard != null) { return vcard; } vcard = new Vcard(); vcard.Name = new Name(ui.LastName, ui.FirstName, null); vcard.Fullname = UserFormatter.GetUserName(ui); vcard.Nickname = ui.UserName; vcard.Description = ui.Notes; if (ui.BirthDate != null) vcard.Birthday = ui.BirthDate.Value; vcard.JabberId = jid; if (ui.Sex.HasValue) { vcard.Gender = ui.Sex.Value ? Gender.MALE : Gender.FEMALE; } var index = ui.Contacts.FindIndex(c => string.Compare(c, "phone", true) == 0) + 1; if (0 < index && index < ui.Contacts.Count) { vcard.AddTelephoneNumber(new Telephone(TelephoneLocation.WORK, TelephoneType.NUMBER, ui.Contacts[index])); } vcard.AddEmailAddress(new Email(EmailType.INTERNET, ui.Email, true)); var tenant = ASCContext.GetCurrentTenant(); var departments = string.Join(", ", CoreContext.UserManager.GetUserGroups(ui.ID).Select(d => HttpUtility.HtmlEncode(d.Name)).ToArray()); if (tenant != null) vcard.Organization = new Organization(tenant.Name, departments); vcard.Title = ui.Title; if (id == null || id.IndexOf("tmtalk", StringComparison.OrdinalIgnoreCase) < 0) { var image = PreparePhoto(ASCContext.UserManager.GetUserPhoto(ui.ID, Guid.Empty)); if (image != null) { vcard.Photo = new Photo(image, ImageFormat.Png); image.Dispose(); } } cache.Insert(jid.ToString(), vcard, CACHE_TIMEOUT); return vcard; } else { return base.GetVCard(jid); } }
public void UppercaseUsernameTest() { const string user = "******"; const string server = "Server.com"; var jid = new Jid { User = user }; Assert.Equal(jid.User, user); jid.Server = server; Assert.Equal(jid.Server, server); Assert.Equal(jid.ToString(), user + "@" + server); jid.SetUser(user); jid.SetServer(server); Assert.Equal(jid.ToString(), "*****@*****.**"); }
private TreeNode FindListViewItem(Jid jid) { foreach (TreeNode lvi in treeView1.Nodes) { if (jid.ToString().ToLower() == lvi.Tag.ToString().ToLower()) { return(lvi); } } return(null); }
public void Register(Type type, Jid jid, IXmppHandlerInvoker invoker) { using (locker.WriteLock()) { var id = uniqueId.CreateId(); types.Add(type, id); jids.Add(jid.ToString(), id); handlerIds.Add(invoker.HandlerId, id); handlers.Add(id, invoker); } }
private ListViewItem FindListViewItem(Jid jid) { foreach (ListViewItem lvi in lvwRoster.Items) { if (jid.ToString().ToLower() == lvi.Tag.ToString().ToLower()) { return(lvi); } } return(null); }
/// <summary> /// Set a attribute of type Jid /// </summary> /// <param name="name"></param> /// <param name="value"></param> public void SetAttribute(string name, Jid value) { if (value != null) { this.SetAttribute(name, value.ToString()); } else { RemoveAttribute(name); } }
public void BuilldJidFromUserAndServerTest() { const string user = "******"; const string server = "server.com"; var jid = new Jid { User = user, Server = server }; Assert.Equal(jid.ToString(), user + "@" + server); }
/// <summary> /// Adds the specified jid. /// </summary> /// <param name="jid">The jid.</param> /// <param name="comparer">The comparer.</param> /// <param name="cb">The callback.</param> /// <param name="cbArg">The callback Arguments.</param> public void Add(Jid jid, IComparer comparer, PresenceCB cb, object cbArg) { lock (m_grabbing) { if (m_grabbing.ContainsKey(jid.ToString())) { return; } } TrackerData td = new TrackerData(); td.cb = cb; td.data = cbArg; td.comparer = comparer; lock (m_grabbing) { m_grabbing.Add(jid.ToString(), td); } }
/// <summary> /// Se envia la precencia a la sala /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmGroupChat_Load(object sender, EventArgs e) { if (_RoomJid != null) { Presence pres = new Presence(); Jid to = new Jid(_RoomJid.ToString()); to.Resource = m_Nickname; pres.To = to; Util.XmppServices.XmppCon.Send(pres); } }
/// <summary> /// Set a attribute of type Jid /// </summary> /// <param name="name">attribute name</param> /// <param name="jid">value of the attribute, or null to remove the attribute</param> public XmppXElement SetAttribute(string name, Jid jid) { if (jid != null) { SetAttribute(name, jid.ToString()); } else { RemoveAttribute(name); } return(this); }
public void RemoveAllOfflineMessages(Jid jid, Jid from) { var messages = GetOfflineMessages(jid); foreach (var message in messages) { if (message.From.Bare == from.ToString()) { ExecuteNonQuery(new SqlDelete("jabber_offmessage").Where("jid", GetBareJid(jid)).Where(Exp.Like("message", String.Format("from=\"{0}", message.From.Bare)))); } } lock (countCache) countCache.Remove(GetBareJid(jid)); }
/// <summary> /// this constructor is used for outgoing file transfers /// </summary> /// <param name="XmppCon"></param> /// <param name="to"></param> public frmFileTransfer(XmppClientConnection XmppCon, Jid to) { InitializeComponent(); this.Text = "Send File to " + to.ToString(); m_To = to; m_XmppCon = XmppCon; // disable commadn buttons we don't need for sending a file cmdAccept.Enabled = false; cmdRefuse.Enabled = false; ChooseFileToSend(); }
/// <summary> /// Remove a RosterItem from the roster /// </summary> /// <param name="jid">The items Jid to remove</param> /// <returns /// >returns true if the item was removed, false if it didn't exist /// and could not be removed /// </returns> public bool RemoveRosterItem(Jid jid) { if (m_Roster.ContainsKey(jid.ToString())) { RosterData d = m_Roster[jid.ToString()]; TreeNode Parent = d.RosterNode.Parent; d.RosterNode.Remove(); m_Roster.Remove(jid.ToString()); if (m_HideEmptyGroups) { if (Parent.Nodes.Count == 0) { Parent.Remove(); } } return(true); } else { return(false); } }
public void JidEscapeTest() { const string user = "******"; const string server = "server.com"; var jid = new Jid(); jid.SetUser(user); Assert.Equal(jid.User, @"gnauck\40ag-software.de"); jid.SetServer(server); Assert.Equal(jid.Server, @"server.com"); Assert.Equal(jid.ToString(), @"gnauck\[email protected]"); }
private void OnDiscoInfoResult(object sender, IQ iq, object data) { // <iq from='proxy.cachet.myjabber.net' to='[email protected]/Exodus' type='result' id='jcl_19'> // <query xmlns='http://jabber.org/protocol/disco#info'> // <identity category='proxy' name='SOCKS5 Bytestreams Service' type='bytestreams'/> // <feature var='http://jabber.org/protocol/bytestreams'/> // <feature var='http://jabber.org/protocol/disco#info'/> // </query> // </iq> if (iq.Type == IqType.result) { if (iq.Query is DiscoInfo) { DiscoInfo di = iq.Query as DiscoInfo; if (di.HasFeature(agsXMPP.Uri.MUC)) { Jid jid = iq.From; listView1.Groups.Add(jid.ToString(), jid.ToString()); discoManager.DiscoverItems(jid, new IqCB(OnDiscoRoomlist), null); } } } }
private void fm_OnFile(object sender, FileTransferEventArgs e) { logTextBox_textChange(DateTime.Now.ToString("HH:mm:ss") + " Получен запрос на получение файла!"); Jid fromJid = new Jid(xmppClient.Username, xmppClient.XmppDomain, "client"); if (e.Jid.ToString().ToLower() == fromJid.ToString().ToLower()) { workMode = e.Description; e.Directory = Path.GetDirectoryName(Application.ExecutablePath); e.Accept = true; } }
public Presence CreateExitRoomStanza(Jid room, string nickname) { var to = new Jid(room.ToString()) { Resource = nickname }; var pres = new Presence { To = to, Type = PresenceType.Unavailable }; return(pres); }
public static string GetKey(Jid jid) { return string.Format("{0}/", jid.ToString().ToLowerInvariant()); }
/// <summary> /// Allow stanzas by Jid /// </summary> /// <param name="JidToBlock"></param> /// <param name="Order"></param> /// <param name="stanza">stanzas you want to block</param> /// <returns></returns> public Item AllowByJid(Jid JidToBlock, int Order, Stanza stanza) { return new Item(Action.allow, Order, CSS.IM.XMPP.protocol.iq.privacy.Type.jid, JidToBlock.ToString(), stanza); }
public void RegisterPlayer(Jid user) { if (_registeredPlayers.Any(x => x.ToString() == user.ToString())) return; _registeredPlayers.Add(user); }
/// <summary> /// Cancels the specified file-transfer. /// </summary> /// <param name="from">From Jid</param> /// <param name="sid">Sid</param> /// <param name="to">To Jid</param> /// <exception cref="ArgumentNullException">The transfer parameter is /// null.</exception> /// <exception cref="ArgumentException">The specified transfer instance does /// not represent an active data-transfer operation.</exception> /// <exception cref="InvalidOperationException">The XmppClient instance is not /// connected to a remote host, or the XmppClient instance has not authenticated with /// the XMPP server.</exception> /// <exception cref="ObjectDisposedException">The XmppClient object has been /// disposed.</exception> public void CancelFileTransfer(string sid, Jid from, Jid to) { #if DEBUG System.Diagnostics.Debug.WriteLine("XmppClient CancelFileTransfer, sid {0}, from {1}, to {2}", sid, from.ToString(), to.ToString()); #endif AssertValid(); sid.ThrowIfNullOrEmpty("sid"); from.ThrowIfNull("from"); to.ThrowIfNull("to"); siFileTransfer.CancelFileTransfer(sid, from, to); }
public virtual UserRosterItem SaveRosterItem(Jid rosterJid, UserRosterItem item) { if (item == null) throw new ArgumentNullException("item"); try { lock (syncRoot) { if (string.IsNullOrEmpty(item.Name)) item.Name = item.Jid.Bare; rosterJid = new Jid(rosterJid.Bare.ToLowerInvariant()); ExecuteNonQuery(new SqlInsert("jabber_roster", true) .InColumnValue("jid", rosterJid.ToString()) .InColumnValue("item_jid", item.Jid.ToString()) .InColumnValue("name", item.Name) .InColumnValue("subscription", (Int32)item.Subscribtion) .InColumnValue("ask", (Int32)item.Ask) .InColumnValue("groups", string.Join(GroupSeparator, item.Groups.ToArray()))); if (!RosterItems.ContainsKey(rosterJid)) RosterItems[rosterJid] = new UserRosterItemDic(); RosterItems[rosterJid][item.Jid] = item; return item; } } catch (Exception e) { throw new JabberException("Could not save or update roster item.", e); } }
/// <summary> /// Change the Nickname in a room /// </summary> /// <param name="room"></param> /// <param name="newNick"></param> public void ChangeNickname(Jid room, string newNick) { Jid to = new Jid(room.ToString()); to.Resource = newNick; Presence pres = new Presence(); pres.To = to; m_connection.Send(pres); }
static void Main(string[] args) { XmppClientConnection xmppCon = new XmppClientConnection(); Console.Title = "Console Client"; // read the jid from the console PrintHelp("Enter you Jid ([email protected]): "); Jid jid = new Jid(Console.ReadLine()); PrintHelp(String.Format("Enter password for '{0}': ", jid.ToString())); xmppCon.Password = Console.ReadLine(); xmppCon.Username = jid.User; xmppCon.Server = jid.Server; xmppCon.AutoAgents = false; xmppCon.AutoPresence = true; xmppCon.AutoRoster = true; xmppCon.AutoResolveConnectServer = true; // Connect to the server now // !!! this is asynchronous !!! try { xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart); xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem); xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd); xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence); xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage); xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin); xmppCon.Open(); } catch (Exception e) { Console.WriteLine(e.Message); } Wait("Login to server, please wait"); PrintCommands(); bool bQuit = false; while (!bQuit) { string command = Console.ReadLine(); string[] commands = command.Split(' '); switch (commands[0].ToLower()) { case "help": PrintCommands(); break; case "quit": bQuit = true; break; case "msg": string msg = command.Substring(command.IndexOf(commands[2])); xmppCon.Send(new Message(new Jid(commands[1]), MessageType.chat, msg)); break; case "status": switch (commands[1]) { case "online": xmppCon.Show = ShowType.NONE; break; case "away": xmppCon.Show = ShowType.away; break; case "xa": xmppCon.Show = ShowType.xa; break; case "chat": xmppCon.Show = ShowType.chat; break; } string status = command.Substring(command.IndexOf(commands[2])); xmppCon.Status = status; xmppCon.SendMyPresence(); break; } } // close connection xmppCon.Close(); }
/// <summary> /// Join a chatroom /// </summary> /// <param name="room">jid of the room to join</param> /// <param name="nickname">nickname to use in the room</param> /// <param name="password">password for password protected chat rooms</param> /// <param name="disableHistory">true for joining without chat room history</param> public void JoinRoom(Jid room, string nickname, string password, bool disableHistory) { /* <presence from='[email protected]/pda' to='[email protected]/thirdwitch'> <x xmlns='http://jabber.org/protocol/muc'> <password>cauldron</password> </x> </presence> join room and request no history <presence from='[email protected]/pda' to='[email protected]/thirdwitch'> <x xmlns='http://jabber.org/protocol/muc'> <history maxchars='0'/> </x> </presence> */ Jid to = new Jid(room.ToString()); to.Resource = nickname; Presence pres = new Presence(); pres.To = to; Muc x = new Muc(); if (password != null) x.Password = password; if (disableHistory) { History hist = new History(); hist.MaxCharacters = 0; x.History = hist; } pres.AddChild(x); m_connection.Send(pres); }
public void RemoveFriend(Jid jid) { if (panel_userList.Controls.ContainsKey("FI" + jid.ToString())) { panel_userList.Controls.RemoveAt(panel_userList.Controls.IndexOfKey("FI" + jid.ToString())); UpdateControls(); } }
protected override void ProcessPlayerMoveMessage(Jid player, PlayerMoveMessage playerMoveMessage) { TournamentManager.ProcessPlayerMove(playerMoveMessage.GameId, player.ToString(), MoveFactory.GetMove(playerMoveMessage.Move)); base.ProcessPlayerMoveMessage(player, playerMoveMessage); }
/// <summary> /// Block stanzas by Jid /// </summary> /// <param name="jidToBlock"></param> /// <param name="order"></param> /// <param name="stanza">stanzas you want to block</param> /// <returns></returns> public Item BlockByJid(Jid jidToBlock, int order, Stanza stanza) { return new Item(Action.deny, order, Type.jid, jidToBlock.ToString(), stanza); }
/// <summary> /// Constructor for Outgoing Messages /// </summary> public frmMsg(XmppClientConnection con, Jid to) : this(con) { xmppCon = con; txtJid.Text = to.ToString(); }
public List<IXmppStanzaHandler> GetStanzaHandlers(Jid to, Type stanzaType) { try { locker.EnterReadLock(); var key = GetHandlerKey(to, stanzaType); if (stanzaHandlers.ContainsKey(key)) return new List<IXmppStanzaHandler>(stanzaHandlers[key]); if (to.Resource != null && to.Resource.Contains("/")) { var newTo = new Jid(to.ToString()); newTo.Resource = newTo.Resource.Substring(0, newTo.Resource.IndexOf('/')); key = GetHandlerKey(newTo, stanzaType); if (stanzaHandlers.ContainsKey(key)) return new List<IXmppStanzaHandler>(stanzaHandlers[key]); } key = GetHandlerKey(to.Bare, stanzaType); if (stanzaHandlers.ContainsKey(key)) return new List<IXmppStanzaHandler>(stanzaHandlers[key]); key = GetHandlerKey(to.Server, stanzaType); if (stanzaHandlers.ContainsKey(key)) return new List<IXmppStanzaHandler>(stanzaHandlers[key]); if (stanzaType != typeof(Stanza)) return GetStanzaHandlers(to, typeof(Stanza)); return new List<IXmppStanzaHandler>(); } finally { locker.ExitReadLock(); } }
/// <summary> /// Leave a conference room /// </summary> /// <param name="room"></param> /// <param name="nickname"></param> public void LeaveRoom(Jid room, string nickname) { Jid to = new Jid(room.ToString()); to.Resource = nickname; Presence pres = new Presence(); pres.To = to; pres.Type = PresenceType.unavailable; m_connection.Send(pres); }
/// <summary> /// Block stanzas by Jid /// </summary> /// <param name="JidToBlock"></param> /// <param name="Order"></param> /// <param name="stanza">stanzas you want to block</param> /// <returns></returns> public Item BlockByJid(Jid JidToBlock, int Order, Stanza stanza) { return new Item(Action.deny, Order, XMPPProtocol.Protocol.iq.privacy.Type.jid, JidToBlock.ToString(), stanza); }
/// <summary> /// Remove a RosterItem from the roster /// </summary> /// <param name="jid">The items Jid to remove</param> /// <returns /// >returns true if the item was removed, false if it didn't exist /// and could not be removed /// </returns> public bool RemoveRosterItem(Jid jid) { if (m_Roster.ContainsKey(jid.ToString())) { RosterData d = m_Roster[jid.ToString()]; TreeNode Parent = d.RosterNode.Parent; d.RosterNode.Remove(); m_Roster.Remove(jid.ToString()); if (m_HideEmptyGroups) { if (Parent.Nodes.Count == 0) Parent.Remove(); } return true; } else return false; }
public virtual void RemoveRosterItem(Jid rosterJid, Jid itemJid) { try { lock (syncRoot) { rosterJid = new Jid(rosterJid.Bare.ToLowerInvariant()); itemJid = new Jid(itemJid.Bare.ToLowerInvariant()); if (RosterItems.ContainsKey(rosterJid) && RosterItems[rosterJid].ContainsKey(itemJid)) { ExecuteNonQuery(new SqlDelete("jabber_roster").Where("jid", rosterJid.ToString()).Where("item_jid", itemJid.ToString())); RosterItems[rosterJid].Remove(itemJid); } } } catch (Exception e) { throw new JabberException("Could not remove roster item.", e); } }
/// <summary> /// Fetch a page of archived messages from a chat /// </summary> /// <param name="pageRequest">Paging options</param> /// <param name="with">The id of the entity that the chat was with</param> /// <param name="start">The start time of the chat</param> public ArchivedChatPage GetArchivedChat(XmppPageRequest pageRequest, Jid with, DateTimeOffset start) { pageRequest.ThrowIfNull(); with.ThrowIfNull(); var request = Xml.Element("retrieve", xmlns); request.Attr("with", with.ToString()); request.Attr("start", start.ToXmppDateTimeString()); var setNode = pageRequest.ToXmlElement(); request.Child(setNode); var response = IM.IqRequest(IqType.Get, null, null, request); if (response.Type == IqType.Error) { throw Util.ExceptionFromError(response, "Failed to get archived chat messages"); } return new ArchivedChatPage(response.Data["chat"]); }
/// <summary> /// Allow stanzas by Jid /// </summary> /// <param name="JidToBlock"> </param> /// <param name="Order"> </param> /// <param name="stanza"> stanzas you want to block </param> /// <returns> </returns> public Item AllowByJid(Jid JidToBlock, int Order, Stanza stanza) { return new Item(Action.allow, Order, Type.jid, JidToBlock.ToString(), stanza); }
/// <summary> /// /// </summary> /// <param name="jid"></param> /// <returns></returns> private ListViewItem FindListViewItem(Jid jid) { foreach (ListViewItem lvi in lvwRoster.Items) { if (jid.ToString().ToLower().Equals(lvi.Tag.ToString().ToLower())) return lvi; } return null; }
void firneItem_OpenChat(Friend friend,Jid sender, string CName) { RosterItem ritem = new RosterItem(sender); friend.Ritem = ritem; if (panel_userList.Controls.ContainsKey("FI" + friend.Ritem.Jid.Bare)) { panel_userList.Controls.RemoveByKey(CName); UpdateControls(); if (OpenChatEvent != null) { OpenChatEvent(friend, sender, CName); } } Debug.WriteLine("打开:"+sender.ToString()); }
/// <summary> /// 添加IM会议室事件 /// </summary> /// <param name="jid"></param> public void OnChatGroupAdd(Jid jid) { if (Util.Services.Finds.Contains(jid)) { return; } pal_chatGroupRef.Location = new Point(1, 3); pal_chatGroupRef.BackColor = Color.White; pal_chatGroupRef.Width = friendListView.Width - 2; pal_chatGroupRef.Height = friendListView.Height - 4; if (InvokeRequired) { BeginInvoke(new OnChatGroupAddDelegate(OnChatGroupAdd), new object[] { jid }); } ChatGroupControl chatgroup = new ChatGroupControl(); chatgroup.MJid = jid; chatgroup.TextName = jid.ToString(); chatgroup.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right))); chatgroup.BackColor = this.BackColor; chatgroup.Location = new Point(1, 56 * pal_chatGroupRef.Controls.Count); chatgroup.Name = jid.ToString(); chatgroup.Size = new Size(pal_chatGroupRef.Width - 2, 55); chatgroup.BackColor = Color.White; chatgroup.ChatGroupOpenEvent += new ChatGroupControl.ChatGroupOpenDelegate(chatgroup_ChatGroupOpenEvent); //friend.FriendInfo = item; //friend.Selecting += new FriendControl.SelectedEventHandler(friend_Selecting); //friend.ShowContextMenu += new FriendControl.ShowContextMenuEventHandler(friend_ShowContextMenu); //friend.OpenChat += new FriendControl.OpenChatEventHandler(friend_OpenChat); //friend.Conn = _connection; //friend.UpdateImage();//更新头像信息 pal_chatGroupRef.Controls.Add(chatgroup); //pal_chatGroupRef.BackColor = Color.Aqua; ///pal_chatGroupRef.Height += 56; //UpdateLayout(panel_user); }
private void tsmi发送消息_Click(object sender, EventArgs e) { if (treeView1.SelectedNode == null) return; if (treeView1.SelectedNode.Tag == null) return; Jid j = new Jid(treeView1.SelectedNode.Tag.ToString(), XmppCon.Server, null); if (!Util.ChatForms.ContainsKey(j.ToString())) { friendListView.UpdateFriendFlicker(j.User); ChatForm chat = new ChatForm(j, XmppCon, j.User); Friend friend = friendListView.Rosters[j.User]; if (friend!=null) { chat.UpdateFriendOnline(friendListView.Rosters[j.User].IsOnline); } if (msgBox.ContainsKey(j.Bare.ToString())) { chat.FristMessage(msgBox[j.Bare.ToString()]); msgBox.Remove(j.Bare.ToString()); } try { chat.Show(); } catch (Exception) { } } }
/// <summary> /// Fetch message history from the server. /// /// The 'start' and 'end' attributes MAY be specified to indicate a date range. /// /// If the 'with' attribute is omitted then collections with any JID are returned. /// /// If only 'start' is specified then all collections on or after that date should be returned. /// /// If only 'end' is specified then all collections prior to that date should be returned. /// </summary> /// <param name="pageRequest">Paging options</param> /// <param name="start">Optional start date range to query</param> /// <param name="end">Optional enddate range to query</param> /// <param name="with">Optional JID to filter archive results by</param> public XmppPage<ArchivedChatId> GetArchivedChatIds(XmppPageRequest pageRequest, DateTimeOffset? start = null, DateTimeOffset? end = null, Jid with = null) { pageRequest.ThrowIfNull(); var request = Xml.Element("list", xmlns); if (with != null) { request.Attr("with", with.ToString()); } if (start != null) { request.Attr("start", start.Value.ToXmppDateTimeString()); } if (end != null) { request.Attr("end", end.Value.ToXmppDateTimeString()); } var setNode = pageRequest.ToXmlElement(); request.Child(setNode); var response = IM.IqRequest(IqType.Get, null, null, request); if (response.Type == IqType.Error) { throw Util.ExceptionFromError(response, "Failed to get archived chat ids"); } return new XmppPage<ArchivedChatId>(response.Data["list"], GetChatIdsFromStanza); }