diff options
| author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-01-02 08:20:59 +0000 |
|---|---|---|
| committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-01-02 08:20:59 +0000 |
| commit | a819cb0cc0f54a042a088dfba9c1f6b817928641 (patch) | |
| tree | 7931a9d81367c184ca2550a1819ef685e3e0c927 | |
| parent | 3617d7978899f830d952d9bac70ed14bb0cc0fd6 (diff) | |
Rewrote the vhost code, and moved it to be part of nickalias instead of in its own list. This also fixes being able to steal other users vhosts with /hs on
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2724 5417fbe8-f217-4b02-8779-1006273d7864
| -rw-r--r-- | include/account.h | 1 | ||||
| -rw-r--r-- | include/extern.h | 21 | ||||
| -rw-r--r-- | include/modules.h | 19 | ||||
| -rw-r--r-- | include/services.h | 63 | ||||
| -rw-r--r-- | src/core/db_plain.cpp | 29 | ||||
| -rw-r--r-- | src/core/hs_del.c | 3 | ||||
| -rw-r--r-- | src/core/hs_delall.c | 3 | ||||
| -rw-r--r-- | src/core/hs_group.c | 37 | ||||
| -rw-r--r-- | src/core/hs_list.c | 125 | ||||
| -rw-r--r-- | src/core/hs_off.c | 9 | ||||
| -rw-r--r-- | src/core/hs_on.c | 28 | ||||
| -rw-r--r-- | src/core/hs_set.c | 3 | ||||
| -rw-r--r-- | src/core/hs_setall.c | 46 | ||||
| -rw-r--r-- | src/core/ns_info.c | 17 | ||||
| -rw-r--r-- | src/hostserv.c | 381 | ||||
| -rw-r--r-- | src/modules/hs_request.c | 159 | ||||
| -rw-r--r-- | src/nickalias.cpp | 2 | ||||
| -rw-r--r-- | src/tools/db-convert.c | 55 | ||||
| -rw-r--r-- | src/tools/db-convert.h | 20 | ||||
| -rw-r--r-- | src/users.c | 2 |
20 files changed, 378 insertions, 645 deletions
diff --git a/include/account.h b/include/account.h index dc0d21c7d..0516b5fe9 100644 --- a/include/account.h +++ b/include/account.h @@ -105,6 +105,7 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag> time_t time_registered; /* When the nick was registered */ time_t last_seen; /* When it was seen online for the last time */ NickCore *nc; /* I'm an alias of this */ + HostInfo hostinfo; }; class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag> diff --git a/include/extern.h b/include/extern.h index 09f12ba77..11ba59bd5 100644 --- a/include/extern.h +++ b/include/extern.h @@ -173,16 +173,12 @@ char *sockstrerror(int error); /**** config.c ****/ E ServerConfig Config; - -E int do_on_id(User * u); -E void delHostCore(const char *nick); -E void hostserv(User * u, char *buf); - E int read_config(int reload); -/**** converter.c ****/ - -E int convert_ircservices_44(); +/* hostserv.c */ +E void do_on_id(User *u); +E void hostserv(User *u, char *buf); +E void HostServSyncVhosts(NickAlias *na); /**** encrypt.c ****/ E void initEncryption(); @@ -200,15 +196,6 @@ E void encmodule_check_password(int (*func)(const char *plaintext, const char *p /**** hostserv.c ****/ E void get_hostserv_stats(long *nrec, long *memuse); E void hostserv_init(); -E void addHostCore(const char *nick, char *vIdent, char *vhost, const char *creator, int32 tmp_time); -E char *getvIdent(char *nick); -E char *getvHost(char *nick); -E HostCore *hostCoreListHead(); -E HostCore *findHostCore(HostCore * head, const char *nick, bool *found); -E HostCore *createHostCorelist(HostCore * next, const char *nick, char *vIdent, char *vHost, const char *creator, int32 tmp_time); -E HostCore *insertHostCore(HostCore * head, HostCore * prev, const char *nick, char *vIdent, char *vHost, const char *creator, int32 tmp_time); -E HostCore *deleteHostCore(HostCore * head, HostCore * prev); -E void set_lastmask(User * u); /**** init.c ****/ diff --git a/include/modules.h b/include/modules.h index 129e2666d..bfd8b3928 100644 --- a/include/modules.h +++ b/include/modules.h @@ -989,20 +989,15 @@ class CoreExport Module */ virtual void OnNickEraseAccess(NickCore *nc, const std::string &entry) { } - /** called when a HostCore is deleted - * @param hc pointer to the HostCore + /** called when a vhost is deleted + * @param na The nickalias of the vhost */ - virtual void OnDeleteHostCore(HostCore *hc) { } + virtual void OnDeleteVhost(NickAlias *na) { } - /** called on findHostCore - * @param nick the name of the HostCore we are searching for + /** Called when a vhost is set + * @param na The nickalias of the vhost */ - virtual void OnFindHostCore(const std::string &nick) { } - - /** called when a new HostCore is inserted - * @param hc pointer to the HostCore - */ - virtual void OnInsertHostCore(HostCore *hc) { } + virtual void OnSetVhost(NickAlias *na) { } /** Called when a mode is set on a channel * @param c The channel @@ -1090,7 +1085,7 @@ enum Implementation I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBotPreLoad, /* HostServ */ - I_OnHostServHelp, I_OnDeleteHostCore, I_OnFindHostCore, I_OnInsertHostCore, + I_OnHostServHelp, I_OnSetVhost, I_OnDeleteVhost, /* MemoServ */ I_OnMemoServHelp, diff --git a/include/services.h b/include/services.h index 5c2a426ed..9393c9091 100644 --- a/include/services.h +++ b/include/services.h @@ -364,7 +364,6 @@ typedef struct userdata_ UserData; typedef struct mailinfo_ MailInfo; typedef struct akill_ Akill; typedef struct sxline_ SXLine; -typedef struct hostcore_ HostCore; typedef struct exception_ Exception; typedef struct session_ Session; @@ -508,6 +507,53 @@ typedef struct { /*************************************************************************/ +class HostInfo +{ + private: + std::string Ident; + std::string Host; + std::string Creator; + time_t Time; + + public: + /** Set a vhost for the user + * @param ident The ident + * @param host The host + * @param creator Who created the vhost + * @param time When the vhost was craated + */ + void SetVhost(const std::string &ident, const std::string &host, const std::string &creator, time_t time = time(NULL)); + + /** Remove a users vhost + **/ + void RemoveVhost(); + + /** Check if the user has a vhost + * @return true or false + */ + bool HasVhost() const; + + /** Retrieve the vhost ident + * @return the ident + */ + const std::string &GetIdent() const; + + /** Retrieve the vhost host + * @return the host + */ + const std::string &GetHost() const; + + /** Retrieve the vhost creator + * @return the creator + */ + const std::string &GetCreator() const; + + /** Retrieve when the vhost was crated + * @return the time it was created + */ + const time_t GetTime() const; +}; + // For NickServ #include "account.h" @@ -1052,20 +1098,6 @@ struct sxline_ { /************************************************************************/ -/* Host serv structures */ - -struct hostcore_ { - HostCore *next; - char *nick; /* Owner of the vHost */ - char *vIdent; /* vIdent for the user */ - char *vHost; /* Vhost for this user */ - char *creator; /* Oper Nick of the oper who set the vhost */ - time_t time; /* Date/Time vHost was set */ -}; - -/*************************************************************************/ - - struct exception_ { char *mask; /* Hosts to which this exception applies */ int limit; /* Session limit for exception */ @@ -1334,6 +1366,7 @@ class CoreExport Anope * @param case_sensitive Whether or not the match is case sensitive, default false. */ static bool Match(const std::string &str, const std::string &mask, bool case_sensitive = false); + inline static bool Match(const ci::string &str, const ci::string &mask) { return Match(str.c_str(), mask.c_str(), false); } }; /*************************************************************************/ diff --git a/src/core/db_plain.cpp b/src/core/db_plain.cpp index 4648378a8..5862e679c 100644 --- a/src/core/db_plain.cpp +++ b/src/core/db_plain.cpp @@ -63,8 +63,10 @@ static void ReadDatabase(Module *m = NULL) if (buf[0] == ':') { buf.erase(buf.begin()); - if (!buf.empty()) + if (!buf.empty() && !sep.StreamEnd()) params.push_back(buf + " " + sep.GetRemaining()); + else if (!buf.empty()) + params.push_back(buf); } else params.push_back(buf); @@ -457,15 +459,6 @@ static void LoadChanInfo(const std::vector<std::string> ¶ms) alog("[db_plain]: loaded channel %s", ci->name); } -static void LoadHostInfo(const std::vector<std::string> ¶ms) -{ - if (!findnick(params[0].c_str())) - return; - addHostCore(params[0].c_str(), params[4].empty() ? NULL : const_cast<char *>(params[4].c_str()), const_cast<char *>(params[3].c_str()), params[1].c_str(), strtol(params[2].c_str(), NULL, 10)); // XXX - if (debug > 1) - alog("[db_plain]: loaded vhost for %s", params[0].c_str()); -} - static void LoadOperInfo(const std::vector<std::string> ¶ms) { if (params[0] == "STATS") @@ -538,8 +531,6 @@ class DBPlain : public Module LoadBotInfo(otherparams); else if (key == "CH") LoadChanInfo(otherparams); - else if (key == "HI") - LoadHostInfo(otherparams); else if (key == "OS") LoadOperInfo(otherparams); @@ -617,6 +608,10 @@ class DBPlain : public Module na->SetFlag(NS_NO_EXPIRE); } } + else if (key == "VHOST") + { + na->hostinfo.SetVhost(params.size() > 3 ? params[3] : "", params[2], params[0], strtol(params[1].c_str(), NULL, 10)); + } return EVENT_CONTINUE; } @@ -927,6 +922,10 @@ class DBPlain : public Module { db << "MD FLAGS" << (na->HasFlag(NS_FORBIDDEN) ? " FORBIDDEN" : "") << (na->HasFlag(NS_NO_EXPIRE) ? " NOEXPIRE " : "") << endl; } + if (na->hostinfo.HasVhost()) + { + db << "MD VHOST " << na->hostinfo.GetCreator() << " " << na->hostinfo.GetTime() << " " << na->hostinfo.GetHost() << " :" << na->hostinfo.GetIdent() << endl; + } FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, na)); } @@ -1083,12 +1082,6 @@ class DBPlain : public Module } } - HostCore *hc; - for (hc = hostCoreListHead(); hc; hc = hc->next) - { - db << "HI " << hc->nick << " " << hc->creator << " " << hc->time << " " << hc->vHost << " :" << hc->vIdent << endl; - } - for (i = 0; i < akills.count; ++i) { Akill *ak = static_cast<Akill *>(akills.list[i]); diff --git a/src/core/hs_del.c b/src/core/hs_del.c index 3c2661197..69d9b8524 100644 --- a/src/core/hs_del.c +++ b/src/core/hs_del.c @@ -34,7 +34,8 @@ class CommandHSDel : public Command return MOD_CONT; } alog("vHost for user \002%s\002 deleted by oper \002%s\002", nick, u->nick); - delHostCore(nick); + FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); + na->hostinfo.RemoveVhost(); notice_lang(Config.s_HostServ, u, HOST_DEL, nick); } else diff --git a/src/core/hs_delall.c b/src/core/hs_delall.c index bd874f30f..89a227207 100644 --- a/src/core/hs_delall.c +++ b/src/core/hs_delall.c @@ -35,11 +35,12 @@ class CommandHSDelAll : public Command notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick); return MOD_CONT; } + FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); nc = na->nc; for (i = 0; i < nc->aliases.count; ++i) { na = static_cast<NickAlias *>(nc->aliases.list[i]); - delHostCore(na->nick); + na->hostinfo.RemoveVhost(); } alog("vHosts for all nicks in group \002%s\002 deleted by oper \002%s\002", nc->display, u->nick); notice_lang(Config.s_HostServ, u, HOST_DELALL, nc->display); diff --git a/src/core/hs_group.c b/src/core/hs_group.c index 4a2ef6036..335044221 100644 --- a/src/core/hs_group.c +++ b/src/core/hs_group.c @@ -26,39 +26,14 @@ class CommandHSGroup : public Command CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) { - HostCore *tmp; - char *vHost = NULL; - char *vIdent = NULL; - char *creator = NULL; - HostCore *head = NULL; - time_t time; - bool found = false; - - head = hostCoreListHead(); - - tmp = findHostCore(head, u->nick, &found); - if (found) + NickAlias *na = findnick(u->nick); + if (na && u->nc == na->nc && na->hostinfo.HasVhost()) { - if (!tmp) - tmp = head; /* incase first in list */ - else if (tmp->next) /* we dont want the previous entry were not inserting! */ - tmp = tmp->next; /* jump to the next */ - - vHost = sstrdup(tmp->vHost); - if (tmp->vIdent) - vIdent = sstrdup(tmp->vIdent); - creator = sstrdup(tmp->creator); - time = tmp->time; - - do_hs_sync(u->nc, vIdent, vHost, creator, time); - if (tmp->vIdent) - notice_lang(Config.s_HostServ, u, HOST_IDENT_GROUP, u->nc->display, vIdent, vHost); + HostServSyncVhosts(na); + if (!na->hostinfo.GetIdent().empty()) + notice_lang(Config.s_HostServ, u, HOST_IDENT_GROUP, u->nc->display, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else - notice_lang(Config.s_HostServ, u, HOST_GROUP, u->nc->display, vHost); - delete [] vHost; - if (vIdent) - delete [] vIdent; - delete [] creator; + notice_lang(Config.s_HostServ, u, HOST_GROUP, u->nc->display, na->hostinfo.GetHost().c_str()); } else notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED); diff --git a/src/core/hs_list.c b/src/core/hs_list.c index 6d36f00dd..4943c2e3c 100644 --- a/src/core/hs_list.c +++ b/src/core/hs_list.c @@ -24,83 +24,55 @@ class CommandHSList : public Command CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) { - const char *key = params.size() ? params[0].c_str() : NULL; - struct tm *tm; - char buf[BUFSIZE]; - int counter = 1; - int from = 0, to = 0; - char *tmp = NULL; - char *s = NULL; + ci::string key = params.size() ? params[0] : ""; + int from = 0, to = 0, counter = 1; unsigned display_counter = 0; - HostCore *head = NULL; - HostCore *current; - - head = hostCoreListHead(); + tm *tm; + char buf[BUFSIZE]; - current = head; - if (!current) - notice_lang(Config.s_HostServ, u, HOST_EMPTY); - else + /** + * Do a check for a range here, then in the next loop + * we'll only display what has been requested.. + **/ + if (!key.empty() && key[0] == '#') { - /** - * Do a check for a range here, then in the next loop - * we'll only display what has been requested.. - **/ - if (key) + size_t tmp = key.find('-'); + if (tmp == ci::string::npos || tmp == key.size() || tmp == 1) + { + notice_lang(Config.s_HostServ, u, LIST_INCORRECT_RANGE); + return MOD_CONT; + } + for (unsigned i = 1; i < key.size(); ++i) { - if (key[0] == '#') + if (!isdigit(key[i]) && i != tmp) { - tmp = myStrGetOnlyToken((key + 1), '-', 0); /* Read FROM out */ - if (!tmp) - { - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - for (s = tmp; *s; ++s) - { - if (!isdigit(*s)) - { - delete [] tmp; - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - } - from = atoi(tmp); - delete [] tmp; - tmp = myStrGetTokenRemainder(key, '-', 1); /* Read TO out */ - if (!tmp) - { - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - for (s = tmp; *s; ++s) - { - if (!isdigit(*s)) - { - delete [] tmp; - notice_lang(Config.s_ChanServ, u, LIST_INCORRECT_RANGE); - return MOD_CONT; - } - } - to = atoi(tmp); - delete [] tmp; - key = NULL; + notice_lang(Config.s_HostServ, u, LIST_INCORRECT_RANGE); + return MOD_CONT; } + from = atoi(key.substr(1, tmp - 1).c_str()); + to = atoi(key.substr(tmp + 1, key.size()).c_str()); } + } - while (current) + for (int j = 0; j < 1024; ++j) + { + for (NickAlias *na = nalists[j]; na; na = na->next) { - if (key) + if (!na->hostinfo.HasVhost()) + continue; + + if (!key.empty() && key[0] != '#') { - if ((Anope::Match(current->nick, key, false) || Anope::Match(current->vHost, key, false)) && display_counter < Config.NSListMax) + if ((Anope::Match(na->nick, key) || Anope::Match(na->hostinfo.GetHost(), key.c_str())) && display_counter < Config.NSListMax) { ++display_counter; - tm = localtime(¤t->time); + time_t time = na->hostinfo.GetTime(); + tm = localtime(&time); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); - if (current->vIdent) - notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf); + if (!na->hostinfo.GetIdent().empty()) + notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); else - notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf); + notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick, na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); } } else @@ -112,26 +84,27 @@ class CommandHSList : public Command if (((counter >= from && counter <= to) || (!from && !to)) && display_counter < Config.NSListMax) { ++display_counter; - tm = localtime(¤t->time); + time_t time = na->hostinfo.GetTime(); + tm = localtime(&time); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); - if (current->vIdent) - notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, current->nick, current->vIdent, current->vHost, current->creator, buf); + if (!na->hostinfo.GetIdent().empty()) + notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, na->nick, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); else - notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, current->nick, current->vHost, current->creator, buf); + notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, na->nick, na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), buf); } } ++counter; - current = current->next; - } - if (key) - notice_lang(Config.s_HostServ, u, HOST_LIST_KEY_FOOTER, key, display_counter); - else { - if (from) - notice_lang(Config.s_HostServ, u, HOST_LIST_RANGE_FOOTER, from, to); - else - notice_lang(Config.s_HostServ, u, HOST_LIST_FOOTER, display_counter); } } + if (!key.empty()) + notice_lang(Config.s_HostServ, u, HOST_LIST_KEY_FOOTER, key.c_str(), display_counter); + else + { + if (from) + notice_lang(Config.s_HostServ, u, HOST_LIST_RANGE_FOOTER, from, to); + else + notice_lang(Config.s_HostServ, u, HOST_LIST_FOOTER, display_counter); + } return MOD_CONT; } diff --git a/src/core/hs_off.c b/src/core/hs_off.c index 84f4527ee..b5953e92c 100644 --- a/src/core/hs_off.c +++ b/src/core/hs_off.c @@ -24,12 +24,9 @@ class CommandHSOff : public Command CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) { - char *vhost; - char *vident = NULL; - - vhost = getvHost(u->nick); - vident = getvIdent(u->nick); - if (!vhost && !vident) + NickAlias *na = findnick(u->nick); + + if (!na || !na->hostinfo.HasVhost()) notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED); else { diff --git a/src/core/hs_on.c b/src/core/hs_on.c index aaddbf28d..8ccf65ff6 100644 --- a/src/core/hs_on.c +++ b/src/core/hs_on.c @@ -24,33 +24,29 @@ class CommandHSOn : public Command CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) { - char *vHost; - char *vIdent = NULL; - - vHost = getvHost(u->nick); - vIdent = getvIdent(u->nick); - if (!vHost) - notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED); - else + NickAlias *na = findnick(u->nick); + if (na && u->nc == na->nc && na->hostinfo.HasVhost()) { - if (vIdent) - notice_lang(Config.s_HostServ, u, HOST_IDENT_ACTIVATED, vIdent, vHost); + if (!na->hostinfo.GetIdent().empty()) + notice_lang(Config.s_HostServ, u, HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else - notice_lang(Config.s_HostServ, u, HOST_ACTIVATED, vHost); - ircdproto->SendVhost(u, vIdent, vHost); + notice_lang(Config.s_HostServ, u, HOST_ACTIVATED, na->hostinfo.GetHost().c_str()); + ircdproto->SendVhost(u, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); if (ircd->vhost) { if (u->vhost) delete [] u->vhost; - u->vhost = sstrdup(vHost); + u->vhost = sstrdup(na->hostinfo.GetHost().c_str()); } if (ircd->vident) { - if (vIdent) - u->SetVIdent(vIdent); + if (!na->hostinfo.GetIdent().empty()) + u->SetVIdent(na->hostinfo.GetIdent()); } - set_lastmask(u); + u->UpdateHost(); } + else + notice_lang(Config.s_HostServ, u, HOST_NOT_ASSIGNED); return MOD_CONT; } diff --git a/src/core/hs_set.c b/src/core/hs_set.c index 75c3b85ec..cd5ce0552 100644 --- a/src/core/hs_set.c +++ b/src/core/hs_set.c @@ -122,7 +122,8 @@ class CommandHSSet : public Command alog("vHost for user \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick); else alog("vHost for user \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick); - addHostCore(nick, vIdent, hostmask, u->nick, tmp_time); + na->hostinfo.SetVhost(vIdent ? vIdent : "", hostmask, u->nick); + FOREACH_MOD(I_OnSetVhost, OnSetVhost(na)); if (vIdent) notice_lang(Config.s_HostServ, u, HOST_IDENT_SET, nick, vIdent, hostmask); else diff --git a/src/core/hs_setall.c b/src/core/hs_setall.c index 7ab5420cd..ab21075da 100644 --- a/src/core/hs_setall.c +++ b/src/core/hs_setall.c @@ -15,8 +15,6 @@ #include "module.h" -extern int do_hs_sync(NickCore *nc, char *vIdent, char *hostmask, char *creator, time_t time); - class CommandHSSetAll : public Command { public: @@ -36,6 +34,17 @@ class CommandHSSetAll : public Command char *vIdent = NULL; + if (!(na = findnick(nick))) + { + notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); + return MOD_CONT; + } + else if (na->HasFlag(NS_FORBIDDEN)) + { + notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick); + return MOD_CONT; + } + vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ if (vIdent) { @@ -107,30 +116,17 @@ class CommandHSSetAll : public Command tmp_time = time(NULL); - if ((na = findnick(nick))) - { - if (na->HasFlag(NS_FORBIDDEN)) - { - notice_lang(Config.s_HostServ, u, NICK_X_FORBIDDEN, nick); - if (vIdent) { - delete [] vIdent; - delete [] rawhostmask; - } - delete [] hostmask; - return MOD_CONT; - } - if (vIdent && ircd->vident) - alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick); - else - alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick); - do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time); - if (vIdent) - notice_lang(Config.s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, hostmask); - else - notice_lang(Config.s_HostServ, u, HOST_SETALL, nick, hostmask); - } + if (vIdent && ircd->vident) + alog("vHost for all nicks in group \002%s\002 set to \002%s@%s\002 by oper \002%s\002", nick, vIdent, hostmask, u->nick); else - notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); + alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick); + na->hostinfo.SetVhost(vIdent ? vIdent : "", hostmask, u->nick); + HostServSyncVhosts(na); + FOREACH_MOD(I_OnSetVhost, OnSetVhost(na)); + if (vIdent) + notice_lang(Config.s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, hostmask); + else + notice_lang(Config.s_HostServ, u, HOST_SETALL, nick, hostmask); if (vIdent) { delete [] vIdent; diff --git a/src/core/ns_info.c b/src/core/ns_info.c index 56fa79c71..6161a05ff 100644 --- a/src/core/ns_info.c +++ b/src/core/ns_info.c @@ -140,17 +140,12 @@ class CommandNSInfo : public Command if (show_hidden) { - if (Config.s_HostServ && ircd->vhost) { - if (getvHost(na->nick) != NULL) { - if (ircd->vident && getvIdent(na->nick) != NULL) { - notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST2, - getvIdent(na->nick), - getvHost(na->nick)); - } else { - notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST, - getvHost(na->nick)); - } - } + if (Config.s_HostServ && ircd->vhost && na->hostinfo.HasVhost()) + { + if (ircd->vident && !na->hostinfo.GetIdent().empty()) + notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST2, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); + else + notice_lang(Config.s_NickServ, u, NICK_INFO_VHOST, na->hostinfo.GetHost().c_str()); } if (na->nc->greet) notice_lang(Config.s_NickServ, u, NICK_INFO_GREET, na->nc->greet); diff --git a/src/hostserv.c b/src/hostserv.c index 8be8ddc39..55a6abb27 100644 --- a/src/hostserv.c +++ b/src/hostserv.c @@ -18,8 +18,6 @@ #define HASH(nick) ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31)) -HostCore *head = NULL; /* head of the HostCore list */ - E int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask, char *creator, time_t time); @@ -42,19 +40,22 @@ void moduleAddHostServCmds() void get_hostserv_stats(long *nrec, long *memuse) { long count = 0, mem = 0; - HostCore *hc; - - for (hc = head; hc; hc = hc->next) { - count++; - mem += sizeof(*hc); - if (hc->nick) - mem += strlen(hc->nick) + 1; - if (hc->vIdent) - mem += strlen(hc->vIdent) + 1; - if (hc->vHost) - mem += strlen(hc->vHost) + 1; - if (hc->creator) - mem += strlen(hc->creator) + 1; + + for (int i = 0; i < 1024; ++i) + { + for (NickAlias *na = nalists[i]; na; na = na->next) + { + if (!na->hostinfo.HasVhost()) + continue; + + if (!na->hostinfo.GetIdent().empty()) + mem += na->hostinfo.GetIdent().size(); + if (!na->hostinfo.GetHost().empty()) + mem += na->hostinfo.GetHost().size(); + if (!na->hostinfo.GetCreator().empty()) + mem += na->hostinfo.GetCreator().size(); + ++count; + } } *nrec = count; @@ -104,314 +105,116 @@ void hostserv(User * u, char *buf) } } -/*************************************************************************/ -/* Start of Linked List routines */ -/*************************************************************************/ - -HostCore *hostCoreListHead() -{ - return head; -} - -/** - * Create HostCore list member - * @param next HostCore next slot - * @param nick Nick to add - * @param vIdent Virtual Ident - * @param vHost Virtual Host - * @param creator Person whom set the vhost - * @param time Time the vhost was Set - * @return HostCore +/** Set a vhost for the user + * @param ident The ident + * @param host The host + * @param creator Who created the vhost + * @param time When the vhost was craated */ -HostCore *createHostCorelist(HostCore * next, const char *nick, char *vIdent, - char *vHost, const char *creator, int32 tmp_time) +void HostInfo::SetVhost(const std::string &ident, const std::string &host, const std::string &creator, time_t time) { - - next = new HostCore; - if (next == NULL) { - ircdproto->SendGlobops(findbot(Config.s_HostServ), - "Unable to allocate memory to create the vHost LL, problems i sense.."); - } else { - next->nick = new char[strlen(nick) + 1]; - next->vHost = new char[strlen(vHost) + 1]; - next->creator = new char[strlen(creator) + 1]; - if (vIdent) - next->vIdent = new char[strlen(vIdent) + 1]; - if ((next->nick == NULL) || (next->vHost == NULL) - || (next->creator == NULL)) { - ircdproto->SendGlobops(findbot(Config.s_HostServ), - "Unable to allocate memory to create the vHost LL, problems i sense.."); - return NULL; - } - strlcpy(next->nick, nick, strlen(nick) + 1); - strlcpy(next->vHost, vHost, strlen(vHost) + 1); - strlcpy(next->creator, creator, strlen(creator) + 1); - if (vIdent) { - if ((next->vIdent == NULL)) { - ircdproto->SendGlobops(findbot(Config.s_HostServ), - "Unable to allocate memory to create the vHost LL, problems i sense.."); - return NULL; - } - strlcpy(next->vIdent, vIdent, strlen(vIdent) + 1); - } else { - next->vIdent = NULL; - } - next->time = tmp_time; - next->next = NULL; - return next; - } - return NULL; + Ident = ident; + Host = host; + Creator = creator; + Time = time; } -/*************************************************************************/ -/** - * Returns either NULL for the head, or the location of the *PREVIOUS* - * record, this is where we need to insert etc.. - * @param head HostCore head - * @param nick Nick to find - * @param found If found - * @return HostCore - */ -HostCore *findHostCore(HostCore * phead, const char *nick, bool* found) -{ - HostCore *previous, *current; - - *found = false; - current = phead; - previous = current; - - if (!nick) { - return NULL; - } - FOREACH_MOD(I_OnFindHostCore, OnFindHostCore(nick)); - while (current != NULL) { - if (stricmp(nick, current->nick) == 0) { - *found = true; - break; - } else if (stricmp(nick, current->nick) < 0) { - /* we know were not gonna find it now.... */ - break; - } else { - previous = current; - current = current->next; - } - } - if (current == phead) { - return NULL; - } else { - return previous; - } -} - -/*************************************************************************/ -HostCore *insertHostCore(HostCore * phead, HostCore * prev, const char *nick, - char *vIdent, char *vHost, const char *creator, - int32 tmp_time) +/** Remove a users vhost + **/ +void HostInfo::RemoveVhost() { - - HostCore *newCore, *tmp; - - if (!nick || !vHost || !creator) { - return NULL; - } - - newCore = new HostCore; - if (newCore == NULL) { - ircdproto->SendGlobops(findbot(Config.s_HostServ), - "Unable to allocate memory to insert into the vHost LL, problems i sense.."); - return NULL; - } else { - newCore->nick = new char[strlen(nick) + 1]; - newCore->vHost = new char[strlen(vHost) + 1]; - newCore->creator = new char[strlen(creator) + 1]; - if (vIdent) - newCore->vIdent = new char[strlen(vIdent) + 1]; - if ((newCore->nic |
