diff options
Diffstat (limited to 'src/servers.c')
-rw-r--r-- | src/servers.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/servers.c b/src/servers.c index 31d7425dd..4aaebc302 100644 --- a/src/servers.c +++ b/src/servers.c @@ -558,4 +558,61 @@ void finish_sync(Server * serv, int sync_links) alog("Server %s is done syncing", serv->name); } +/*******************************************************************/ + +/* TS6 UID generator common code. + * + * Derived from atheme-services, uid.c (hg 2954:116d46894b4c). + * -nenolod + */ +static int ts6_uid_initted = 0; +static char ts6_new_uid[10]; /* allow for \0 */ +static unsigned int ts6_uid_index = 9; /* last slot in uid buf */ + +void ts6_uid_init(void) +{ + unsigned int i; + char buf[BUFSIZE]; + + /* check just in case... you can never be too safe. */ + if (TS6SID != NULL) { + snprintf(ts6_new_uid, 10, "%sAAAAAA", TS6SID); + ts6_uid_initted = 1; + } else { + alog("warning: no TS6SID specified, disabling TS6 support."); + UseTS6 = 0; + + return; + } +} + +void ts6_uid_increment(unsigned int slot) +{ + if (slot != strlen(TS6SID)) { + if (ts6_new_uid[slot] == 'Z') + ts6_new_uid[slot] = '0'; + else if (ts6_new_uid[slot] == '9') { + ts6_new_uid[slot] = 'A'; + ts6_uid_increment(slot - 1); + } else + ts6_new_uid[slot]++; + } else { + if (ts6_new_uid[slot] == 'Z') + for (slot = 3; slot < 9; slot++) + ts6_new_uid[slot] = 'A'; + else + ts6_new_uid[slot]++; + } +} + +char *ts6_uid_retrieve(void) +{ + if (ts6_uid_initted != 1) + ts6_uid_init(); + + ts6_uid_increment(ts6_uid_index - 1); + + return ts6_new_uid; +} + /* EOF */ |