private void ProcessPresence(Presence pres) { if (pres.Type == PresenceType.Subscribe) { // RFC 3.1.2. Server Processing of Outbound Subscription Request } else if (pres.Type == PresenceType.Subscribed) { // RFC 3.1.5. Server Processing of Outbound Subscription Approval } else if (pres.Type == PresenceType.Unsubscribed) { // RFC 3.2.2. Server Processing of Outbound Subscription Cancellation } else if (pres.Type == PresenceType.Unsubscribe) { // RFC 3.3.2. Server Processing of Outbound Unsubscribe } else if (pres.Type == PresenceType.Available || pres.Type == PresenceType.Unavailable) { ProcessOutboundPresence(pres); } }
private void ProcessOutboundPresence(Presence pres) { if (pres.To == null || pres.To.Equals(XmppDomain, new FullJidComparer())) { // a presence to the server if (pres.Type == PresenceType.Available) { if (IsBinded && !InitialPresence) { InitialPresence = true; // request all initial presences of the contacts for (int i = 0; i < 11; i++) { // but not myself if (Jid.User.EndsWith(i.ToString())) { continue; } var jid = new Jid("user" + i + "@" + XmppDomain); var con = Global.ServerConnections.FirstOrDefault(sc => sc.Jid.Equals(jid, new BareJidComparer())); if (con != null && con.LastPresence != null) { Send(con.LastPresence); } } } } else if (pres.Type == PresenceType.Unavailable) { } // distribute presence // to all own resources, pres.From = Jid; pres.To = null; LastPresence = pres; /* * then to all subscribed contacts * 4.2.2. Server Processing of Outbound Initial Presence * * Upon receiving initial presence from a client, the user's server MUST send the initial presence stanza from the * full JID <user@domainpart/resourcepart> of the user to all contacts that are subscribed to the user's presence; * such contacts are those for which a JID is present in the user's roster with the 'subscription' attribute set to * a value of "from" or "both". */ for (int i = 0; i < 11; i++) { // but not myself if (Jid.User.EndsWith(i.ToString())) { continue; } var jid = new Jid("user" + i + "@" + XmppDomain); var con = Global.ServerConnections.FirstOrDefault(sc => sc.Jid.Equals(jid, new BareJidComparer())); if (con != null) { con.Send(pres); } } // Send the presence to all my own connected resources (sessions) Global.ServerConnections .Where(sc => sc.Jid.Equals(Jid, new BareJidComparer())) .ToList() .ForEach( c => c.Send(pres) ); } }