/** * gen_vhostonreg.C: Sets usercloak metadata on register. * * 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 © 2005-2006 William Pitcock, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: gen_vhostonreg.C,v 1.5 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: gen_vhostonreg.C,v 1.5 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("misc/vhostonreg", false, "The Ermyth Team "); /* allow us-ascii letters, digits and the following characters */ #define VALID_SPECIALS "-" static int counter; static void handle_register (myuser_t *mu) { char newhost[HOSTLEN]; int maxlen1, i; bool invalidchar = false; char const *p; myuser_t::login_vector::iterator it, it_end; if (me.hidehostsuffix == NULL) return; maxlen1 = HOSTLEN - 2 - strlen (me.hidehostsuffix); if (maxlen1 < 9) return; p = mu->name; i = 0; while (i < maxlen1 && *p != '\0') { if (isalnum (*p) || strchr (VALID_SPECIALS, *p)) newhost[i++] = *p; else invalidchar = true; p++; } if (invalidchar || *p != '\0') { if (i > maxlen1 - 6) i = maxlen1 - 6; snprintf (newhost + i, sizeof newhost - i, "-%05d", counter); counter++; if (counter >= 100000) counter = 0; if (nicksvs.me != NULL) { mu->notice (nicksvs.nick, "Your account name cannot be used in a vhost directly. To ensure uniqueness, a number was added."); mu->notice (nicksvs.nick, "To avoid this, register an account name containing only letters, digits and %s.", VALID_SPECIALS); if (!nicksvs.no_nick_ownership && nicksvs.me->cmdtree->find ("GROUP")) mu->notice (nicksvs.nick, "If you drop %s you can group it to your new account.", mu->name); } } else newhost[i] = '\0'; strlcat (newhost, ".", sizeof newhost); strlcat (newhost, me.hidehostsuffix, sizeof newhost); mu->add_metadata ("private:usercloak", newhost); for (it = mu->logins.begin (), it_end = mu->logins.end (); it != it_end; ++it) (*it)->callback.identify (*it); } bool _modinit (module *m) { myuser_t::callback.registered.attach (handle_register); counter = (NOW << 8) % 100000; if (counter < 0) counter += 100000; return true; } void _moddeinit (void) { myuser_t::callback.registered.detach (handle_register); }