summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-02 08:20:59 +0000
committerAdam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864>2010-01-02 08:20:59 +0000
commita819cb0cc0f54a042a088dfba9c1f6b817928641 (patch)
tree7931a9d81367c184ca2550a1819ef685e3e0c927 /src/core
parent3617d7978899f830d952d9bac70ed14bb0cc0fd6 (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
Diffstat (limited to 'src/core')
-rw-r--r--src/core/db_plain.cpp29
-rw-r--r--src/core/hs_del.c3
-rw-r--r--src/core/hs_delall.c3
-rw-r--r--src/core/hs_group.c37
-rw-r--r--src/core/hs_list.c125
-rw-r--r--src/core/hs_off.c9
-rw-r--r--src/core/hs_on.c28
-rw-r--r--src/core/hs_set.c3
-rw-r--r--src/core/hs_setall.c46
-rw-r--r--src/core/ns_info.c17
10 files changed, 114 insertions, 186 deletions
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> &params)
alog("[db_plain]: loaded channel %s", ci->name);
}
-static void LoadHostInfo(const std::vector<std::string> &params)
-{
- 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> &params)
{
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> &params)
{
- 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> &params)
{
- 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(&current->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(&current->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> &params)
{
- 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> &params)
{
- 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);