/** * subscribe.C: NickServ/SUBSCRIBE command implementation. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Rights to this code are documented in doc/pod/license.pod. * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) * * $Id: subscribe.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #include static char const rcsid[] = "$Id: subscribe.C,v 1.8 2007/09/22 14:27:28 pippijn Exp $"; static void on_metadata_change (has_metadata *hm, char const * const key, char const * const value); REGISTER_MODULE ("nickserv/subscribe", false, "The Ermyth Team "); static void cmd_subscribe (sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu = si->smu, *tmu; char *name = parv[0], *tag; bool remove = false; metadata_subscription_t *md; if (parc < 1) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "SUBSCRIBE"); command_fail (si, fault::needmoreparams, _("Syntax: SUBSCRIBE [-]username [tags]")); return; } if (mu == NULL) { command_fail (si, fault::noprivs, _("You are not logged in.")); return; } if (*name == '-') { remove = true; name++; } if ((tmu = myuser_t::find_ext (name)) == NULL) { command_fail (si, fault::badparams, _("\2%s\2 is not registered."), name); return; } if (remove) { node_t *n; bool found = false; LIST_FOREACH (n, tmu->subscriptions.head) { md = (metadata_subscription_t *) n->data; if (md->mu == mu) { found = true; break; } } if (found) { node_t *tn; LIST_FOREACH_SAFE (n, tn, md->taglist.head) { sfree (n->data); node_del (n, &md->taglist); node_free (n); } delete md; node_del (n, &tmu->subscriptions); node_free (n); command_success_nodata (si, _("\2%s\2 has been removed from your subscriptions."), name); return; } command_fail (si, fault::badparams, _("\2%s\2 was not found on your subscription list."), name); return; } /* tags are mandatory for new subscriptions */ if (parc < 2) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "SUBSCRIBE"); command_fail (si, fault::needmoreparams, _("Syntax: SUBSCRIBE [-]username tags")); return; } md = new metadata_subscription_t; md->mu = mu; tag = strtok (parv[1], ","); do { slog (LG_DEBUG, "subscription: parsing tag %s", tag); node_add (sstrdup (tag), node_create (), &md->taglist); } while ((tag = strtok (NULL, ",")) != NULL); node_add (md, node_create (), &tmu->subscriptions); command_success_nodata (si, _("\2%s\2 has been added to your subscriptions."), name); } command_t const ns_subscribe = { "SUBSCRIBE", N_("Manages your subscription list."), AC_NONE, 2, cmd_subscribe }; E cmdvec ns_cmdtree; static void on_metadata_change (has_metadata *hm, char const * const key, char const * const value) { myuser_t *mu = static_cast (hm); node_t *n, *tn; if (!hm->mdMuOK ()) return; /* don't allow private metadata to be exposed to users. */ if (strchr (key, ':')) return; LIST_FOREACH (n, mu->subscriptions.head) { metadata_subscription_t *mds = static_cast (n->data); LIST_FOREACH (tn, mds->taglist.head) { if (!match (static_cast (tn->data), key) && value != NULL) mds->mu->notice (nicksvs.nick, "\2%s\2 has changed \2%s\2 to \2%s\2.", mu->name, key, value); } } } bool _modinit (module *m) { ns_cmdtree << ns_subscribe; has_metadata::callback.metadata_change.attach (on_metadata_change); return true; } void _moddeinit (void) { ns_cmdtree >> ns_subscribe; has_metadata::callback.metadata_change.detach (on_metadata_change); }