diff options
author | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-03-25 16:12:24 +0000 |
---|---|---|
committer | cyberbotx <cyberbotx@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-03-25 16:12:24 +0000 |
commit | 8fc031fb84e7e266fbdf476b59d97f529c28dc36 (patch) | |
tree | 07ff1458e48da24b41b8800537409fe1f30d7ecd | |
parent | d8c4e705a2139682e6da65b864097df8d66f8432 (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
-rw-r--r-- | include/extern.h | 2 | ||||
-rw-r--r-- | include/services.h | 2 | ||||
-rw-r--r-- | src/core/os_jupe.c | 4 | ||||
-rw-r--r-- | src/protocol/bahamut.c | 8 | ||||
-rw-r--r-- | src/protocol/inspircd11.c | 8 | ||||
-rw-r--r-- | src/protocol/inspircd12.cpp | 8 | ||||
-rw-r--r-- | src/protocol/ratbox.c | 10 | ||||
-rw-r--r-- | src/protocol/unreal32.c | 24 | ||||
-rw-r--r-- | src/servers.c | 74 |
9 files changed, 110 insertions, 30 deletions
diff --git a/include/extern.h b/include/extern.h index ad79cf00c..e16665714 100644 --- a/include/extern.h +++ b/include/extern.h @@ -841,6 +841,8 @@ E void ts6_uid_init(); E void ts6_uid_increment(unsigned int slot); E const char *ts6_uid_retrieve(); +E const char *ts6_sid_retrieve(); + /**** sessions.c ****/ E Exception *exceptions; diff --git a/include/services.h b/include/services.h index 82631d883..e340d21f8 100644 --- a/include/services.h +++ b/include/services.h @@ -1321,7 +1321,7 @@ class CoreExport IRCDProto virtual void SendSVSPart(const char *, const char *, const char *) { } virtual void SendSWhois(const char *, const char *, const char *) { } virtual void SendEOB() { } - virtual void SendServer(const char *, int, const char *) = 0; + virtual void SendServer(Server *) = 0; virtual void ProcessUsermodes(User *, int, const char **) = 0; virtual int IsNickValid(const char *) { return 1; } virtual int IsChannelValid(const char *) { return 1; } diff --git a/src/core/os_jupe.c b/src/core/os_jupe.c index 0a8e80a4f..36dbc4376 100644 --- a/src/core/os_jupe.c +++ b/src/core/os_jupe.c @@ -36,8 +36,8 @@ class CommandOSJupe : public Command snprintf(rbuf, sizeof(rbuf), "Juped by %s%s%s", u->nick, reason ? ": " : "", reason ? reason : ""); if (findserver(servlist, jserver)) ircdproto->SendSquit(jserver, rbuf); - ircdproto->SendServer(jserver, 2, rbuf); - new_server(me_server, jserver, rbuf, SERVER_JUPED, NULL); + Server *juped_server = new_server(me_server, jserver, rbuf, SERVER_JUPED, ircd->ts6 ? ts6_sid_retrieve() : NULL); + ircdproto->SendServer(juped_server); if (WallOSJupe) ircdproto->SendGlobops(s_OperServ, "\2%s\2 used JUPE on \2%s\2", u->nick, jserver); diff --git a/src/protocol/bahamut.c b/src/protocol/bahamut.c index 5e0b5a7a4..89fd91740 100644 --- a/src/protocol/bahamut.c +++ b/src/protocol/bahamut.c @@ -698,17 +698,17 @@ class BahamutIRCdProto : public IRCDProto } /* SERVER */ - void SendServer(const char *servname, int hop, const char *descript) + void SendServer(Server *server) { - send_cmd(NULL, "SERVER %s %d :%s", servname, hop, descript); + send_cmd(NULL, "SERVER %s %d :%s", server->name, server->hops, server->desc); } void SendConnect() { - me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL); bahamut_cmd_pass(uplink_server->password); bahamut_cmd_capab(); - SendServer(ServerName, 1, ServerDesc); + me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL); + SendServer(me_server); bahamut_cmd_svinfo(); bahamut_cmd_burst(); } diff --git a/src/protocol/inspircd11.c b/src/protocol/inspircd11.c index 94ec42c24..17351937d 100644 --- a/src/protocol/inspircd11.c +++ b/src/protocol/inspircd11.c @@ -560,9 +560,9 @@ class InspIRCdProto : public IRCDProto /* SERVER services-dev.chatspike.net password 0 :Description here */ - void SendServer(const char *servname, int hop, const char *descript) + void SendServer(Server *server) { - send_cmd(ServerName, "SERVER %s %s %d :%s", servname, currentpass, hop, descript); + send_cmd(ServerName, "SERVER %s %s %d :%s", server->name, currentpass, server->hops, server->desc); } /* JOIN */ @@ -604,10 +604,10 @@ class InspIRCdProto : public IRCDProto void SendConnect() { inspircd_cmd_pass(uplink_server->password); - SendServer(ServerName, 0, ServerDesc); + me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL); + SendServer(me_server); send_cmd(NULL, "BURST"); send_cmd(ServerName, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModule, version_build); - me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL); } /* CHGIDENT */ diff --git a/src/protocol/inspircd12.cpp b/src/protocol/inspircd12.cpp index 7cd040823..8e1ddf989 100644 --- a/src/protocol/inspircd12.cpp +++ b/src/protocol/inspircd12.cpp @@ -564,9 +564,9 @@ class InspIRCdProto : public IRCDProto } /* SERVER services-dev.chatspike.net password 0 :Description here */ - void SendServer(const char *servname, int hop, const char *descript) + void SendServer(Server *server) { - send_cmd(NULL, "SERVER %s %s %d %s :%s", servname, currentpass, hop, TS6SID, descript); + send_cmd(NULL, "SERVER %s %s %d %s :%s", server->name, currentpass, server->hops, server->suid, server->desc); } /* JOIN */ @@ -605,10 +605,10 @@ class InspIRCdProto : public IRCDProto void SendConnect() { inspircd_cmd_pass(uplink_server->password); - SendServer(ServerName, 0, ServerDesc); + me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, TS6SID); + SendServer(me_server); send_cmd(NULL, "BURST"); send_cmd(TS6SID, "VERSION :Anope-%s %s :%s - %s (%s) -- %s", version_number, ServerName, ircd->name, version_flags, EncModule, version_build); - me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, TS6SID); } /* CHGIDENT */ diff --git a/src/protocol/ratbox.c b/src/protocol/ratbox.c index dea79b952..acde49ac0 100644 --- a/src/protocol/ratbox.c +++ b/src/protocol/ratbox.c @@ -585,18 +585,18 @@ class RatboxProto : public IRCDTS6Proto } /* SERVER name hop descript */ - void SendServer(const char *servname, int hop, const char *descript) + void SendServer(Server *server) { - send_cmd(NULL, "SERVER %s %d :%s", servname, hop, descript); + send_cmd(NULL, "SERVER %s %d :%s", server->name, server->hops, server->desc); } void SendConnect() { - /* Make myself known to myself in the serverlist */ - me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, TS6SID); ratbox_cmd_pass(uplink_server->password); ratbox_cmd_capab(); - SendServer(ServerName, 1, ServerDesc); + /* Make myself known to myself in the serverlist */ + me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, TS6SID); + SendServer(me_server); ratbox_cmd_svinfo(); } diff --git a/src/protocol/unreal32.c b/src/protocol/unreal32.c index b00b89379..17a49a75b 100644 --- a/src/protocol/unreal32.c +++ b/src/protocol/unreal32.c @@ -538,17 +538,17 @@ class UnrealIRCdProto : public IRCDProto --ac; if (!user || !modes) return; /* Prevent NULLs from doing bad things */ if (debug) alog("debug: Changing mode for %s to %s", user->nick, modes); - + while (*modes) { uint32 backup = user->mode; - + /* This looks better, much better than "add ? (do_add) : (do_remove)". * At least this is readable without paying much attention :) -GD */ if (add) user->mode |= umodes[static_cast<int>(*modes)]; else user->mode &= ~umodes[static_cast<int>(*modes)]; - + switch (*modes++) { case '+': @@ -682,10 +682,12 @@ class UnrealIRCdProto : public IRCDProto /* SERVER name hop descript */ /* Unreal 3.2 actually sends some info about itself in the descript area */ - void SendServer(const char *servname, int hop, const char *descript) + void SendServer(Server *server) { - if (Numeric) send_cmd(NULL, "SERVER %s %d :U0-*-%s %s", servname, hop, Numeric, descript); - else send_cmd(NULL, "SERVER %s %d :%s", servname, hop, descript); + if (Numeric) + send_cmd(NULL, "SERVER %s %d :U0-*-%s %s", server->name, server->hops, Numeric, server->desc); + else + send_cmd(NULL, "SERVER %s %d :%s", server->name, server->hops, server->desc); } /* JOIN */ @@ -750,11 +752,13 @@ class UnrealIRCdProto : public IRCDProto void SendConnect() { - if (Numeric) me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, Numeric); - else me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL); unreal_cmd_capab(); unreal_cmd_pass(uplink_server->password); - SendServer(ServerName, 1, ServerDesc); + if (Numeric) + me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, Numeric); + else + me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME, NULL); + SendServer(me_server); } /* SVSHOLD - set */ @@ -1200,7 +1204,7 @@ int anope_event_sethost(const char *source, int ac, const char **av) */ /* do_nick(const char *source, char *nick, char *username, char *host, - char *server, char *realname, time_t ts, + char *server, char *realname, time_t ts, uint32 ip, char *vhost, char *uid) */ int anope_event_nick(const char *source, int ac, const char **av) 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 */ |