diff options
| author | Adam <Adam@anope.org> | 2011-04-22 03:16:11 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2011-05-16 04:06:17 -0400 |
| commit | c8c23158a4ff74822d6c7d201dc53d879e3d91e8 (patch) | |
| tree | 4bc9ae029691d5e7c03ebc1481683a010b733844 /src | |
| parent | 1782ce260c5bc214ec0b2e39257ab1371b68ae9c (diff) | |
Moved the core pseudo clients out into their own modules
Diffstat (limited to 'src')
| -rw-r--r-- | src/bots.cpp | 75 | ||||
| -rw-r--r-- | src/botserv.cpp | 554 | ||||
| -rw-r--r-- | src/channels.cpp | 52 | ||||
| -rw-r--r-- | src/chanserv.cpp | 274 | ||||
| -rw-r--r-- | src/commands.cpp | 8 | ||||
| -rw-r--r-- | src/config.cpp | 207 | ||||
| -rw-r--r-- | src/hostserv.cpp | 97 | ||||
| -rw-r--r-- | src/init.cpp | 47 | ||||
| -rw-r--r-- | src/logger.cpp | 65 | ||||
| -rw-r--r-- | src/main.cpp | 57 | ||||
| -rw-r--r-- | src/memoserv.cpp | 334 | ||||
| -rw-r--r-- | src/misc.cpp | 310 | ||||
| -rw-r--r-- | src/modes.cpp | 2 | ||||
| -rw-r--r-- | src/nickalias.cpp | 11 | ||||
| -rw-r--r-- | src/nickcore.cpp | 20 | ||||
| -rw-r--r-- | src/nickserv.cpp | 242 | ||||
| -rw-r--r-- | src/operserv.cpp | 294 | ||||
| -rw-r--r-- | src/protocol.cpp | 64 | ||||
| -rw-r--r-- | src/regchannel.cpp | 16 | ||||
| -rw-r--r-- | src/servers.cpp | 4 | ||||
| -rw-r--r-- | src/sessions.cpp | 292 | ||||
| -rw-r--r-- | src/users.cpp | 109 | ||||
| -rw-r--r-- | src/win32/anope_windows.h | 6 | ||||
| -rw-r--r-- | src/win32/windows.cpp | 152 |
24 files changed, 419 insertions, 2873 deletions
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<BotInfo *> BotListByNick; Anope::map<BotInfo *> 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<BotFlag, BI_END>(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<Anope::string>::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<BotInfo *>::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<BanData *>::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<BanData *>::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<BanData *>::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; - |
