summaryrefslogtreecommitdiff
path: root/src/servers.c
diff options
context:
space:
mode:
authorcyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2009-03-25 16:12:24 +0000
committercyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864>2009-03-25 16:12:24 +0000
commit8fc031fb84e7e266fbdf476b59d97f529c28dc36 (patch)
tree07ff1458e48da24b41b8800537409fe1f30d7ecd /src/servers.c
parentd8c4e705a2139682e6da65b864097df8d66f8432 (diff)
Fix bug #1009, patch inspired by DukePyrolator, add a TS6 SID generator from DukePyrolator, as well as change SendServer() to take a Server struct and use the result of new_server() in the SendServer() call instead.
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2206 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/servers.c')
-rw-r--r--src/servers.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/servers.c b/src/servers.c
index 576abf8de..b6f16eaa7 100644
--- a/src/servers.c
+++ b/src/servers.c
@@ -641,4 +641,78 @@ const char *ts6_uid_retrieve()
return ts6_new_uid;
}
+/*******************************************************************/
+
+/*
+ * TS6 generator code, provided by DukePyrolator
+ */
+
+static int ts6_sid_initted = 0;
+static char ts6_new_sid[4];
+
+static void ts6_sid_increment(unsigned pos)
+{
+ /*
+ * An SID must be exactly 3 characters long, starts with a digit,
+ * and the other two characters are A-Z or digits
+ * The rules for generating an SID go like this...
+ * --> ABCDEFGHIJKLMNOPQRSTUVWXYZ --> 0123456789 --> WRAP
+ */
+ if (!pos)
+ {
+ /* At pos 0, if we hit '9', we've run out of available SIDs,
+ * reset the SID to the smallest possible value and try again. */
+ if (ts6_new_sid[pos] == '9')
+ {
+ ts6_new_sid[0] = '0';
+ ts6_new_sid[1] = 'A';
+ ts6_new_sid[2] = 'A';
+ }
+ else
+ // But if we haven't, just keep incrementing merrily.
+ ++ts6_new_sid[0];
+ }
+ else
+ {
+ if (ts6_new_sid[pos] == 'Z')
+ ts6_new_sid[pos] = '0';
+ else if (ts6_new_sid[pos] == '9')
+ {
+ ts6_new_sid[pos] = 'A';
+ ts6_sid_increment(pos - 1);
+ }
+ else
+ ++ts6_new_sid[pos];
+ }
+}
+
+const char *ts6_sid_retrieve()
+{
+ if (!ircd->ts6)
+ {
+ if (debug)
+ alog("TS6 not supported on this ircd");
+ return "";
+ }
+
+ if (!ts6_sid_initted)
+ {
+ // Initialize ts6_new_sid with the services server SID
+ snprintf(ts6_new_sid, 4, "%s", TS6SID);
+ ts6_sid_initted = 1;
+ }
+ while (1)
+ {
+ // Check if the new SID is used by a known server
+ if (!findserver_uid(servlist, ts6_new_sid))
+ // return the new SID
+ return ts6_new_sid;
+
+ // Add one to the last SID
+ ts6_sid_increment(2);
+ }
+ /* not reached */
+ return "";
+}
+
/* EOF */