/** * rnc.C: This file contains functionality implementing OperServ RNC. * * 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: * Copyright © 2006 Robin Burchell * Rights to this code are documented in doc/LICENCE. * * $Id: rnc.C,v 1.6 2007/09/22 14:27:28 pippijn Exp $ */ #include #include "atheme.h" #include static char const rcsid[] = "$Id: rnc.C,v 1.6 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("operserv/rnc", false, "Robin Burchell "); static void os_cmd_rnc (sourceinfo_t *si, int parc, char *parv[]); command_t const os_rnc = { "RNC", N_("Shows the most frequent realnames on the network"), PRIV_USER_AUSPEX, 1, os_cmd_rnc }; E cmdvec os_cmdtree; E helpvec os_helptree; typedef struct rnc_t_ rnc_t; struct rnc_t_ { char gecos[GECOSLEN]; int count; }; bool _modinit (module *m) { os_cmdtree << os_rnc; help_addentry (os_helptree, "RNC", "help/operserv/rnc", NULL); return true; } void _moddeinit (void) { os_cmdtree >> os_rnc; help_delentry (os_helptree, "RNC"); } static void os_cmd_rnc (sourceinfo_t *si, int parc, char *parv[]) { char *param = parv[0]; int count = param ? atoi (param) : 20; node_t *n1, *n2, *biggest = NULL; user_t *u; rnc_t *rnc; list_t realnames; int i, found = 0; realnames.head = NULL; realnames.tail = NULL; realnames.count = 0; foreach (user_t::pair_type &up, user_t::map) { u = up.second; LIST_FOREACH (n2, realnames.head) { rnc = static_cast (n2->data); if (strcmp (rnc->gecos, u->gecos) == 0) { /* existing match */ rnc->count++; found = 1; } } if (found == 0) { /* new realname */ rnc = new rnc_t; sprintf (rnc->gecos, "%s", u->gecos); rnc->count = 1; node_add (rnc, node_create (), &realnames); } found = 0; } found = 0; /* XXX: this is ugly to the max :P */ for (i = 1; i <= count; i++) { LIST_FOREACH (n1, realnames.head) { rnc = static_cast (n1->data); if (rnc->count > found) { found = rnc->count; biggest = n1; } } if (biggest == NULL) break; command_success_nodata (si, _("\2%d\2: \2%d\2 matches for realname \2%s\2"), i, ((rnc_t *) (biggest->data))->count, ((rnc_t *) biggest->data)->gecos); delete static_cast (biggest->data); node_del (biggest, &realnames); node_free (biggest); found = 0; biggest = NULL; } /* cleanup */ LIST_FOREACH_SAFE (n1, n2, realnames.head) { rnc = static_cast < rnc_t * >(n1->data); delete rnc; node_del (n1, &realnames); node_free (n1); } logcommand (si, CMDLOG_ADMIN, "RNC %d", count); snoop ("RNC: by \2%s\2", get_oper_name (si)); }