/* * uid.C: UID management. * * 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) */ static char const rcsid[] = "$Id: uid.C,v 1.5 2007/09/16 18:54:45 pippijn Exp $"; #include "atheme.h" static char new_uid[9]; /* allow for \0 */ static unsigned int uindex = 0; void init_uid (void) { unsigned int i; char buf[BUFSIZE]; if (ircd->uses_p10 == true) { me.numeric = sstrdup (uinttobase64 (buf, atoi (me.numeric), 2)); uindex = 5; } else uindex = 9; memset (new_uid, 0, sizeof (new_uid)); if (me.numeric != NULL) memcpy (new_uid, me.numeric, strlen (me.numeric)); else return; for (i = 0; i < strlen (me.numeric); i++) if (new_uid[i] == '\0') new_uid[i] = 'A'; for (i = strlen (me.numeric); i < uindex; i++) new_uid[i] = 'A'; } static void add_one_to_uid (unsigned int i) { if (i != strlen (me.numeric)) /* Not reached server SID portion yet? */ { if (new_uid[i] == 'Z') new_uid[i] = '0'; else if (new_uid[i] == '9') { new_uid[i] = 'A'; add_one_to_uid (i - 1); } else new_uid[i] = new_uid[i] + 1; } else { if (new_uid[i] == 'Z') for (i = strlen (me.numeric); i < 9; i++) new_uid[i] = 'A'; else new_uid[i] = new_uid[i] + 1; } } char * uid_get (void) { add_one_to_uid (uindex - 1); /* index from 0 */ return (new_uid); }