From c8c23158a4ff74822d6c7d201dc53d879e3d91e8 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 22 Apr 2011 03:16:11 -0400 Subject: Moved the core pseudo clients out into their own modules --- src/bots.cpp | 75 +++---- src/botserv.cpp | 554 ---------------------------------------------- src/channels.cpp | 52 +---- src/chanserv.cpp | 274 +---------------------- src/commands.cpp | 8 +- src/config.cpp | 207 ++++------------- src/hostserv.cpp | 97 -------- src/init.cpp | 47 +--- src/logger.cpp | 65 ++---- src/main.cpp | 57 +---- src/memoserv.cpp | 334 ---------------------------- src/misc.cpp | 310 ++++++-------------------- src/modes.cpp | 2 +- src/nickalias.cpp | 11 - src/nickcore.cpp | 20 -- src/nickserv.cpp | 242 -------------------- src/operserv.cpp | 294 +++--------------------- src/protocol.cpp | 64 ++---- src/regchannel.cpp | 16 +- src/servers.cpp | 4 - src/sessions.cpp | 292 ------------------------ src/users.cpp | 109 ++------- src/win32/anope_windows.h | 6 +- src/win32/windows.cpp | 152 ++++++++++++- 24 files changed, 419 insertions(+), 2873 deletions(-) delete mode 100644 src/sessions.cpp (limited to 'src') diff --git a/src/bots.cpp b/src/bots.cpp index 95a5c2aa5..c67456ba4 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -12,14 +12,6 @@ Anope::insensitive_map BotListByNick; Anope::map BotListByUID; -BotInfo *BotServ = NULL; -BotInfo *ChanServ = NULL; -BotInfo *Global = NULL; -BotInfo *HostServ = NULL; -BotInfo *MemoServ = NULL; -BotInfo *NickServ = NULL; -BotInfo *OperServ = NULL; - BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal) : User(nnick, nuser, nhost, ts6_uid_retrieve()), Flags(BotFlagString) { this->realname = nreal; @@ -28,24 +20,6 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A this->chancount = 0; this->lastmsg = this->created = Anope::CurTime; - this->SetFlag(BI_CORE); - if (!Config->s_ChanServ.empty() && nnick.equals_ci(Config->s_ChanServ)) - ChanServ = this; - else if (!Config->s_BotServ.empty() && nnick.equals_ci(Config->s_BotServ)) - BotServ = this; - else if (!Config->s_HostServ.empty() && nnick.equals_ci(Config->s_HostServ)) - HostServ = this; - else if (!Config->s_OperServ.empty() && nnick.equals_ci(Config->s_OperServ)) - OperServ = this; - else if (!Config->s_MemoServ.empty() && nnick.equals_ci(Config->s_MemoServ)) - MemoServ = this; - else if (!Config->s_NickServ.empty() && nnick.equals_ci(Config->s_NickServ)) - NickServ = this; - else if (!Config->s_GlobalNoticer.empty() && nnick.equals_ci(Config->s_GlobalNoticer)) - Global = this; - else - this->UnsetFlag(BI_CORE); - BotListByNick[this->nick] = this; if (!this->uid.empty()) BotListByUID[this->uid] = this; @@ -60,6 +34,31 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A this->SetModeInternal(ModeManager::FindUserModeByName(UMODE_PROTECTED)); this->SetModeInternal(ModeManager::FindUserModeByName(UMODE_GOD)); + + for (unsigned i = 0; i < Config->LogInfos.size(); ++i) + { + LogInfo *l = Config->LogInfos[i]; + + if (!ircd->join2msg && !l->Inhabit) + continue; + + for (std::list::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit) + { + const Anope::string &target = *sit; + + if (target[0] == '#') + { + Channel *c = findchan(target); + if (!c) + c = new Channel(target); + c->SetFlag(CH_LOGCHAN); + c->SetFlag(CH_PERSIST); + + if (!c->FindUser(this)) + this->Join(c, &Config->BotModeList); + } + } + } } BotInfo::~BotInfo() @@ -91,24 +90,6 @@ BotInfo::~BotInfo() BotListByNick.erase(this->nick); if (!this->uid.empty()) BotListByUID.erase(this->uid); - - if (this->HasFlag(BI_CORE)) - { - if (this == ChanServ) - ChanServ = NULL; - else if (this == BotServ) - BotServ = NULL; - else if (this == HostServ) - HostServ = NULL; - else if (this == OperServ) - OperServ = NULL; - else if (this == MemoServ) - MemoServ = NULL; - else if (this == NickServ) - NickServ = NULL; - else if (this == Global) - Global = NULL; - } } void BotInfo::SetNewNick(const Anope::string &newnick) @@ -213,3 +194,9 @@ void BotInfo::Part(Channel *c, const Anope::string &reason) ircdproto->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); c->DeleteUser(this); } + +void BotInfo::OnMessage(User *u, const Anope::string &message) +{ + mod_run_cmd(this, u, NULL, message); +} + diff --git a/src/botserv.cpp b/src/botserv.cpp index 119264c1d..45d30b395 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -14,351 +14,6 @@ #include "services.h" #include "modules.h" -static UserData *get_user_data(Channel *c, User *u); - -E void moduleAddBotServCmds(); - -/*************************************************************************/ - -void moduleAddBotServCmds() -{ - ModuleManager::LoadModuleList(Config->BotServCoreModules); -} - -/*************************************************************************/ -/*************************************************************************/ - -/* Return information on memory use. Assumes pointers are valid. */ - -void get_botserv_stats(long *nrec, long *memuse) -{ - long count = 0, mem = 0; - - for (Anope::insensitive_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) - { - BotInfo *bi = it->second; - - ++count; - mem += sizeof(*bi); - mem += bi->nick.length() + 1; - mem += bi->GetIdent().length() + 1; - mem += bi->host.length() + 1; - mem += bi->realname.length() + 1; - } - - *nrec = count; - *memuse = mem; -} - -/*************************************************************************/ -/*************************************************************************/ - -/* BotServ initialization. */ - -void bs_init() -{ - if (!Config->s_BotServ.empty()) - moduleAddBotServCmds(); -} - -/*************************************************************************/ - -/* Handles all messages that are sent to registered channels where a - * bot is on. - */ - -void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) -{ - if (!u || !ci || !ci->c || buf.empty()) - return; - - /* Answer to ping if needed */ - if (buf.substr(0, 6).equals_ci("\1PING ") && buf[buf.length() - 1] == '\1') - { - Anope::string ctcp = buf; - ctcp.erase(ctcp.begin()); - ctcp.erase(ctcp.length() - 1); - ircdproto->SendCTCP(ci->bi, u->nick, "%s", ctcp.c_str()); - } - - bool was_action = false; - Anope::string realbuf = buf; - - /* If it's a /me, cut the CTCP part because the ACTION will cause - * problems with the caps or badwords kicker - */ - if (realbuf.substr(0, 8).equals_ci("\1ACTION ") && realbuf[realbuf.length() - 1] == '\1') - { - realbuf.erase(0, 8); - realbuf.erase(realbuf.length() - 1); - was_action = true; - } - - if (realbuf.empty()) - return; - - /* Now we can make kicker stuff. We try to order the checks - * from the fastest one to the slowest one, since there's - * no need to process other kickers if a user is kicked before - * the last kicker check. - * - * But FIRST we check whether the user is protected in any - * way. - */ - - bool Allow = true; - if (check_access(u, ci, CA_NOKICK)) - Allow = false; - else if (ci->botflags.HasFlag(BS_DONTKICKOPS) && (ci->c->HasUserStatus(u, CMODE_HALFOP) || ci->c->HasUserStatus(u, CMODE_OP) || ci->c->HasUserStatus(u, CMODE_PROTECT) || ci->c->HasUserStatus(u, CMODE_OWNER))) - Allow = false; - else if (ci->botflags.HasFlag(BS_DONTKICKVOICES) && ci->c->HasUserStatus(u, CMODE_VOICE)) - Allow = false; - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPrivmsg, OnPrivmsg(u, ci, realbuf, Allow)); - if (MOD_RESULT == EVENT_STOP) - return; - - if (Allow) - { - /* Bolds kicker */ - if (ci->botflags.HasFlag(BS_KICK_BOLDS) && realbuf.find(2) != Anope::string::npos) - { - check_ban(ci, u, TTB_BOLDS); - bot_kick(ci, u, _("Don't use bolds on this channel!")); - return; - } - - /* Color kicker */ - if (ci->botflags.HasFlag(BS_KICK_COLORS) && realbuf.find(3) != Anope::string::npos) - { - check_ban(ci, u, TTB_COLORS); - bot_kick(ci, u, _("Don't use colors on this channel!")); - return; - } - - /* Reverses kicker */ - if (ci->botflags.HasFlag(BS_KICK_REVERSES) && realbuf.find(22) != Anope::string::npos) - { - check_ban(ci, u, TTB_REVERSES); - bot_kick(ci, u, _("Don't use reverses on this channel!")); - return; - } - - /* Italics kicker */ - if (ci->botflags.HasFlag(BS_KICK_ITALICS) && realbuf.find(29) != Anope::string::npos) - { - check_ban(ci, u, TTB_ITALICS); - bot_kick(ci, u, _("Don't use italics on this channel!")); - return; - } - - /* Underlines kicker */ - if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && realbuf.find(31) != Anope::string::npos) - { - check_ban(ci, u, TTB_UNDERLINES); - bot_kick(ci, u, _("Don't use underlines on this channel!")); - return; - } - - /* Caps kicker */ - if (ci->botflags.HasFlag(BS_KICK_CAPS) && realbuf.length() >= ci->capsmin) - { - int i = 0, l = 0; - - for (unsigned j = 0, end = realbuf.length(); j < end; ++j) - { - if (isupper(realbuf[j])) - ++i; - else if (islower(realbuf[j])) - ++l; - } - - /* i counts uppercase chars, l counts lowercase chars. Only - * alphabetic chars (so islower || isupper) qualify for the - * percentage of caps to kick for; the rest is ignored. -GD - */ - - if ((i || l) && i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent) - { - check_ban(ci, u, TTB_CAPS); - bot_kick(ci, u, _("Turn caps lock OFF!")); - return; - } - } - - /* Bad words kicker */ - if (ci->botflags.HasFlag(BS_KICK_BADWORDS)) - { - bool mustkick = false; - - /* Normalize the buffer */ - Anope::string nbuf = normalizeBuffer(realbuf); - - for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i) - { - BadWord *bw = ci->GetBadWord(i); - - if (bw->type == BW_ANY && ((Config->BSCaseSensitive && nbuf.find(bw->word) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(bw->word) != Anope::string::npos))) - mustkick = true; - else if (bw->type == BW_SINGLE) - { - size_t len = bw->word.length(); - - if ((Config->BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config->BSCaseSensitive && bw->word.equals_ci(nbuf))) - mustkick = true; - else if (nbuf.find(' ') == len && ((Config->BSCaseSensitive && bw->word.equals_cs(nbuf)) || (!Config->BSCaseSensitive && bw->word.equals_ci(nbuf)))) - mustkick = true; - else - { - if (nbuf.rfind(' ') == nbuf.length() - len - 1 && ((Config->BSCaseSensitive && nbuf.find(bw->word) == nbuf.length() - len) || (!Config->BSCaseSensitive && nbuf.find_ci(bw->word) == nbuf.length() - len))) - mustkick = true; - else - { - Anope::string wordbuf = " " + bw->word + " "; - - if ((Config->BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) - mustkick = true; - } - } - } - else if (bw->type == BW_START) - { - size_t len = bw->word.length(); - - if ((Config->BSCaseSensitive && nbuf.substr(0, len).equals_cs(bw->word)) || (!Config->BSCaseSensitive && nbuf.substr(0, len).equals_ci(bw->word))) - mustkick = true; - else - { - Anope::string wordbuf = " " + bw->word; - - if ((Config->BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) - mustkick = true; - } - } - else if (bw->type == BW_END) - { - size_t len = bw->word.length(); - - if ((Config->BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_cs(bw->word)) || (!Config->BSCaseSensitive && nbuf.substr(nbuf.length() - len).equals_ci(bw->word))) - mustkick = true; - else - { - Anope::string wordbuf = bw->word + " "; - - if ((Config->BSCaseSensitive && nbuf.find(wordbuf) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(wordbuf) != Anope::string::npos)) - mustkick = true; - } - } - - if (mustkick) - { - check_ban(ci, u, TTB_BADWORDS); - if (Config->BSGentleBWReason) - bot_kick(ci, u, _("Watch your language!")); - else - bot_kick(ci, u, _("Don't use the word \"%s\" on this channel!"), bw->word.c_str()); - - return; - } - } - } - - /* Flood kicker */ - if (ci->botflags.HasFlag(BS_KICK_FLOOD)) - { - UserData *ud = get_user_data(ci->c, u); - if (!ud) - return; - - if (Anope::CurTime - ud->last_start > ci->floodsecs) - { - ud->last_start = Anope::CurTime; - ud->lines = 0; - } - - ++ud->lines; - if (ud->lines >= ci->floodlines) - { - check_ban(ci, u, TTB_FLOOD); - bot_kick(ci, u, _("Stop flooding!")); - return; - } - } - - /* Repeat kicker */ - if (ci->botflags.HasFlag(BS_KICK_REPEAT)) - { - UserData *ud = get_user_data(ci->c, u); - if (!ud) - return; - - if (!ud->lastline.empty() && !ud->lastline.equals_ci(buf)) - { - ud->lastline = buf; - ud->times = 0; - } - else - { - if (ud->lastline.empty()) - ud->lastline = buf; - ++ud->times; - } - - if (ud->times >= ci->repeattimes) - { - check_ban(ci, u, TTB_REPEAT); - bot_kick(ci, u, _("Stop repeating yourself!")); - return; - } - } - } - - /* Fantaisist commands */ - if (ci->botflags.HasFlag(BS_FANTASY) && buf[0] == Config->BSFantasyCharacter[0] && !was_action) - { - Anope::string message = buf; - /* Strip off the fantasy character */ - message.erase(message.begin()); - - size_t space = message.find(' '); - Anope::string command, rest; - if (space == Anope::string::npos) - command = message; - else - { - command = message.substr(0, space); - rest = message.substr(space + 1); - } - - if (check_access(u, ci, CA_FANTASIA)) - { - - Command *cmd = FindCommand(ChanServ, command); - - /* Command exists and can be called by fantasy */ - if (cmd && !cmd->HasFlag(CFLAG_DISABLE_FANTASY)) - { - Anope::string params = rest; - /* Some commands don't need the channel name added.. eg !help */ - if (!cmd->HasFlag(CFLAG_STRIP_CHANNEL)) - params = ci->name + " " + params; - params = command + " " + params; - - mod_run_cmd(ChanServ, u, ci, params); - } - - FOREACH_MOD(I_OnBotFantasy, OnBotFantasy(command, u, ci, rest)); - } - else - { - FOREACH_MOD(I_OnBotNoFantasyAccess, OnBotNoFantasyAccess(command, u, ci, rest)); - } - } -} - -/*************************************************************************/ - BotInfo *findbot(const Anope::string &nick) { BotInfo *bi = NULL; @@ -380,138 +35,6 @@ BotInfo *findbot(const Anope::string &nick) return bi; } -/*************************************************************************/ - -/* Returns ban data associated with a user if it exists, allocates it - otherwise. */ - -static BanData *get_ban_data(Channel *c, User *u) -{ - if (!c || !u) - return NULL; - - Anope::string mask = u->GetIdent() + "@" + u->GetDisplayedHost(); - /* XXX This should really be on some sort of timer/garbage collector, and use std::map */ - for (std::list::iterator it = c->bd.begin(), it_end = c->bd.end(), it_next; it != it_end; it = it_next) - { - it_next = it; - ++it_next; - - if (Anope::CurTime - (*it)->last_use > Config->BSKeepData) - { - delete *it; - c->bd.erase(it); - continue; - } - if ((*it)->mask.equals_ci(mask)) - { - (*it)->last_use = Anope::CurTime; - return *it; - } - } - - /* If we fall here it is that we haven't found the record */ - BanData *bd = new BanData(); - bd->mask = mask; - bd->last_use = Anope::CurTime; - for (int x = 0; x < TTB_SIZE; ++x) - bd->ttb[x] = 0; - - c->bd.push_front(bd); - - return bd; -} - -/*************************************************************************/ - -/* Returns BotServ data associated with a user on a given channel. - * Allocates it if necessary. - */ - -static UserData *get_user_data(Channel *c, User *u) -{ - if (!c || !u) - return NULL; - - for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) - { - UserContainer *uc = *it; - - if (uc->user == u) - { - /* Checks whether data is obsolete */ - if (Anope::CurTime - uc->ud.last_use > Config->BSKeepData) - { - /* We should not free and realloc, but reset to 0 - instead. */ - uc->ud.Clear(); - uc->ud.last_use = Anope::CurTime; - } - - return &uc->ud; - } - } - - return NULL; -} - -/*************************************************************************/ - -/** Check if a user should be banned by botserv - * @param ci The channel the user is on - * @param u The user - * @param ttbtype The type of bot kicker the user should be checked against - */ -void check_ban(ChannelInfo *ci, User *u, int ttbtype) -{ - BanData *bd = get_ban_data(ci->c, u); - - if (!bd) - return; - - /* Don't ban ulines */ - if (u->server->IsULined()) - return; - - ++bd->ttb[ttbtype]; - if (ci->ttb[ttbtype] && bd->ttb[ttbtype] >= ci->ttb[ttbtype]) - { - /* Should not use == here because bd->ttb[ttbtype] could possibly be > ci->ttb[ttbtype] - * if the TTB was changed after it was not set (0) before and the user had already been - * kicked a few times. Bug #1056 - Adam */ - Anope::string mask; - - bd->ttb[ttbtype] = 0; - - get_idealban(ci, u, mask); - - if (ci->c) - ci->c->SetMode(NULL, CMODE_BAN, mask); - FOREACH_MOD(I_OnBotBan, OnBotBan(u, ci, mask)); - } -} - -/*************************************************************************/ - -/* This makes a bot kick a user. Works somewhat like notice_lang in fact ;) */ - -void bot_kick(ChannelInfo *ci, User *u, const char *message, ...) -{ - va_list args; - char buf[1024]; - - if (!ci || !ci->bi || !ci->c || !u) - return; - - Anope::string fmt = GetString(u->Account(), message); - va_start(args, message); - if (fmt.empty()) - return; - vsnprintf(buf, sizeof(buf), fmt.c_str(), args); - va_end(args); - - ci->c->Kick(ci->bi, u, "%s", buf); -} /*************************************************************************/ @@ -585,80 +108,3 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, User *u, const Anope::string ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str()); } -/*************************************************************************/ - -/** - * Normalize buffer stripping control characters and colors - * @param A string to be parsed for control and color codes - * @return A string stripped of control and color codes - */ -Anope::string normalizeBuffer(const Anope::string &buf) -{ - Anope::string newbuf; - - for (unsigned i = 0, end = buf.length(); i < end; ++i) - { - switch (buf[i]) - { - /* ctrl char */ - case 1: - break; - /* Bold ctrl char */ - case 2: - break; - /* Color ctrl char */ - case 3: - /* If the next character is a digit, its also removed */ - if (isdigit(buf[i + 1])) - { - ++i; - - /* not the best way to remove colors - * which are two digit but no worse then - * how the Unreal does with +S - TSL - */ - if (isdigit(buf[i + 1])) - ++i; - - /* Check for background color code - * and remove it as well - */ - if (buf[i + 1] == ',') - { - ++i; - - if (isdigit(buf[i + 1])) - ++i; - /* not the best way to remove colors - * which are two digit but no worse then - * how the Unreal does with +S - TSL - */ - if (isdigit(buf[i + 1])) - ++i; - } - } - - break; - /* line feed char */ - case 10: - break; - /* carriage returns char */ - case 13: - break; - /* Reverse ctrl char */ - case 22: - break; - /* Underline ctrl char */ - case 31: - break; - /* Italic ctrl char */ - case 29: - break; - /* A valid char gets copied into the new buffer */ - default: - newbuf += buf[i]; - } - } - - return newbuf; -} diff --git a/src/channels.cpp b/src/channels.cpp index 2fe4e037d..29e34cfaf 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -52,9 +52,6 @@ Channel::~Channel() Log(NULL, this, "destroy"); - for (std::list::iterator it = this->bd.begin(), it_end = this->bd.end(); it != it_end; ++it) - delete *it; - if (this->ci) this->ci->c = NULL; @@ -128,14 +125,6 @@ void Channel::JoinUser(User *user) this->Reset(); } - if (this->ci && check_access(user, this->ci, CA_MEMO) && this->ci->memos.memos.size() > 0) - { - if (this->ci->memos.memos.size() == 1) - user->SendMessage(MemoServ, _("There is \002%d\002 memo on channel %s."), this->ci->memos.memos.size(), this->ci->name.c_str()); - else - user->SendMessage(MemoServ, _("There are \002%d\002 memos on channel %s."), this->ci->memos.memos.size(), this->ci->name.c_str()); - } - if (!Config->s_BotServ.empty() && this->ci && this->ci->bi) { /** @@ -838,8 +827,8 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) FOREACH_RESULT(I_OnBotKick, OnBotKick(bi, this, u, buf)); if (MOD_RESULT == EVENT_STOP) return false; - ircdproto->SendKick(bi ? bi : whosends(this->ci), this, u, "%s", buf); - this->KickInternal(bi ? bi->nick : whosends(this->ci)->nick, u->nick, buf); + ircdproto->SendKick(bi ? bi : this->ci->WhoSends(), this, u, "%s", buf); + this->KickInternal(bi ? bi->nick : this->ci->WhoSends()->nick, u->nick, buf); return true; } @@ -891,7 +880,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop this->topic_setter = u ? u->nick : user; this->topic_time = ts; - ircdproto->SendTopic(whosends(this->ci), this); + ircdproto->SendTopic(this->ci->WhoSends(), this); FOREACH_MOD(I_OnTopicUpdated, OnTopicUpdated(this, this->topic)); @@ -914,41 +903,6 @@ Channel *findchan(const Anope::string &chan) /*************************************************************************/ -/* Return statistics. Pointers are assumed to be valid. */ - -void get_channel_stats(long *nrec, long *memuse) -{ - long count = 0, mem = 0; - Anope::string buf; - - for (channel_map::const_iterator cit = ChannelList.begin(); cit != ChannelList.end(); ++cit) - { - Channel *chan = cit->second; - - ++count; - mem += sizeof(*chan); - if (!chan->topic.empty()) - mem += chan->topic.length() + 1; - for (CUserList::iterator it = chan->users.begin(), it_end = chan->users.end(); it != it_end; ++it) - { - mem += sizeof(*it); - mem += sizeof((*it)->ud); - if (!(*it)->ud.lastline.empty()) - mem += (*it)->ud.lastline.length() + 1; - } - for (std::list::iterator it = chan->bd.begin(), it_end = chan->bd.end(); it != it_end; ++it) - { - if (!(*it)->mask.empty()) - mem += (*it)->mask.length() + 1; - mem += sizeof(*it); - } - } - *nrec = count; - *memuse = mem; -} - -/*************************************************************************/ - /* Is the given nick on the given channel? This function supports links. */ diff --git a/src/chanserv.cpp b/src/chanserv.cpp index ef7005667..fe86cdae3 100644 --- a/src/chanserv.cpp +++ b/src/chanserv.cpp @@ -13,6 +13,7 @@ #include "services.h" #include "modules.h" +#include "chanserv.h" registered_channel_map RegisteredChannelList; @@ -140,70 +141,6 @@ Anope::string get_mlock_modes(ChannelInfo *ci, int complete) /*************************************************************************/ -/* Return information on memory use. Assumes pointers are valid. */ - -void get_chanserv_stats(long *nrec, long *memuse) -{ - long count = 0, mem = 0; - ModeLock *ml; - - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) - { - ChannelInfo *ci = it->second; - - ++count; - mem += sizeof(*ci); - if (!ci->desc.empty()) - mem += ci->desc.length() + 1; - mem += ci->GetAccessCount() * sizeof(ChanAccess); - mem += ci->GetAkickCount() * sizeof(AutoKick); - - ml = ci->GetMLock(CMODE_KEY); - if (ml && !ml->param.empty()) - mem += ml->param.length() + 1; - - ml = ci->GetMLock(CMODE_FLOOD); - if (ml && !ml->param.empty()) - mem += ml->param.length() + 1; - - ml = ci->GetMLock(CMODE_REDIRECT); - if (ml && !ml->param.empty()) - mem += ml->param.length() + 1; - - if (!ci->last_topic.empty()) - mem += ci->last_topic.length() + 1; - if (!ci->forbidby.empty()) - mem += ci->forbidby.length() + 1; - if (!ci->forbidreason.empty()) - mem += ci->forbidreason.length() + 1; - if (ci->levels) - mem += sizeof(*ci->levels) * CA_SIZE; - unsigned memos = ci->memos.memos.size(); - mem += memos * sizeof(Memo); - for (unsigned j = 0; j < memos; ++j) - if (!ci->memos.memos[j]->text.empty()) - mem += ci->memos.memos[j]->text.length() + 1; - if (ci->ttb) - mem += sizeof(*ci->ttb) * TTB_SIZE; - mem += ci->GetBadWordCount() * sizeof(BadWord); - } - *nrec = count; - *memuse = mem; -} - -/*************************************************************************/ -/*************************************************************************/ - -/* ChanServ initialization. */ - -void cs_init() -{ - if (!Config->s_ChanServ.empty()) - ModuleManager::LoadModuleList(Config->ChanServCoreModules); -} - -/*************************************************************************/ - /* Check the current modes on a channel; if they conflict with a mode lock, * fix them. */ @@ -288,194 +225,6 @@ void check_modes(Channel *c) /*************************************************************************/ -int check_valid_admin(User *user, Channel *chan, int servermode) -{ - ChannelMode *cm; - - if (!chan || !chan->ci) - return 1; - - if (!(cm = ModeManager::FindChannelModeByName(CMODE_PROTECT))) - return 0; - - /* They will be kicked; no need to deop, no need to update our internal struct too */ - if (chan->ci->HasFlag(CI_FORBIDDEN)) - return 0; - - if (servermode && !check_access(user, chan->ci, CA_AUTOPROTECT)) - { - user->SendMessage(ChanServ, _("This channel has been registered with %s."), Config->s_ChanServ.c_str()); - chan->RemoveMode(NULL, CMODE_PROTECT, user->nick); - return 0; - } - - return 1; -} - -/*************************************************************************/ - -/* Check whether a user is allowed to be opped on a channel; if they - * aren't, deop them. If serverop is 1, the +o was done by a server. - * Return 1 if the user is allowed to be opped, 0 otherwise. */ - -int check_valid_op(User *user, Channel *chan, int servermode) -{ - ChannelMode *owner, *protect, *halfop; - if (!chan || !chan->ci) - return 1; - - /* They will be kicked; no need to deop, no need to update our internal struct too */ - if (chan->ci->HasFlag(CI_FORBIDDEN)) - return 0; - - owner = ModeManager::FindChannelModeByName(CMODE_OWNER); - protect = ModeManager::FindChannelModeByName(CMODE_PROTECT); - halfop = ModeManager::FindChannelModeByName(CMODE_HALFOP); - - if (servermode && !check_access(user, chan->ci, CA_AUTOOP)) - { - user->SendMessage(ChanServ, _("This channel has been registered with %s."), Config->s_ChanServ.c_str()); - - if (owner) - chan->RemoveMode(NULL, CMODE_OWNER, user->nick); - if (protect) - chan->RemoveMode(NULL, CMODE_PROTECT, user->nick); - chan->RemoveMode(NULL, CMODE_OP, user->nick); - if (halfop && !check_access(user, chan->ci, CA_AUTOHALFOP)) - chan->RemoveMode(NULL, CMODE_HALFOP, user->nick); - - return 0; - } - - return 1; -} - -/*************************************************************************/ - -/* Remove all channels which have expired. */ - -void expire_chans() -{ - if (!Config->CSExpire) - return; - - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ) - { - ChannelInfo *ci = it->second; - ++it; - - bool expire = false; - if (ci->HasFlag(CI_SUSPENDED)) - { - if (Config->CSSuspendExpire && Anope::CurTime - ci->last_used >= Config->CSSuspendExpire) - expire = true; - } - else if (ci->HasFlag(CI_FORBIDDEN)) - { - if (Config->CSForbidExpire && Anope::CurTime - ci->last_used >= Config->CSForbidExpire) - expire = true; - } - else if (!ci->c && Anope::CurTime - ci->last_used >= Config->CSExpire) - expire = true; - - if (ci->HasFlag(CI_NO_EXPIRE)) - expire = false; - - if (expire) - { - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreChanExpire, OnPreChanExpire(ci)); - if (MOD_RESULT == EVENT_STOP) - continue; - - Anope::string extra; - if (ci->HasFlag(CI_FORBIDDEN)) - extra = "forbidden "; - else if (ci->HasFlag(CI_SUSPENDED)) - extra = "suspended "; - - Log(LOG_NORMAL, "chanserv/expire") << "Expiring " << extra << "channel " << ci->name << " (founder: " << (ci->founder ? ci->founder->display : "(none)") << ")"; - FOREACH_MOD(I_OnChanExpire, OnChanExpire(ci)); - delete ci; - } - } -} - -/*************************************************************************/ - -// XXX this is slightly inefficient -void cs_remove_nick(NickCore *nc) -{ - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end;) - { - ChannelInfo *ci = it->second; - ++it; - - for (unsigned j = ci->GetAkickCount(); j > 0; --j) - { - AutoKick *akick = ci->GetAkick(j - 1); - if (akick->HasFlag(AK_ISNICK) && akick->nc == nc) - ci->EraseAkick(j - 1); - } - - if (ci->founder == nc) - { - NickCore *newowner = NULL; - if (ci->successor && (ci->successor->IsServicesOper() || !Config->CSMaxReg || ci->successor->channelcount < Config->CSMaxReg)) - newowner = ci->successor; - else - { - ChanAccess *highest = NULL; - for (unsigned j = 0; j < ci->GetAccessCount(); ++j) - { - ChanAccess *ca = ci->GetAccess(j); - - if (!ca->nc || (!ca->nc->IsServicesOper() && Config->CSMaxReg && ca->nc->channelcount >= Config->CSMaxReg) || (ca->nc == nc)) - continue; - if (!highest || ca->level > highest->level) - highest = ca; - } - if (highest) - newowner = highest->nc; - } - - if (newowner) - { - Log(LOG_NORMAL, "chanserv/expire") << "Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to " << newowner->display; - ci->founder = newowner; - ci->successor = NULL; - ++newowner->channelcount; - } - else - { - Log(LOG_NORMAL, "chanserv/expire") << "Deleting channel " << ci->name << " owned by deleted nick " << nc->display; - - if (ModeManager::FindChannelModeByName(CMODE_REGISTERED)) - { - /* Maybe move this to delchan() ? */ - if (ci->c && ci->c->HasMode(CMODE_REGISTERED)) - ci->c->RemoveMode(NULL, CMODE_REGISTERED, true); - } - - delete ci; - continue; - } - } - - if (ci->successor == nc) - ci->successor = NULL; - - /* Note that it is important we lookup the access for the channel after the new founder - * has been determined incase this user was the founder and also was on the access list! - */ - ChanAccess *access = ci->GetAccess(nc); - if (access) - ci->EraseAccess(access); - } -} - -/*************************************************************************/ - ChannelInfo *cs_findchan(const Anope::string &chan) { FOREACH_MOD(I_OnFindChan, OnFindChan(chan)); @@ -534,10 +283,6 @@ int check_access(User *user, ChannelInfo *ci, int what) return level >= ci->levels[what]; } -/*************************************************************************/ -/*********************** ChanServ private routines ***********************/ -/*************************************************************************/ - /* Reset channel access level values to their default state. */ void reset_levels(ChannelInfo *ci) @@ -657,26 +402,29 @@ Anope::string get_xop_level(int level) ChanServTimer::ChanServTimer(Channel *chan) : Timer(Config->CSInhabit), c(chan) { - if (!ChanServ) + if (!chanserv) return; if (c->ci) c->ci->SetFlag(CI_INHABIT); if (!c->ci || !c->ci->bi) - ChanServ->Join(*c); + chanserv->Bot()->Join(c); else if (!c->FindUser(c->ci->bi)) - c->ci->bi->Join(*c); + c->ci->bi->Join(c); } void ChanServTimer::Tick(time_t) { - if (!c || !c->ci || !ChanServ) + if (!c || !c->ci) return; c->ci->UnsetFlag(CI_INHABIT); - if (!c->ci->bi && ChanServ) - ChanServ->Part(*c); + if (!c->ci->bi) + { + if (chanserv) + chanserv->Bot()->Part(c); + } else if (c->users.size() == 1 || c->users.size() < Config->BSMinUsers) - c->ci->bi->Part(*c); + c->ci->bi->Part(c); } diff --git a/src/commands.cpp b/src/commands.cpp index cfff8c764..03bc368cd 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -93,7 +93,7 @@ void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, Command *c, const Anope: } bool fantasy = ci != NULL; - if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && (bi == ChanServ || bi == BotServ)) +/* if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && (bi == ChanServ || bi == BotServ)) { if (ircdproto->IsChannelValid(params[0])) { @@ -121,15 +121,15 @@ void mod_run_cmd(BotInfo *bi, User *u, ChannelInfo *ci, Command *c, const Anope: PopLanguage(); return; } - } + }*/ /* A user not giving a channel name for a param that should be a channel */ - else +/* else { u->SendMessage(bi, _(CHAN_X_INVALID), params[0].c_str()); PopLanguage(); return; } - } + }*/ CommandSource source; source.u = u; diff --git a/src/config.cpp b/src/config.cpp index f75913fc9..293f3947f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -20,16 +20,6 @@ ServerConfig *Config = NULL; static Anope::string Modules; static Anope::string EncModules; static Anope::string DBModules; -static Anope::string HostCoreModules; -static Anope::string MemoCoreModules; -static Anope::string BotCoreModules; -static Anope::string OperCoreModules; -static Anope::string NickCoreModules; -static Anope::string ChanCoreModules; -static Anope::string DefCon1; -static Anope::string DefCon2; -static Anope::string DefCon3; -static Anope::string DefCon4; static Anope::string UlineServers; static Anope::string OSNotifications; static Anope::string BSDefaults; @@ -212,12 +202,6 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C this->ModulesAutoLoad = BuildStringList(Modules); this->EncModuleList = BuildStringList(EncModules); this->DBModuleList = BuildStringList(DBModules); - this->HostServCoreModules = BuildStringList(HostCoreModules); - this->MemoServCoreModules = BuildStringList(MemoCoreModules); - this->BotServCoreModules = BuildStringList(BotCoreModules); - this->OperServCoreModules = BuildStringList(OperCoreModules); - this->ChanServCoreModules = BuildStringList(ChanCoreModules); - this->NickServCoreModules = BuildStringList(NickCoreModules); if (this->LimitSessions) { @@ -237,93 +221,7 @@ ServerConfig::ServerConfig() : config_data(), NSDefFlags(NickCoreFlagStrings), C if (this->UserKey1 == this->UserKey2 || this->UserKey1 == this->UserKey3 || this->UserKey3 == this->UserKey2) Log() << "Every UserKey must be different. It's for YOUR safety! Remember that!"; - /** - * Check all DEFCON dependiencies... - **/ - if (this->DefConLevel) - { - /* Build DefCon's */ - DefCon.resize(6); - DefCon[5].reset(); - for (unsigned int level = 1; level < 5; ++level) - { - DefCon[level] = 0; - Anope::string *levelDefinition = NULL; - switch (level) - { - case 1: - levelDefinition = &DefCon1; - break; - case 2: - levelDefinition = &DefCon2; - break; - case 3: - levelDefinition = &DefCon3; - break; - case 4: - levelDefinition = &DefCon4; - } - spacesepstream operations(*levelDefinition); - Anope::string operation; - while (operations.GetToken(operation)) - { - if (operation.equals_ci("nonewchannels")) - AddDefCon(level, DEFCON_NO_NEW_CHANNELS); - else if (operation.equals_ci("nonewnicks")) - AddDefCon(level, DEFCON_NO_NEW_NICKS); - else if (operation.equals_ci("nomlockchanges")) - AddDefCon(level, DEFCON_NO_MLOCK_CHANGE); - else if (operation.equals_ci("forcechanmodes")) - AddDefCon(level, DEFCON_FORCE_CHAN_MODES); - else if (operation.equals_ci("reducedsessions")) - AddDefCon(level, DEFCON_REDUCE_SESSION); - else if (operation.equals_ci("nonewclients")) - AddDefCon(level, DEFCON_NO_NEW_CLIENTS); - else if (operation.equals_ci("operonly")) - AddDefCon(level, DEFCON_OPER_ONLY); - else if (operation.equals_ci("silentoperonly")) - AddDefCon(level, DEFCON_SILENT_OPER_ONLY); - else if (operation.equals_ci("akillnewclients")) - AddDefCon(level, DEFCON_AKILL_NEW_CLIENTS); - else if (operation.equals_ci("nonewmemos")) - AddDefCon(level, DEFCON_NO_NEW_MEMOS); - } - } - - /* Check any defcon needed settings */ - for (int defconCount = 1; defconCount <= 5; ++defconCount) - { - if (CheckDefCon(defconCount, DEFCON_REDUCE_SESSION)) - { - if (!this->DefConSessionLimit) - { - throw ConfigException("this->DefConSessionLimit missing"); - } - } - if (CheckDefCon(defconCount, DEFCON_AKILL_NEW_CLIENTS)) - { - if (!this->DefConAKILL) - { - throw ConfigException("this->DefConAKILL missing"); - } - if (this->DefConAkillReason.empty()) - { - throw ConfigException("this->DefConAkillReason missing"); - } - } - if (CheckDefCon(defconCount, DEFCON_FORCE_CHAN_MODES)) - { - if (this->DefConChanModes.empty()) - { - throw ConfigException("this->DefConChanModes missing"); - } - } - } - } - SetDefaultMLock(this); - if (ircd) - InitLogChannels(this); if (IsFile(this->NameServer)) { @@ -614,7 +512,7 @@ bool ValidateOperServ(ServerConfig *config, const Anope::string &tag, const Anop bool ValidateGlobal(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data) { - if (!config->s_GlobalNoticer.empty()) + if (!config->s_Global.empty()) { if (value.equals_ci("description") && data.GetValue().empty()) throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when Global is enabled!"); @@ -622,37 +520,6 @@ bool ValidateGlobal(ServerConfig *config, const Anope::string &tag, const Anope: return true; } -bool ValidateDefCon(ServerConfig *config, const Anope::string &tag, const Anope::string &value, ValueItem &data) -{ - if (value.equals_ci("defaultlevel")) - { - int level = data.GetInteger(); - if (!level) - return true; - if (level > 5) - throw ConfigException("The value for must be between 1 through 5 if you wish to use DefCon or 0 if you wish to disable it!"); - } - else if (config->DefConLevel) - { - if ((value.substr(0, 5).equals_ci("level") && isdigit(value[5])) || value.equals_ci("chanmodes") || value.equals_ci("akillreason")) - { - if (data.GetValue().empty()) - throw ConfigException("The value for <" + tag + ":" + value + "> cannot be empty when DefCon is enabled!"); - } - else if (value.equals_ci("message") && config->GlobalOnDefconMore) - { - if (data.GetValue().empty()) - throw ConfigException("The value for cannot be empty when globalondefconmore is enabled!"); - } - else if (value.equals_ci("sessionlimit") || value.equals_ci("akillexpire")) - { - if (!data.GetInteger() && dotime(data.GetValue()) <= 0) - throw ConfigException("The value for <" + tag + ":" + value + "> must be non-zero when DefCon is enabled!"); - } - } - return true; -} - bool ValidateNickLen(ServerConfig *, const Anope::string &, const Anope::string &, ValueItem &data) { int nicklen = data.GetInteger(); @@ -927,10 +794,8 @@ bool InitLogs(ServerConfig *config, const Anope::string &) UserContainer *uc = *cit; BotInfo *bi = findbot(uc->user->nick); - if (bi && bi->HasFlag(BI_CORE)) - { + if (bi) bi->Part(c, "Reloading configuration"); - } } c->UnsetFlag(CH_PERSIST); @@ -989,6 +854,35 @@ bool DoneLogs(ServerConfig *config, const Anope::string &) { Log() << "Loaded " << config->LogInfos.size() << " log blocks"; + for (unsigned i = 0; i < config->LogInfos.size(); ++i) + { + LogInfo *l = config->LogInfos[i]; + + if ((!ircd || !ircd->join2msg) && !l->Inhabit) + continue; + + for (std::list::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit) + { + const Anope::string &target = *sit; + + if (target[0] == '#') + { + Channel *c = findchan(target); + if (!c) + c = new Channel(target); + c->SetFlag(CH_LOGCHAN); + c->SetFlag(CH_PERSIST); + + for (Anope::insensitive_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) + { + BotInfo *bi = it->second; + if (!c->FindUser(bi)) + bi->Join(c, &config->BotModeList); + } + } + } + } + return true; } @@ -1144,10 +1038,6 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"options", "useprivmsg", "no", new ValueContainerBool(&conf->UsePrivmsg), DT_BOOLEAN, NoValidation}, {"options", "usestrictprivmsg", "no", new ValueContainerBool(&conf->UseStrictPrivMsg), DT_BOOLEAN, NoValidation}, {"options", "hidestatso", "no", new ValueContainerBool(&conf->HideStatsO), DT_BOOLEAN, NoValidation}, - {"options", "globaloncycle", "no", new ValueContainerBool(&conf->GlobalOnCycle), DT_BOOLEAN, NoValidation}, - {"options", "globaloncycledown", "", new ValueContainerString(&conf->GlobalOnCycleMessage), DT_STRING, ValidateGlobalOnCycle}, - {"options", "globaloncycleup", "", new ValueContainerString(&conf->GlobalOnCycleUP), DT_STRING, ValidateGlobalOnCycle}, - {"options", "anonymousglobal", "no", new ValueContainerBool(&conf->AnonymousGlobal), DT_BOOLEAN, NoValidation}, {"options", "nickregdelay", "0", new ValueContainerUInt(&conf->NickRegDelay), DT_UINTEGER, NoValidation}, {"options", "restrictopernicks", "no", new ValueContainerBool(&conf->RestrictOperNicks), DT_BOOLEAN, NoValidation}, {"options", "newscount", "3", new ValueContainerUInt(&conf->NewsCount), DT_UINTEGER, NoValidation}, @@ -1161,7 +1051,7 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"nickserv", "nick", "NickServ", new ValueContainerString(&conf->s_NickServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"nickserv", "description", "Nickname Registration Service", new ValueContainerString(&conf->desc_NickServ), DT_STRING | DT_NORELOAD, ValidateNotEmpty}, {"nickserv", "emailregistration", "no", new ValueContainerBool(&conf->NSEmailReg), DT_BOOLEAN, NoValidation}, - {"nickserv", "modules", "", new ValueContainerString(&NickCoreModules), DT_STRING, NoValidation}, + {"nickserv", "modules", "", new ValueContainerString(&conf->NickCoreModules), DT_STRING, NoValidation}, {"nickserv", "forceemail", "no", new ValueContainerBool(&conf->NSForceEmail), DT_BOOLEAN, ValidateEmailReg}, {"nickserv", "confirmemailchanges", "no", new ValueContainerBool(&conf->NSConfirmEmailChanges), DT_BOOLEAN, NoValidation}, {"nickserv", "defaults", "secure memosignon memoreceive", new ValueContainerString(&NSDefaults), DT_STRING, NoValidation}, @@ -1197,7 +1087,7 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"dns", "timeout", "5", new ValueContainerTime(&conf->DNSTimeout), DT_TIME, NoValidation}, {"chanserv", "nick", "", new ValueContainerString(&conf->s_ChanServ), DT_STRING | DT_NORELOAD, NoValidation}, {"chanserv", "description", "Channel Registration Service", new ValueContainerString(&conf->desc_ChanServ), DT_STRING | DT_NORELOAD, ValidateChanServ}, - {"chanserv", "modules", "", new ValueContainerString(&ChanCoreModules), DT_STRING, ValidateChanServ}, + {"chanserv", "modules", "", new ValueContainerString(&conf->ChanCoreModules), DT_STRING, ValidateChanServ}, {"chanserv", "defaults", "keeptopic secure securefounder signkick", new ValueContainerString(&CSDefaults), DT_STRING, ValidateChanServ}, {"chanserv", "maxregistered", "0", new ValueContainerUInt(&conf->CSMaxReg), DT_UINTEGER, ValidateChanServ}, {"chanserv", "expire", "14d", new ValueContainerTime(&conf->CSExpire), DT_TIME, ValidateChanServ}, @@ -1213,14 +1103,14 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"chanserv", "opersonly", "no", new ValueContainerBool(&conf->CSOpersOnly), DT_BOOLEAN, ValidateChanServ}, {"memoserv", "nick", "", new ValueContainerString(&conf->s_MemoServ), DT_STRING | DT_NORELOAD, NoValidation}, {"memoserv", "description", "Memo Service", new ValueContainerString(&conf->desc_MemoServ), DT_STRING | DT_NORELOAD, ValidateMemoServ}, - {"memoserv", "modules", "", new ValueContainerString(&MemoCoreModules), DT_STRING, NoValidation}, + {"memoserv", "modules", "", new ValueContainerString(&Config->MemoCoreModules), DT_STRING, NoValidation}, {"memoserv", "maxmemos", "0", new ValueContainerUInt(&conf->MSMaxMemos), DT_UINTEGER, NoValidation}, {"memoserv", "senddelay", "0", new ValueContainerTime(&conf->MSSendDelay), DT_TIME, NoValidation}, {"memoserv", "notifyall", "no", new ValueContainerBool(&conf->MSNotifyAll), DT_BOOLEAN, NoValidation}, {"memoserv", "memoreceipt", "0", new ValueContainerUInt(&conf->MSMemoReceipt), DT_UINTEGER, NoValidation}, {"botserv", "nick", "", new ValueContainerString(&conf->s_BotServ), DT_STRING | DT_NORELOAD, NoValidation}, {"botserv", "description", "Bot Service", new ValueContainerString(&conf->desc_BotServ), DT_STRING | DT_NORELOAD, ValidateBotServ}, - {"botserv", "modules", "", new ValueContainerString(&BotCoreModules), DT_STRING, NoValidation}, + {"botserv", "modules", "", new ValueContainerString(&conf->BotCoreModules), DT_STRING, NoValidation}, {"botserv", "defaults", "", new ValueContainerString(&BSDefaults), DT_STRING, NoValidation}, {"botserv", "minusers", "0", new ValueContainerUInt(&conf->BSMinUsers), DT_UINTEGER, ValidateBotServ}, {"botserv", "badwordsmax", "0", new ValueContainerUInt(&conf->BSBadWordsMax), DT_UINTEGER, ValidateBotServ}, @@ -1231,10 +1121,10 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"botserv", "fantasycharacter", "!", new ValueContainerString(&conf->BSFantasyCharacter), DT_STRING, NoValidation}, {"hostserv", "nick", "", new ValueContainerString(&conf->s_HostServ), DT_STRING | DT_NORELOAD, NoValidation}, {"hostserv", "description", "vHost Service", new ValueContainerString(&conf->desc_HostServ), DT_STRING | DT_NORELOAD, ValidateHostServ}, - {"hostserv", "modules", "", new ValueContainerString(&HostCoreModules), DT_STRING, NoValidation}, + {"hostserv", "modules", "", new ValueContainerString(&conf->HostCoreModules), DT_STRING, NoValidation}, {"operserv", "nick", "", new ValueContainerString(&conf->s_OperServ), DT_STRING | DT_NORELOAD, NoValidation}, {"operserv", "description", "Operator Service", new ValueContainerString(&conf->desc_OperServ), DT_STRING | DT_NORELOAD, ValidateOperServ}, - {"operserv", "modules", "", new ValueContainerString(&OperCoreModules), DT_STRING, NoValidation}, + {"operserv", "modules", "", new ValueContainerString(&conf->OperCoreModules), DT_STRING, NoValidation}, {"operserv", "superadmin", "no", new ValueContainerBool(&conf->SuperAdmin), DT_BOOLEAN, NoValidation}, {"operserv", "autokillexpiry", "0", new ValueContainerTime(&conf->AutokillExpiry), DT_TIME, ValidateOperServ}, {"operserv", "chankillexpiry", "0", new ValueContainerTime(&conf->ChankillExpiry), DT_TIME, ValidateOperServ}, @@ -1255,22 +1145,13 @@ ConfigItems::ConfigItems(ServerConfig *conf) {"operserv", "sessionautokillexpiry", "0", new ValueContainerTime(&conf->SessionAutoKillExpiry), DT_TIME, NoValidation}, {"operserv", "addakiller", "no", new ValueContainerBool(&conf->AddAkiller), DT_BOOLEAN, NoValidation}, {"operserv", "opersonly", "no", new ValueContainerBool(&conf->OSOpersOnly), DT_BOOLEAN, NoValidation}, - {"global", "nick", "", new ValueContainerString(&conf->s_GlobalNoticer), DT_STRING | DT_NORELOAD, NoValidation}, - {"global", "description", "Global Noticer", new ValueContainerString(&conf->desc_GlobalNoticer), DT_STRING | DT_NORELOAD, ValidateGlobal}, - {"defcon", "defaultlevel", "0", new ValueContainerInt(&conf->DefConLevel), DT_INTEGER, ValidateDefCon}, - {"defcon", "level4", "", new ValueContainerString(&DefCon4), DT_STRING, ValidateDefCon}, - {"defcon", "level3", "", new ValueContainerString(&DefCon3), DT_STRING, ValidateDefCon}, - {"defcon", "level2", "", new ValueContainerString(&DefCon2), DT_STRING, ValidateDefCon}, - {"defcon", "level1", "", new ValueContainerString(&DefCon1), DT_STRING, ValidateDefCon}, - {"defcon", "sessionlimit", "0", new ValueContainerUInt(&conf->DefConSessionLimit), DT_UINTEGER, ValidateDefCon}, - {"defcon", "akillexpire", "0", new ValueContainerTime(&conf->DefConAKILL), DT_TIME, ValidateDefCon}, - {"defcon", "chanmodes", "", new ValueContainerString(&conf->DefConChanModes), DT_STRING, ValidateDefCon}, - {"defcon", "timeout", "0", new ValueContainerTime(&conf->DefConTimeOut), DT_TIME, NoValidation}, - {"defcon", "globalondefcon", "no", new ValueContainerBool(&conf->GlobalOnDefcon), DT_BOOLEAN, NoValidation}, - {"defcon", "globalondefconmore", "no", new ValueContainerBool(&conf->GlobalOnDefconMore), DT_BOOLEAN, NoValidation}, - {"defcon", "message", "", new ValueContainerString(&conf->DefconMessage), DT_STRING, ValidateDefCon}, - {"defcon", "offmessage", "", new ValueContainerString(&conf->DefConOffMessage), DT_STRING, NoValidation}, - {"defcon", "akillreason", "", new ValueContainerString(&conf->DefConAkillReason), DT_STRING, ValidateDefCon}, + {"global", "nick", "", new ValueContainerString(&conf->s_Global), DT_STRING | DT_NORELOAD, NoValidation}, + {"global", "description", "Global Noticer", new ValueContainerString(&conf->desc_Global), DT_STRING | DT_NORELOAD, ValidateGlobal}, + {"global", "modules", "", new ValueContainerString(&conf->GlobalCoreModules), DT_STRING, NoValidation}, + {"global", "globaloncycle", "no", new ValueContainerBool(&conf->GlobalOnCycle), DT_BOOLEAN, NoValidation}, + {"global", "globaloncycledown", "", new ValueContainerString(&conf->GlobalOnCycleMessage), DT_STRING, ValidateGlobalOnCycle}, + {"global", "globaloncycleup", "", new ValueContainerString(&conf->GlobalOnCycleUP), DT_STRING, ValidateGlobalOnCycle}, + {"global", "anonymousglobal", "no", new ValueContainerBool(&conf->AnonymousGlobal), DT_BOOLEAN, NoValidation}, {"", "", "", NULL, DT_NOTHING, NoValidation} }; diff --git a/src/hostserv.cpp b/src/hostserv.cpp index bfd68f17f..d3000d552 100644 --- a/src/hostserv.cpp +++ b/src/hostserv.cpp @@ -12,59 +12,6 @@ #include "services.h" #include "modules.h" -E void moduleAddHostServCmds(); - -/*************************************************************************/ - -void moduleAddHostServCmds() -{ - ModuleManager::LoadModuleList(Config->HostServCoreModules); -} - -/*************************************************************************/ - -/** - * Return information on memory use. - * Assumes pointers are valid. - **/ - -void get_hostserv_stats(long *nrec, long *memuse) -{ - long count = 0, mem = 0; - - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) - { - NickAlias *na = it->second; - - if (!na->hostinfo.HasVhost()) - continue; - - if (!na->hostinfo.GetIdent().empty()) - mem += na->hostinfo.GetIdent().length(); - if (!na->hostinfo.GetHost().empty()) - mem += na->hostinfo.GetHost().length(); - if (!na->hostinfo.GetCreator().empty()) - mem += na->hostinfo.GetCreator().length(); - ++count; - } - - *nrec = count; - *memuse = mem; -} - -/*************************************************************************/ - -/** - * HostServ initialization. - * @return void - */ -void hostserv_init() -{ - if (!Config->s_HostServ.empty()) - moduleAddHostServCmds(); -} - -/*************************************************************************/ /** Set a vhost for the user * @param ident The ident @@ -130,47 +77,3 @@ const time_t HostInfo::GetTime() const return Time; } -/*************************************************************************/ -/* Start of Generic Functions */ -/*************************************************************************/ - -/** Sync all vhosts in a group to the same thing - * @param na The nick with the vhost wanting to by synced - */ -void HostServSyncVhosts(NickAlias *na) -{ - if (!na || !na->hostinfo.HasVhost()) - return; - - for (std::list::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it) - { - NickAlias *nick = *it; - nick->hostinfo.SetVhost(na->hostinfo.GetIdent(), na->hostinfo.GetHost(), na->hostinfo.GetCreator()); - } -} - -/*************************************************************************/ - -void do_on_id(User *u) -{ - if (!u) - return; - NickAlias *na = findnick(u->nick); - if (!na || !na->hostinfo.HasVhost()) - return; - - if (u->vhost.empty() || !u->vhost.equals_cs(na->hostinfo.GetHost()) || (!na->hostinfo.GetIdent().empty() && !u->GetVIdent().equals_cs(na->hostinfo.GetIdent()))) - { - ircdproto->SendVhost(u, na->hostinfo.GetIdent(), na->hostinfo.GetHost()); - if (ircd->vhost) - u->vhost = na->hostinfo.GetHost(); - if (ircd->vident && !na->hostinfo.GetIdent().empty()) - u->SetVIdent(na->hostinfo.GetIdent()); - u->UpdateHost(); - - if (!na->hostinfo.GetIdent().empty()) - u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); - else - u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->hostinfo.GetHost().c_str()); - } -} diff --git a/src/init.cpp b/src/init.cpp index 31d525c7b..f79de5a34 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -342,33 +342,6 @@ void Init(int ac, char **av) /* Create me */ Me = new Server(NULL, Config->ServerName, 0, Config->ServerDesc, Config->Numeric); - /* First thing, add our core bots internally. Before modules are loaded and before the database is read - * This is used for modules adding commands and for the BotInfo* poiners in the command classes. - * When these bots are loaded from the databases the proper user/host/rname are added. - * - * If a user renames a bot in the configuration file, the new bot gets created here, and the old bot - * that is in the database gets created aswell, on its old nick. The old nick remains in all the channels - * etc and the new bot becomes the new client to accept commands. The user can use /bs bot del later - * if they want the old bot deleted. - * - * Note that it is important this is after loading the protocol module. The ircd struct must exist for - * the ts6_ functions - */ - if (!Config->s_OperServ.empty()) - new BotInfo(Config->s_OperServ, Config->ServiceUser, Config->ServiceHost, Config->desc_OperServ); - if (!Config->s_NickServ.empty()) - new BotInfo(Config->s_NickServ, Config->ServiceUser, Config->ServiceHost, Config->desc_NickServ); - if (!Config->s_ChanServ.empty()) - new BotInfo(Config->s_ChanServ, Config->ServiceUser, Config->ServiceHost, Config->desc_ChanServ); - if (!Config->s_HostServ.empty()) - new BotInfo(Config->s_HostServ, Config->ServiceUser, Config->ServiceHost, Config->desc_HostServ); - if (!Config->s_MemoServ.empty()) - new BotInfo(Config->s_MemoServ, Config->ServiceUser, Config->ServiceHost, Config->desc_MemoServ); - if (!Config->s_BotServ.empty()) - new BotInfo(Config->s_BotServ, Config->ServiceUser, Config->ServiceHost, Config->desc_BotServ); - if (!Config->s_GlobalNoticer.empty()) - new BotInfo(Config->s_GlobalNoticer, Config->ServiceUser, Config->ServiceHost, Config->desc_GlobalNoticer); - /* Add Encryption Modules */ ModuleManager::LoadModuleList(Config->EncModuleList); @@ -379,14 +352,7 @@ void Init(int ac, char **av) /* Add Database Modules */ ModuleManager::LoadModuleList(Config->DBModuleList); - try - { - DNSEngine = new DNSManager(); - } - catch (const SocketException &ex) - { - throw FatalException(ex.GetReason()); - } + DNSEngine = new DNSManager(); #ifndef _WIN32 if (!nofork) @@ -440,14 +406,6 @@ void Init(int ac, char **av) Log(LOG_DEBUG) << "Loading Languages..."; InitLanguages(); - /* Initialize subservices */ - ns_init(); - cs_init(); - ms_init(); - bs_init(); - os_init(); - hostserv_init(); - /* load any custom modules */ if (!nothird) ModuleManager::LoadModuleList(Config->ModulesAutoLoad); @@ -456,9 +414,6 @@ void Init(int ac, char **av) rand_init(); add_entropy_userkeys(); - /* Init log channels */ - InitLogChannels(Config); - /* Load up databases */ Log() << "Loading databases..."; EventReturn MOD_RESULT; diff --git a/src/logger.cpp b/src/logger.cpp index 51a8ce69c..4ccfa813f 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -10,39 +10,10 @@ */ #include "services.h" - -void InitLogChannels(ServerConfig *config) -{ - for (unsigned i = 0; i < config->LogInfos.size(); ++i) - { - LogInfo *l = config->LogInfos[i]; - - if (!ircd->join2msg && !l->Inhabit) - continue; - - for (std::list::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit) - { - const Anope::string &target = *sit; - - if (target[0] == '#') - { - Channel *c = findchan(target); - if (!c) - c = new Channel(target); - c->SetFlag(CH_LOGCHAN); - c->SetFlag(CH_PERSIST); - - for (Anope::insensitive_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) - { - BotInfo *bi = it->second; - - if (bi->HasFlag(BI_CORE) && !c->FindUser(bi)) - bi->Join(c, &config->BotModeList); - } - } - } - } -} +#include "modules.h" +#include "chanserv.h" +#include "operserv.h" +#include "global.h" static Anope::string GetTimeStamp() { @@ -96,10 +67,10 @@ Anope::string LogFile::GetName() const Log::Log(LogType type, const Anope::string &category, BotInfo *b) : bi(b), Type(type), Category(category) { - if (!b) - b = Global; - if (b) - this->Sources.push_back(b->nick); + if (!bi && global) + bi = global->Bot(); + if (bi) + this->Sources.push_back(bi->nick); } Log::Log(LogType type, User *u, Command *c, ChannelInfo *ci) : Type(type) @@ -110,7 +81,7 @@ Log::Log(LogType type, User *u, Command *c, ChannelInfo *ci) : Type(type) if (type != LOG_COMMAND && type != LOG_OVERRIDE && type != LOG_ADMIN) throw CoreException("This constructor does not support this log type"); - this->bi = c->service ? c->service : Global; + this->bi = c->service ? c->service : (global ? global->Bot() : NULL); this->Category = (c->service ? c->service->nick + "/" : "") + c->name; if (this->bi) this->Sources.push_back(this->bi->nick); @@ -135,7 +106,7 @@ Log::Log(User *u, Channel *c, const Anope::string &category) : Type(LOG_CHANNEL) if (!c) throw CoreException("Invalid pointers passed to Log::Log"); - this->bi = ChanServ; + this->bi = chanserv ? chanserv->Bot() : NULL; this->Category = category; if (this->bi) this->Sources.push_back(this->bi->nick); @@ -150,11 +121,13 @@ Log::Log(User *u, Channel *c, const Anope::string &category) : Type(LOG_CHANNEL) buf << this->Category << " " << c->name << " "; } -Log::Log(User *u, const Anope::string &category) : bi(Global), Type(LOG_USER), Category(category) +Log::Log(User *u, const Anope::string &category) : bi(NULL), Type(LOG_USER), Category(category) { if (!u) throw CoreException("Invalid pointers passed to Log::Log"); + if (!this->bi && global) + this->bi = global->Bot(); if (this->bi) this->Sources.push_back(this->bi->nick); this->Sources.push_back(u->nick); @@ -162,13 +135,15 @@ Log::Log(User *u, const Anope::string &category) : bi(Global), Type(LOG_USER), C buf << "USERS: " << u->GetMask() << " "; } -Log::Log(Server *s, const Anope::string &category) : bi(OperServ), Type(LOG_SERVER), Category(category) +Log::Log(Server *s, const Anope::string &category) : bi(NULL), Type(LOG_SERVER), Category(category) { if (!s) throw CoreException("Invalid pointer passed to Log::Log"); - if (!this->bi) - this->bi = Global; + if (operserv) + this->bi = operserv->Bot(); + if (!this->bi && global) + this->bi = global->Bot(); if (this->bi) this->Sources.push_back(this->bi->nick); this->Sources.push_back(s->GetName()); @@ -178,8 +153,8 @@ Log::Log(Server *s, const Anope::string &category) : bi(OperServ), Type(LOG_SERV Log::Log(BotInfo *b, const Anope::string &category) : bi(b), Type(LOG_NORMAL), Category(category) { - if (!b) - this->bi = Global; + if (!b && global) + this->bi = global->Bot(); if (this->bi) this->Sources.push_back(bi->nick); } diff --git a/src/main.cpp b/src/main.cpp index b71a7754a..fd3ab52d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,22 +79,10 @@ static bool started = false; /*************************************************************************/ -class ExpireTimer : public Timer -{ - public: - ExpireTimer(time_t timeout, time_t now) : Timer(timeout, now, true) { } - - void Tick(time_t) - { - if (!readonly && !noexpire) - expire_all(); - } -}; - class UpdateTimer : public Timer { public: - UpdateTimer(time_t timeout, time_t now) : Timer(timeout, now, true) { } + UpdateTimer(time_t timeout) : Timer(timeout, Anope::CurTime, true) { } void Tick(time_t) { @@ -123,26 +111,6 @@ bool UplinkSocket::Read(const Anope::string &buf) /*************************************************************************/ -/* Run expiration routines */ - -extern void expire_all() -{ - if (noexpire || readonly) - // Definitely *do not* want. - return; - - FOREACH_MOD(I_OnPreDatabaseExpire, OnPreDatabaseExpire()); - - Log(LOG_DEBUG) << "Running expire routines"; - expire_nicks(); - expire_chans(); - expire_exceptions(); - - FOREACH_MOD(I_OnDatabaseExpire, OnDatabaseExpire()); -} - -/*************************************************************************/ - void save_databases() { if (readonly) @@ -160,7 +128,6 @@ void do_restart_services() { if (!readonly) { - expire_all(); save_databases(); } Log() << "Restarting"; @@ -261,23 +228,25 @@ void sighandler(int signum) { #ifndef _WIN32 case SIGHUP: + { Log() << "Received SIGHUP: Saving databases & rehashing configuration"; - expire_all(); save_databases(); + ServerConfig *old_config = Config; try { - ServerConfig *newconfig = new ServerConfig(); - delete Config; - Config = newconfig; - FOREACH_MOD(I_OnReload, OnReload(true)); + Config = new ServerConfig(); + FOREACH_MOD(I_OnReload, OnReload()); + delete old_config; } catch (const ConfigException &ex) { + Config = old_config; Log() << "Error reloading configuration file: " << ex.GetReason(); } break; + } #endif case SIGINT: case SIGTERM: @@ -292,11 +261,8 @@ void sighandler(int signum) Log() << "Received signal " << signum << ", exiting."; #endif - if (Config->GlobalOnCycle) - oper_global("", "%s", Config->GlobalOnCycleMessage.c_str()); - - expire_all(); save_databases(); + services_shutdown(); default: fatal = true; break; @@ -455,8 +421,7 @@ int main(int ac, char **av, char **envp) /* Set up timers */ time_t last_check = Anope::CurTime; - ExpireTimer expireTimer(Config->ExpireTimeout, Anope::CurTime); - UpdateTimer updateTimer(Config->UpdateTimeout, Anope::CurTime); + UpdateTimer updateTimer(Config->UpdateTimeout); /*** Main loop. ***/ while (!quitting) @@ -467,8 +432,6 @@ int main(int ac, char **av, char **envp) if (!readonly && (save_data || shutting_down)) { - if (!noexpire) - expire_all(); if (shutting_down) ircdproto->SendGlobops(NULL, "Updating databases on shutdown, please wait."); save_databases(); diff --git a/src/memoserv.cpp b/src/memoserv.cpp index f10a11d5f..21940aca1 100644 --- a/src/memoserv.cpp +++ b/src/memoserv.cpp @@ -12,281 +12,8 @@ #include "services.h" #include "modules.h" -static bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m); - Memo::Memo() : Flags(MemoFlagStrings) { } -/** - * MemoServ initialization. - * @return void - */ -void ms_init() -{ - if (!Config->s_MemoServ.empty()) - ModuleManager::LoadModuleList(Config->MemoServCoreModules); -} - -/*************************************************************************/ -/** - * check_memos: See if the given user has any unread memos, and send a - * NOTICE to that user if so (and if the appropriate flag is - * set). - * @param u User Struct - * @return void - */ -void check_memos(User *u) -{ - if (Config->s_MemoServ.empty()) - return; - - if (!u) - { - Lo