private void Prec(object sender, Presence p) { if (p.Type == agsXMPP.protocol.client.PresenceType.subscribe) { PresenceManager OnUser = new PresenceManager(x); if (AutoAccept) { try { Message(owner, p.From.User + " sent you a friend request."); OnUser.ApproveSubscriptionRequest(p.From); Message(owner, p.From.User + " is accepted now"); } catch { } } else { try { Message(owner, p.From.User + " sent you a friend request."); addeduserlist.Text += p.From.User + "\n"; } catch { } } } else if (p.Type == PresenceType.subscribed) { Message(owner, p.From.User + "@nimbuzz.com accepted your friend request."); } else if (p.Type == PresenceType.unsubscribed) { // Message(owner, "" + p.From.User + "@nimbuzz.com has deleted you from his/her friend list."); } }
//用户状态事件 void objXmpp_OnPresence(object sender, agsXMPP.protocol.client.Presence pres) { if (pres.Type == PresenceType.available)//当服务端在线时 { //UserStatus(pres); if (pres.From.Bare == strMonitorServer) { //thSendMessage.IsBackground = false; if (thSendMessage == null) { Monitor_Start(); } else if (thSendMessage.ThreadState == ThreadState.Suspended) { thSendMessage.Resume(); } } } else if (pres.Type == PresenceType.unavailable)//当服务端离线时 { if (pres.From.Bare == strMonitorServer) { thSendMessage.Suspend(); } } else if (pres.Type == PresenceType.subscribe)//自动处理加好友请求 { PresenceManager PM = new PresenceManager(objXmpp); PM.ApproveSubscriptionRequest(new Jid(pres.From.ToString()));//同意订阅 PM.Subscribe(new Jid(pres.From.ToString())); } }
private void cmdApprove_Click(object sender, EventArgs e) { PresenceManager pm = new PresenceManager(_connection); pm.ApproveSubscriptionRequest(_from); this.Close(); }
/// <summary> /// Accept a friend request /// </summary> /// <param name="jid"></param> public void Approve(string jid) { Log.Info("Approving friend request " + jid); presenceManager.ApproveSubscriptionRequest(jid); Log.Info("Subscribing to " + jid); presenceManager.Subscribe(jid); }
public void HandleAuthorizationsRequest(VsJid id) { var to = XmppIdConverter.Convert(id); var name = GetInterlocutor(id).Name; _queue.PushToFront(new AuthorizationRequestMessage( name, () => _presenceManager.ApproveSubscriptionRequest(to), () => _presenceManager.RefuseSubscriptionRequest(to))); }
//状态处理 void objXmpp_OnPresence(object sender, Presence pres) { G_Status("", String.Format("Got presence from: {0}", pres.From.ToString())); G_Status("", String.Format("type: {0}", pres.Type.ToString())); G_Status("", String.Format("status: {0}", pres.Status)); //自动处理加好友请求 if (pres.Type == PresenceType.subscribe) { PresenceManager PM = new PresenceManager(objXmpp); PM.ApproveSubscriptionRequest(new Jid(pres.From.ToString()));//同意订阅 PM.Subscribe(new Jid(pres.From.ToString())); } //PresenceType.available 在线 //PresenceType.unavailable 离线 }
void objXmpp_OnPresence(object sender, agsXMPP.protocol.client.Presence pres) { if (pres.Type == PresenceType.available) { UserStatus(pres); } else if (pres.Type == PresenceType.unavailable) { UserStatus(pres); } else if (pres.Type == PresenceType.subscribe)//自动处理加好友请求 { PresenceManager PM = new PresenceManager(objXmpp); PM.ApproveSubscriptionRequest(new Jid(pres.From.ToString()));//同意订阅 PM.Subscribe(new Jid(pres.From.ToString())); } }
private void Presence(object sender, Presence pFrom) { if (pFrom.Type == agsXMPP.protocol.client.PresenceType.subscribe) { PresenceManager pr = new PresenceManager(x); if (this.opti1.ToLower() == "on") { pr.ApproveSubscriptionRequest(pFrom.From); } else if (this.opti1 == "off") { pr.RefuseSubscriptionRequest(pFrom.From); } else { pr.RefuseSubscriptionRequest(pFrom.From); } } }
public void AcceptRequest(string jid, string nickname, string group) { _presence.ApproveSubscriptionRequest(jid); Add(jid, nickname, group); }
private void xmppClient_OnPresence(object sender, PresenceEventArgs e) { DisplayEvent(string.Format("OnPresence\t{0}", e.Presence.From)); if (e.Presence.Type == PresenceType.Subscribe) { //presenceManager.ApproveSubscriptionRequest(e.Presence.From); var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem; if (item != null) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); } else { var input = new FrmAddUser(_dictContactGroups, true, xmppClient); input.Address = e.Presence.From; if (input.ShowDialog() == DialogResult.OK) { _dictContactGroups = input.DictContactGroups; var rm = new RosterManager(xmppClient); Jid jid = input.Address; rm.Add(jid, input.Name, input.Group); var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); //string reason = input.Message; //pm.Subscribe(jid, reason, input.Name); } } } else if (e.Presence.Type == PresenceType.Subscribed) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); } else if (e.Presence.Type == PresenceType.Unsubscribe) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); var rm = new RosterManager(xmppClient); Jid jid = e.Presence.From; rm.Remove(jid); } else if (e.Presence.Type == PresenceType.Unsubscribed) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); var rm = new RosterManager(xmppClient); Jid jid = e.Presence.From; rm.Remove(jid); } else { var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem; if (item != null) { item.ImageIndex = Util.GetRosterImageIndex(e.Presence); string resource = e.Presence.From.Resource; if (e.Presence.Type != PresenceType.Unavailable) { if (!item.Resources.Contains(resource)) { item.Resources.Add(resource); } } else { if (item.Resources.Contains(resource)) { item.Resources.Remove(resource); } } } } }
private void xmppClient_OnPresence(object sender, PresenceEventArgs e) { DisplayEvent(string.Format("OnPresence\t{0}", e.Presence.From)); if (e.Presence.Type == PresenceType.Subscribe) { //presenceManager.ApproveSubscriptionRequest(e.Presence.From); var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem; if (item != null) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); } else { var input = new FrmAddUser(_dictContactGroups, true, xmppClient); input.Address = e.Presence.From; if (input.ShowDialog() == DialogResult.OK) { _dictContactGroups = input.DictContactGroups; var rm = new RosterManager(xmppClient); Jid jid = input.Address; rm.Add(jid, input.Name, input.Group); var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); //string reason = input.Message; //pm.Subscribe(jid, reason, input.Name); } } } else if (e.Presence.Type == PresenceType.Subscribed) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); } else if (e.Presence.Type == PresenceType.Unsubscribe) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); var rm = new RosterManager(xmppClient); Jid jid = e.Presence.From; rm.Remove(jid); } else if (e.Presence.Type == PresenceType.Unsubscribed) { var pm = new PresenceManager(xmppClient); pm.ApproveSubscriptionRequest(e.Presence.From); var rm = new RosterManager(xmppClient); Jid jid = e.Presence.From; rm.Remove(jid); } else { var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem; if (item != null) { item.ImageIndex = Util.GetRosterImageIndex(e.Presence); string resource = e.Presence.From.Resource; if (e.Presence.Type != PresenceType.Unavailable) { if (!item.Resources.Contains(resource)) item.Resources.Add(resource); } else { if (item.Resources.Contains(resource)) item.Resources.Remove(resource); } } } }
private void OnMessage(object sender, agsXMPP.protocol.client.Message NewMessage) { if (NewMessage.Type == MessageType.error || NewMessage.Type == null) { return; } else { Thread thre = new Thread(() => { try { string[] mc = Messages.Lines; if (NewMessage.Type == MessageType.chat) { if (NewMessage.Body.Trim() != string.Empty) { if (NewMessage.From.User.ToLower().Trim() != owner.ToLower().Trim()) { x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[35].Replace("[MESSAGE]$", "").Replace("%L%", Environment.NewLine).Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%to%", NewMessage.From.User).Replace("%masters%", owner).Replace("%time%", DateTime.Now.ToString()))); } if (NewMessage.From.User.ToLower().Trim() == owner.ToLower().Trim() && Selftesting) { x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[35].Replace("[MESSAGE]$", "").Replace("%L%", Environment.NewLine).Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%to%", NewMessage.From.User).Replace("%masters%", owner).Replace("%time%", DateTime.Now.ToString()))); } } if (NewMessage.From.User == owner) { //stop if (NewMessage.Body.ToLower().StartsWith("#logout")) { reconnectable = false; x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(NewMessage.From.User + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[27].Replace("[MESSAGE]$", ""))); x.Close(); } if (NewMessage.Body.Trim().ToLower().StartsWith("add#")) { PresenceManager presx = new PresenceManager(x); string[] sp = NewMessage.Body.Split('#'); try { if (sp[1].Trim() != string.Empty) { Jid jid = new Jid(sp[1] + "@nimbuzz.com"); x.RosterManager.AddRosterItem(jid); presx.Subscribe(jid); Message(owner, "Friend request was sent to '" + jid + "' and you will be notified he/she acceptes."); } else { Message(owner, "Command syntax error!"); } } catch { Message(owner, "Command syntax error!"); } } if (NewMessage.Body.Trim().ToLower().StartsWith("del#")) { PresenceManager presx = new PresenceManager(x); string[] sp = NewMessage.Body.Split('#'); try { if (sp[1].Trim() != string.Empty) { Jid jid = new Jid(sp[1] + "@nimbuzz.com"); x.RosterManager.RemoveRosterItem(jid); presx.Unsubscribe(jid); Message(owner, "'" + jid + "' is deleted."); Userslist.Items.Remove(jid); x.RequestRoster(); } else { Message(owner, "Command syntax error!"); } } catch { Message(owner, "Command syntax error!"); } } //reply if (NewMessage.Body.ToLower().StartsWith("chat/")) { if (NewMessage.From.User == owner) { string[] sp = NewMessage.Body.Split('/'); try { x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(sp[1] + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, sp[2])); x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(NewMessage.From.User + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[36].Replace("[MESSAGE]$", "").Replace("%to%", sp[1]).Replace("%L%", Environment.NewLine))); } catch { Message(NewMessage.From.User, "Command syntax error!"); } } else { x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, NewMessage.Body)); } } //status if (NewMessage.Body.Trim() != string.Empty && NewMessage.From.User.ToLower() == owner.ToLower()) { switch (NewMessage.Body.ToLower().Trim()) { case "#online": { x.Status = sts; x.SendMyPresence(); x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[42].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%sts%", "online").Replace("%thisid%", ID))); break; } case "#away": { x.Show = ShowType.away; x.Status = sts; x.SendMyPresence(); x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[42].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%sts%", "away").Replace("%thisid%", ID).Replace("%to%", NewMessage.From.User.Remove(0)))); break; } case "#busy": { x.Show = ShowType.dnd; x.Status = sts; x.SendMyPresence(); x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[42].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%sts%", "busy").Replace("%thisid%", ID).Replace("%to%", NewMessage.From.User.Remove(0)))); break; } case "+test": { Selftesting = true; Message(owner, "Self Testing is turned on"); break; } case "-test": { Selftesting = false; Message(owner, "Self Testing is turned off"); break; } case "+autoaccept": { AutoAccept = true; Message(owner, "Auto friend request accept is turned on"); break; } case "-autoaccept": { AutoAccept = false; Message(owner, "Auto friend request accept is turned off"); break; } case "+notify": { NotifyOnline = true; Message(owner, "Online Notifier is turned on"); break; } case "-notify": { NotifyOnline = false; Message(owner, "Online Notifier is turned off"); break; } case "#cpanel": { Message(owner, Form1.Fhelp.Replace("%master%", owner)); break; } case "#users": { Message(owner, "\nOnline users list:\n" + Listout()); break; } case "#accept": { int count = 0; if (addeduserlist.Text.Trim() != string.Empty) { PresenceManager presx = new PresenceManager(x); foreach (string l in addeduserlist.Lines) { if (l.Trim() != string.Empty) { try { Jid jid = new Jid(l + "@nimbuzz.com"); x.RosterManager.AddRosterItem(jid); presx.Subscribe(jid); presx.ApproveSubscriptionRequest(jid); count++; Message(owner, jid + " is accepted"); } catch { } } } addeduserlist.Clear(); } else { Message(owner, "No friend request sent."); } break; } default: { break; } } } if (NewMessage.Body.ToLower().StartsWith("stm#") && NewMessage.From.User == owner) { string[] sp = NewMessage.Body.Split('#'); x.Status = sp[1]; sts = sp[1]; x.SendMyPresence(); x.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(owner + "@nimbuzz.com"), agsXMPP.protocol.client.MessageType.chat, mc[43].Replace("[MESSAGE]$", "").Replace("%from%", NewMessage.From.User).Replace("%msg%", NewMessage.Body).Replace("%L%", Environment.NewLine).Replace("%stm%", sts).Replace("%thisid%", ID).Replace("%to%", NewMessage.From.User))); } } } } catch (Exception v) { } }); thre.IsBackground = true; thre.Start(); } }