diff options
author | Adam <Adam@anope.org> | 2010-11-24 21:40:56 -0600 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-12-12 19:36:19 -0500 |
commit | cb6ef574e3df5cc846247450b74ca37d265f319e (patch) | |
tree | 8ce3374a537c312af63c78125bfea4622bb188f0 /modules | |
parent | 37e02a3594fdddc3d5a3df0501c528f42db6c4da (diff) |
Send replies from fantasy commands back to the channel, this will be expanded on later
Diffstat (limited to 'modules')
149 files changed, 2347 insertions, 2098 deletions
diff --git a/modules/core/bs_act.cpp b/modules/core/bs_act.cpp index b575f5030..87c7125ee 100644 --- a/modules/core/bs_act.cpp +++ b/modules/core/bs_act.cpp @@ -20,26 +20,27 @@ class CommandBSAct : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; Anope::string message = params[1]; if (!check_access(u, ci, CA_SAY)) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (!ci->bi) { - u->SendMessage(BotServ, BOT_NOT_ASSIGNED); + source.Reply(BOT_NOT_ASSIGNED); return MOD_CONT; } if (!ci->c || !ci->c->FindUser(ci->bi)) { - u->SendMessage(BotServ, BOT_NOT_ON_CHANNEL, ci->name.c_str()); + source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str()); return MOD_CONT; } diff --git a/modules/core/bs_assign.cpp b/modules/core/bs_assign.cpp index c328c2f51..a390d952c 100644 --- a/modules/core/bs_assign.cpp +++ b/modules/core/bs_assign.cpp @@ -20,42 +20,41 @@ class CommandBSAssign : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string nick = params[1]; - BotInfo *bi; - ChannelInfo *ci; + const Anope::string &chan = params[0]; + const Anope::string &nick = params[1]; + User *u = source.u; + ChannelInfo *ci = source.ci; if (readonly) { - u->SendMessage(BotServ, BOT_ASSIGN_READONLY); + source.Reply(BOT_ASSIGN_READONLY); return MOD_CONT; } - if (!(bi = findbot(nick))) + BotInfo *bi = findbot(nick); + if (!bi) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, nick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } - ci = cs_findchan(chan); - if (ci->botflags.HasFlag(BS_NOBOT) || (!check_access(u, ci, CA_ASSIGN) && !u->Account()->HasPriv("botserv/administration"))) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (bi->HasFlag(BI_PRIVATE) && !u->Account()->HasCommand("botserv/assign/private")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (ci->bi && nick.equals_ci(ci->bi->nick)) { - u->SendMessage(BotServ, BOT_ASSIGN_ALREADY, ci->bi->nick.c_str(), chan.c_str()); + source.Reply(BOT_ASSIGN_ALREADY, ci->bi->nick.c_str(), chan.c_str()); return MOD_CONT; } diff --git a/modules/core/bs_badwords.cpp b/modules/core/bs_badwords.cpp index d6fe6bfd5..d1c3a9070 100644 --- a/modules/core/bs_badwords.cpp +++ b/modules/core/bs_badwords.cpp @@ -15,88 +15,87 @@ class BadwordsListCallback : public NumberList { - User *u; - ChannelInfo *ci; + CommandSource &source; bool SentHeader; public: - BadwordsListCallback(User *_u, ChannelInfo *_ci, const Anope::string &list) : NumberList(list, false), u(_u), ci(_ci), SentHeader(false) + BadwordsListCallback(CommandSource &_source, const Anope::string &list) : NumberList(list, false), source(_source), SentHeader(false) { } ~BadwordsListCallback() { if (!SentHeader) - u->SendMessage(BotServ, BOT_BADWORDS_NO_MATCH, ci->name.c_str()); + source.Reply(BOT_BADWORDS_NO_MATCH, source.ci->name.c_str()); } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetBadWordCount()) + if (!Number || Number > source.ci->GetBadWordCount()) return; if (!SentHeader) { SentHeader = true; - u->SendMessage(BotServ, BOT_BADWORDS_LIST_HEADER, ci->name.c_str()); + source.Reply(BOT_BADWORDS_LIST_HEADER, source.ci->name.c_str()); } - DoList(u, ci, Number - 1, ci->GetBadWord(Number - 1)); + DoList(source, Number - 1, source.ci->GetBadWord(Number - 1)); } - static void DoList(User *u, ChannelInfo *ci, unsigned Number, BadWord *bw) + static void DoList(CommandSource &source, unsigned Number, BadWord *bw) { - u->SendMessage(BotServ, BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), bw->type == BW_SINGLE ? "(SINGLE)" : (bw->type == BW_START ? "(START)" : (bw->type == BW_END ? "(END)" : ""))); + source.Reply(BOT_BADWORDS_LIST_FORMAT, Number + 1, bw->word.c_str(), bw->type == BW_SINGLE ? "(SINGLE)" : (bw->type == BW_START ? "(START)" : (bw->type == BW_END ? "(END)" : ""))); } }; class BadwordsDelCallback : public NumberList { - User *u; - ChannelInfo *ci; + CommandSource &source; Command *c; unsigned Deleted; bool override; public: - BadwordsDelCallback(User *_u, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), c(_c), Deleted(0), override(false) + BadwordsDelCallback(CommandSource &_source, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), c(_c), Deleted(0), override(false) { - if (!check_access(u, ci, CA_BADWORDS) && u->Account()->HasPriv("botserv/administration")) + if (!check_access(source.u, source.ci, CA_BADWORDS) && source.u->Account()->HasPriv("botserv/administration")) this->override = true; } ~BadwordsDelCallback() { if (!Deleted) - u->SendMessage(BotServ, BOT_BADWORDS_NO_MATCH, ci->name.c_str()); + source.Reply(BOT_BADWORDS_NO_MATCH, source.ci->name.c_str()); else if (Deleted == 1) - u->SendMessage(BotServ, BOT_BADWORDS_DELETED_ONE, ci->name.c_str()); + source.Reply(BOT_BADWORDS_DELETED_ONE, source.ci->name.c_str()); else - u->SendMessage(BotServ, BOT_BADWORDS_DELETED_SEVERAL, Deleted, ci->name.c_str()); + source.Reply(BOT_BADWORDS_DELETED_SEVERAL, Deleted, source.ci->name.c_str()); } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetBadWordCount()) + if (!Number || Number > source.ci->GetBadWordCount()) return; - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, c, ci) << "DEL " << ci->GetBadWord(Number -1 )->word; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, source.ci) << "DEL " << source.ci->GetBadWord(Number - 1)->word; ++Deleted; - ci->EraseBadWord(Number - 1); + source.ci->EraseBadWord(Number - 1); } }; class CommandBSBadwords : public Command { private: - CommandReturn DoList(User *u, ChannelInfo *ci, const Anope::string &word) + CommandReturn DoList(CommandSource &source, const Anope::string &word) { - bool override = !check_access(u, ci, CA_BADWORDS); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "LIST"; + ChannelInfo *ci = source.ci; + bool override = !check_access(source.u, ci, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "LIST"; if (!ci->GetBadWordCount()) - u->SendMessage(BotServ, BOT_BADWORDS_LIST_EMPTY, ci->name.c_str()); + source.Reply(BOT_BADWORDS_LIST_EMPTY, ci->name.c_str()); else if (!word.empty() && word.find_first_not_of("1234567890,-") == Anope::string::npos) { - BadwordsListCallback list(u, ci, word); + BadwordsListCallback list(source, word); list.Process(); } else @@ -113,21 +112,22 @@ class CommandBSBadwords : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(BotServ, BOT_BADWORDS_LIST_HEADER, ci->name.c_str()); + source.Reply(BOT_BADWORDS_LIST_HEADER, ci->name.c_str()); } - BadwordsListCallback::DoList(u, ci, i, bw); + BadwordsListCallback::DoList(source, i, bw); } if (!SentHeader) - u->SendMessage(BotServ, BOT_BADWORDS_NO_MATCH, ci->name.c_str()); + source.Reply(BOT_BADWORDS_NO_MATCH, ci->name.c_str()); } return MOD_CONT; } - CommandReturn DoAdd(User *u, ChannelInfo *ci, const Anope::string &word) + CommandReturn DoAdd(CommandSource &source, const Anope::string &word) { + ChannelInfo *ci = source.ci; size_t pos = word.rfind(' '); BadWordType type = BW_ANY; Anope::string realword = word; @@ -149,7 +149,7 @@ class CommandBSBadwords : public Command if (ci->GetBadWordCount() >= Config->BSBadWordsMax) { - u->SendMessage(BotServ, BOT_BADWORDS_REACHED_LIMIT, Config->BSBadWordsMax); + source.Reply(BOT_BADWORDS_REACHED_LIMIT, Config->BSBadWordsMax); return MOD_CONT; } @@ -159,26 +159,27 @@ class CommandBSBadwords : public Command if (!bw->word.empty() && ((Config->BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config->BSCaseSensitive && realword.equals_ci(bw->word)))) { - u->SendMessage(BotServ, BOT_BADWORDS_ALREADY_EXISTS, bw->word.c_str(), ci->name.c_str()); + source.Reply(BOT_BADWORDS_ALREADY_EXISTS, bw->word.c_str(), ci->name.c_str()); return MOD_CONT; } } - bool override = !check_access(u, ci, CA_BADWORDS); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "ADD " << realword; + bool override = !check_access(source.u, ci, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "ADD " << realword; ci->AddBadWord(realword, type); - u->SendMessage(BotServ, BOT_BADWORDS_ADDED, realword.c_str(), ci->name.c_str()); + source.Reply(BOT_BADWORDS_ADDED, realword.c_str(), ci->name.c_str()); return MOD_CONT; } - CommandReturn DoDelete(User *u, ChannelInfo *ci, const Anope::string &word) + CommandReturn DoDelete(CommandSource &source, const Anope::string &word) { + ChannelInfo *ci = source.ci; /* Special case: is it a number/list? Only do search if it isn't. */ if (!word.empty() && isdigit(word[0]) && word.find_first_not_of("1234567890,-") == Anope::string::npos) { - BadwordsDelCallback list(u, ci, this, word); + BadwordsDelCallback list(source, this, word); list.Process(); } else @@ -196,27 +197,28 @@ class CommandBSBadwords : public Command if (i == end) { - u->SendMessage(BotServ, BOT_BADWORDS_NOT_FOUND, word.c_str(), ci->name.c_str()); + source.Reply(BOT_BADWORDS_NOT_FOUND, word.c_str(), ci->name.c_str()); return MOD_CONT; } - bool override = !check_access(u, ci, CA_BADWORDS); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "DEL " << badword->word; + bool override = !check_access(source.u, ci, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "DEL " << badword->word; ci->EraseBadWord(i); - u->SendMessage(BotServ, BOT_BADWORDS_DELETED, badword->word.c_str(), ci->name.c_str()); + source.Reply(BOT_BADWORDS_DELETED, badword->word.c_str(), ci->name.c_str()); } return MOD_CONT; } - CommandReturn DoClear(User *u, ChannelInfo *ci) + CommandReturn DoClear(CommandSource &source) { - bool override = !check_access(u, ci, CA_BADWORDS); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "CLEAR"; + ChannelInfo *ci = source.ci; + bool override = !check_access(source.u, ci, CA_BADWORDS); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "CLEAR"; ci->ClearBadWords(); - u->SendMessage(BotServ, BOT_BADWORDS_CLEAR); + source.Reply(BOT_BADWORDS_CLEAR); return MOD_CONT; } public: @@ -224,12 +226,12 @@ class CommandBSBadwords : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string cmd = params[1]; - Anope::string word = params.size() > 2 ? params[2] : ""; - ChannelInfo *ci; + const Anope::string &cmd = params[1]; + const Anope::string &word = params.size() > 2 ? params[2] : ""; + User *u = source.u; + ChannelInfo *ci = source.ci; bool need_args = cmd.equals_ci("LIST") || cmd.equals_ci("CLEAR"); if (!need_args && word.empty()) @@ -238,28 +240,26 @@ class CommandBSBadwords : public Command return MOD_CONT; } - ci = cs_findchan(chan); - if (!check_access(u, ci, CA_BADWORDS) && (!need_args || !u->Account()->HasPriv("botserv/administration"))) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (readonly) { - u->SendMessage(BotServ, BOT_BADWORDS_DISABLED); + source.Reply(BOT_BADWORDS_DISABLED); return MOD_CONT; } if (cmd.equals_ci("ADD")) - return this->DoAdd(u, ci, word); + return this->DoAdd(source, word); else if (cmd.equals_ci("DEL")) - return this->DoDelete(u, ci, word); + return this->DoDelete(source, word); else if (cmd.equals_ci("LIST")) - return this->DoList(u, ci, word); + return this->DoList(source, word); else if (cmd.equals_ci("CLEAR")) - return this->DoClear(u, ci); + return this->DoClear(source); else this->OnSyntaxError(u, ""); diff --git a/modules/core/bs_bot.cpp b/modules/core/bs_bot.cpp index 067633964..e16c4795a 100644 --- a/modules/core/bs_bot.cpp +++ b/modules/core/bs_bot.cpp @@ -16,70 +16,70 @@ class CommandBSBot : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[1]; - Anope::string user = params[2]; - Anope::string host = params[3]; - Anope::string real = params[4]; + const Anope::string &nick = params[1]; + const Anope::string &user = params[2]; + const Anope::string &host = params[3]; + const Anope::string &real = params[4]; BotInfo *bi; if (findbot(nick)) { - u->SendMessage(BotServ, BOT_BOT_ALREADY_EXISTS, nick.c_str()); + source.Reply(BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } if (nick.length() > Config->NickLen) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } if (user.length() > Config->UserLen) { - u->SendMessage(BotServ, BOT_LONG_IDENT, Config->UserLen); + source.Reply(BOT_LONG_IDENT, Config->UserLen); return MOD_CONT; } if (host.length() > Config->HostLen) { - u->SendMessage(BotServ, BOT_LONG_HOST, Config->HostLen); + source.Reply(BOT_LONG_HOST, Config->HostLen); return MOD_CONT; } /* Check the nick is valid re RFC 2812 */ if (isdigit(nick[0]) || nick[0] == '-') { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } for (unsigned i = 0, end = nick.length(); i < end && i < Config->NickLen; ++i) if (!isvalidnick(nick[i])) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } /* check for hardcored ircd forbidden nicks */ if (!ircdproto->IsNickValid(nick)) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } /* Check the host is valid re RFC 2812 */ if (!isValidHost(host, 3)) { - u->SendMessage(BotServ, BOT_BAD_HOST); + source.Reply(BOT_BAD_HOST); return MOD_CONT; } for (unsigned i = 0, end = user.length(); i < end && i < Config->UserLen; ++i) if (!isalnum(user[i])) { - u->SendMessage(BotServ, BOT_BAD_IDENT, Config->UserLen); + source.Reply(BOT_BAD_IDENT, Config->UserLen); return MOD_CONT; } @@ -89,73 +89,73 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - u->SendMessage(BotServ, NICK_ALREADY_REGISTERED, nick.c_str()); + source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } if (!(bi = new BotInfo(nick, user, host, real))) { // XXX this cant happen? - u->SendMessage(BotServ, BOT_BOT_CREATION_FAILED); + source.Reply(BOT_BOT_CREATION_FAILED); return MOD_CONT; } - Log(LOG_ADMIN, u, this) << "ADD " << bi->GetMask() << " " << bi->realname; + Log(LOG_ADMIN, source.u, this) << "ADD " << bi->GetMask() << " " << bi->realname; - u->SendMessage(BotServ, BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); + source.Reply(BOT_BOT_ADDED, bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); FOREACH_MOD(I_OnBotCreate, OnBotCreate(bi)); return MOD_CONT; } - CommandReturn DoChange(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoChange(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string oldnick = params[1]; - Anope::string nick = params.size() > 2 ? params[2] : ""; - Anope::string user = params.size() > 3 ? params[3] : ""; - Anope::string host = params.size() > 4 ? params[4] : ""; - Anope::string real = params.size() > 5 ? params[5] : ""; + const Anope::string &oldnick = params[1]; + const Anope::string &nick = params.size() > 2 ? params[2] : ""; + const Anope::string &user = params.size() > 3 ? params[3] : ""; + const Anope::string &host = params.size() > 4 ? params[4] : ""; + const Anope::string &real = params.size() > 5 ? params[5] : ""; BotInfo *bi; if (oldnick.empty() || nick.empty()) { - this->OnSyntaxError(u, "CHANGE"); + this->OnSyntaxError(source.u, "CHANGE"); return MOD_CONT; } if (!(bi = findbot(oldnick))) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, oldnick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } if (!oldnick.equals_ci(nick) && nickIsServices(oldnick, false)) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, oldnick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } if (nick.length() > Config->NickLen) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } if (!user.empty() && user.length() > Config->UserLen) { - u->SendMessage(BotServ, BOT_LONG_IDENT, Config->UserLen); + source.Reply(BOT_LONG_IDENT, Config->UserLen); return MOD_CONT; } if (!host.empty() && host.length() > Config->HostLen) { - u->SendMessage(BotServ, BOT_LONG_HOST, Config->HostLen); + source.Reply(BOT_LONG_HOST, Config->HostLen); return MOD_CONT; } if (!oldnick.equals_ci(nick) && nickIsServices(nick, false)) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, oldnick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str()); return MOD_CONT; } @@ -166,34 +166,34 @@ class CommandBSBot : public Command */ if (nick.equals_cs(bi->nick) && (!user.empty() ? user.equals_cs(bi->GetIdent()) : 1) && (!host.empty() ? host.equals_cs(bi->host) : 1) && (!real.empty() ? real.equals_cs(bi->realname) : 1)) { - u->SendMessage(BotServ, BOT_BOT_ANY_CHANGES); + source.Reply(BOT_BOT_ANY_CHANGES); return MOD_CONT; } /* Check the nick is valid re RFC 2812 */ if (isdigit(nick[0]) || nick[0] == '-') { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } for (unsigned i = 0, end = nick.length(); i < end && i < Config->NickLen; ++i) if (!isvalidnick(nick[i])) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } /* check for hardcored ircd forbidden nicks */ if (!ircdproto->IsNickValid(nick)) { - u->SendMessage(BotServ, BOT_BAD_NICK); + source.Reply(BOT_BAD_NICK); return MOD_CONT; } if (!host.empty() && !isValidHost(host, 3)) { - u->SendMessage(BotServ, BOT_BAD_HOST); + source.Reply(BOT_BAD_HOST); return MOD_CONT; } @@ -201,13 +201,13 @@ class CommandBSBot : public Command for (unsigned i = 0, end = user.length(); i < end && i < Config->UserLen; ++i) if (!isalnum(user[i])) { - u->SendMessage(BotServ, BOT_BAD_IDENT, Config->UserLen); + source.Reply(BOT_BAD_IDENT, Config->UserLen); return MOD_CONT; } if (!nick.equals_ci(bi->nick) && findbot(nick)) { - u->SendMessage(BotServ, BOT_BOT_ALREADY_EXISTS, nick.c_str()); + source.Reply(BOT_BOT_ALREADY_EXISTS, nick.c_str()); return MOD_CONT; } @@ -219,7 +219,7 @@ class CommandBSBot : public Command */ if (findnick(nick)) { - u->SendMessage(BotServ, NICK_ALREADY_REGISTERED, nick.c_str()); + source.Reply(NICK_ALREADY_REGISTERED, nick.c_str()); return MOD_CONT; } @@ -262,46 +262,46 @@ class CommandBSBot : public Command bi->RejoinAll(); } - u->SendMessage(BotServ, BOT_BOT_CHANGED, oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); - Log(LOG_ADMIN, u, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; + source.Reply(BOT_BOT_CHANGED, oldnick.c_str(), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); + Log(LOG_ADMIN, source.u, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; FOREACH_MOD(I_OnBotChange, OnBotChange(bi)); return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[1]; + const Anope::string &nick = params[1]; BotInfo *bi; if (nick.empty()) { - this->OnSyntaxError(u, "DEL"); + this->OnSyntaxError(source.u, "DEL"); return MOD_CONT; } if (!(bi = findbot(nick))) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, nick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } if (nickIsServices(nick, false)) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, nick.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, nick.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); - ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", u->nick.c_str()); + ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", source.u->nick.c_str()); XLine x(bi->nick); ircdproto->SendSQLineDel(&x); - Log(LOG_ADMIN, u, this) << "DEL " << bi->nick; + Log(LOG_ADMIN, source.u, this) << "DEL " << bi->nick; + source.Reply(BOT_BOT_DELETED, nick.c_str()); delete bi; - u->SendMessage(BotServ, BOT_BOT_DELETED, nick.c_str()); return MOD_CONT; } public: @@ -310,13 +310,14 @@ class CommandBSBot : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + const Anope::string &cmd = params[0]; + User *u = source.u; if (readonly) { - u->SendMessage(BotServ, BOT_BOT_READONLY); + source.Reply(BOT_BOT_READONLY); return MOD_CONT; } @@ -325,7 +326,7 @@ class CommandBSBot : public Command // ADD nick user host real - 5 if (!u->Account()->HasCommand("botserv/bot/add")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -340,7 +341,7 @@ class CommandBSBot : public Command if (tempparams.size() >= 6) tempparams[4] = tempparams[4] + " " + tempparams[5]; - return this->DoAdd(u, tempparams); + return this->DoAdd(source, tempparams); } else if (cmd.equals_ci("CHANGE")) { @@ -348,7 +349,7 @@ class CommandBSBot : public Command // but only oldn and newn are required if (!u->Account()->HasCommand("botserv/bot/change")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -358,14 +359,14 @@ class CommandBSBot : public Command return MOD_CONT; } - return this->DoChange(u, params); + return this->DoChange(source, params); } else if (cmd.equals_ci("DEL")) { // DEL nick if (!u->Account()->HasCommand("botserv/bot/del")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -375,7 +376,7 @@ class CommandBSBot : public Command return MOD_CONT; } - return this->DoDel(u, params); + return this->DoDel(source, params); } else this->OnSyntaxError(u, ""); diff --git a/modules/core/bs_botlist.cpp b/modules/core/bs_botlist.cpp index 2fdf5ec5a..0e06db6d0 100644 --- a/modules/core/bs_botlist.cpp +++ b/modules/core/bs_botlist.cpp @@ -20,13 +20,14 @@ class CommandBSBotList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; unsigned count = 0; if (BotListByNick.empty()) { - u->SendMessage(BotServ, BOT_BOTLIST_EMPTY); + source.Reply(BOT_BOTLIST_EMPTY); return MOD_CONT; } @@ -37,15 +38,15 @@ class CommandBSBotList : public Command if (!bi->HasFlag(BI_PRIVATE)) { if (!count) - u->SendMessage(BotServ, BOT_BOTLIST_HEADER); + source.Reply(BOT_BOTLIST_HEADER); ++count; - u->SendMessage(Config->s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); + source.Reply(" %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); } } if (u->Account()->HasCommand("botserv/botlist") && count < BotListByNick.size()) { - u->SendMessage(BotServ, BOT_BOTLIST_PRIVATE_HEADER); + source.Reply(BOT_BOTLIST_PRIVATE_HEADER); for (patricia_tree<BotInfo *>::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) { @@ -53,16 +54,16 @@ class CommandBSBotList : public Command if (bi->HasFlag(BI_PRIVATE)) { - u->SendMessage(Config->s_BotServ, " %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); + source.Reply(" %-15s (%s@%s)", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str()); ++count; } } } if (!count) - u->SendMessage(BotServ, BOT_BOTLIST_EMPTY); + source.Reply(BOT_BOTLIST_EMPTY); else - u->SendMessage(BotServ, BOT_BOTLIST_FOOTER, count); + source.Reply(BOT_BOTLIST_FOOTER, count); return MOD_CONT; } diff --git a/modules/core/bs_help.cpp b/modules/core/bs_help.cpp index fec543417..12614ac55 100644 --- a/modules/core/bs_help.cpp +++ b/modules/core/bs_help.cpp @@ -22,8 +22,9 @@ class CommandBSHelp : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; mod_help_cmd(findbot(Config->s_BotServ), u, params[0]); return MOD_CONT; } diff --git a/modules/core/bs_info.cpp b/modules/core/bs_info.cpp index 2cb3475d8..0a86748c3 100644 --- a/modules/core/bs_info.cpp +++ b/modules/core/bs_info.cpp @@ -17,7 +17,7 @@ class CommandBSInfo : public Command { private: - void send_bot_channels(User *u, BotInfo *bi) + void send_bot_channels(CommandSource &source, BotInfo *bi) { Anope::string buf; for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) @@ -28,7 +28,7 @@ class CommandBSInfo : public Command { if (buf.length() + ci->name.length() > 300) { - u->SendMessage(Config->s_BotServ, "%s", buf.c_str()); + source.Reply("%s", buf.c_str()); buf.clear(); } buf += " " + ci->name + " "; @@ -36,7 +36,7 @@ class CommandBSInfo : public Command } if (!buf.empty()) - u->SendMessage(Config->s_BotServ, "%s", buf.c_str()); + source.Reply("%s", buf.c_str()); return; } public: @@ -45,159 +45,160 @@ class CommandBSInfo : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - BotInfo *bi; - ChannelInfo *ci; - Anope::string query = params[0]; + const Anope::string &query = params[0]; - int need_comma = 0; + bool need_comma = false; char buf[BUFSIZE], *end; - if ((bi = findbot(query))) + User *u = source.u; + BotInfo *bi = findbot(query); + ChannelInfo *ci; + if (bi) { - u->SendMessage(BotServ, BOT_INFO_BOT_HEADER, bi->nick.c_str()); - u->SendMessage(BotServ, BOT_INFO_BOT_MASK, bi->GetIdent().c_str(), bi->host.c_str()); - u->SendMessage(BotServ, BOT_INFO_BOT_REALNAME, bi->realname.c_str()); - u->SendMessage(BotServ, BOT_INFO_BOT_CREATED, do_strftime(bi->created).c_str()); - u->SendMessage(BotServ, BOT_INFO_BOT_OPTIONS, GetString(u, (bi->HasFlag(BI_PRIVATE) ? NICK_INFO_OPT_PRIVATE : NICK_INFO_OPT_NONE)).c_str()); - u->SendMessage(BotServ, BOT_INFO_BOT_USAGE, bi->chancount); + source.Reply(BOT_INFO_BOT_HEADER, bi->nick.c_str()); + source.Reply(BOT_INFO_BOT_MASK, bi->GetIdent().c_str(), bi->host.c_str()); + source.Reply(BOT_INFO_BOT_REALNAME, bi->realname.c_str()); + source.Reply(BOT_INFO_BOT_CREATED, do_strftime(bi->created).c_str()); + source.Reply(BOT_INFO_BOT_OPTIONS, GetString(u, (bi->HasFlag(BI_PRIVATE) ? NICK_INFO_OPT_PRIVATE : NICK_INFO_OPT_NONE)).c_str()); + source.Reply(BOT_INFO_BOT_USAGE, bi->chancount); if (u->Account()->HasPriv("botserv/administration")) - this->send_bot_channels(u, bi); + this->send_bot_channels(source, bi); } else if ((ci = cs_findchan(query))) { if (!check_access(u, ci, CA_FOUNDER) && !u->Account()->HasPriv("botserv/administration")) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } - u->SendMessage(BotServ, CHAN_INFO_HEADER, ci->name.c_str()); + source.Reply(CHAN_INFO_HEADER, ci->name.c_str()); if (ci->bi) - u->SendMessage(BotServ, BOT_INFO_CHAN_BOT, ci->bi->nick.c_str()); + source.Reply(BOT_INFO_CHAN_BOT, ci->bi->nick.c_str()); else - u->SendMessage(BotServ, BOT_INFO_CHAN_BOT_NONE); + source.Reply(BOT_INFO_CHAN_BOT_NONE); if (ci->botflags.HasFlag(BS_KICK_BADWORDS)) { if (ci->ttb[TTB_BADWORDS]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_BADWORDS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_BADWORDS]); + source.Reply(BOT_INFO_CHAN_KICK_BADWORDS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_BADWORDS]); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_BADWORDS, GetString(u, BOT_INFO_ACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_BADWORDS, GetString(u, BOT_INFO_ACTIVE).c_str()); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_BADWORDS, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_BADWORDS, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_BOLDS)) { if (ci->ttb[TTB_BOLDS]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_BOLDS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_BOLDS]); + source.Reply(BOT_INFO_CHAN_KICK_BOLDS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_BOLDS]); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_BOLDS, GetString(u, BOT_INFO_ACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_BOLDS, GetString(u, BOT_INFO_ACTIVE).c_str()); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_BOLDS, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_BOLDS, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_CAPS)) { if (ci->ttb[TTB_CAPS]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_CAPS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_CAPS], ci->capsmin, ci->capspercent); + source.Reply(BOT_INFO_CHAN_KICK_CAPS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_CAPS], ci->capsmin, ci->capspercent); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_CAPS_ON, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->capsmin, ci->capspercent); + source.Reply(BOT_INFO_CHAN_KICK_CAPS_ON, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->capsmin, ci->capspercent); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_CAPS_OFF, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_CAPS_OFF, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_COLORS)) { if (ci->ttb[TTB_COLORS]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_COLORS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_COLORS]); + source.Reply(BOT_INFO_CHAN_KICK_COLORS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_COLORS]); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_COLORS, GetString(u, BOT_INFO_ACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_COLORS, GetString(u, BOT_INFO_ACTIVE).c_str()); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_COLORS, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_COLORS, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_FLOOD)) { if (ci->ttb[TTB_FLOOD]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_FLOOD_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_FLOOD], ci->floodlines, ci->floodsecs); + source.Reply(BOT_INFO_CHAN_KICK_FLOOD_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_FLOOD], ci->floodlines, ci->floodsecs); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_FLOOD_ON, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->floodlines, ci->floodsecs); + source.Reply(BOT_INFO_CHAN_KICK_FLOOD_ON, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->floodlines, ci->floodsecs); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_FLOOD_OFF, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_FLOOD_OFF, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_REPEAT)) { if (ci->ttb[TTB_REPEAT]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_REPEAT_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_REPEAT], ci->repeattimes); + source.Reply(BOT_INFO_CHAN_KICK_REPEAT_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_REPEAT], ci->repeattimes); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_REPEAT_ON, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->repeattimes); + source.Reply(BOT_INFO_CHAN_KICK_REPEAT_ON, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->repeattimes); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_REPEAT_OFF, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_REPEAT_OFF, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_REVERSES)) { if (ci->ttb[TTB_REVERSES]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_REVERSES_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_REVERSES]); + source.Reply(BOT_INFO_CHAN_KICK_REVERSES_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_REVERSES]); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_REVERSES, GetString(u, BOT_INFO_ACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_REVERSES, GetString(u, BOT_INFO_ACTIVE).c_str()); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_REVERSES, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_REVERSES, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_UNDERLINES)) { if (ci->ttb[TTB_UNDERLINES]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_UNDERLINES_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_UNDERLINES]); + source.Reply(BOT_INFO_CHAN_KICK_UNDERLINES_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_UNDERLINES]); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_UNDERLINES, GetString(u, BOT_INFO_ACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_UNDERLINES, GetString(u, BOT_INFO_ACTIVE).c_str()); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_UNDERLINES, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_UNDERLINES, GetString(u, BOT_INFO_INACTIVE).c_str()); if (ci->botflags.HasFlag(BS_KICK_ITALICS)) { if (ci->ttb[TTB_ITALICS]) - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_ITALICS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_ITALICS]); + source.Reply(BOT_INFO_CHAN_KICK_ITALICS_BAN, GetString(u, BOT_INFO_ACTIVE).c_str(), ci->ttb[TTB_ITALICS]); else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_ITALICS, GetString(u, BOT_INFO_ACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_ITALICS, GetString(u, BOT_INFO_ACTIVE).c_str()); } else - u->SendMessage(BotServ, BOT_INFO_CHAN_KICK_ITALICS, GetString(u, BOT_INFO_INACTIVE).c_str()); + source.Reply(BOT_INFO_CHAN_KICK_ITALICS, GetString(u, BOT_INFO_INACTIVE).c_str()); end = buf; *end = 0; if (ci->botflags.HasFlag(BS_DONTKICKOPS)) { end += snprintf(end, sizeof(buf) - (end - buf), "%s", GetString(u, BOT_INFO_OPT_DONTKICKOPS).c_str()); - need_comma = 1; + need_comma = true; } if (ci->botflags.HasFlag(BS_DONTKICKVOICES)) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", GetString(u, BOT_INFO_OPT_DONTKICKVOICES).c_str()); - need_comma = 1; + need_comma = true; } if (ci->botflags.HasFlag(BS_FANTASY)) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", GetString(u, BOT_INFO_OPT_FANTASY).c_str()); - need_comma = 1; + need_comma = true; } if (ci->botflags.HasFlag(BS_GREET)) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", GetString(u, BOT_INFO_OPT_GREET).c_str()); - need_comma = 1; + need_comma = true; } if (ci->botflags.HasFlag(BS_NOBOT)) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", GetString(u, BOT_INFO_OPT_NOBOT).c_str()); - need_comma = 1; + need_comma = true; } if (ci->botflags.HasFlag(BS_SYMBIOSIS)) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? ", " : "", GetString(u, BOT_INFO_OPT_SYMBIOSIS).c_str()); - need_comma = 1; + need_comma = true; } - u->SendMessage(BotServ, BOT_INFO_CHAN_OPTIONS, *buf ? buf : GetString(u, BOT_INFO_OPT_NONE).c_str()); + source.Reply(BOT_INFO_CHAN_OPTIONS, *buf ? buf : GetString(u, BOT_INFO_OPT_NONE).c_str()); } else - u->SendMessage(BotServ, BOT_INFO_NOT_FOUND, query.c_str()); + source.Reply(BOT_INFO_NOT_FOUND, query.c_str()); return MOD_CONT; } diff --git a/modules/core/bs_kick.cpp b/modules/core/bs_kick.cpp index 380236a43..950e0b4fe 100644 --- a/modules/core/bs_kick.cpp +++ b/modules/core/bs_kick.cpp @@ -21,25 +21,26 @@ class CommandBSKick : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string option = params[1]; - Anope::string value = params[2]; - Anope::string ttb = params.size() > 3 ? params[3] : ""; + const Anope::string &chan = params[0]; + const Anope::string &option = params[1]; + const Anope::string &value = params[2]; + const Anope::string &ttb = params.size() > 3 ? params[3] : ""; - ChannelInfo *ci = cs_findchan(chan); + User *u = source.u; + ChannelInfo *ci = source.ci; if (readonly) - u->SendMessage(BotServ, BOT_KICK_DISABLED); + source.Reply(BOT_KICK_DISABLED); else if (chan.empty() || option.empty() || value.empty()) SyntaxError(BotServ, u, "KICK", BOT_KICK_SYNTAX); else if (!value.equals_ci("ON") && !value.equals_ci("OFF")) SyntaxError(BotServ, u, "KICK", BOT_KICK_SYNTAX); else if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!ci->bi) - u->SendMessage(BotServ, BOT_NOT_ASSIGNED); + source.Reply(BOT_NOT_ASSIGNED); else { bool override = !check_access(u, ci, CA_SET); @@ -60,7 +61,7 @@ class CommandBSKick : public Command Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BADWORDS]; /* reset the value back to 0 - TSL */ ci->ttb[TTB_BADWORDS] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -68,14 +69,14 @@ class CommandBSKick : public Command ci->ttb[TTB_BADWORDS] = 0; ci->botflags.SetFlag(BS_KICK_BADWORDS); if (ci->ttb[TTB_BADWORDS]) - u->SendMessage(BotServ, BOT_KICK_BADWORDS_ON_BAN, ci->ttb[TTB_BADWORDS]); + source.Reply(BOT_KICK_BADWORDS_ON_BAN, ci->ttb[TTB_BADWORDS]); else - u->SendMessage(BotServ, BOT_KICK_BADWORDS_ON); + source.Reply(BOT_KICK_BADWORDS_ON); } else { ci->botflags.UnsetFlag(BS_KICK_BADWORDS); - u->SendMessage(BotServ, BOT_KICK_BADWORDS_OFF); + source.Reply(BOT_KICK_BADWORDS_OFF); } } else if (option.equals_ci("BOLDS")) @@ -90,7 +91,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_BOLDS]; ci->ttb[TTB_BOLDS] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -98,14 +99,14 @@ class CommandBSKick : public Command ci->ttb[TTB_BOLDS] = 0; ci->botflags.SetFlag(BS_KICK_BOLDS); if (ci->ttb[TTB_BOLDS]) - u->SendMessage(BotServ, BOT_KICK_BOLDS_ON_BAN, ci->ttb[TTB_BOLDS]); + source.Reply(BOT_KICK_BOLDS_ON_BAN, ci->ttb[TTB_BOLDS]); else - u->SendMessage(BotServ, BOT_KICK_BOLDS_ON); + source.Reply(BOT_KICK_BOLDS_ON); } else { ci->botflags.UnsetFlag(BS_KICK_BOLDS); - u->SendMessage(BotServ, BOT_KICK_BOLDS_OFF); + source.Reply(BOT_KICK_BOLDS_OFF); } } else if (option.equals_ci("CAPS")) @@ -123,7 +124,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_CAPS]; ci->ttb[TTB_CAPS] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -146,14 +147,14 @@ class CommandBSKick : public Command ci->botflags.SetFlag(BS_KICK_CAPS); if (ci->ttb[TTB_CAPS]) - u->SendMessage(BotServ, BOT_KICK_CAPS_ON_BAN, ci->capsmin, ci->capspercent, ci->ttb[TTB_CAPS]); + source.Reply(BOT_KICK_CAPS_ON_BAN, ci->capsmin, ci->capspercent, ci->ttb[TTB_CAPS]); else - u->SendMessage(BotServ, BOT_KICK_CAPS_ON, ci->capsmin, ci->capspercent); + source.Reply(BOT_KICK_CAPS_ON, ci->capsmin, ci->capspercent); } else { ci->botflags.UnsetFlag(BS_KICK_CAPS); - u->SendMessage(BotServ, BOT_KICK_CAPS_OFF); + source.Reply(BOT_KICK_CAPS_OFF); } } else if (option.equals_ci("COLORS")) @@ -168,7 +169,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_COLORS]; ci->ttb[TTB_COLORS] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -176,14 +177,14 @@ class CommandBSKick : public Command ci->ttb[TTB_COLORS] = 0; ci->botflags.SetFlag(BS_KICK_COLORS); if (ci->ttb[TTB_COLORS]) - u->SendMessage(BotServ, BOT_KICK_COLORS_ON_BAN, ci->ttb[TTB_COLORS]); + source.Reply(BOT_KICK_COLORS_ON_BAN, ci->ttb[TTB_COLORS]); else - u->SendMessage(BotServ, BOT_KICK_COLORS_ON); + source.Reply(BOT_KICK_COLORS_ON); } else { ci->botflags.UnsetFlag(BS_KICK_COLORS); - u->SendMessage(BotServ, BOT_KICK_COLORS_OFF); + source.Reply(BOT_KICK_COLORS_OFF); } } else if (option.equals_ci("FLOOD")) @@ -201,7 +202,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_FLOOD]; ci->ttb[TTB_FLOOD] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -224,14 +225,14 @@ class CommandBSKick : public Command ci->botflags.SetFlag(BS_KICK_FLOOD); if (ci->ttb[TTB_FLOOD]) - u->SendMessage(BotServ, BOT_KICK_FLOOD_ON_BAN, ci->floodlines, ci->floodsecs, ci->ttb[TTB_FLOOD]); + source.Reply(BOT_KICK_FLOOD_ON_BAN, ci->floodlines, ci->floodsecs, ci->ttb[TTB_FLOOD]); else - u->SendMessage(BotServ, BOT_KICK_FLOOD_ON, ci->floodlines, ci->floodsecs); + source.Reply(BOT_KICK_FLOOD_ON, ci->floodlines, ci->floodsecs); } else { ci->botflags.UnsetFlag(BS_KICK_FLOOD); - u->SendMessage(BotServ, BOT_KICK_FLOOD_OFF); + source.Reply(BOT_KICK_FLOOD_OFF); } } else if (option.equals_ci("REPEAT")) @@ -248,7 +249,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REPEAT]; ci->ttb[TTB_REPEAT] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -264,14 +265,14 @@ class CommandBSKick : public Command ci->botflags.SetFlag(BS_KICK_REPEAT); if (ci->ttb[TTB_REPEAT]) - u->SendMessage(BotServ, BOT_KICK_REPEAT_ON_BAN, ci->repeattimes, ci->ttb[TTB_REPEAT]); + source.Reply(BOT_KICK_REPEAT_ON_BAN, ci->repeattimes, ci->ttb[TTB_REPEAT]); else - u->SendMessage(BotServ, BOT_KICK_REPEAT_ON, ci->repeattimes); + source.Reply(BOT_KICK_REPEAT_ON, ci->repeattimes); } else { ci->botflags.UnsetFlag(BS_KICK_REPEAT); - u->SendMessage(BotServ, BOT_KICK_REPEAT_OFF); + source.Reply(BOT_KICK_REPEAT_OFF); } } else if (option.equals_ci("REVERSES")) @@ -286,7 +287,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_REVERSES]; ci->ttb[TTB_REVERSES] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -294,14 +295,14 @@ class CommandBSKick : public Command ci->ttb[TTB_REVERSES] = 0; ci->botflags.SetFlag(BS_KICK_REVERSES); if (ci->ttb[TTB_REVERSES]) - u->SendMessage(BotServ, BOT_KICK_REVERSES_ON_BAN, ci->ttb[TTB_REVERSES]); + source.Reply(BOT_KICK_REVERSES_ON_BAN, ci->ttb[TTB_REVERSES]); else - u->SendMessage(BotServ, BOT_KICK_REVERSES_ON); + source.Reply(BOT_KICK_REVERSES_ON); } else { ci->botflags.UnsetFlag(BS_KICK_REVERSES); - u->SendMessage(BotServ, BOT_KICK_REVERSES_OFF); + source.Reply(BOT_KICK_REVERSES_OFF); } } else if (option.equals_ci("UNDERLINES")) @@ -316,7 +317,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_UNDERLINES]; ci->ttb[TTB_UNDERLINES] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -324,14 +325,14 @@ class CommandBSKick : public Command ci->ttb[TTB_UNDERLINES] = 0; ci->botflags.SetFlag(BS_KICK_UNDERLINES); if (ci->ttb[TTB_UNDERLINES]) - u->SendMessage(BotServ, BOT_KICK_UNDERLINES_ON_BAN, ci->ttb[TTB_UNDERLINES]); + source.Reply(BOT_KICK_UNDERLINES_ON_BAN, ci->ttb[TTB_UNDERLINES]); else - u->SendMessage(BotServ, BOT_KICK_UNDERLINES_ON); + source.Reply(BOT_KICK_UNDERLINES_ON); } else { ci->botflags.UnsetFlag(BS_KICK_UNDERLINES); - u->SendMessage(BotServ, BOT_KICK_UNDERLINES_OFF); + source.Reply(BOT_KICK_UNDERLINES_OFF); } } else if (option.equals_ci("ITALICS")) @@ -346,7 +347,7 @@ class CommandBSKick : public Command { Log(LOG_DEBUG) << "remainder of ttb " << error << " ttb " << ci->ttb[TTB_ITALICS]; ci->ttb[TTB_ITALICS] = 0; - u->SendMessage(BotServ, BOT_KICK_BAD_TTB, ttb.c_str()); + source.Reply(BOT_KICK_BAD_TTB, ttb.c_str()); return MOD_CONT; } } @@ -354,18 +355,18 @@ class CommandBSKick : public Command ci->ttb[TTB_ITALICS] = 0; ci->botflags.SetFlag(BS_KICK_ITALICS); if (ci->ttb[TTB_ITALICS]) - u->SendMessage(BotServ, BOT_KICK_ITALICS_ON_BAN, ci->ttb[TTB_ITALICS]); + source.Reply(BOT_KICK_ITALICS_ON_BAN, ci->ttb[TTB_ITALICS]); else - u->SendMessage(BotServ, BOT_KICK_ITALICS_ON); + source.Reply(BOT_KICK_ITALICS_ON); } else { ci->botflags.UnsetFlag(BS_KICK_ITALICS); - u->SendMessage(BotServ, BOT_KICK_ITALICS_OFF); + source.Reply(BOT_KICK_ITALICS_OFF); } } else - u->SendMessage(BotServ, BOT_KICK_UNKNOWN, option.c_str()); + source.Reply(BOT_KICK_UNKNOWN, option.c_str()); } return MOD_CONT; } diff --git a/modules/core/bs_say.cpp b/modules/core/bs_say.cpp index a829cf368..aedcf05e8 100644 --- a/modules/core/bs_say.cpp +++ b/modules/core/bs_say.cpp @@ -20,30 +20,28 @@ class CommandBSSay : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci; + const Anope::string &text = params[1]; - Anope::string chan = params[0]; - Anope::string text = params[1]; - - ci = cs_findchan(chan); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!check_access(u, ci, CA_SAY)) { - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (!ci->bi) { - u->SendMessage(BotServ, BOT_NOT_ASSIGNED); + source.Reply(BOT_NOT_ASSIGNED); return MOD_CONT; } if (!ci->c || !ci->c->FindUser(ci->bi)) { - u->SendMessage(BotServ, BOT_NOT_ON_CHANNEL, ci->name.c_str()); + source.Reply(BOT_NOT_ON_CHANNEL, ci->name.c_str()); return MOD_CONT; } diff --git a/modules/core/bs_set.cpp b/modules/core/bs_set.cpp index 7f9acc5ed..99cf6c415 100644 --- a/modules/core/bs_set.cpp +++ b/modules/core/bs_set.cpp @@ -21,47 +21,45 @@ class CommandBSSet : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string option = params[1]; - Anope::string value = params[2]; + const Anope::string &chan = params[0]; + const Anope::string &option = params[1]; + const Anope::string &value = params[2]; + + User *u = source.u; ChannelInfo *ci; if (readonly) - { - u->SendMessage(BotServ, BOT_SET_DISABLED); - return MOD_CONT; - } - - if (u->Account()->HasCommand("botserv/set/private") && option.equals_ci("PRIVATE")) + source.Reply(BOT_SET_DISABLED); + else if (u->Account()->HasCommand("botserv/set/private") && option.equals_ci("PRIVATE")) { BotInfo *bi; if (!(bi = findbot(chan))) { - u->SendMessage(BotServ, BOT_DOES_NOT_EXIST, chan.c_str()); + source.Reply(BOT_DOES_NOT_EXIST, chan.c_str()); return MOD_CONT; } if (value.equals_ci("ON")) { bi->SetFlag(BI_PRIVATE); - u->SendMessage(BotServ, BOT_SET_PRIVATE_ON, bi->nick.c_str()); + source.Reply(BOT_SET_PRIVATE_ON, bi->nick.c_str()); } else if (value.equals_ci("OFF")) { bi->UnsetFlag(BI_PRIVATE); - u->SendMessage(BotServ, BOT_SET_PRIVATE_OFF, bi->nick.c_str()); + source.Reply(BOT_SET_PRIVATE_OFF, bi->nick.c_str()); } else SyntaxError(BotServ, u, "SET PRIVATE", BOT_SET_PRIVATE_SYNTAX); return MOD_CONT; } else if (!(ci = cs_findchan(chan))) - u->SendMessage(BotServ, CHAN_X_NOT_REGISTERED, chan.c_str()); + source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); else if (!u->Account()->HasPriv("botserv/administration") && !check_access(u, ci, CA_SET)) - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { bool override = !check_access(u, ci, CA_SET); @@ -72,12 +70,12 @@ class CommandBSSet : public Command if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_DONTKICKOPS); - u->SendMessage(BotServ, BOT_SET_DONTKICKOPS_ON, ci->name.c_str()); + source.Reply(BOT_SET_DONTKICKOPS_ON, ci->name.c_str()); } else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_DONTKICKOPS); - u->SendMessage(BotServ, BOT_SET_DONTKICKOPS_OFF, ci->name.c_str()); + source.Reply(BOT_SET_DONTKICKOPS_OFF, ci->name.c_str()); } else SyntaxError(BotServ, u, "SET DONTKICKOPS", BOT_SET_DONTKICKOPS_SYNTAX); @@ -87,12 +85,12 @@ class CommandBSSet : public Command if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_DONTKICKVOICES); - u->SendMessage(BotServ, BOT_SET_DONTKICKVOICES_ON, ci->name.c_str()); + source.Reply(BOT_SET_DONTKICKVOICES_ON, ci->name.c_str()); } else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_DONTKICKVOICES); - u->SendMessage(BotServ, BOT_SET_DONTKICKVOICES_OFF, ci->name.c_str()); + source.Reply(BOT_SET_DONTKICKVOICES_OFF, ci->name.c_str()); } else SyntaxError(BotServ, u, "SET DONTKICKVOICES", BOT_SET_DONTKICKVOICES_SYNTAX); @@ -102,12 +100,12 @@ class CommandBSSet : public Command if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_FANTASY); - u->SendMessage(BotServ, BOT_SET_FANTASY_ON, ci->name.c_str()); + source.Reply(BOT_SET_FANTASY_ON, ci->name.c_str()); } else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_FANTASY); - u->SendMessage(BotServ, BOT_SET_FANTASY_OFF, ci->name.c_str()); + source.Reply(BOT_SET_FANTASY_OFF, ci->name.c_str()); } else SyntaxError(BotServ, u, "SET FANTASY", BOT_SET_FANTASY_SYNTAX); @@ -117,12 +115,12 @@ class CommandBSSet : public Command if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_GREET); - u->SendMessage(BotServ, BOT_SET_GREET_ON, ci->name.c_str()); + source.Reply(BOT_SET_GREET_ON, ci->name.c_str()); } else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_GREET); - u->SendMessage(BotServ, BOT_SET_GREET_OFF, ci->name.c_str()); + source.Reply(BOT_SET_GREET_OFF, ci->name.c_str()); } else SyntaxError(BotServ, u, "SET GREET", BOT_SET_GREET_SYNTAX); @@ -134,12 +132,12 @@ class CommandBSSet : public Command ci->botflags.SetFlag(BS_NOBOT); if (ci->bi) ci->bi->UnAssign(u, ci); - u->SendMessage(BotServ, BOT_SET_NOBOT_ON, ci->name.c_str()); + source.Reply(BOT_SET_NOBOT_ON, ci->name.c_str()); } else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_NOBOT); - u->SendMessage(BotServ, BOT_SET_NOBOT_OFF, ci->name.c_str()); + source.Reply(BOT_SET_NOBOT_OFF, ci->name.c_str()); } else SyntaxError(BotServ, u, "SET NOBOT", BOT_SET_NOBOT_SYNTAX); @@ -149,19 +147,20 @@ class CommandBSSet : public Command if (value.equals_ci("ON")) { ci->botflags.SetFlag(BS_SYMBIOSIS); - u->SendMessage(BotServ, BOT_SET_SYMBIOSIS_ON, ci->name.c_str()); + source.Reply(BOT_SET_SYMBIOSIS_ON, ci->name.c_str()); } else if (value.equals_ci("OFF")) { ci->botflags.UnsetFlag(BS_SYMBIOSIS); - u->SendMessage(BotServ, BOT_SET_SYMBIOSIS_OFF, ci->name.c_str()); + source.Reply(BOT_SET_SYMBIOSIS_OFF, ci->name.c_str()); } else SyntaxError(BotServ, u, "SET SYMBIOSIS", BOT_SET_SYMBIOSIS_SYNTAX); } else - u->SendMessage(BotServ, BOT_SET_UNKNOWN, option.c_str()); + source.Reply(BOT_SET_UNKNOWN, option.c_str()); } + return MOD_CONT; } diff --git a/modules/core/bs_unassign.cpp b/modules/core/bs_unassign.cpp index c381ec61a..b1962c51f 100644 --- a/modules/core/bs_unassign.cpp +++ b/modules/core/bs_unassign.cpp @@ -20,27 +20,28 @@ class CommandBSUnassign : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - ChannelInfo *ci = cs_findchan(chan); ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PERM); + User *u = source.u; + ChannelInfo *ci = source.ci; + if (readonly) - u->SendMessage(BotServ, BOT_ASSIGN_READONLY); + source.Reply(BOT_ASSIGN_READONLY); else if (!u->Account()->HasPriv("botserv/administration") && !check_access(u, ci, CA_ASSIGN)) - u->SendMessage(BotServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!ci->bi) - u->SendMessage(BotServ, BOT_NOT_ASSIGNED); + source.Reply(BOT_NOT_ASSIGNED); else if (ci->HasFlag(CI_PERSIST) && !cm) - u->SendMessage(BotServ, BOT_UNASSIGN_PERSISTANT_CHAN); + source.Reply(BOT_UNASSIGN_PERSISTANT_CHAN); else { bool override = !check_access(u, ci, CA_ASSIGN); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "for " << ci->bi->nick; ci->bi->UnAssign(u, ci); - u->SendMessage(BotServ, BOT_UNASSIGN_UNASSIGNED, ci->name.c_str()); + source.Reply(BOT_UNASSIGN_UNASSIGNED, ci->name.c_str()); } return MOD_CONT; } diff --git a/modules/core/cs_access.cpp b/modules/core/cs_access.cpp index 77f63ac09..2878efbfe 100644 --- a/modules/core/cs_access.cpp +++ b/modules/core/cs_access.cpp @@ -16,71 +16,72 @@ class AccessListCallback : public NumberList { protected: - User *u; - ChannelInfo *ci; + CommandSource &source; bool SentHeader; public: - AccessListCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false) + AccessListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false) { } ~AccessListCallback() { if (SentHeader) - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_FOOTER, source.ci->name.c_str()); else - u->SendMessage(ChanServ, CHAN_ACCESS_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_ACCESS_NO_MATCH, source.ci->name.c_str()); } virtual void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAccessCount()) + if (!Number || Number > source.ci->GetAccessCount()) return; if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_HEADER, source.ci->name.c_str()); } - DoList(u, ci, Number - 1, ci->GetAccess(Number - 1)); + DoList(source, Number - 1, source.ci->GetAccess(Number - 1)); } - static void DoList(User *u, ChannelInfo *ci, unsigned Number, ChanAccess *access) + static void DoList(CommandSource &source, unsigned Number, ChanAccess *access) { - if (ci->HasFlag(CI_XOP)) + if (source.ci->HasFlag(CI_XOP)) { Anope::string xop = get_xop_level(access->level); - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_XOP_FORMAT, Number + 1, xop.c_str(), access->nc->display.c_str()); + source.Reply(CHAN_ACCESS_LIST_XOP_FORMAT, Number + 1, xop.c_str(), access->nc->display.c_str()); } else - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_AXS_FORMAT, Number + 1, access->level, access->nc->display.c_str()); + source.Reply(CHAN_ACCESS_LIST_AXS_FORMAT, Number + 1, access->level, access->nc->display.c_str()); } }; class AccessViewCallback : public AccessListCallback { public: - AccessViewCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : AccessListCallback(_u, _ci, numlist) + AccessViewCallback(CommandSource &_source, const Anope::string &numlist) : AccessListCallback(_source, numlist) { } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAccessCount()) + if (!Number || Number > source.ci->GetAccessCount()) return; if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_HEADER, source.ci->name.c_str()); } - DoList(u, ci, Number - 1, ci->GetAccess(Number - 1)); + DoList(source, Number - 1, source.ci->GetAccess(Number - 1)); } - static void DoList(User *u, ChannelInfo *ci, unsigned Number, ChanAccess *access) + static void DoList(CommandSource &source, unsigned Number, ChanAccess *access) { + User *u = source.u; + ChannelInfo *ci = source.ci; Anope::string timebuf; if (ci->c && nc_on_chan(ci->c, access->nc)) timebuf = "Now"; @@ -92,51 +93,53 @@ class AccessViewCallback : public AccessListCallback if (ci->HasFlag(CI_XOP)) { Anope::string xop = get_xop_level(access->level); - u->SendMessage(ChanServ, CHAN_ACCESS_VIEW_XOP_FORMAT, Number + 1, xop.c_str(), access->nc->display.c_str(), access->creator.c_str(), timebuf.c_str()); + source.Reply(CHAN_ACCESS_VIEW_XOP_FORMAT, Number + 1, xop.c_str(), access->nc->display.c_str(), access->creator.c_str(), timebuf.c_str()); } else - u->SendMessage(ChanServ, CHAN_ACCESS_VIEW_AXS_FORMAT, Number + 1, access->level, access->nc->display.c_str(), access->creator.c_str(), timebuf.c_str()); + source.Reply(CHAN_ACCESS_VIEW_AXS_FORMAT, Number + 1, access->level, access->nc->display.c_str(), access->creator.c_str(), timebuf.c_str()); } }; class AccessDelCallback : public NumberList { - User *u; - ChannelInfo *ci; + CommandSource &source; Command *c; unsigned Deleted; Anope::string Nicks; bool Denied; bool override; public: - AccessDelCallback(User *_u, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), c(_c), Deleted(0), Denied(false) + AccessDelCallback(CommandSource &_source, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), c(_c), Deleted(0), Denied(false) { - if (!check_access(u, ci, CA_ACCESS_CHANGE) && u->Account()->HasPriv("chanserv/access/modify")) + if (!check_access(source.u, source.ci, CA_ACCESS_CHANGE) && source.u->Account()->HasPriv("chanserv/access/modify")) this->override = true; } ~AccessDelCallback() { if (Denied && !Deleted) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!Deleted) - u->SendMessage(ChanServ, CHAN_ACCESS_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_ACCESS_NO_MATCH, source.ci->name.c_str()); else { - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, c, ci) << "for user" << (Deleted == 1 ? " " : "s ") << Nicks; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, source.ci) << "for user" << (Deleted == 1 ? " " : "s ") << Nicks; if (Deleted == 1) - u->SendMessage(ChanServ, CHAN_ACCESS_DELETED_ONE, ci->name.c_str()); + source.Reply(CHAN_ACCESS_DELETED_ONE, source.ci->name.c_str()); else - u->SendMessage(ChanServ, CHAN_ACCESS_DELETED_SEVERAL, Deleted, ci->name.c_str()); + source.Reply(CHAN_ACCESS_DELETED_SEVERAL, Deleted, source.ci->name.c_str()); } } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAccessCount()) + if (!Number || Number > source.ci->GetAccessCount()) return; + User *u = source.u; + ChannelInfo *ci = source.ci; + ChanAccess *access = ci->GetAccess(Number - 1); if (get_access(u, ci) <= access->level && !u->Account()->HasPriv("chanserv/access/modify")) @@ -159,26 +162,29 @@ class AccessDelCallback : public NumberList class CommandCSAccess : public Command { - CommandReturn DoAdd(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[2]; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &nick = params[2]; int level = params[3].is_number_only() ? convertTo<int>(params[3]) : ACCESS_INVALID; int ulev = get_access(u, ci); if (level >= ulev && !u->Account()->HasPriv("chanserv/access/modify")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (!level) { - u->SendMessage(ChanServ, CHAN_ACCESS_LEVEL_NONZERO); + source.Reply(CHAN_ACCESS_LEVEL_NONZERO); return MOD_CONT; } else if (level <= ACCESS_INVALID || level >= ACCESS_FOUNDER) { - u->SendMessage(ChanServ, CHAN_ACCESS_LEVEL_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); + source.Reply(CHAN_ACCESS_LEVEL_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); return MOD_CONT; } @@ -187,12 +193,12 @@ class CommandCSAccess : public Command NickAlias *na = findnick(nick); if (!na) { - u->SendMessage(ChanServ, CHAN_ACCESS_NICKS_ONLY); + source.Reply(CHAN_ACCESS_NICKS_ONLY); return MOD_CONT; } else if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(ChanServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } @@ -203,12 +209,12 @@ class CommandCSAccess : public Command /* Don't allow lowering from a level >= ulev */ if (access->level >= ulev && !u->Account()->HasPriv("chanserv/access/modify")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (access->level == level) { - u->SendMessage(ChanServ, CHAN_ACCESS_LEVEL_UNCHANGED, access->nc->display.c_str(), ci->name.c_str(), level); + source.Reply(CHAN_ACCESS_LEVEL_UNCHANGED, access->nc->display.c_str(), ci->name.c_str(), level); return MOD_CONT; } access->level = level; @@ -216,13 +222,13 @@ class CommandCSAccess : public Command FOREACH_MOD(I_OnAccessChange, OnAccessChange(ci, u, na->nc, level)); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "ADD " << na->nick << " (group: " << nc->display << ") (level: " << level << ") as level " << ulev; - u->SendMessage(ChanServ, CHAN_ACCESS_LEVEL_CHANGED, nc->display.c_str(), ci->name.c_str(), level); + source.Reply(CHAN_ACCESS_LEVEL_CHANGED, nc->display.c_str(), ci->name.c_str(), level); return MOD_CONT; } if (ci->GetAccessCount() >= Config->CSAccessMax) { - u->SendMessage(ChanServ, CHAN_ACCESS_REACHED_LIMIT, Config->CSAccessMax); + source.Reply(CHAN_ACCESS_REACHED_LIMIT, Config->CSAccessMax); return MOD_CONT; } @@ -236,15 +242,18 @@ class CommandCSAccess : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[2]; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &nick = params[2]; if (!ci->GetAccessCount()) - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); else if (isdigit(nick[0]) && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { - AccessDelCallback list(u, ci, this, nick); + AccessDelCallback list(source, this, nick); list.Process(); } else @@ -252,7 +261,7 @@ class CommandCSAccess : public Command NickAlias *na = findnick(nick); if (!na) { - u->SendMessage(ChanServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } @@ -269,12 +278,12 @@ class CommandCSAccess : public Command } if (i == end) - u->SendMessage(ChanServ, CHAN_ACCESS_NOT_FOUND, nick.c_str(), ci->name.c_str()); + source.Reply(CHAN_ACCESS_NOT_FOUND, nick.c_str(), ci->name.c_str()); else if (nc != u->Account() && check_access(u, ci, CA_NOJOIN) && get_access(u, ci) <= access->level && !u->Account()->HasPriv("chanserv/access/modify")) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { - u->SendMessage(ChanServ, CHAN_ACCESS_DELETED, access->nc->display.c_str(), ci->name.c_str()); + source.Reply(CHAN_ACCESS_DELETED, access->nc->display.c_str(), ci->name.c_str()); bool override = !check_access(u, ci, CA_ACCESS_CHANGE) && nc != u->Account(); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "DEL " << na->nick << " (group: " << access->nc->display << ") from level " << access->level; @@ -287,15 +296,17 @@ class CommandCSAccess : public Command return MOD_CONT; } - CommandReturn DoList(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params.size() > 2 ? params[2] : ""; + ChannelInfo *ci = source.ci; + + const Anope::string &nick = params.size() > 2 ? params[2] : ""; if (!ci->GetAccessCount()) - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); else if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { - AccessListCallback list(u, ci, nick); + AccessListCallback list(source, nick); list.Process(); } else @@ -312,30 +323,32 @@ class CommandCSAccess : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_HEADER, ci->name.c_str()); } - AccessListCallback::DoList(u, ci, i, access); + AccessListCallback::DoList(source, i, access); } if (SentHeader) - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_FOOTER, ci->name.c_str()); else - u->SendMessage(ChanServ, CHAN_ACCESS_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_ACCESS_NO_MATCH, ci->name.c_str()); } return MOD_CONT; } - CommandReturn DoView(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + CommandReturn DoView(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params.size() > 2 ? params[2] : ""; + ChannelInfo *ci = source.ci; + + const Anope::string &nick = params.size() > 2 ? params[2] : ""; if (!ci->GetAccessCount()) - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_EMPTY, ci->name.c_str()); else if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { - AccessViewCallback list(u, ci, nick); + AccessViewCallback list(source, nick); list.Process(); } else @@ -352,32 +365,35 @@ class CommandCSAccess : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_HEADER, ci->name.c_str()); } - AccessViewCallback::DoList(u, ci, i, access); + AccessViewCallback::DoList(source, i, access); } if (SentHeader) - u->SendMessage(ChanServ, CHAN_ACCESS_LIST_FOOTER, ci->name.c_str()); + source.Reply(CHAN_ACCESS_LIST_FOOTER, ci->name.c_str()); else - u->SendMessage(ChanServ, CHAN_ACCESS_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_ACCESS_NO_MATCH, ci->name.c_str()); } return MOD_CONT; } - CommandReturn DoClear(User *u, ChannelInfo *ci) + CommandReturn DoClear(CommandSource &source) { + User *u = source.u; + ChannelInfo *ci = source.ci; + if (!IsFounder(u, ci) && !u->Account()->HasPriv("chanserv/access/modify")) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { ci->ClearAccess(); FOREACH_MOD(I_OnAccessClear, OnAccessClear(ci, u)); - u->SendMessage(ChanServ, CHAN_ACCESS_CLEAR, ci->name.c_str()); + source.Reply(CHAN_ACCESS_CLEAR, ci->name.c_str()); bool override = !IsFounder(u, ci); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "CLEAR"; @@ -391,14 +407,14 @@ class CommandCSAccess : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string cmd = params[1]; - Anope::string nick = params.size() > 2 ? params[2] : ""; - Anope::string s = params.size() > 3 ? params[3] : ""; + const Anope::string &cmd = params[1]; + const Anope::string &nick = params.size() > 2 ? params[2] : ""; + const Anope::string &s = params.size() > 3 ? params[3] : ""; - ChannelInfo *ci = cs_findchan(chan); + User *u = source.u; + ChannelInfo *ci = source.ci; bool is_list = cmd.equals_ci("LIST") || cmd.equals_ci("VIEW"); bool is_clear = cmd.equals_ci("CLEAR"); @@ -422,27 +438,27 @@ class CommandCSAccess : public Command if (is_list || is_clear ? 0 : (cmd.equals_ci("DEL") ? (nick.empty() || !s.empty()) : s.empty())) this->OnSyntaxError(u, cmd); else if (!has_access) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); /* We still allow LIST and CLEAR in xOP mode, but not others */ else if (ci->HasFlag(CI_XOP) && !is_list && !is_clear) { if (ModeManager::FindChannelModeByName(CMODE_HALFOP)) - u->SendMessage(ChanServ, CHAN_ACCESS_XOP_HOP, Config->s_ChanServ.c_str()); + source.Reply(CHAN_ACCESS_XOP_HOP, Config->s_ChanServ.c_str()); else - u->SendMessage(ChanServ, CHAN_ACCESS_XOP, Config->s_ChanServ.c_str()); + source.Reply(CHAN_ACCESS_XOP, Config->s_ChanServ.c_str()); } else if (readonly && !is_list) - u->SendMessage(ChanServ, CHAN_ACCESS_DISABLED); + source.Reply(CHAN_ACCESS_DISABLED); else if (cmd.equals_ci("ADD")) - this->DoAdd(u, ci, params); + this->DoAdd(source, params); else if (cmd.equals_ci("DEL")) - this->DoDel(u, ci, params); + this->DoDel(source, params); else if (cmd.equals_ci("LIST")) - this->DoList(u, ci, params); + this->DoList(source, params); else if (cmd.equals_ci("VIEW")) - this->DoView(u, ci, params); + this->DoView(source, params); else if (cmd.equals_ci("CLEAR")) - this->DoClear(u, ci); + this->DoClear(source); else this->OnSyntaxError(u, ""); @@ -464,10 +480,13 @@ class CommandCSAccess : public Command class CommandCSLevels : public Command { - CommandReturn DoSet(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + CommandReturn DoSet(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string what = params[2]; - Anope::string lev = params[3]; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &what = params[2]; + const Anope::string &lev = params[3]; Anope::string error; int level = (lev.is_number_only() ? convertTo<int>(lev, error, false) : 0); @@ -483,7 +502,7 @@ class CommandCSLevels : public Command if (!error.empty()) this->OnSyntaxError(u, "SET"); else if (level <= ACCESS_INVALID || level > ACCESS_FOUNDER) - u->SendMessage(ChanServ, CHAN_LEVELS_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); + source.Reply(CHAN_LEVELS_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); else { for (int i = 0; levelinfo[i].what >= 0; ++i) @@ -497,22 +516,25 @@ class CommandCSLevels : public Command Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "SET " << levelinfo[i].name << " to " << level; if (level == ACCESS_FOUNDER) - u->SendMessage(ChanServ, CHAN_LEVELS_CHANGED_FOUNDER, levelinfo[i].name.c_str(), ci->name.c_str()); + source.Reply(CHAN_LEVELS_CHANGED_FOUNDER, levelinfo[i].name.c_str(), ci->name.c_str()); else - u->SendMessage(ChanServ, CHAN_LEVELS_CHANGED, levelinfo[i].name.c_str(), ci->name.c_str(), level); + source.Reply(CHAN_LEVELS_CHANGED, levelinfo[i].name.c_str(), ci->name.c_str(), level); return MOD_CONT; } } - u->SendMessage(ChanServ, CHAN_LEVELS_UNKNOWN, what.c_str(), Config->s_ChanServ.c_str()); + source.Reply(CHAN_LEVELS_UNKNOWN, what.c_str(), Config->s_ChanServ.c_str()); } return MOD_CONT; } - CommandReturn DoDisable(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + CommandReturn DoDisable(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string what = params[2]; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &what = params[2]; /* Don't allow disabling of the founder level. It would be hard to change it back if you dont have access to use this command */ if (what.equals_ci("FOUNDER")) @@ -526,19 +548,21 @@ class CommandCSLevels : public Command bool override = !check_access(u, ci, CA_FOUNDER); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "DISABLE " << levelinfo[i].name; - u->SendMessage(ChanServ, CHAN_LEVELS_DISABLED, levelinfo[i].name.c_str(), ci->name.c_str()); + source.Reply(CHAN_LEVELS_DISABLED, levelinfo[i].name.c_str(), ci->name.c_str()); return MOD_CONT; } } - u->SendMessage(ChanServ, CHAN_LEVELS_UNKNOWN, what.c_str(), Config->s_ChanServ.c_str()); + source.Reply(CHAN_LEVELS_UNKNOWN, what.c_str(), Config->s_ChanServ.c_str()); return MOD_CONT; } - CommandReturn DoList(User *u, ChannelInfo *ci) + CommandReturn DoList(CommandSource &source) { - u->SendMessage(ChanServ, CHAN_LEVELS_LIST_HEADER, ci->name.c_str()); + ChannelInfo *ci = source.ci; + + source.Reply(CHAN_LEVELS_LIST_HEADER, ci->name.c_str()); if (!levelinfo_maxwidth) for (int i = 0; levelinfo[i].what >= 0; ++i) @@ -556,19 +580,22 @@ class CommandCSLevels : public Command { j = levelinfo[i].what; - u->SendMessage(ChanServ, CHAN_LEVELS_LIST_DISABLED, levelinfo_maxwidth, levelinfo[i].name.c_str()); + source.Reply(CHAN_LEVELS_LIST_DISABLED, levelinfo_maxwidth, levelinfo[i].name.c_str()); } else if (j == ACCESS_FOUNDER) - u->SendMessage(ChanServ, CHAN_LEVELS_LIST_FOUNDER, levelinfo_maxwidth, levelinfo[i].name.c_str()); + source.Reply(CHAN_LEVELS_LIST_FOUNDER, levelinfo_maxwidth, levelinfo[i].name.c_str()); else - u->SendMessage(ChanServ, CHAN_LEVELS_LIST_NORMAL, levelinfo_maxwidth, levelinfo[i].name.c_str(), j); + source.Reply(CHAN_LEVELS_LIST_NORMAL, levelinfo_maxwidth, levelinfo[i].name.c_str(), j); } return MOD_CONT; } - CommandReturn DoReset(User *u, ChannelInfo *ci) + CommandReturn DoReset(CommandSource &source) { + User *u = source.u; + ChannelInfo *ci = source.ci; + reset_levels(ci); FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, -1, 0)); @@ -584,14 +611,14 @@ class CommandCSLevels : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string cmd = params[1]; - Anope::string what = params.size() > 2 ? params[2] : ""; - Anope::string s = params.size() > 3 ? params[3] : ""; + const Anope::string &cmd = params[1]; + const Anope::string &what = params.size() > 2 ? params[2] : ""; + const Anope::string &s = params.size() > 3 ? params[3] : ""; - ChannelInfo *ci = cs_findchan(chan); + User *u = source.u; + ChannelInfo *ci = source.ci; /* If SET, we want two extra parameters; if DIS[ABLE] or FOUNDER, we want only * one; else, we want none. @@ -599,17 +626,17 @@ class CommandCSLevels : public Command if (cmd.equals_ci("SET") ? s.empty() : (cmd.substr(0, 3).equals_ci("DIS") ? (what.empty() || !s.empty()) : !what.empty())) this->OnSyntaxError(u, cmd); else if (ci->HasFlag(CI_XOP)) - u->SendMessage(ChanServ, CHAN_LEVELS_XOP); + source.Reply(CHAN_LEVELS_XOP); else if (!check_access(u, ci, CA_FOUNDER) && !u->Account()->HasPriv("chanserv/access/modify")) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (cmd.equals_ci("SET")) - this->DoSet(u, ci, params); + this->DoSet(source, params); else if (cmd.equals_ci("DIS") || cmd.equals_ci("DISABLE")) - this->DoDisable(u, ci, params); + this->DoDisable(source, params); else if (cmd.equals_ci("LIST")) - this->DoList(u, ci); + this->DoList(source); else if (cmd.equals_ci("RESET")) - this->DoReset(u, ci); + this->DoReset(source); else this->OnSyntaxError(u, ""); diff --git a/modules/core/cs_akick.cpp b/modules/core/cs_akick.cpp index df1171589..a9bf53270 100644 --- a/modules/core/cs_akick.cpp +++ b/modules/core/cs_akick.cpp @@ -54,114 +54,119 @@ static void split_usermask(const Anope::string &mask, Anope::string &nick, Anope class AkickListCallback : public NumberList { protected: - User *u; - ChannelInfo *ci; + CommandSource &source; bool SentHeader; public: - AkickListCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), u(_u), ci(_ci), SentHeader(false) + AkickListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false) { } ~AkickListCallback() { if (!SentHeader) - u->SendMessage(ChanServ, CHAN_AKICK_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_AKICK_NO_MATCH, source.ci->name.c_str()); } virtual void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAkickCount()) + if (!Number || Number > source.ci->GetAkickCount()) return; if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_AKICK_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_AKICK_LIST_HEADER, source.ci->name.c_str()); } - DoList(u, ci, Number - 1, ci->GetAkick(Number - 1)); + DoList(source, Number - 1, source.ci->GetAkick(Number - 1)); } - static void DoList(User *u, ChannelInfo *ci, unsigned index, AutoKick *akick) + static void DoList(CommandSource &source, unsigned index, AutoKick *akick) { - u->SendMessage(ChanServ, CHAN_AKICK_LIST_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() :akick->mask.c_str(), !akick->reason.empty() ? akick->reason.c_str() : GetString(u, NO_REASON).c_str()); + source.Reply(CHAN_AKICK_LIST_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), !akick->reason.empty() ? akick->reason.c_str() : GetString(source.u, NO_REASON).c_str()); } }; class AkickViewCallback : public AkickListCallback { public: - AkickViewCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist) : AkickListCallback(_u, _ci, numlist) + AkickViewCallback(CommandSource &_source, const Anope::string &numlist) : AkickListCallback(_source, numlist) { } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAkickCount()) + if (!Number || Number > source.ci->GetAkickCount()) return; if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_AKICK_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_AKICK_LIST_HEADER, source.ci->name.c_str()); } - DoList(u, ci, Number - 1, ci->GetAkick(Number - 1)); + DoList(source, Number - 1, source.ci->GetAkick(Number - 1)); } - static void DoList(User *u, ChannelInfo *ci, unsigned index, AutoKick *akick) + static void DoList(CommandSource &source, unsigned index, AutoKick *akick) { + User *u = source.u; Anope::string timebuf; + if (akick->addtime) timebuf = do_strftime(akick->addtime); else timebuf = GetString(u, UNKNOWN); - u->SendMessage(ChanServ, CHAN_AKICK_VIEW_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), !akick->creator.empty() ? akick->creator.c_str() : GetString(u, UNKNOWN).c_str(), timebuf.c_str(), !akick->reason.empty() ? akick->reason.c_str() : GetString(u, NO_REASON).c_str()); + source.Reply(CHAN_AKICK_VIEW_FORMAT, index + 1, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), !akick->creator.empty() ? akick->creator.c_str() : GetString(u, UNKNOWN).c_str(), timebuf.c_str(), !akick->reason.empty() ? akick->reason.c_str() : GetString(u, NO_REASON).c_str()); if (akick->last_used) - u->SendMessage(ChanServ, CHAN_AKICK_LAST_USED, do_strftime(akick->last_used).c_str()); + source.Reply(CHAN_AKICK_LAST_USED, do_strftime(akick->last_used).c_str()); } }; class AkickDelCallback : public NumberList { - User *u; - ChannelInfo *ci; + CommandSource &source; Command *c; unsigned Deleted; public: - AkickDelCallback(User *_u, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), c(_c), Deleted(0) + AkickDelCallback(CommandSource &_source, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), c(_c), Deleted(0) { } ~AkickDelCallback() { + User *u = source.u; + ChannelInfo *ci = source.ci; bool override = !check_access(u, ci, CA_AKICK); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, c, ci) << "DEL on " << Deleted << " users"; if (!Deleted) - u->SendMessage(ChanServ, CHAN_AKICK_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_AKICK_NO_MATCH, ci->name.c_str()); else if (Deleted == 1) - u->SendMessage(ChanServ, CHAN_AKICK_DELETED_ONE, ci->name.c_str()); + source.Reply(CHAN_AKICK_DELETED_ONE, ci->name.c_str()); else - u->SendMessage(ChanServ, CHAN_AKICK_DELETED_SEVERAL, Deleted, ci->name.c_str()); + source.Reply(CHAN_AKICK_DELETED_SEVERAL, Deleted, ci->name.c_str()); } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAkickCount()) + if (!Number || Number > source.ci->GetAkickCount()) return; ++Deleted; - ci->EraseAkick(Number - 1); + source.ci->EraseAkick(Number - 1); } }; class CommandCSAKick : public Command { - void DoAdd(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + ChannelInfo *ci = source.ci; + Anope::string mask = params[2]; Anope::string reason = params.size() > 3 ? params[3] : ""; NickAlias *na = findnick(mask); @@ -179,7 +184,7 @@ class CommandCSAKick : public Command { if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(ChanServ, NICK_X_FORBIDDEN, mask.c_str()); + source.Reply(NICK_X_FORBIDDEN, mask.c_str()); return; } @@ -189,7 +194,7 @@ class CommandCSAKick : public Command /* Check excepts BEFORE we get this far */ if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted_mask(ci, mask)) { - u->SendMessage(ChanServ, CHAN_EXCEPTED, mask.c_str(), ci->name.c_str()); + source.Reply(CHAN_EXCEPTED, mask.c_str(), ci->name.c_str()); return; } @@ -199,7 +204,7 @@ class CommandCSAKick : public Command { if (nc == ci->founder || get_access_level(ci, nc) >= get_access(u, ci)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return; } } @@ -213,7 +218,7 @@ class CommandCSAKick : public Command if ((check_access(u2, ci, CA_FOUNDER) || get_access(u2, ci) >= get_access(u, ci)) && match_usermask(mask, u2)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return; } } @@ -232,7 +237,7 @@ class CommandCSAKick : public Command Anope::string buf = na2->nick + "!" + na2->last_usermask; if (Anope::Match(buf, mask)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return; } } @@ -244,14 +249,14 @@ class CommandCSAKick : public Command akick = ci->GetAkick(j); if (akick->HasFlag(AK_ISNICK) ? akick->nc == nc : mask.equals_ci(akick->mask)) { - u->SendMessage(ChanServ, CHAN_AKICK_ALREADY_EXISTS, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), ci->name.c_str()); + source.Reply(CHAN_AKICK_ALREADY_EXISTS, akick->HasFlag(AK_ISNICK) ? akick->nc->display.c_str() : akick->mask.c_str(), ci->name.c_str()); return; } } if (ci->GetAkickCount() >= Config->CSAutokickMax) { - u->SendMessage(ChanServ, CHAN_AKICK_REACHED_LIMIT, Config->CSAutokickMax); + source.Reply(CHAN_AKICK_REACHED_LIMIT, Config->CSAutokickMax); return; } @@ -265,27 +270,30 @@ class CommandCSAKick : public Command FOREACH_MOD(I_OnAkickAdd, OnAkickAdd(u, ci, akick)); - u->SendMessage(ChanServ, CHAN_AKICK_ADDED, mask.c_str(), ci->name.c_str()); + source.Reply(CHAN_AKICK_ADDED, mask.c_str(), ci->name.c_str()); - this->DoEnforce(u, ci); + this->DoEnforce(source); } - void DoDel(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mask = params[2]; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &mask = params[2]; AutoKick *akick; unsigned i, end; if (!ci->GetAkickCount()) { - u->SendMessage(ChanServ, CHAN_AKICK_LIST_EMPTY, ci->name.c_str()); + source.Reply(CHAN_AKICK_LIST_EMPTY, ci->name.c_str()); return; } /* Special case: is it a number/list? Only do search if it isn't. */ if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickDelCallback list(u, ci, this, mask); + AkickDelCallback list(source, this, mask); list.Process(); } else @@ -303,7 +311,7 @@ class CommandCSAKick : public Command if (i == ci->GetAkickCount()) { - u->SendMessage(ChanServ, CHAN_AKICK_NOT_FOUND, mask.c_str(), ci->name.c_str()); + source.Reply(CHAN_AKICK_NOT_FOUND, mask.c_str(), ci->name.c_str()); return; } @@ -312,26 +320,29 @@ class CommandCSAKick : public Command ci->EraseAkick(i); - u->SendMessage(ChanServ, CHAN_AKICK_DELETED, mask.c_str(), ci->name.c_str()); + source.Reply(CHAN_AKICK_DELETED, mask.c_str(), ci->name.c_str()); } } - void DoList(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mask = params.size() > 2 ? params[2] : ""; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &mask = params.size() > 2 ? params[2] : ""; bool override = !check_access(u, ci, CA_AKICK); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "LIST"; if (!ci->GetAkickCount()) { - u->SendMessage(ChanServ, CHAN_AKICK_LIST_EMPTY, ci->name.c_str()); + source.Reply(CHAN_AKICK_LIST_EMPTY, ci->name.c_str()); return; } if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickListCallback list(u, ci, mask); + AkickListCallback list(source, mask); list.Process(); } else @@ -353,33 +364,36 @@ class CommandCSAKick : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_AKICK_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_AKICK_LIST_HEADER, ci->name.c_str()); } - AkickListCallback::DoList(u, ci, i, akick); + AkickListCallback::DoList(source, i, akick); } if (!SentHeader) - u->SendMessage(ChanServ, CHAN_AKICK_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_AKICK_NO_MATCH, ci->name.c_str()); } } - void DoView(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoView(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mask = params.size() > 2 ? params[2] : ""; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &mask = params.size() > 2 ? params[2] : ""; bool override = !check_access(u, ci, CA_AKICK); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "VIEW"; if (!ci->GetAkickCount()) { - u->SendMessage(ChanServ, CHAN_AKICK_LIST_EMPTY, ci->name.c_str()); + source.Reply(CHAN_AKICK_LIST_EMPTY, ci->name.c_str()); return; } if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkickViewCallback list(u, ci, mask); + AkickViewCallback list(source, mask); list.Process(); } else @@ -401,25 +415,27 @@ class CommandCSAKick : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, CHAN_AKICK_LIST_HEADER, ci->name.c_str()); + source.Reply(CHAN_AKICK_LIST_HEADER, ci->name.c_str()); } - AkickViewCallback::DoList(u, ci, i, akick); + AkickViewCallback::DoList(source, i, akick); } if (!SentHeader) - u->SendMessage(ChanServ, CHAN_AKICK_NO_MATCH, ci->name.c_str()); + source.Reply(CHAN_AKICK_NO_MATCH, ci->name.c_str()); } } - void DoEnforce(User *u, ChannelInfo *ci) + void DoEnforce(CommandSource &source) { + User *u = source.u; + ChannelInfo *ci = source.ci; Channel *c = ci->c; int count = 0; if (!c) { - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, ci->name.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str()); return; } @@ -437,8 +453,10 @@ class CommandCSAKick : public Command u->SendMessage(ChanServ, CHAN_AKICK_ENFORCE_DONE, ci->name.c_str(), count); } - void DoClear(User *u, ChannelInfo *ci) + void DoClear(CommandSource &source) { + User *u = source.u; + ChannelInfo *ci = source.ci; bool override = !check_access(u, ci, CA_AKICK); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "CLEAR"; @@ -451,32 +469,33 @@ class CommandCSAKick : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { Anope::string chan = params[0]; Anope::string cmd = params[1]; Anope::string mask = params.size() > 2 ? params[2] : ""; - ChannelInfo *ci = cs_findchan(chan); + User *u = source.u; + ChannelInfo *ci = source.ci; if (mask.empty() && (cmd.equals_ci("ADD") || cmd.equals_ci("DEL"))) this->OnSyntaxError(u, cmd); else if (!check_access(u, ci, CA_AKICK) && !u->Account()->HasPriv("chanserv/access/modify")) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!cmd.equals_ci("LIST") && !cmd.equals_ci("VIEW") && !cmd.equals_ci("ENFORCE") && readonly) - u->SendMessage(ChanServ, CHAN_AKICK_DISABLED); + source.Reply(CHAN_AKICK_DISABLED); else if (cmd.equals_ci("ADD")) - this->DoAdd(u, ci, params); + this->DoAdd(source, params); else if (cmd.equals_ci("DEL")) - this->DoDel(u, ci, params); + this->DoDel(source, params); else if (cmd.equals_ci("LIST")) - this->DoList(u, ci, params); + this->DoList(source, params); else if (cmd.equals_ci("VIEW")) - this->DoView(u, ci, params); + this->DoView(source, params); else if (cmd.equals_ci("ENFORCE")) - this->DoEnforce(u, ci); + this->DoEnforce(source); else if (cmd.equals_ci("CLEAR")) - this->DoClear(u, ci); + this->DoClear(source); else this->OnSyntaxError(u, ""); diff --git a/modules/core/cs_ban.cpp b/modules/core/cs_ban.cpp index e39256ef4..25cc36946 100644 --- a/modules/core/cs_ban.cpp +++ b/modules/core/cs_ban.cpp @@ -20,39 +20,35 @@ class CommandCSBan : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string target = params[1]; - Anope::string reason = params.size() > 2 ? params[2] : "Requested"; + const Anope::string &chan = params[0]; + const Anope::string &target = params[1]; + const Anope::string &reason = params.size() > 2 ? params[2] : "Requested"; - Channel *c = findchan(chan); - ChannelInfo *ci; + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; User *u2; - int is_same; - - is_same = target.equals_ci(u->nick); - - if (c) - ci = c->ci; + bool is_same = target.equals_ci(u->nick); if (!c) - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); else if (is_same ? !(u2 = u) : !(u2 = finduser(target))) - u->SendMessage(ChanServ, NICK_X_NOT_IN_USE, target.c_str()); + source.Reply(NICK_X_NOT_IN_USE, target.c_str()); else if (!is_same ? !check_access(u, ci, CA_BAN) : !check_access(u, ci, CA_BANME)) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!is_same && (ci->HasFlag(CI_PEACE)) && (get_access(u2, ci) >= get_access(u, ci))) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); /* * Dont ban/kick the user on channels where he is excepted * to prevent services <-> server wars. */ else if (ModeManager::FindChannelModeByName(CMODE_EXCEPT) && is_excepted(ci, u2)) - u->SendMessage(ChanServ, CHAN_EXCEPTED, u2->nick.c_str(), ci->name.c_str()); + source.Reply(CHAN_EXCEPTED, u2->nick.c_str(), ci->name.c_str()); else if (u2->IsProtected()) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { Anope::string mask; @@ -89,8 +85,7 @@ class CommandCSBan : public Command void OnServHelp(User *u) { - if (this->name.equals_ci("BAN")) - u->SendMessage(ChanServ, CHAN_HELP_CMD_BAN); + u->SendMessage(ChanServ, CHAN_HELP_CMD_BAN); } }; diff --git a/modules/core/cs_clearusers.cpp b/modules/core/cs_clearusers.cpp index 028c7e5d6..316513200 100644 --- a/modules/core/cs_clearusers.cpp +++ b/modules/core/cs_clearusers.cpp @@ -20,20 +20,22 @@ class CommandCSClearUsers : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string what = params[1]; - Channel *c = findchan(chan); - ChannelInfo *ci = c ? c->ci : NULL; + const Anope::string &chan = params[0]; + + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; + Anope::string modebuf; if (!c) - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); else if (!check_access(u, ci, CA_FOUNDER)) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); - Anope::string buf = "CLEAR USERS command from " + u->nick + " (" + u->Account()->display + ")"; + Anope::string buf = "CLEARUSERS command from " + u->nick + " (" + u->Account()->display + ")"; for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { diff --git a/modules/core/cs_clone.cpp b/modules/core/cs_clone.cpp index a6568290c..6365b41a3 100644 --- a/modules/core/cs_clone.cpp +++ b/modules/core/cs_clone.cpp @@ -20,33 +20,35 @@ public: { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { const Anope::string &channel = params[0]; const Anope::string &target = params[1]; Anope::string what = params.size() > 2 ? params[2] : ""; - ChannelInfo *ci = cs_findchan(channel); + User *u = source.u; + ChannelInfo *ci = source.ci; + if (!check_access(u, ci, CA_SET)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } ChannelInfo *target_ci = cs_findchan(target); if (!target_ci) { - u->SendMessage(ChanServ, CHAN_X_NOT_REGISTERED, target.c_str()); + source.Reply(CHAN_X_NOT_REGISTERED, target.c_str()); return MOD_CONT; } if (!IsFounder(u, ci) || !IsFounder(u, target_ci)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (Config->CSMaxReg && u->Account()->channelcount >= Config->CSMaxReg && !u->Account()->HasPriv("chanserv/no-register-limit")) { - u->SendMessage(ChanServ, u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, Config->CSMaxReg); + source.Reply(u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, Config->CSMaxReg); return MOD_CONT; } @@ -98,7 +100,7 @@ public: FOREACH_MOD(I_OnChanRegistered, OnChanRegistered(target_ci)); - u->SendMessage(ChanServ, CHAN_CLONED, channel.c_str(), target.c_str()); + source.Reply(CHAN_CLONED, channel.c_str(), target.c_str()); } else if (what.equals_ci("ACCESS")) { @@ -109,7 +111,7 @@ public: target_ci->AddAccess(access->nc, access->level, access->creator, access->last_seen); } - u->SendMessage(ChanServ, CHAN_CLONED_ACCESS, channel.c_str(), target.c_str()); + source.Reply(CHAN_CLONED_ACCESS, channel.c_str(), target.c_str()); } else if (what.equals_ci("AKICK")) { @@ -123,7 +125,7 @@ public: target_ci->AddAkick(akick->creator, akick->mask, akick->reason, akick->addtime, akick->last_used); } - u->SendMessage(ChanServ, CHAN_CLONED_AKICK, channel.c_str(), target.c_str()); + source.Reply(CHAN_CLONED_AKICK, channel.c_str(), target.c_str()); } else if (what.equals_ci("BADWORDS")) { @@ -134,7 +136,7 @@ public: target_ci->AddBadWord(bw->word, bw->type); } - u->SendMessage(ChanServ, CHAN_CLONED_BADWORDS, channel.c_str(), target.c_str()); + source.Reply(CHAN_CLONED_BADWORDS, channel.c_str(), target.c_str()); } else { diff --git a/modules/core/cs_drop.cpp b/modules/core/cs_drop.cpp index 64d6ed1c7..453f819fe 100644 --- a/modules/core/cs_drop.cpp +++ b/modules/core/cs_drop.cpp @@ -22,14 +22,16 @@ class CommandCSDrop : public Command this->SetFlag(CFLAG_ALLOW_SUSPENDED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - ChannelInfo *ci; + const Anope::string &chan = params[0]; + + User *u = source.u; + ChannelInfo *ci = source.ci; if (readonly) { - u->SendMessage(ChanServ, CHAN_DROP_DISABLED); // XXX: READ_ONLY_MODE? + source.Reply(CHAN_DROP_DISABLED); // XXX: READ_ONLY_MODE? return MOD_CONT; } @@ -37,19 +39,19 @@ class CommandCSDrop : public Command if (ci->HasFlag(CI_FORBIDDEN) && !u->Account()->HasCommand("chanserv/drop")) { - u->SendMessage(ChanServ, CHAN_X_FORBIDDEN, chan.c_str()); + source.Reply(CHAN_X_FORBIDDEN, chan.c_str()); return MOD_CONT; } if (ci->HasFlag(CI_SUSPENDED) && !u->Account()->HasCommand("chanserv/drop")) { - u->SendMessage(ChanServ, CHAN_X_FORBIDDEN, chan.c_str()); + source.Reply(CHAN_X_FORBIDDEN, chan.c_str()); return MOD_CONT; } if ((ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER)) && !u->Account()->HasCommand("chanserv/drop")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } diff --git a/modules/core/cs_forbid.cpp b/modules/core/cs_forbid.cpp index 14f35b57c..669f6f5e7 100644 --- a/modules/core/cs_forbid.cpp +++ b/modules/core/cs_forbid.cpp @@ -21,13 +21,13 @@ class CommandCSForbid : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTEREDCHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci; - Anope::string chan = params[0]; - Anope::string reason = params.size() > 1 ? params[1] : ""; + const Anope::string &chan = params[0]; + const Anope::string &reason = params.size() > 1 ? params[1] : ""; - Channel *c; + User *u = source.u; + ChannelInfo *ci = source.ci; if (Config->ForceForbidReason && reason.empty()) { @@ -37,13 +37,13 @@ class CommandCSForbid : public Command if (chan[0] != '#') { - u->SendMessage(ChanServ, CHAN_SYMBOL_REQUIRED); + source.Reply(CHAN_SYMBOL_REQUIRED); return MOD_CONT; } if (readonly) { - u->SendMessage(ChanServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } @@ -55,7 +55,8 @@ class CommandCSForbid : public Command ci->forbidby = u->nick; ci->forbidreason = reason; - if ((c = ci->c)) + Channel *c = ci->c; + if (c) { /* Before banning everyone, it might be prudent to clear +e and +I lists.. * to prevent ppl from rejoining.. ~ Viper */ diff --git a/modules/core/cs_getkey.cpp b/modules/core/cs_getkey.cpp index 179af4272..09cc40c45 100644 --- a/modules/core/cs_getkey.cpp +++ b/modules/core/cs_getkey.cpp @@ -20,23 +20,23 @@ class CommandCSGetKey : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - ChannelInfo *ci; - Anope::string key; + const Anope::string &chan = params[0]; - ci = cs_findchan(chan); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!check_access(u, ci, CA_GETKEY) && !u->Account()->HasCommand("chanserv/getkey")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } + Anope::string key; if (!ci->c || !ci->c->GetParam(CMODE_KEY, key)) { - u->SendMessage(ChanServ, CHAN_GETKEY_NOKEY, chan.c_str()); + source.Reply(CHAN_GETKEY_NOKEY, chan.c_str()); return MOD_CONT; } diff --git a/modules/core/cs_help.cpp b/modules/core/cs_help.cpp index a8ac4041f..9d7fcd300 100644 --- a/modules/core/cs_help.cpp +++ b/modules/core/cs_help.cpp @@ -22,9 +22,9 @@ class CommandCSHelp : public Command this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(ChanServ, u, params[0]); + mod_help_cmd(ChanServ, source.u, params[0]); return MOD_CONT; } diff --git a/modules/core/cs_info.cpp b/modules/core/cs_info.cpp index bae7e118c..fdf160310 100644 --- a/modules/core/cs_info.cpp +++ b/modules/core/cs_info.cpp @@ -34,20 +34,22 @@ class CommandCSInfo : public Command this->SetFlag(CFLAG_ALLOW_FORBIDDEN); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; + const Anope::string &chan = params[0]; + + User *u = source.u; + ChannelInfo *ci = source.ci; + bool has_auspex = u->IsIdentified() && u->Account()->HasPriv("chanserv/auspex"); bool show_all = false; - ChannelInfo *ci = cs_findchan(chan); - if (ci->HasFlag(CI_FORBIDDEN)) { if (is_oper(u) && !ci->forbidby.empty()) - u->SendMessage(ChanServ, CHAN_X_FORBIDDEN_OPER, chan.c_str(), ci->forbidby.c_str(), !ci->forbidreason.empty() ? ci->forbidreason.c_str() : GetString(u, NO_REASON).c_str()); + source.Reply(CHAN_X_FORBIDDEN_OPER, chan.c_str(), ci->forbidby.c_str(), !ci->forbidreason.empty() ? ci->forbidreason.c_str() : GetString(u, NO_REASON).c_str()); else - u->SendMessage(ChanServ, CHAN_X_FORBIDDEN, chan.c_str()); + source.Reply(CHAN_X_FORBIDDEN, chan.c_str()); return MOD_CONT; } @@ -60,7 +62,7 @@ class CommandCSInfo : public Command u->SendMessage(ChanServ, CHAN_INFO_NO_FOUNDER, ci->founder->display.c_str()); if (show_all && ci->successor) - u->SendMessage(ChanServ, CHAN_INFO_NO_SUCCESSOR, ci->successor->display.c_str()); + source.Reply(CHAN_INFO_NO_SUCCESSOR, ci->successor->display.c_str()); u->SendMessage(ChanServ, CHAN_INFO_DESCRIPTION, ci->desc.c_str()); u->SendMessage(ChanServ, CHAN_INFO_TIME_REGGED, do_strftime(ci->time_registered).c_str()); @@ -69,13 +71,13 @@ class CommandCSInfo : public Command ModeLock *secret = ci->GetMLock(CMODE_SECRET); if (!ci->last_topic.empty() && (show_all || ((!secret || secret->set == false) && (!ci->c || !ci->c->HasMode(CMODE_SECRET))))) { - u->SendMessage(ChanServ, CHAN_INFO_LAST_TOPIC, ci->last_topic.c_str()); - u->SendMessage(ChanServ, CHAN_INFO_TOPIC_SET_BY, ci->last_topic_setter.c_str()); + source.Reply(CHAN_INFO_LAST_TOPIC, ci->last_topic.c_str()); + source.Reply(CHAN_INFO_TOPIC_SET_BY, ci->last_topic_setter.c_str()); } if (show_all) { - u->SendMessage(ChanServ, CHAN_INFO_BANTYPE, ci->bantype); + source.Reply(CHAN_INFO_BANTYPE, ci->bantype); Anope::string optbuf; CheckOptStr(optbuf, CI_KEEPTOPIC, GetString(u, CHAN_INFO_OPT_KEEPTOPIC), ci, u->Account()); @@ -94,17 +96,17 @@ class CommandCSInfo : public Command CheckOptStr(optbuf, CI_XOP, GetString(u, CHAN_INFO_OPT_XOP), ci, u->Account()); CheckOptStr(optbuf, CI_PERSIST, GetString(u, CHAN_INFO_OPT_PERSIST), ci, u->Account()); - u->SendMessage(ChanServ, NICK_INFO_OPTIONS, optbuf.empty() ? GetString(u, NICK_INFO_OPT_NONE).c_str() : optbuf.c_str()); - u->SendMessage(ChanServ, CHAN_INFO_MODE_LOCK, get_mlock_modes(ci, 1).c_str()); + source.Reply(NICK_INFO_OPTIONS, optbuf.empty() ? GetString(u, NICK_INFO_OPT_NONE).c_str() : optbuf.c_str()); + source.Reply(CHAN_INFO_MODE_LOCK, get_mlock_modes(ci, 1).c_str()); // XXX: we could just as easily (and tidily) merge this in with the flags display above. if (ci->HasFlag(CI_NO_EXPIRE)) - u->SendMessage(ChanServ, CHAN_INFO_NO_EXPIRE); + source.Reply(CHAN_INFO_NO_EXPIRE); else - u->SendMessage(ChanServ, CHAN_INFO_EXPIRE, do_strftime(ci->last_used + Config->CSExpire).c_str()); + source.Reply(CHAN_INFO_EXPIRE, do_strftime(ci->last_used + Config->CSExpire).c_str()); } if (ci->HasFlag(CI_SUSPENDED)) - u->SendMessage(ChanServ, CHAN_X_SUSPENDED, ci->forbidby.c_str(), !ci->forbidreason.empty() ? ci->forbidreason.c_str() : GetString(u, NO_REASON).c_str()); + source.Reply(CHAN_X_SUSPENDED, ci->forbidby.c_str(), !ci->forbidreason.empty() ? ci->forbidreason.c_str() : GetString(u, NO_REASON).c_str()); FOREACH_MOD(I_OnChanInfo, OnChanInfo(u, ci, show_all)); diff --git a/modules/core/cs_invite.cpp b/modules/core/cs_invite.cpp index 105dc56d5..7bb7544e0 100644 --- a/modules/core/cs_invite.cpp +++ b/modules/core/cs_invite.cpp @@ -20,16 +20,17 @@ class CommandCSInvite : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Channel *c; - ChannelInfo *ci; - User *u2; + const Anope::string &chan = params[0]; + + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; if (!(c = findchan(chan))) { - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); return MOD_CONT; } @@ -37,17 +38,18 @@ class CommandCSInvite : public Command if (!check_access(u, ci, CA_INVITE)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } + User *u2; if (params.size() == 1) u2 = u; else { if (!(u2 = finduser(params[1]))) { - u->SendMessage(ChanServ, NICK_X_NOT_IN_USE, params[1].c_str()); + source.Reply(NICK_X_NOT_IN_USE, params[1].c_str()); return MOD_CONT; } } @@ -56,11 +58,11 @@ class CommandCSInvite : public Command Log(LOG_COMMAND, u, this, ci) << "for " << u2->nick; if (c->FindUser(u2)) - u->SendMessage(ChanServ, CHAN_INVITE_ALREADY_IN, c->name.c_str()); + source.Reply(CHAN_INVITE_ALREADY_IN, c->name.c_str()); else { ircdproto->SendInvite(whosends(ci), chan, u2->nick); - u->SendMessage(whosends(ci), CHAN_INVITE_OTHER_SUCCESS, u2->nick.c_str(), c->name.c_str()); + source.Reply(CHAN_INVITE_OTHER_SUCCESS, u2->nick.c_str(), c->name.c_str()); u2->SendMessage(whosends(ci), CHAN_INVITE_SUCCESS, c->name.c_str()); } return MOD_CONT; diff --git a/modules/core/cs_kick.cpp b/modules/core/cs_kick.cpp index 43f3dda80..d02ae36a5 100644 --- a/modules/core/cs_kick.cpp +++ b/modules/core/cs_kick.cpp @@ -20,35 +20,31 @@ class CommandCSKick : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string target = params[1]; - Anope::string reason = params.size() > 2 ? params[2] : "Requested"; + const Anope::string &chan = params[0]; + const Anope::string &target = params[1]; + const Anope::string &reason = params.size() > 2 ? params[2] : "Requested"; - Channel *c = findchan(chan); - ChannelInfo *ci; + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; User *u2; - int is_same; - - is_same = target.equals_cs(u->nick) ? 1 : target.equals_ci(u->nick); - - if (c) - ci = c->ci; + bool is_same = target.equals_ci(u->nick); if (!c) - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); else if (is_same ? !(u2 = u) : !(u2 = finduser(target))) - u->SendMessage(ChanServ, NICK_X_NOT_IN_USE, target.c_str()); + source.Reply(NICK_X_NOT_IN_USE, target.c_str()); else if (!is_same ? !check_access(u, ci, CA_KICK) : !check_access(u, ci, CA_KICKME)) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!is_same && (ci->HasFlag(CI_PEACE)) && get_access(u2, ci) >= get_access(u, ci)) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (u2->IsProtected()) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!c->FindUser(u2)) - u->SendMessage(ChanServ, NICK_X_NOT_ON_CHAN, u2->nick.c_str(), c->name.c_str()); + source.Reply(NICK_X_NOT_ON_CHAN, u2->nick.c_str(), c->name.c_str()); else { // XXX @@ -75,8 +71,7 @@ class CommandCSKick : public Command void OnServHelp(User *u) { - if (this->name.equals_ci("KICK")) - u->SendMessage(ChanServ, CHAN_HELP_CMD_KICK); + u->SendMessage(ChanServ, CHAN_HELP_CMD_KICK); } }; diff --git a/modules/core/cs_list.cpp b/modules/core/cs_list.cpp index 8654647fe..613cc55f4 100644 --- a/modules/core/cs_list.cpp +++ b/modules/core/cs_list.cpp @@ -22,8 +22,10 @@ public: this->SetFlag(CFLAG_STRIP_CHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + Anope::string pattern = params[0]; unsigned nchans; char buf[BUFSIZE]; @@ -33,7 +35,7 @@ public: if (Config->CSListOpersOnly && !is_oper(u)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_STOP; } @@ -42,28 +44,28 @@ public: Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */ if (tmp.empty()) { - u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); - u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); + source.Reply(CS_LIST_INCORRECT_RANGE); return MOD_CONT; } if (!tmp.is_number_only()) { - u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); - u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); + source.Reply(CS_LIST_INCORRECT_RANGE); return MOD_CONT; } from = convertTo<int>(tmp); tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */ if (tmp.empty()) { - u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); - u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); + source.Reply(CS_LIST_INCORRECT_RANGE); return MOD_CONT; } if (!tmp.is_number_only()) { - u->SendMessage(ChanServ, LIST_INCORRECT_RANGE); - u->SendMessage(ChanServ, CS_LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); + source.Reply(CS_LIST_INCORRECT_RANGE); return MOD_CONT; } to = convertTo<int>(tmp); @@ -119,7 +121,7 @@ public: else snprintf(buf, sizeof(buf), "%-20s %s", ci->name.c_str(), !ci->desc.empty() ? ci->desc.c_str() : ""); - u->SendMessage(Config->s_ChanServ, " %c%s", noexpire_char, buf); + source.Reply(" %c%s", noexpire_char, buf); } ++count; } diff --git a/modules/core/cs_mode.cpp b/modules/core/cs_mode.cpp index e92a76988..93b358386 100644 --- a/modules/core/cs_mode.cpp +++ b/modules/core/cs_mode.cpp @@ -15,8 +15,10 @@ class CommandCSMode : public Command { - void DoLock(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoLock(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + ChannelInfo *ci = source.ci; const Anope::string &subcommand = params[2]; const Anope::string ¶m = params.size() > 3 ? params[3] : ""; @@ -44,18 +46,18 @@ class CommandCSMode : public Command ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); if (!cm || !cm->CanSet(u)) { - u->SendMessage(ChanServ, CHAN_MODE_LOCK_UNKNOWN, modes[i]); + source.Reply(CHAN_MODE_LOCK_UNKNOWN, modes[i]); break; } Anope::string mode_param; if (((cm->Type == MODE_STATUS || cm->Type == MODE_LIST) && !sep.GetToken(mode_param)) || (cm->Type == MODE_PARAM && adding && !sep.GetToken(mode_param))) - u->SendMessage(ChanServ, CHAN_MODE_LOCK_MISSING_PARAM, cm->ModeChar); + source.Reply(CHAN_MODE_LOCK_MISSING_PARAM, cm->ModeChar); else { ci->SetMLock(cm, adding, mode_param, u->nick); if (!mode_param.empty()) mode_param = " " + mode_param; - u->SendMessage(ChanServ, CHAN_MODE_LOCKED, adding ? '+' : '-', cm->ModeChar, mode_param.c_str(), ci->name.c_str()); + source.Reply(CHAN_MODE_LOCKED, adding ? '+' : '-', cm->ModeChar, mode_param.c_str(), ci->name.c_str()); } } } @@ -87,22 +89,22 @@ class CommandCSMode : public Command ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[i]); if (!cm || !cm->CanSet(u)) { - u->SendMessage(ChanServ, CHAN_MODE_LOCK_UNKNOWN, modes[i]); + source.Reply(CHAN_MODE_LOCK_UNKNOWN, modes[i]); break; } Anope::string mode_param; if (!cm->Type == MODE_REGULAR && !sep.GetToken(mode_param)) - u->SendMessage(ChanServ, CHAN_MODE_LOCK_MISSING_PARAM, cm->ModeChar); + source.Reply(CHAN_MODE_LOCK_MISSING_PARAM, cm->ModeChar); else { if (ci->RemoveMLock(cm, mode_param)) { if (!mode_param.empty()) mode_param = " " + mode_param; - u->SendMessage(ChanServ, CHAN_MODE_UNLOCKED, adding == 1 ? '+' : '-', cm->ModeChar, mode_param.c_str(), ci->name.c_str()); + source.Reply(CHAN_MODE_UNLOCKED, adding == 1 ? '+' : '-', cm->ModeChar, mode_param.c_str(), ci->name.c_str()); } else - u->SendMessage(ChanServ, CHAN_MODE_NOT_LOCKED, cm->ModeChar, ci->name.c_str()); + source.Reply(CHAN_MODE_NOT_LOCKED, cm->ModeChar, ci->name.c_str()); } } } @@ -112,11 +114,11 @@ class CommandCSMode : public Command const std::multimap<ChannelModeName, ModeLock> &mlocks = ci->GetMLock(); if (mlocks.empty()) { - u->SendMessage(ChanServ, CHAN_MODE_LOCK_NONE, ci->name.c_str()); + source.Reply(CHAN_MODE_LOCK_NONE, ci->name.c_str()); } else { - u->SendMessage(ChanServ, CHAN_MODE_LOCK_HEADER, ci->name.c_str()); + source.Reply(CHAN_MODE_LOCK_HEADER, ci->name.c_str()); for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it) { const ModeLock &ml = it->second; @@ -130,7 +132,7 @@ class CommandCSMode : public Command Anope::string setter = ml.setter; if (setter.empty()) setter = ci->founder ? ci->founder->display : "Unknown"; - u->SendMessage(ChanServ, CHAN_MODE_LIST_FMT, ml.set ? '+' : '-', cm->ModeChar, modeparam.c_str(), setter.c_str(), do_strftime(ml.created).c_str()); + source.Reply(CHAN_MODE_LIST_FMT, ml.set ? '+' : '-', cm->ModeChar, modeparam.c_str(), setter.c_str(), do_strftime(ml.created).c_str()); } } } @@ -138,8 +140,11 @@ class CommandCSMode : public Command this->OnSyntaxError(u, subcommand); } - void DoSet(User *u, ChannelInfo *ci, const std::vector<Anope::string> ¶ms) + void DoSet(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + ChannelInfo *ci = source.ci; + spacesepstream sep(params.size() > 3 ? params[3] : ""); Anope::string modes = params[2], param; @@ -252,20 +257,21 @@ class CommandCSMode : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { const Anope::string &subcommand = params[1]; - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci || !ci->c) - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, ci->name.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str()); else if (!check_access(u, ci, CA_MODE) && !u->Account()->HasCommand("chanserv/mode")) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (subcommand.equals_ci("LOCK")) - this->DoLock(u, ci, params); + this->DoLock(source, params); else if (subcommand.equals_ci("SET")) - this->DoSet(u, ci, params); + this->DoSet(source, params); else this->OnSyntaxError(u, ""); diff --git a/modules/core/cs_modes.cpp b/modules/core/cs_modes.cpp index 7e616d886..7fffdc193 100644 --- a/modules/core/cs_modes.cpp +++ b/modules/core/cs_modes.cpp @@ -68,8 +68,9 @@ class CommandCSOp : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP); return do_util(u, this, cm, params[0], params.size() > 1 ? params[1] : "", true, CA_OPDEOP, CA_OPDEOPME, "OP", CI_OPNOTICE); @@ -99,8 +100,9 @@ class CommandCSDeOp : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OP); return do_util(u, this, cm, params[0], params.size() > 1 ? params[1] : "", false, CA_OPDEOP, CA_OPDEOPME, "DEOP", CI_OPNOTICE); @@ -130,8 +132,9 @@ class CommandCSVoice : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE); return do_util(u, this, cm, params[0], params.size() > 1 ? params[1] : "", true, CA_VOICE, CA_VOICEME, "VOICE", CI_BEGIN); @@ -161,8 +164,9 @@ class CommandCSDeVoice : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_VOICE); return do_util(u, this, cm, params[0], params.size() > 1 ? params[1] : "", false, CA_VOICE, CA_VOICEME, "DEVOICE", CI_BEGIN); @@ -192,14 +196,13 @@ class CommandCSHalfOp : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP); if (!cm) - { return MOD_CONT; - } return do_util(u, this, cm, params[0], params.size() > 1 ? params[1] : "", true, CA_HALFOP, CA_HALFOPME, "HALFOP", CI_BEGIN); } @@ -228,8 +231,9 @@ class CommandCSDeHalfOp : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_HALFOP); if (!cm) @@ -262,8 +266,9 @@ class CommandCSProtect : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT); if (!cm) @@ -296,8 +301,9 @@ class CommandCSDeProtect : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PROTECT); if (!cm) @@ -330,8 +336,9 @@ class CommandCSOwner : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER); if (!cm) @@ -364,8 +371,9 @@ class CommandCSDeOwner : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_OWNER); if (!cm) diff --git a/modules/core/cs_register.cpp b/modules/core/cs_register.cpp index bef71a726..940c534b5 100644 --- a/modules/core/cs_register.cpp +++ b/modules/core/cs_register.cpp @@ -21,32 +21,33 @@ class CommandCSRegister : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTEREDCHANNEL); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string desc = params[1]; - Channel *c = findchan(chan); - ChannelInfo *ci; - ChannelMode *cm; + const Anope::string &chan = params[0]; + const Anope::string &desc = params[1]; + + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; if (readonly) { - u->SendMessage(ChanServ, CHAN_REGISTER_DISABLED); + source.Reply(CHAN_REGISTER_DISABLED); return MOD_CONT; } if (chan[0] == '&') - u->SendMessage(ChanServ, CHAN_REGISTER_NOT_LOCAL); + source.Reply(CHAN_REGISTER_NOT_LOCAL); else if (chan[0] != '#') - u->SendMessage(ChanServ, CHAN_SYMBOL_REQUIRED); + source.Reply(CHAN_SYMBOL_REQUIRED); else if (!ircdproto->IsChannelValid(chan)) - u->SendMessage(ChanServ, CHAN_X_INVALID, chan.c_str()); + source.Reply(CHAN_X_INVALID, chan.c_str()); else if ((ci = cs_findchan(chan))) - u->SendMessage(ChanServ, CHAN_ALREADY_REGISTERED, chan.c_str()); + source.Reply(CHAN_ALREADY_REGISTERED, chan.c_str()); else if (c && !c->HasUserStatus(u, CMODE_OP)) - u->SendMessage(ChanServ, CHAN_MUST_BE_CHANOP); + source.Reply(CHAN_MUST_BE_CHANOP); else if (Config->CSMaxReg && u->Account()->channelcount >= Config->CSMaxReg && !u->Account()->HasPriv("chanserv/no-register-limit")) - u->SendMessage(ChanServ, u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, Config->CSMaxReg); + source.Reply(u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, Config->CSMaxReg); else { ci = new ChannelInfo(chan); @@ -65,13 +66,14 @@ class CommandCSRegister : public Command ci->bi = NULL; ++ci->founder->channelcount; Log(LOG_COMMAND, u, this, ci); - u->SendMessage(ChanServ, CHAN_REGISTERED, chan.c_str(), u->nick.c_str()); + source.Reply(CHAN_REGISTERED, chan.c_str(), u->nick.c_str()); /* Implement new mode lock */ if (c) { check_modes(c); + ChannelMode *cm; if (u->FindChannel(c) != NULL) { /* On most ircds you do not receive the admin/owner mode till its registered */ diff --git a/modules/core/cs_saset.cpp b/modules/core/cs_saset.cpp index 491e5725f..70588b4bb 100644 --- a/modules/core/cs_saset.cpp +++ b/modules/core/cs_saset.cpp @@ -28,18 +28,20 @@ class CommandCSSASet : public Command this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + if (readonly) { - u->SendMessage(ChanServ, CHAN_SET_DISABLED); + source.Reply(CHAN_SET_DISABLED); return MOD_CONT; } // XXX Remove after 1.9.4 release if (params[1].equals_ci("MLOCK")) { - u->SendMessage(ChanServ, CHAN_SET_MLOCK_DEPRECATED); + source.Reply(CHAN_SET_MLOCK_DEPRECATED); return MOD_CONT; } @@ -47,7 +49,7 @@ class CommandCSSASet : public Command if (c) { - ChannelInfo *ci = cs_findchan(params[0]); + ChannelInfo *ci = source.ci; Anope::string cmdparams = ci->name; for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; @@ -56,8 +58,8 @@ class CommandCSSASet : public Command } else { - u->SendMessage(ChanServ, NICK_SET_UNKNOWN_OPTION, params[1].c_str()); - u->SendMessage(ChanServ, MORE_INFO, Config->s_ChanServ.c_str(), "SET"); + source.Reply(NICK_SET_UNKNOWN_OPTION, params[1].c_str()); + source.Reply(MORE_INFO, Config->s_ChanServ.c_str(), "SET"); } return MOD_CONT; diff --git a/modules/core/cs_saset_noexpire.cpp b/modules/core/cs_saset_noexpire.cpp index 388fa88f1..0e2a47177 100644 --- a/modules/core/cs_saset_noexpire.cpp +++ b/modules/core/cs_saset_noexpire.cpp @@ -20,21 +20,22 @@ class CommandCSSASetNoexpire : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSASetNoexpire"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_NO_EXPIRE); - u->SendMessage(ChanServ, CHAN_SET_NOEXPIRE_ON, ci->name.c_str()); + source.Reply(CHAN_SET_NOEXPIRE_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_NO_EXPIRE); - u->SendMessage(ChanServ, CHAN_SET_NOEXPIRE_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_NOEXPIRE_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "NOEXPIRE"); diff --git a/modules/core/cs_set.cpp b/modules/core/cs_set.cpp index e9774ba42..84cedbf26 100644 --- a/modules/core/cs_set.cpp +++ b/modules/core/cs_set.cpp @@ -28,23 +28,25 @@ class CommandCSSet : public Command this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + if (readonly) { - u->SendMessage(ChanServ, CHAN_SET_DISABLED); + source.Reply(CHAN_SET_DISABLED); return MOD_CONT; } if (!check_access(u, cs_findchan(params[0]), CA_SET)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } // XXX Remove after 1.9.4 release if (params[1].equals_ci("MLOCK")) { - u->SendMessage(ChanServ, CHAN_SET_MLOCK_DEPRECATED, Config->s_ChanServ.c_str()); + source.Reply(CHAN_SET_MLOCK_DEPRECATED, Config->s_ChanServ.c_str()); return MOD_CONT; } @@ -52,7 +54,7 @@ class CommandCSSet : public Command if (c) { - ChannelInfo *ci = cs_findchan(params[0]); + ChannelInfo *ci = source.ci; Anope::string cmdparams = ci->name; for (std::vector<Anope::string>::const_iterator it = params.begin() + 2, it_end = params.end(); it != it_end; ++it) cmdparams += " " + *it; @@ -60,8 +62,8 @@ class CommandCSSet : public Command } else { - u->SendMessage(ChanServ, NICK_SET_UNKNOWN_OPTION, params[1].c_str()); - u->SendMessage(ChanServ, MORE_INFO, Config->s_ChanServ.c_str(), "SET"); + source.Reply(NICK_SET_UNKNOWN_OPTION, params[1].c_str()); + source.Reply(MORE_INFO, Config->s_ChanServ.c_str(), "SET"); } return MOD_CONT; diff --git a/modules/core/cs_set_bantype.cpp b/modules/core/cs_set_bantype.cpp index 628eb10cd..0670f971c 100644 --- a/modules/core/cs_set_bantype.cpp +++ b/modules/core/cs_set_bantype.cpp @@ -20,9 +20,9 @@ class CommandCSSetBanType : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetBanType"); @@ -31,11 +31,11 @@ class CommandCSSetBanType : public Command int16 bantype = convertTo<int16>(params[1], end, false); if (!end.empty() || bantype < 0 || bantype > 3) - u->SendMessage(ChanServ, CHAN_SET_BANTYPE_INVALID, params[1].c_str()); + source.Reply(CHAN_SET_BANTYPE_INVALID, params[1].c_str()); else { ci->bantype = bantype; - u->SendMessage(ChanServ, CHAN_SET_BANTYPE_CHANGED, ci->name.c_str(), ci->bantype); + source.Reply(CHAN_SET_BANTYPE_CHANGED, ci->name.c_str(), ci->bantype); } return MOD_CONT; diff --git a/modules/core/cs_set_description.cpp b/modules/core/cs_set_description.cpp index 9fe6eb61e..b4d13b92c 100644 --- a/modules/core/cs_set_description.cpp +++ b/modules/core/cs_set_description.cpp @@ -20,9 +20,10 @@ class CommandCSSetDescription : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetDescription"); diff --git a/modules/core/cs_set_founder.cpp b/modules/core/cs_set_founder.cpp index a78542d65..3cb4c114f 100644 --- a/modules/core/cs_set_founder.cpp +++ b/modules/core/cs_set_founder.cpp @@ -20,15 +20,16 @@ class CommandCSSetFounder : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetFounder"); if (this->permission.empty() && (ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER))) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -37,19 +38,19 @@ class CommandCSSetFounder : public Command if (!na) { - u->SendMessage(ChanServ, NICK_X_NOT_REGISTERED, params[1].c_str()); + source.Reply(NICK_X_NOT_REGISTERED, params[1].c_str()); return MOD_CONT; } else if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(ChanServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } nc = na->nc; if (Config->CSMaxReg && nc->channelcount >= Config->CSMaxReg && !u->Account()->HasPriv("chanserv/no-register-limit")) { - u->SendMessage(ChanServ, CHAN_SET_FOUNDER_TOO_MANY_CHANS, na->nick.c_str()); + source.Reply(CHAN_SET_FOUNDER_TOO_MANY_CHANS, na->nick.c_str()); return MOD_CONT; } diff --git a/modules/core/cs_set_keeptopic.cpp b/modules/core/cs_set_keeptopic.cpp index 2f4aa6400..d208736d6 100644 --- a/modules/core/cs_set_keeptopic.cpp +++ b/modules/core/cs_set_keeptopic.cpp @@ -20,21 +20,22 @@ class CommandCSSetKeepTopic : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetKeepTopic"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_KEEPTOPIC); - u->SendMessage(ChanServ, CHAN_SET_KEEPTOPIC_ON, ci->name.c_str()); + source.Reply(CHAN_SET_KEEPTOPIC_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_KEEPTOPIC); - u->SendMessage(ChanServ, CHAN_SET_KEEPTOPIC_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_KEEPTOPIC_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "KEEPTOPIC"); diff --git a/modules/core/cs_set_opnotice.cpp b/modules/core/cs_set_opnotice.cpp index 41a7c1d22..e02c0d8d9 100644 --- a/modules/core/cs_set_opnotice.cpp +++ b/modules/core/cs_set_opnotice.cpp @@ -20,21 +20,22 @@ class CommandCSSetOpNotice : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetOpNotice"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_OPNOTICE); - u->SendMessage(ChanServ, CHAN_SET_OPNOTICE_ON, ci->name.c_str()); + source.Reply(CHAN_SET_OPNOTICE_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_OPNOTICE); - u->SendMessage(ChanServ, CHAN_SET_OPNOTICE_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_OPNOTICE_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "OPNOTICE"); diff --git a/modules/core/cs_set_peace.cpp b/modules/core/cs_set_peace.cpp index e8f2b9458..a21d0e51f 100644 --- a/modules/core/cs_set_peace.cpp +++ b/modules/core/cs_set_peace.cpp @@ -20,21 +20,22 @@ class CommandCSSetPeace : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetPeace"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_PEACE); - u->SendMessage(ChanServ, CHAN_SET_PEACE_ON, ci->name.c_str()); + source.Reply(CHAN_SET_PEACE_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_PEACE); - u->SendMessage(ChanServ, CHAN_SET_PEACE_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_PEACE_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "PEACE"); diff --git a/modules/core/cs_set_persist.cpp b/modules/core/cs_set_persist.cpp index 1a567ef83..a3ca57517 100644 --- a/modules/core/cs_set_persist.cpp +++ b/modules/core/cs_set_persist.cpp @@ -20,9 +20,10 @@ class CommandCSSetPersist : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetPersist"); @@ -65,7 +66,7 @@ class CommandCSSetPersist : public Command } } - u->SendMessage(ChanServ, CHAN_SET_PERSIST_ON, ci->name.c_str()); + source.Reply(CHAN_SET_PERSIST_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { @@ -92,7 +93,7 @@ class CommandCSSetPersist : public Command ChanServ->UnAssign(NULL, ci); } - u->SendMessage(ChanServ, CHAN_SET_PERSIST_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_PERSIST_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "PERSIST"); diff --git a/modules/core/cs_set_private.cpp b/modules/core/cs_set_private.cpp index 73e4968c1..1199dbfad 100644 --- a/modules/core/cs_set_private.cpp +++ b/modules/core/cs_set_private.cpp @@ -20,21 +20,22 @@ class CommandCSSetPrivate : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetPrivate"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_PRIVATE); - u->SendMessage(ChanServ, CHAN_SET_PRIVATE_ON, ci->name.c_str()); + source.Reply(CHAN_SET_PRIVATE_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_PRIVATE); - u->SendMessage(ChanServ, CHAN_SET_PRIVATE_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_PRIVATE_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "PRIVATE"); diff --git a/modules/core/cs_set_restricted.cpp b/modules/core/cs_set_restricted.cpp index bc8aedf41..482e6e137 100644 --- a/modules/core/cs_set_restricted.cpp +++ b/modules/core/cs_set_restricted.cpp @@ -19,9 +19,10 @@ class CommandCSSetRestricted : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetRestricted"); @@ -30,14 +31,14 @@ class CommandCSSetRestricted : public Command ci->SetFlag(CI_RESTRICTED); if (ci->levels[CA_NOJOIN] < 0) ci->levels[CA_NOJOIN] = 0; - u->SendMessage(ChanServ, CHAN_SET_RESTRICTED_ON, ci->name.c_str()); + source.Reply(CHAN_SET_RESTRICTED_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_RESTRICTED); if (ci->levels[CA_NOJOIN] >= 0) ci->levels[CA_NOJOIN] = -2; - u->SendMessage(ChanServ, CHAN_SET_RESTRICTED_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_RESTRICTED_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "RESTRICTED"); diff --git a/modules/core/cs_set_secure.cpp b/modules/core/cs_set_secure.cpp index bec6bd81f..8fa6c533e 100644 --- a/modules/core/cs_set_secure.cpp +++ b/modules/core/cs_set_secure.cpp @@ -20,21 +20,22 @@ class CommandCSSetSecure : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetSecure"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECURE); - u->SendMessage(ChanServ, CHAN_SET_SECURE_ON, ci->name.c_str()); + source.Reply(CHAN_SET_SECURE_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECURE); - u->SendMessage(ChanServ, CHAN_SET_SECURE_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_SECURE_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "SECURE"); diff --git a/modules/core/cs_set_securefounder.cpp b/modules/core/cs_set_securefounder.cpp index f5a1af53c..ec9716e50 100644 --- a/modules/core/cs_set_securefounder.cpp +++ b/modules/core/cs_set_securefounder.cpp @@ -20,27 +20,28 @@ class CommandCSSetSecureFounder : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetSecureFounder"); if (this->permission.empty() && ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECUREFOUNDER); - u->SendMessage(ChanServ, CHAN_SET_SECUREFOUNDER_ON, ci->name.c_str()); + source.Reply(CHAN_SET_SECUREFOUNDER_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECUREFOUNDER); - u->SendMessage(ChanServ, CHAN_SET_SECUREFOUNDER_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_SECUREFOUNDER_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "SECUREFOUNDER"); diff --git a/modules/core/cs_set_secureops.cpp b/modules/core/cs_set_secureops.cpp index 138a03b54..822953e75 100644 --- a/modules/core/cs_set_secureops.cpp +++ b/modules/core/cs_set_secureops.cpp @@ -20,21 +20,22 @@ class CommandCSSetSecureOps : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetSecureIos"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_SECUREOPS); - u->SendMessage(ChanServ, CHAN_SET_SECUREOPS_ON, ci->name.c_str()); + source.Reply(CHAN_SET_SECUREOPS_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SECUREOPS); - u->SendMessage(ChanServ, CHAN_SET_SECUREOPS_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_SECUREOPS_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "SECUREOPS"); diff --git a/modules/core/cs_set_signkick.cpp b/modules/core/cs_set_signkick.cpp index cc2ca249b..1960709b3 100644 --- a/modules/core/cs_set_signkick.cpp +++ b/modules/core/cs_set_signkick.cpp @@ -20,9 +20,10 @@ class CommandCSSetSignKick : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetSignKick"); @@ -30,19 +31,19 @@ class CommandCSSetSignKick : public Command { ci->SetFlag(CI_SIGNKICK); ci->UnsetFlag(CI_SIGNKICK_LEVEL); - u->SendMessage(ChanServ, CHAN_SET_SIGNKICK_ON, ci->name.c_str()); + source.Reply(CHAN_SET_SIGNKICK_ON, ci->name.c_str()); } else if (params[1].equals_ci("LEVEL")) { ci->SetFlag(CI_SIGNKICK_LEVEL); ci->UnsetFlag(CI_SIGNKICK); - u->SendMessage(ChanServ, CHAN_SET_SIGNKICK_LEVEL, ci->name.c_str()); + source.Reply(CHAN_SET_SIGNKICK_LEVEL, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_SIGNKICK); ci->UnsetFlag(CI_SIGNKICK_LEVEL); - u->SendMessage(ChanServ, CHAN_SET_SIGNKICK_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_SIGNKICK_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "SIGNKICK"); diff --git a/modules/core/cs_set_successor.cpp b/modules/core/cs_set_successor.cpp index 2e3c67044..f45065c6e 100644 --- a/modules/core/cs_set_successor.cpp +++ b/modules/core/cs_set_successor.cpp @@ -20,15 +20,16 @@ class CommandCSSetSuccessor : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetSuccessor"); if (this->permission.empty() && ci->HasFlag(CI_SECUREFOUNDER) ? !IsFounder(u, ci) : !check_access(u, ci, CA_FOUNDER)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -40,17 +41,17 @@ class CommandCSSetSuccessor : public Command if (!na) { - u->SendMessage(ChanServ, NICK_X_NOT_REGISTERED, params[1].c_str()); + source.Reply(NICK_X_NOT_REGISTERED, params[1].c_str()); return MOD_CONT; } if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(ChanServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } if (na->nc == ci->founder) { - u->SendMessage(ChanServ, CHAN_SUCCESSOR_IS_FOUNDER, na->nick.c_str(), ci->name.c_str()); + source.Reply(CHAN_SUCCESSOR_IS_FOUNDER, na->nick.c_str(), ci->name.c_str()); return MOD_CONT; } nc = na->nc; @@ -63,9 +64,9 @@ class CommandCSSetSuccessor : public Command ci->successor = nc; if (nc) - u->SendMessage(ChanServ, CHAN_SUCCESSOR_CHANGED, ci->name.c_str(), nc->display.c_str()); + source.Reply(CHAN_SUCCESSOR_CHANGED, ci->name.c_str(), nc->display.c_str()); else - u->SendMessage(ChanServ, CHAN_SUCCESSOR_UNSET, ci->name.c_str()); + source.Reply(CHAN_SUCCESSOR_UNSET, ci->name.c_str()); return MOD_CONT; } diff --git a/modules/core/cs_set_topiclock.cpp b/modules/core/cs_set_topiclock.cpp index 5a6938e0b..f3327045d 100644 --- a/modules/core/cs_set_topiclock.cpp +++ b/modules/core/cs_set_topiclock.cpp @@ -20,21 +20,22 @@ class CommandCSSetTopicLock : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetTopicLock"); if (params[1].equals_ci("ON")) { ci->SetFlag(CI_TOPICLOCK); - u->SendMessage(ChanServ, CHAN_SET_TOPICLOCK_ON, ci->name.c_str()); + source.Reply(CHAN_SET_TOPICLOCK_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_TOPICLOCK); - u->SendMessage(ChanServ, CHAN_SET_TOPICLOCK_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_TOPICLOCK_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "TOPICLOCK"); diff --git a/modules/core/cs_set_xop.cpp b/modules/core/cs_set_xop.cpp index 36992d2b8..ec872e3fd 100644 --- a/modules/core/cs_set_xop.cpp +++ b/modules/core/cs_set_xop.cpp @@ -21,15 +21,17 @@ class CommandCSSetXOP : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + ChannelInfo *ci = source.ci; + if (!FindModule("cs_xop")) { - u->SendMessage(ChanServ, CHAN_XOP_NOT_AVAILABLE, "XOP"); + source.Reply(CHAN_XOP_NOT_AVAILABLE, "XOP"); return MOD_CONT; } - ChannelInfo *ci = cs_findchan(params[0]); if (!ci) throw CoreException("NULL ci in CommandCSSetXOP"); @@ -65,14 +67,14 @@ class CommandCSSetXOP : public Command } Log(LOG_COMMAND, u, this, ci) << "to enable XOP"; - u->SendMessage(ChanServ, CHAN_SET_XOP_ON, ci->name.c_str()); + source.Reply(CHAN_SET_XOP_ON, ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { ci->UnsetFlag(CI_XOP); Log(LOG_COMMAND, u, this, ci) << "to disable XOP"; - u->SendMessage(ChanServ, CHAN_SET_XOP_OFF, ci->name.c_str()); + source.Reply(CHAN_SET_XOP_OFF, ci->name.c_str()); } else this->OnSyntaxError(u, "XOP"); diff --git a/modules/core/cs_status.cpp b/modules/core/cs_status.cpp index d40e721d8..9310f3382 100644 --- a/modules/core/cs_status.cpp +++ b/modules/core/cs_status.cpp @@ -20,27 +20,17 @@ class CommandCSStatus : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci; - User *u2; - Anope::string chan = params[0]; - Anope::string nick = params[1]; - Anope::string temp; + User *u = source.u; + ChannelInfo *ci = source.ci; + const Anope::string &nick = params[1]; - if (!(ci = cs_findchan(chan))) - { - temp = chan; - chan = nick; - nick = temp; - ci = cs_findchan(chan); - } - if (!ci) - u->SendMessage(ChanServ, CHAN_STATUS_NOT_REGGED, temp.c_str()); - else if ((u2 = finduser(nick))) - u->SendMessage(ChanServ, CHAN_STATUS_INFO, chan.c_str(), nick.c_str(), get_access(u2, ci)); + User *u2 = finduser(nick); + if (u2) + source.Reply(CHAN_STATUS_INFO, ci->name.c_str(), u2->nick.c_str(), get_access(u2, ci)); else /* !u2 */ - u->SendMessage(ChanServ, CHAN_STATUS_NOTONLINE, nick.c_str()); + source.Reply(CHAN_STATUS_NOTONLINE, nick.c_str()); return MOD_CONT; } diff --git a/modules/core/cs_suspend.cpp b/modules/core/cs_suspend.cpp index 085ac6a65..97ff9c0c7 100644 --- a/modules/core/cs_suspend.cpp +++ b/modules/core/cs_suspend.cpp @@ -20,13 +20,13 @@ class CommandCSSuspend : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string reason = params.size() > 1 ? params[1] : ""; - ChannelInfo *ci = cs_findchan(chan); + const Anope::string &reason = params.size() > 1 ? params[1] : ""; - Channel *c; + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; /* Assumes that permission checking has already been done. */ if (Config->ForceForbidReason && reason.empty()) @@ -35,28 +35,22 @@ class CommandCSSuspend : public Command return MOD_CONT; } - if (chan[0] != '#') - { - u->SendMessage(ChanServ, CHAN_UNSUSPEND_ERROR); - return MOD_CONT; - } - /* You should not SUSPEND a FORBIDEN channel */ if (ci->HasFlag(CI_FORBIDDEN)) { - u->SendMessage(ChanServ, CHAN_MAY_NOT_BE_REGISTERED, chan.c_str()); + source.Reply(CHAN_MAY_NOT_BE_REGISTERED, ci->name.c_str()); return MOD_CONT; } if (readonly) - u->SendMessage(ChanServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); ci->SetFlag(CI_SUSPENDED); ci->forbidby = u->nick; if (!reason.empty()) ci->forbidreason = reason; - if ((c = findchan(ci->name))) + if (c) { for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { @@ -73,7 +67,7 @@ class CommandCSSuspend : public Command ircdproto->SendGlobops(ChanServ, "\2%s\2 used SUSPEND on channel \2%s\2", u->nick.c_str(), ci->name.c_str()); Log(LOG_ADMIN, u, this, ci) << (!reason.empty() ? reason : "No reason"); - u->SendMessage(ChanServ, CHAN_SUSPEND_SUCCEEDED, chan.c_str()); + u->SendMessage(ChanServ, CHAN_SUSPEND_SUCCEEDED, ci->name.c_str()); FOREACH_MOD(I_OnChanSuspend, OnChanSuspend(ci)); @@ -105,23 +99,18 @@ class CommandCSUnSuspend : public Command this->SetFlag(CFLAG_ALLOW_SUSPENDED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - ChannelInfo *ci = cs_findchan(chan); + User *u = source.u; + ChannelInfo *ci = source.ci; - if (chan[0] != '#') - { - u->SendMessage(ChanServ, CHAN_UNSUSPEND_ERROR); - return MOD_CONT; - } if (readonly) - u->SendMessage(ChanServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); /* Only UNSUSPEND already suspended channels */ if (!ci->HasFlag(CI_SUSPENDED)) { - u->SendMessage(ChanServ, CHAN_UNSUSPEND_FAILED, chan.c_str()); + source.Reply(CHAN_UNSUSPEND_FAILED, ci->name.c_str()); return MOD_CONT; } @@ -134,7 +123,7 @@ class CommandCSUnSuspend : public Command if (Config->WallForbid) ircdproto->SendGlobops(ChanServ, "\2%s\2 used UNSUSPEND on channel \2%s\2", u->nick.c_str(), ci->name.c_str()); - u->SendMessage(ChanServ, CHAN_UNSUSPEND_SUCCEEDED, chan.c_str()); + u->SendMessage(ChanServ, CHAN_UNSUSPEND_SUCCEEDED, ci->name.c_str()); FOREACH_MOD(I_OnChanUnsuspend, OnChanUnsuspend(ci)); diff --git a/modules/core/cs_topic.cpp b/modules/core/cs_topic.cpp index e178aa9f2..11495284e 100644 --- a/modules/core/cs_topic.cpp +++ b/modules/core/cs_topic.cpp @@ -20,18 +20,18 @@ class CommandCSTopic : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string topic = params.size() > 1 ? params[1] : ""; + const Anope::string &topic = params.size() > 1 ? params[1] : ""; - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; Channel *c = ci->c; if (!c) - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str()); else if (!check_access(u, ci, CA_TOPIC) && !u->Account()->HasCommand("chanserv/topic")) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { bool has_topiclock = ci->HasFlag(CI_TOPICLOCK); diff --git a/modules/core/cs_unban.cpp b/modules/core/cs_unban.cpp index 4ac42f9b4..629c94974 100644 --- a/modules/core/cs_unban.cpp +++ b/modules/core/cs_unban.cpp @@ -20,39 +20,40 @@ class CommandCSUnban : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Channel *c; - User *u2; + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; - if (!(c = findchan(chan))) + if (!c) { - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, ci->name.c_str()); return MOD_CONT; } - if (!check_access(u, c->ci, CA_UNBAN)) + if (!check_access(u, ci, CA_UNBAN)) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } - u2 = u; + User *u2 = u; if (params.size() > 1) u2 = finduser(params[1]); if (!u2) { - u->SendMessage(ChanServ, NICK_X_NOT_IN_USE, params[1].c_str()); + source.Reply(NICK_X_NOT_IN_USE, params[1].c_str()); return MOD_CONT; } - common_unban(c->ci, u2->nick); + common_unban(ci, u2->nick); if (u2 == u) - u->SendMessage(ChanServ, CHAN_UNBANNED, c->name.c_str()); + source.Reply(CHAN_UNBANNED, c->name.c_str()); else - u->SendMessage(ChanServ, CHAN_UNBANNED_OTHER, u2->nick.c_str(), c->name.c_str()); + source.Reply(CHAN_UNBANNED_OTHER, u2->nick.c_str(), c->name.c_str()); + return MOD_CONT; } diff --git a/modules/core/cs_xop.cpp b/modules/core/cs_xop.cpp index a37ccaf4c..9a996e033 100644 --- a/modules/core/cs_xop.cpp +++ b/modules/core/cs_xop.cpp @@ -111,22 +111,21 @@ LanguageString xop_msgs[XOP_TYPES][XOP_MESSAGES] = { class XOPListCallback : public NumberList { - User *u; - ChannelInfo *ci; + CommandSource &source; int level; LanguageString *messages; bool SentHeader; public: - XOPListCallback(User *_u, ChannelInfo *_ci, const Anope::string &numlist, int _level, LanguageString *_messages) : NumberList(numlist, false), u(_u), ci(_ci), level(_level), messages(_messages), SentHeader(false) + XOPListCallback(CommandSource &_source, const Anope::string &numlist, int _level, LanguageString *_messages) : NumberList(numlist, false), source(_source), level(_level), messages(_messages), SentHeader(false) { } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAccessCount()) + if (!Number || Number > source.ci->GetAccessCount()) return; - ChanAccess *access = ci->GetAccess(Number - 1); + ChanAccess *access = source.ci->GetAccess(Number - 1); if (level != access->level) return; @@ -134,53 +133,52 @@ class XOPListCallback : public NumberList if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, messages[XOP_LIST_HEADER], ci->name.c_str()); + source.Reply(messages[XOP_LIST_HEADER], source.ci->name.c_str()); } - DoList(u, ci, access, Number - 1, level, messages); + DoList(source, access, Number - 1, level, messages); } - static void DoList(User *u, ChannelInfo *ci, ChanAccess *access, unsigned index, int level, LanguageString *messages) + static void DoList(CommandSource &source, ChanAccess *access, unsigned index, int level, LanguageString *messages) { - u->SendMessage(ChanServ, CHAN_XOP_LIST_FORMAT, index, access->nc->display.c_str()); + source.Reply(CHAN_XOP_LIST_FORMAT, index, access->nc->display.c_str()); } }; class XOPDelCallback : public NumberList { - User *u; - ChannelInfo *ci; + CommandSource &source; Command *c; LanguageString *messages; unsigned Deleted; Anope::string Nicks; bool override; public: - XOPDelCallback(User *_u, Command *_c, ChannelInfo *_ci, LanguageString *_messages, bool _override, const Anope::string &numlist) : NumberList(numlist, true), u(_u), ci(_ci), c(_c), messages(_messages), Deleted(0), override(_override) + XOPDelCallback(CommandSource &_source, Command *_c, LanguageString *_messages, bool _override, const Anope::string &numlist) : NumberList(numlist, true), source(_source), c(_c), messages(_messages), Deleted(0), override(_override) { } ~XOPDelCallback() { if (!Deleted) - u->SendMessage(ChanServ, messages[XOP_NO_MATCH], ci->name.c_str()); + source.Reply(messages[XOP_NO_MATCH], source.ci->name.c_str()); else { - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, c, ci) << "deleted access of users " << Nicks; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, source.ci) << "deleted access of users " << Nicks; if (Deleted == 1) - u->SendMessage(ChanServ, messages[XOP_DELETED_ONE], ci->name.c_str()); + source.Reply(messages[XOP_DELETED_ONE], source.ci->name.c_str()); else - u->SendMessage(ChanServ, messages[XOP_DELETED_SEVERAL], Deleted, ci->name.c_str()); + source.Reply(messages[XOP_DELETED_SEVERAL], Deleted, source.ci->name.c_str()); } } void HandleNumber(unsigned Number) { - if (!Number || Number > ci->GetAccessCount()) + if (!Number || Number > source.ci->GetAccessCount()) return; - ChanAccess *access = ci->GetAccess(Number - 1); + ChanAccess *access = source.ci->GetAccess(Number - 1); ++Deleted; if (!Nicks.empty()) @@ -188,18 +186,21 @@ class XOPDelCallback : public NumberList else Nicks = access->nc->display; - FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, access->nc)); + FOREACH_MOD(I_OnAccessDel, OnAccessDel(source.ci, source.u, access->nc)); - ci->EraseAccess(Number - 1); + source.ci->EraseAccess(Number - 1); } }; class XOPBase : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms, ChannelInfo *ci, int level, LanguageString *messages) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms, int level, LanguageString *messages) { - Anope::string nick = params.size() > 2 ? params[2] : ""; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &nick = params.size() > 2 ? params[2] : ""; ChanAccess *access; int change = 0; @@ -211,7 +212,7 @@ class XOPBase : public Command if (readonly) { - u->SendMessage(ChanServ, messages[XOP_DISABLED]); + source.Reply(messages[XOP_DISABLED]); return MOD_CONT; } @@ -219,19 +220,19 @@ class XOPBase : public Command if ((level >= ulev || ulev < ACCESS_AOP) && !u->Account()->HasPriv("chanserv/access/modify")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } NickAlias *na = findnick(nick); if (!na) { - u->SendMessage(ChanServ, messages[XOP_NICKS_ONLY]); + source.Reply(messages[XOP_NICKS_ONLY]); return MOD_CONT; } else if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(ChanServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } @@ -244,7 +245,7 @@ class XOPBase : public Command **/ if (access->level >= ulev && !u->Account()->HasPriv("chanserv/access/modify")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } ++change; @@ -252,7 +253,7 @@ class XOPBase : public Command if (!change && ci->GetAccessCount() >= Config->CSAccessMax) { - u->SendMessage(ChanServ, CHAN_XOP_REACHED_LIMIT, Config->CSAccessMax); + source.Reply(CHAN_XOP_REACHED_LIMIT, Config->CSAccessMax); return MOD_CONT; } @@ -271,20 +272,23 @@ class XOPBase : public Command if (!change) { FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, u, nc, level)); - u->SendMessage(ChanServ, messages[XOP_ADDED], nc->display.c_str(), ci->name.c_str()); + source.Reply(messages[XOP_ADDED], nc->display.c_str(), ci->name.c_str()); } else { FOREACH_MOD(I_OnAccessChange, OnAccessChange(ci, u, na->nc, level)); - u->SendMessage(ChanServ, messages[XOP_MOVED], nc->display.c_str(), ci->name.c_str()); + source.Reply(messages[XOP_MOVED], nc->display.c_str(), ci->name.c_str()); } return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms, ChannelInfo *ci, int level, LanguageString *messages) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms, int level, LanguageString *messages) { - Anope::string nick = params.size() > 2 ? params[2] : ""; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &nick = params.size() > 2 ? params[2] : ""; ChanAccess *access; if (nick.empty()) @@ -295,13 +299,13 @@ class XOPBase : public Command if (readonly) { - u->SendMessage(ChanServ, messages[XOP_DISABLED]); + source.Reply(messages[XOP_DISABLED]); return MOD_CONT; } if (!ci->GetAccessCount()) { - u->SendMessage(ChanServ, messages[XOP_LIST_EMPTY], ci->name.c_str()); + source.Reply(messages[XOP_LIST_EMPTY], ci->name.c_str()); return MOD_CONT; } @@ -311,7 +315,7 @@ class XOPBase : public Command na = findnick(nick); if (!na) { - u->SendMessage(ChanServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } } @@ -320,7 +324,7 @@ class XOPBase : public Command if ((!na || na->nc != u->Account()) && (level >= ulev || ulev < ACCESS_AOP) && !u->Account()->HasPriv("chanserv/access/modify")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -328,7 +332,7 @@ class XOPBase : public Command if (isdigit(nick[0]) && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { bool override = level >= ulev || ulev < ACCESS_AOP; - XOPDelCallback list(u, this, ci, messages, override, nick); + XOPDelCallback list(source, this, messages, override, nick); list.Process(); } else @@ -345,18 +349,18 @@ class XOPBase : public Command if (i == end) { - u->SendMessage(ChanServ, messages[XOP_NOT_FOUND], nick.c_str(), ci->name.c_str()); + source.Reply(messages[XOP_NOT_FOUND], nick.c_str(), ci->name.c_str()); return MOD_CONT; } if (nc != u->Account() && ulev <= access->level && !u->Account()->HasPriv("chanserv/access/modify")) - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { bool override = ulev <= access->level; Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "DEL " << access->nc->display; - u->SendMessage(ChanServ, messages[XOP_DELETED], access->nc->display.c_str(), ci->name.c_str()); + source.Reply(messages[XOP_DELETED], access->nc->display.c_str(), ci->name.c_str()); FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, na->nc)); @@ -367,13 +371,16 @@ class XOPBase : public Command return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms, ChannelInfo *ci, int level, LanguageString *messages) + CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> ¶ms, int level, LanguageString *messages) { - Anope::string nick = params.size() > 2 ? params[2] : ""; + User *u = source.u; + ChannelInfo *ci = source.ci; + + const Anope::string &nick = params.size() > 2 ? params[2] : ""; if (!get_access(u, ci) && !u->Account()->HasCommand("chanserv/access/list")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -382,13 +389,13 @@ class XOPBase : public Command if (!ci->GetAccessCount()) { - u->SendMessage(ChanServ, messages[XOP_LIST_EMPTY], ci->name.c_str()); + source.Reply(messages[XOP_LIST_EMPTY], ci->name.c_str()); return MOD_CONT; } if (!nick.empty() && nick.find_first_not_of("1234567890,-") == Anope::string::npos) { - XOPListCallback list(u, ci, nick, level, messages); + XOPListCallback list(source, nick, level, messages); list.Process(); } else @@ -407,36 +414,39 @@ class XOPBase : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(ChanServ, messages[XOP_LIST_HEADER], ci->name.c_str()); + source.Reply(messages[XOP_LIST_HEADER], ci->name.c_str()); } - XOPListCallback::DoList(u, ci, access, i + 1, level, messages); + XOPListCallback::DoList(source, access, i + 1, level, messages); } if (!SentHeader) - u->SendMessage(ChanServ, messages[XOP_NO_MATCH], ci->name.c_str()); + source.Reply(messages[XOP_NO_MATCH], ci->name.c_str()); } return MOD_CONT; } - CommandReturn DoClear(User *u, ChannelInfo *ci, int level, LanguageString *messages) + CommandReturn DoClear(CommandSource &source, int level, LanguageString *messages) { + User *u = source.u; + ChannelInfo *ci = source.ci; + if (readonly) { - u->SendMessage(ChanServ, messages[XOP_DISABLED]); + source.Reply(messages[XOP_DISABLED]); return MOD_CONT; } if (!ci->GetAccessCount()) { - u->SendMessage(ChanServ, messages[XOP_LIST_EMPTY], ci->name.c_str()); + source.Reply(messages[XOP_LIST_EMPTY], ci->name.c_str()); return MOD_CONT; } if (!check_access(u, ci, CA_FOUNDER) && !u->Account()->HasPriv("chanserv/access/modify")) { - u->SendMessage(ChanServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -457,25 +467,26 @@ class XOPBase : public Command return MOD_CONT; } protected: - CommandReturn DoXop(User *u, const std::vector<Anope::string> ¶ms, int level, LanguageString *messages) + CommandReturn DoXop(CommandSource &source, const std::vector<Anope::string> ¶ms, int level, LanguageString *messages) { - Anope::string chan = params[0]; - Anope::string cmd = params[1]; + User *u = source.u; + ChannelInfo *ci = source.ci; - ChannelInfo *ci = cs_findchan(chan); + const Anope::string &cmd = params[1]; if (!ci->HasFlag(CI_XOP)) - u->SendMessage(ChanServ, CHAN_XOP_ACCESS, Config->s_ChanServ.c_str()); + source.Reply(CHAN_XOP_ACCESS, Config->s_ChanServ.c_str()); else if (cmd.equals_ci("ADD")) - return this->DoAdd(u, params, ci, level, messages); + return this->DoAdd(source, params, level, messages); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, params, ci, level, messages); + return this->DoDel(source, params, level, messages); else if (cmd.equals_ci("LIST")) - return this->DoList(u, params, ci, level, messages); + return this->DoList(source, params, level, messages); else if (cmd.equals_ci("CLEAR")) - return this->DoClear(u, ci, level, messages); + return this->DoClear(source, level, messages); else this->OnSyntaxError(u, ""); + return MOD_CONT; } public: @@ -487,7 +498,7 @@ class XOPBase : public Command { } - virtual CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) = 0; + virtual CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) = 0; virtual bool OnHelp(User *u, const Anope::string &subcommand) = 0; @@ -503,9 +514,9 @@ class CommandCSQOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoXop(u, params, ACCESS_QOP, xop_msgs[XOP_QOP]); + return this->DoXop(source, params, ACCESS_QOP, xop_msgs[XOP_QOP]); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -532,9 +543,9 @@ class CommandCSAOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoXop(u, params, ACCESS_AOP, xop_msgs[XOP_AOP]); + return this->DoXop(source, params, ACCESS_AOP, xop_msgs[XOP_AOP]); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -561,9 +572,9 @@ class CommandCSHOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoXop(u, params, ACCESS_HOP, xop_msgs[XOP_HOP]); + return this->DoXop(source, params, ACCESS_HOP, xop_msgs[XOP_HOP]); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -590,9 +601,9 @@ class CommandCSSOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoXop(u, params, ACCESS_SOP, xop_msgs[XOP_SOP]); + return this->DoXop(source, params, ACCESS_SOP, xop_msgs[XOP_SOP]); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -619,9 +630,9 @@ class CommandCSVOP : public XOPBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoXop(u, params, ACCESS_VOP, xop_msgs[XOP_VOP]); + return this->DoXop(source, params, ACCESS_VOP, xop_msgs[XOP_VOP]); } bool OnHelp(User *u, const Anope::string &subcommand) diff --git a/modules/core/hs_del.cpp b/modules/core/hs_del.cpp index 2908fa3db..6ebbbd89c 100644 --- a/modules/core/hs_del.cpp +++ b/modules/core/hs_del.cpp @@ -20,24 +20,26 @@ class CommandHSDel : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - NickAlias *na; - Anope::string nick = params[0]; - if ((na = findnick(nick))) + User *u = source.u; + const Anope::string &nick = params[0]; + NickAlias *na = findnick(nick); + if (na) { if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(HostServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } Log(LOG_ADMIN, u, this) << "for user " << na->nick; FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); na->hostinfo.RemoveVhost(); - u->SendMessage(HostServ, HOST_DEL, nick.c_str()); + source.Reply(HOST_DEL, nick.c_str()); } else - u->SendMessage(HostServ, HOST_NOREG, nick.c_str()); + source.Reply(HOST_NOREG, nick.c_str()); + return MOD_CONT; } diff --git a/modules/core/hs_delall.cpp b/modules/core/hs_delall.cpp index 53b08f283..10d290f43 100644 --- a/modules/core/hs_delall.cpp +++ b/modules/core/hs_delall.cpp @@ -20,15 +20,16 @@ class CommandHSDelAll : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - NickAlias *na; - if ((na = findnick(nick))) + const Anope::string &nick = params[0]; + User *u = source.u; + NickAlias *na = findnick(nick); + if (na) { if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(HostServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na)); @@ -39,10 +40,11 @@ class CommandHSDelAll : public Command na->hostinfo.RemoveVhost(); } Log(LOG_ADMIN, u, this) << "for all nicks in group " << nc->display; - u->SendMessage(HostServ, HOST_DELALL, nc->display.c_str()); + source.Reply(HOST_DELALL, nc->display.c_str()); } else - u->SendMessage(HostServ, HOST_NOREG, nick.c_str()); + source.Reply(HOST_NOREG, nick.c_str()); + return MOD_CONT; } diff --git a/modules/core/hs_group.cpp b/modules/core/hs_group.cpp index 11b56ba07..056cbaab1 100644 --- a/modules/core/hs_group.cpp +++ b/modules/core/hs_group.cpp @@ -20,19 +20,20 @@ class CommandHSGroup : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(u->nick); if (na && u->Account() == na->nc && na->hostinfo.HasVhost()) { HostServSyncVhosts(na); if (!na->hostinfo.GetIdent().empty()) - u->SendMessage(HostServ, HOST_IDENT_GROUP, u->Account()->display.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); + source.Reply(HOST_IDENT_GROUP, u->Account()->display.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else - u->SendMessage(HostServ, HOST_GROUP, u->Account()->display.c_str(), na->hostinfo.GetHost().c_str()); + source.Reply(HOST_GROUP, u->Account()->display.c_str(), na->hostinfo.GetHost().c_str()); } else - u->SendMessage(HostServ, HOST_NOT_ASSIGNED); + source.Reply(HOST_NOT_ASSIGNED); return MOD_CONT; } diff --git a/modules/core/hs_help.cpp b/modules/core/hs_help.cpp index 45d4d2314..e2f49a3e7 100644 --- a/modules/core/hs_help.cpp +++ b/modules/core/hs_help.cpp @@ -21,9 +21,9 @@ class CommandHSHelp : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(HostServ, u, params[0]); + mod_help_cmd(HostServ, source.u, params[0]); return MOD_CONT; } diff --git a/modules/core/hs_list.cpp b/modules/core/hs_list.cpp index c0408844d..543aa273a 100644 --- a/modules/core/hs_list.cpp +++ b/modules/core/hs_list.cpp @@ -20,9 +20,11 @@ class CommandHSList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string key = !params.empty() ? params[0] : ""; + User *u = source.u; + + const Anope::string &key = !params.empty() ? params[0] : ""; int from = 0, to = 0, counter = 1; unsigned display_counter = 0; @@ -35,14 +37,14 @@ class CommandHSList : public Command size_t tmp = key.find('-'); if (tmp == Anope::string::npos || tmp == key.length() || tmp == 1) { - u->SendMessage(HostServ, LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); return MOD_CONT; } for (unsigned i = 1, end = key.length(); i < end; ++i) { if (!isdigit(key[i]) && i != tmp) { - u->SendMessage(HostServ, LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); return MOD_CONT; } from = convertTo<int>(key.substr(1, tmp - 1)); @@ -63,9 +65,9 @@ class CommandHSList : public Command { ++display_counter; if (!na->hostinfo.GetIdent().empty()) - u->SendMessage(HostServ, HOST_IDENT_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); + source.Reply(HOST_IDENT_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); else - u->SendMessage(HostServ, HOST_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); + source.Reply(HOST_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); } } else @@ -78,21 +80,21 @@ class CommandHSList : public Command { ++display_counter; if (!na->hostinfo.GetIdent().empty()) - u->SendMessage(HostServ, HOST_IDENT_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); + source.Reply(HOST_IDENT_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); else - u->SendMessage(HostServ, HOST_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); + source.Reply(HOST_ENTRY, counter, na->nick.c_str(), na->hostinfo.GetHost().c_str(), na->hostinfo.GetCreator().c_str(), do_strftime(na->hostinfo.GetTime()).c_str()); } } ++counter; } if (!key.empty()) - u->SendMessage(HostServ, HOST_LIST_KEY_FOOTER, key.c_str(), display_counter); + source.Reply(HOST_LIST_KEY_FOOTER, key.c_str(), display_counter); else { if (from) - u->SendMessage(HostServ, HOST_LIST_RANGE_FOOTER, from, to); + source.Reply(HOST_LIST_RANGE_FOOTER, from, to); else - u->SendMessage(HostServ, HOST_LIST_FOOTER, display_counter); + source.Reply(HOST_LIST_FOOTER, display_counter); } return MOD_CONT; } diff --git a/modules/core/hs_off.cpp b/modules/core/hs_off.cpp index 535139106..8c69a8821 100644 --- a/modules/core/hs_off.cpp +++ b/modules/core/hs_off.cpp @@ -20,17 +20,18 @@ class CommandHSOff : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(u->nick); if (!na || !na->hostinfo.HasVhost()) - u->SendMessage(HostServ, HOST_NOT_ASSIGNED); + source.Reply(HOST_NOT_ASSIGNED); else { ircdproto->SendVhostDel(u); Log(LOG_COMMAND, u, this) << "to disable their vhost"; - u->SendMessage(HostServ, HOST_OFF); + source.Reply(HOST_OFF); } return MOD_CONT; diff --git a/modules/core/hs_on.cpp b/modules/core/hs_on.cpp index c8e953e73..dd11e1c9b 100644 --- a/modules/core/hs_on.cpp +++ b/modules/core/hs_on.cpp @@ -20,15 +20,16 @@ class CommandHSOn : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(u->nick); if (na && u->Account() == na->nc && na->hostinfo.HasVhost()) { if (!na->hostinfo.GetIdent().empty()) - u->SendMessage(HostServ, HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); + source.Reply(HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else - u->SendMessage(HostServ, HOST_ACTIVATED, na->hostinfo.GetHost().c_str()); + source.Reply(HOST_ACTIVATED, na->hostinfo.GetHost().c_str()); Log(LOG_COMMAND, u, this) << "to enable their vhost of " << (!na->hostinfo.GetIdent().empty() ? na->hostinfo.GetIdent() + "@" : "") << na->hostinfo.GetHost(); ircdproto->SendVhost(u, na->hostinfo.GetIdent(), na->hostinfo.GetHost()); if (ircd->vhost) @@ -41,7 +42,7 @@ class CommandHSOn : public Command u->UpdateHost(); } else - u->SendMessage(HostServ, HOST_NOT_ASSIGNED); + source.Reply(HOST_NOT_ASSIGNED); return MOD_CONT; } diff --git a/modules/core/hs_set.cpp b/modules/core/hs_set.cpp index 00b7d4556..8cd25bdc2 100644 --- a/modules/core/hs_set.cpp +++ b/modules/core/hs_set.cpp @@ -20,27 +20,26 @@ class CommandHSSet : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + Anope::string nick = params[0]; Anope::string rawhostmask = params[1]; Anope::string hostmask; - NickAlias *na; - int32 tmp_time; - Anope::string vIdent = myStrGetToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ if (!vIdent.empty()) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ if (rawhostmask.empty()) { - u->SendMessage(HostServ, HOST_SET_SYNTAX, Config->s_HostServ.c_str()); + source.Reply(HOST_SET_SYNTAX, Config->s_HostServ.c_str()); return MOD_CONT; } if (vIdent.length() > Config->UserLen) { - u->SendMessage(HostServ, HOST_SET_IDENTTOOLONG, Config->UserLen); + source.Reply(HOST_SET_IDENTTOOLONG, Config->UserLen); return MOD_CONT; } else @@ -48,13 +47,13 @@ class CommandHSSet : public Command for (Anope::string::iterator s = vIdent.begin(), s_end = vIdent.end(); s != s_end; ++s) if (!isvalidchar(*s)) { - u->SendMessage(HostServ, HOST_SET_IDENT_ERROR); + source.Reply(HOST_SET_IDENT_ERROR); return MOD_CONT; } } if (!ircd->vident) { - u->SendMessage(HostServ, HOST_NO_VIDENT); + source.Reply(HOST_NO_VIDENT); return MOD_CONT; } } @@ -62,23 +61,22 @@ class CommandHSSet : public Command hostmask = rawhostmask; else { - u->SendMessage(HostServ, HOST_SET_TOOLONG, Config->HostLen); + source.Reply(HOST_SET_TOOLONG, Config->HostLen); return MOD_CONT; } if (!isValidHost(hostmask, 3)) { - u->SendMessage(HostServ, HOST_SET_ERROR); + source.Reply(HOST_SET_ERROR); return MOD_CONT; } - tmp_time = Anope::CurTime; - + NickAlias *na = findnick(nick); if ((na = findnick(nick))) { if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(HostServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } @@ -87,12 +85,12 @@ class CommandHSSet : public Command na->hostinfo.SetVhost(vIdent, hostmask, u->nick); FOREACH_MOD(I_OnSetVhost, OnSetVhost(na)); if (!vIdent.empty()) - u->SendMessage(HostServ, HOST_IDENT_SET, nick.c_str(), vIdent.c_str(), hostmask.c_str()); + source.Reply(HOST_IDENT_SET, nick.c_str(), vIdent.c_str(), hostmask.c_str()); else - u->SendMessage(HostServ, HOST_SET, nick.c_str(), hostmask.c_str()); + source.Reply(HOST_SET, nick.c_str(), hostmask.c_str()); } else - u->SendMessage(HostServ, HOST_NOREG, nick.c_str()); + source.Reply(HOST_NOREG, nick.c_str()); return MOD_CONT; } diff --git a/modules/core/hs_setall.cpp b/modules/core/hs_setall.cpp index 304a000b8..4a2f27ab6 100644 --- a/modules/core/hs_setall.cpp +++ b/modules/core/hs_setall.cpp @@ -20,23 +20,24 @@ class CommandHSSetAll : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + User *u = source.u; + + const Anope::string &nick = params[0]; Anope::string rawhostmask = params[1]; - Anope::string hostmask; - NickAlias *na; int32 tmp_time; - if (!(na = findnick(nick))) + NickAlias *na = findnick(nick); + if (!na) { - u->SendMessage(HostServ, HOST_NOREG, nick.c_str()); + source.Reply(HOST_NOREG, nick.c_str()); return MOD_CONT; } else if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(HostServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } @@ -46,12 +47,12 @@ class CommandHSSetAll : public Command rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ if (rawhostmask.empty()) { - u->SendMessage(HostServ, HOST_SETALL_SYNTAX, Config->s_HostServ.c_str()); + source.Reply(HOST_SETALL_SYNTAX, Config->s_HostServ.c_str()); return MOD_CONT; } if (vIdent.length() > Config->UserLen) { - u->SendMessage(HostServ, HOST_SET_IDENTTOOLONG, Config->UserLen); + source.Reply(HOST_SET_IDENTTOOLONG, Config->UserLen); return MOD_CONT; } else @@ -59,28 +60,29 @@ class CommandHSSetAll : public Command for (Anope::string::iterator s = vIdent.begin(), s_end = vIdent.end(); s != s_end; ++s) if (!isvalidchar(*s)) { - u->SendMessage(HostServ, HOST_SET_IDENT_ERROR); + source.Reply(HOST_SET_IDENT_ERROR); return MOD_CONT; } } if (!ircd->vident) { - u->SendMessage(HostServ, HOST_NO_VIDENT); + source.Reply(HOST_NO_VIDENT); return MOD_CONT; } } + Anope::string hostmask; if (rawhostmask.length() < Config->HostLen) hostmask = rawhostmask; else { - u->SendMessage(HostServ, HOST_SET_TOOLONG, Config->HostLen); + source.Reply(HOST_SET_TOOLONG, Config->HostLen); return MOD_CONT; } if (!isValidHost(hostmask, 3)) { - u->SendMessage(HostServ, HOST_SET_ERROR); + source.Reply(HOST_SET_ERROR); return MOD_CONT; } @@ -92,9 +94,9 @@ class CommandHSSetAll : public Command HostServSyncVhosts(na); FOREACH_MOD(I_OnSetVhost, OnSetVhost(na)); if (!vIdent.empty()) - u->SendMessage(HostServ, HOST_IDENT_SETALL, nick.c_str(), vIdent.c_str(), hostmask.c_str()); + source.Reply(HOST_IDENT_SETALL, nick.c_str(), vIdent.c_str(), hostmask.c_str()); else - u->SendMessage(HostServ, HOST_SETALL, nick.c_str(), hostmask.c_str()); + source.Reply(HOST_SETALL, nick.c_str(), hostmask.c_str()); return MOD_CONT; } diff --git a/modules/core/ms_cancel.cpp b/modules/core/ms_cancel.cpp index 46799a148..dc8cbe050 100644 --- a/modules/core/ms_cancel.cpp +++ b/modules/core/ms_cancel.cpp @@ -22,33 +22,34 @@ class CommandMSCancel : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + + const Anope::string &nname = params[0]; + bool ischan, isforbid; - Anope::string nname = params[0]; MemoInfo *mi; if (!(mi = getmemoinfo(nname, ischan, isforbid))) { if (isforbid) - u->SendMessage(MemoServ, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, nname.c_str()); + source.Reply(ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, nname.c_str()); else - u->SendMessage(MemoServ, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nname.c_str()); + source.Reply(ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nname.c_str()); } else { - int i; - - for (i = mi->memos.size() - 1; i >= 0; --i) + for (int i = mi->memos.size() - 1; i >= 0; --i) if (mi->memos[i]->HasFlag(MF_UNREAD) && u->Account()->display.equals_ci(mi->memos[i]->sender) && !mi->memos[i]->HasFlag(MF_NOTIFYS)) { FOREACH_MOD(I_OnMemoDel, OnMemoDel(findnick(nname)->nc, mi, mi->memos[i])); mi->Del(mi->memos[i]); - u->SendMessage(MemoServ, MEMO_CANCELLED, nname.c_str()); + source.Reply(MEMO_CANCELLED, nname.c_str()); return MOD_CONT; } - u->SendMessage(MemoServ, MEMO_CANCEL_NONE); + source.Reply(MEMO_CANCEL_NONE); } return MOD_CONT; } diff --git a/modules/core/ms_check.cpp b/modules/core/ms_check.cpp index f6d9e9833..80b30d2ac 100644 --- a/modules/core/ms_check.cpp +++ b/modules/core/ms_check.cpp @@ -20,46 +20,48 @@ class CommandMSCheck : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - NickAlias *na = NULL; - MemoInfo *mi = NULL; - int i, found = 0; - Anope::string recipient = params[0]; + User *u = source.u; - if (!(na = findnick(recipient))) + const Anope::string &recipient = params[0]; + + bool found = false; + + NickAlias *na = findnick(recipient); + if (!na) { - u->SendMessage(MemoServ, NICK_X_NOT_REGISTERED, recipient.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, recipient.c_str()); return MOD_CONT; } if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(MemoServ, NICK_X_FORBIDDEN, recipient.c_str()); + source.Reply(NICK_X_FORBIDDEN, recipient.c_str()); return MOD_CONT; } - mi = &na->nc->memos; + MemoInfo *mi = &na->nc->memos; /* Okay, I know this looks strange but we wanna get the LAST memo, so we have to loop backwards */ - for (i = mi->memos.size() - 1; i >= 0; --i) + for (int i = mi->memos.size() - 1; i >= 0; --i) { if (u->Account()->display.equals_ci(mi->memos[i]->sender)) { - found = 1; /* Yes, we've found the memo */ + found = true; /* Yes, we've found the memo */ if (mi->memos[i]->HasFlag(MF_UNREAD)) - u->SendMessage(MemoServ, MEMO_CHECK_NOT_READ, na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str()); + source.Reply(MEMO_CHECK_NOT_READ, na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str()); else - u->SendMessage(MemoServ, MEMO_CHECK_READ, na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str()); + source.Reply(MEMO_CHECK_READ, na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str()); break; } } if (!found) - u->SendMessage(MemoServ, MEMO_CHECK_NO_MEMO, na->nick.c_str()); + source.Reply(MEMO_CHECK_NO_MEMO, na->nick.c_str()); return MOD_CONT; } diff --git a/modules/core/ms_del.cpp b/modules/core/ms_del.cpp index 2d69fba5e..443674a88 100644 --- a/modules/core/ms_del.cpp +++ b/modules/core/ms_del.cpp @@ -15,11 +15,11 @@ class MemoDelCallback : public NumberList { - User *u; + CommandSource &source; ChannelInfo *ci; MemoInfo *mi; public: - MemoDelCallback(User *_u, ChannelInfo *_ci, MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), u(_u), ci(_ci), mi(_mi) + MemoDelCallback(CommandSource &_source, ChannelInfo *_ci, MemoInfo *_mi, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), mi(_mi) { } @@ -31,10 +31,10 @@ class MemoDelCallback : public NumberList if (ci) FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[Number - 1])); else - FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[Number - 1])); + FOREACH_MOD(I_OnMemoDel, OnMemoDel(source.u->Account(), mi, mi->memos[Number - 1])); mi->Del(Number - 1); - u->SendMessage(MemoServ, MEMO_DELETED_ONE, Number); + source.Reply(MEMO_DELETED_ONE, Number); } }; @@ -45,12 +45,13 @@ class CommandMSDel : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + MemoInfo *mi; ChannelInfo *ci = NULL; Anope::string numstr = !params.empty() ? params[0] : "", chan; - unsigned i, end; if (!numstr.empty() && numstr[0] == '#') { @@ -59,17 +60,17 @@ class CommandMSDel : public Command if (!(ci = cs_findchan(chan))) { - u->SendMessage(MemoServ, CHAN_X_NOT_REGISTERED, chan.c_str()); + source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); return MOD_CONT; } else if (readonly) { - u->SendMessage(MemoServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } else if (!check_access(u, ci, CA_MEMO)) { - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } mi = &ci->memos; @@ -81,15 +82,15 @@ class CommandMSDel : public Command else if (mi->memos.empty()) { if (!chan.empty()) - u->SendMessage(MemoServ, MEMO_X_HAS_NO_MEMOS, chan.c_str()); + source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str()); else - u->SendMessage(MemoServ, MEMO_HAVE_NO_MEMOS); + source.Reply(MEMO_HAVE_NO_MEMOS); } else { if (isdigit(numstr[0])) { - MemoDelCallback list(u, ci, mi, numstr); + MemoDelCallback list(source, ci, mi, numstr); list.Process(); } else if (numstr.equals_ci("LAST")) @@ -100,7 +101,7 @@ class CommandMSDel : public Command else FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[mi->memos.size() - 1])); mi->Del(mi->memos[mi->memos.size() - 1]); - u->SendMessage(MemoServ, MEMO_DELETED_ONE, mi->memos.size() + 1); + source.Reply(MEMO_DELETED_ONE, mi->memos.size() + 1); } else { @@ -109,13 +110,13 @@ class CommandMSDel : public Command else FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, NULL)); /* Delete all memos. */ - for (i = 0, end = mi->memos.size(); i < end; ++i) + for (unsigned i = 0, end = mi->memos.size(); i < end; ++i) delete mi->memos[i]; mi->memos.clear(); if (!chan.empty()) - u->SendMessage(MemoServ, MEMO_CHAN_DELETED_ALL, chan.c_str()); + source.Reply(MEMO_CHAN_DELETED_ALL, chan.c_str()); else - u->SendMessage(MemoServ, MEMO_DELETED_ALL); + source.Reply(MEMO_DELETED_ALL); } } return MOD_CONT; diff --git a/modules/core/ms_help.cpp b/modules/core/ms_help.cpp index 3f1e82798..025bed6aa 100644 --- a/modules/core/ms_help.cpp +++ b/modules/core/ms_help.cpp @@ -21,9 +21,9 @@ class CommandMSHelp : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(MemoServ, u, params[0]); + mod_help_cmd(MemoServ, source.u, params[0]); return MOD_CONT; } diff --git a/modules/core/ms_ignore.cpp b/modules/core/ms_ignore.cpp index 347657437..078f8abcc 100644 --- a/modules/core/ms_ignore.cpp +++ b/modules/core/ms_ignore.cpp @@ -20,8 +20,10 @@ class CommandMSIgnore : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + Anope::string channel = params[0]; Anope::string command = (params.size() > 1 ? params[1] : ""); Anope::string param = (params.size() > 2 ? params[2] : ""); @@ -38,21 +40,21 @@ class CommandMSIgnore : public Command if (!mi) { if (isforbid) - u->SendMessage(MemoServ, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, channel.c_str()); + source.Reply(ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, channel.c_str()); else - u->SendMessage(MemoServ, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, channel.c_str()); + source.Reply(ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, channel.c_str()); } else if (ischan && !check_access(u, cs_findchan(channel), CA_MEMO)) - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (command.equals_ci("ADD") && !param.empty()) { if (std::find(mi->ignores.begin(), mi->ignores.end(), param.ci_str()) == mi->ignores.end()) { mi->ignores.push_back(param.ci_str()); - u->SendMessage(MemoServ, MEMO_IGNORE_ADD, param.c_str()); + source.Reply(MEMO_IGNORE_ADD, param.c_str()); } else - u->SendMessage(MemoServ, MEMO_IGNORE_ALREADY_IGNORED, param.c_str()); + source.Reply(MEMO_IGNORE_ALREADY_IGNORED, param.c_str()); } else if (command.equals_ci("DEL") && !param.empty()) { @@ -61,20 +63,20 @@ class CommandMSIgnore : public Command if (it != mi->ignores.end()) { mi->ignores.erase(it); - u->SendMessage(MemoServ, MEMO_IGNORE_DEL, param.c_str()); + source.Reply(MEMO_IGNORE_DEL, param.c_str()); } else - u->SendMessage(MemoServ, MEMO_IGNORE_NOT_IGNORED, param.c_str()); + source.Reply(MEMO_IGNORE_NOT_IGNORED, param.c_str()); } else if (command.equals_ci("LIST")) { if (mi->ignores.empty()) - u->SendMessage(MemoServ, MEMO_IGNORE_LIST_EMPTY); + source.Reply(MEMO_IGNORE_LIST_EMPTY); else { - u->SendMessage(MemoServ, MEMO_IGNORE_LIST_HEADER); + source.Reply(MEMO_IGNORE_LIST_HEADER); for (unsigned i = 0; i < mi->ignores.size(); ++i) - u->SendMessage(Config->s_MemoServ, " %s", mi->ignores[i].c_str()); + source.Reply(" %s", mi->ignores[i].c_str()); } } else diff --git a/modules/core/ms_info.cpp b/modules/core/ms_info.cpp index 09bf8f97d..04e1087e6 100644 --- a/modules/core/ms_info.cpp +++ b/modules/core/ms_info.cpp @@ -20,12 +20,14 @@ class CommandMSInfo : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + const MemoInfo *mi; NickAlias *na = NULL; ChannelInfo *ci = NULL; - Anope::string nname = !params.empty() ? params[0] : ""; + const Anope::string &nname = !params.empty() ? params[0] : ""; int hardmax = 0; if (!nname.empty() && nname[0] != '#' && u->Account()->HasPriv("memoserv/info")) @@ -33,12 +35,12 @@ class CommandMSInfo : public Command na = findnick(nname); if (!na) { - u->SendMessage(MemoServ, NICK_X_NOT_REGISTERED, nname.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nname.c_str()); return MOD_CONT; } else if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(MemoServ, NICK_X_FORBIDDEN, nname.c_str()); + source.Reply(NICK_X_FORBIDDEN, nname.c_str()); return MOD_CONT; } mi = &na->nc->memos; @@ -48,12 +50,12 @@ class CommandMSInfo : public Command { if (!(ci = cs_findchan(nname))) { - u->SendMessage(MemoServ, CHAN_X_NOT_REGISTERED, nname.c_str()); + source.Reply(CHAN_X_NOT_REGISTERED, nname.c_str()); return MOD_CONT; } else if (!check_access(u, ci, CA_MEMO)) { - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } mi = &ci->memos; @@ -61,7 +63,7 @@ class CommandMSInfo : public Command } else if (!nname.empty()) /* It's not a chan and we aren't services admin */ { - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } else @@ -73,13 +75,13 @@ class CommandMSInfo : public Command if (!nname.empty() && (ci || na->nc != u->Account())) { if (mi->memos.empty()) - u->SendMessage(MemoServ, MEMO_INFO_X_NO_MEMOS, nname.c_str()); + source.Reply(MEMO_INFO_X_NO_MEMOS, nname.c_str()); else if (mi->memos.size() == 1) { if (mi->memos[0]->HasFlag(MF_UNREAD)) - u->SendMessage(MemoServ, MEMO_INFO_X_MEMO_UNREAD, nname.c_str()); + source.Reply(MEMO_INFO_X_MEMO_UNREAD, nname.c_str()); else - u->SendMessage(MemoServ, MEMO_INFO_X_MEMO, nname.c_str()); + source.Reply(MEMO_INFO_X_MEMO, nname.c_str()); } else { @@ -88,55 +90,55 @@ class CommandMSInfo : public Command if (mi->memos[i]->HasFlag(MF_UNREAD)) ++count; if (count == mi->memos.size()) - u->SendMessage(MemoServ, MEMO_INFO_X_MEMOS_ALL_UNREAD, nname.c_str(), count); + source.Reply(MEMO_INFO_X_MEMOS_ALL_UNREAD, nname.c_str(), count); else if (!count) - u->SendMessage(MemoServ, MEMO_INFO_X_MEMOS, nname.c_str(), mi->memos.size()); + source.Reply(MEMO_INFO_X_MEMOS, nname.c_str(), mi->memos.size()); else if (count == 1) - u->SendMessage(MemoServ, MEMO_INFO_X_MEMOS_ONE_UNREAD, nname.c_str(), mi->memos.size()); + source.Reply(MEMO_INFO_X_MEMOS_ONE_UNREAD, nname.c_str(), mi->memos.size()); else - u->SendMessage(MemoServ, MEMO_INFO_X_MEMOS_SOME_UNREAD, nname.c_str(), mi->memos.size(), count); + source.Reply(MEMO_INFO_X_MEMOS_SOME_UNREAD, nname.c_str(), mi->memos.size(), count); } if (!mi->memomax) { if (hardmax) - u->SendMessage(MemoServ, MEMO_INFO_X_HARD_LIMIT, nname.c_str(), mi->memomax); + source.Reply(MEMO_INFO_X_HARD_LIMIT, nname.c_str(), mi->memomax); else - u->SendMessage(MemoServ, MEMO_INFO_X_LIMIT, nname.c_str(), mi->memomax); + source.Reply(MEMO_INFO_X_LIMIT, nname.c_str(), mi->memomax); } else if (mi->memomax > 0) { if (hardmax) - u->SendMessage(MemoServ, MEMO_INFO_X_HARD_LIMIT, nname.c_str(), mi->memomax); + source.Reply(MEMO_INFO_X_HARD_LIMIT, nname.c_str(), mi->memomax); else - u->SendMessage(MemoServ, MEMO_INFO_X_LIMIT, nname.c_str(), mi->memomax); + source.Reply(MEMO_INFO_X_LIMIT, nname.c_str(), mi->memomax); } else - u->SendMessage(MemoServ, MEMO_INFO_X_NO_LIMIT, nname.c_str()); + source.Reply(MEMO_INFO_X_NO_LIMIT, nname.c_str()); /* I ripped this code out of ircservices 4.4.5, since I didn't want to rewrite the whole thing (it pisses me off). */ if (na) { if (na->nc->HasFlag(NI_MEMO_RECEIVE) && na->nc->HasFlag(NI_MEMO_SIGNON)) - u->SendMessage(MemoServ, MEMO_INFO_X_NOTIFY_ON, nname.c_str()); + source.Reply(MEMO_INFO_X_NOTIFY_ON, nname.c_str()); else if (na->nc->HasFlag(NI_MEMO_RECEIVE)) - u->SendMessage(MemoServ, MEMO_INFO_X_NOTIFY_RECEIVE, nname.c_str()); + source.Reply(MEMO_INFO_X_NOTIFY_RECEIVE, nname.c_str()); else if (na->nc->HasFlag(NI_MEMO_SIGNON)) - u->SendMessage(MemoServ, MEMO_INFO_X_NOTIFY_SIGNON, nname.c_str()); + source.Reply(MEMO_INFO_X_NOTIFY_SIGNON, nname.c_str()); else - u->SendMessage(MemoServ, MEMO_INFO_X_NOTIFY_OFF, nname.c_str()); + source.Reply(MEMO_INFO_X_NOTIFY_OFF, nname.c_str()); } } else /* !nname || (!ci || na->nc == u->Account()) */ { if (mi->memos.empty()) - u->SendMessage(MemoServ, MEMO_INFO_NO_MEMOS); + source.Reply(MEMO_INFO_NO_MEMOS); else if (mi->memos.size() == 1) { if (mi->memos[0]->HasFlag(MF_UNREAD)) - u->SendMessage(MemoServ, MEMO_INFO_MEMO_UNREAD); + source.Reply(MEMO_INFO_MEMO_UNREAD); else - u->SendMessage(MemoServ, MEMO_INFO_MEMO); + source.Reply(MEMO_INFO_MEMO); } else { @@ -145,41 +147,41 @@ class CommandMSInfo : public Command if (mi->memos[i]->HasFlag(MF_UNREAD)) ++count; if (count == mi->memos.size()) - u->SendMessage(MemoServ, MEMO_INFO_MEMOS_ALL_UNREAD, count); + source.Reply(MEMO_INFO_MEMOS_ALL_UNREAD, count); else if (!count) - u->SendMessage(MemoServ, MEMO_INFO_MEMOS, mi->memos.size()); + source.Reply(MEMO_INFO_MEMOS, mi->memos.size()); else if (count == 1) - u->SendMessage(MemoServ, MEMO_INFO_MEMOS_ONE_UNREAD, mi->memos.size()); + source.Reply(MEMO_INFO_MEMOS_ONE_UNREAD, mi->memos.size()); else - u->SendMessage(MemoServ, MEMO_INFO_MEMOS_SOME_UNREAD, mi->memos.size(), count); + source.Reply(MEMO_INFO_MEMOS_SOME_UNREAD, mi->memos.size(), count); } if (!mi->memomax) { if (!u->Account()->IsServicesOper() && hardmax) - u->SendMessage(MemoServ, MEMO_INFO_HARD_LIMIT_ZERO); + source.Reply(MEMO_INFO_HARD_LIMIT_ZERO); else - u->SendMessage(MemoServ, MEMO_INFO_LIMIT_ZERO); + source.Reply(MEMO_INFO_LIMIT_ZERO); } else if (mi->memomax > 0) { if (!u->Account()->IsServicesOper() && hardmax) - u->SendMessage(MemoServ, MEMO_INFO_HARD_LIMIT, mi->memomax); + source.Reply(MEMO_INFO_HARD_LIMIT, mi->memomax); else - u->SendMessage(MemoServ, MEMO_INFO_LIMIT, mi->memomax); + source.Reply(MEMO_INFO_LIMIT, mi->memomax); } else - u->SendMessage(MemoServ, MEMO_INFO_NO_LIMIT); + source.Reply(MEMO_INFO_NO_LIMIT); /* Ripped too. But differently because of a seg fault (loughs) */ if (u->Account()->HasFlag(NI_MEMO_RECEIVE) && u->Account()->HasFlag(NI_MEMO_SIGNON)) - u->SendMessage(MemoServ, MEMO_INFO_NOTIFY_ON); + source.Reply(MEMO_INFO_NOTIFY_ON); else if (u->Account()->HasFlag(NI_MEMO_RECEIVE)) - u->SendMessage(MemoServ, MEMO_INFO_NOTIFY_RECEIVE); + source.Reply(MEMO_INFO_NOTIFY_RECEIVE); else if (u->Account()->HasFlag(NI_MEMO_SIGNON)) - u->SendMessage(MemoServ, MEMO_INFO_NOTIFY_SIGNON); + source.Reply(MEMO_INFO_NOTIFY_SIGNON); else - u->SendMessage(MemoServ, MEMO_INFO_NOTIFY_OFF); + source.Reply(MEMO_INFO_NOTIFY_OFF); } return MOD_CONT; } diff --git a/modules/core/ms_list.cpp b/modules/core/ms_list.cpp index f71df75fb..3656fd94d 100644 --- a/modules/core/ms_list.cpp +++ b/modules/core/ms_list.cpp @@ -15,12 +15,12 @@ class MemoListCallback : public NumberList { - User *u; + CommandSource &source; ChannelInfo *ci; const MemoInfo *mi; bool SentHeader; public: - MemoListCallback(User *_u, ChannelInfo *_ci, const MemoInfo *_mi, const Anope::string &list) : NumberList(list, false), u(_u), ci(_ci), mi(_mi), SentHeader(false) + MemoListCallback(CommandSource &_source, ChannelInfo *_ci, const MemoInfo *_mi, const Anope::string &list) : NumberList(list, false), source(_source), ci(_ci), mi(_mi), SentHeader(false) { } @@ -33,20 +33,20 @@ class MemoListCallback : public NumberList { SentHeader = true; if (ci) - u->SendMessage(MemoServ, MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config->s_MemoServ.c_str(), ci->name.c_str()); + source.Reply(MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config->s_MemoServ.c_str(), ci->name.c_str()); else - u->SendMessage(MemoServ, MEMO_LIST_MEMOS, u->nick.c_str(), Config->s_MemoServ.c_str()); + source.Reply(MEMO_LIST_MEMOS, source.u->nick.c_str(), Config->s_MemoServ.c_str()); - u->SendMessage(MemoServ, MEMO_LIST_HEADER); + source.Reply(MEMO_LIST_HEADER); } - DoList(u, ci, mi, Number - 1); + DoList(source, mi, Number - 1); } - static void DoList(User *u, ChannelInfo *ci, const MemoInfo *mi, unsigned index) + static void DoList(CommandSource &source, const MemoInfo *mi, unsigned index) { Memo *m = mi->memos[index]; - u->SendMessage(MemoServ, MEMO_LIST_FORMAT, (m->HasFlag(MF_UNREAD)) ? '*' : ' ', index + 1, m->sender.c_str(), do_strftime(m->time).c_str()); + source.Reply(MEMO_LIST_FORMAT, (m->HasFlag(MF_UNREAD)) ? '*' : ' ', index + 1, m->sender.c_str(), do_strftime(m->time).c_str()); } }; @@ -57,8 +57,10 @@ class CommandMSList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + Anope::string param = !params.empty() ? params[0] : "", chan; ChannelInfo *ci = NULL; const MemoInfo *mi; @@ -71,12 +73,12 @@ class CommandMSList : public Command if (!(ci = cs_findchan(chan))) { - u->SendMessage(MemoServ, CHAN_X_NOT_REGISTERED, chan.c_str()); + source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); return MOD_CONT; } else if (!check_access(u, ci, CA_MEMO)) { - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } mi = &ci->memos; @@ -88,15 +90,15 @@ class CommandMSList : public Command else if (!mi->memos.size()) { if (!chan.empty()) - u->SendMessage(MemoServ, MEMO_X_HAS_NO_MEMOS, chan.c_str()); + source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str()); else - u->SendMessage(MemoServ, MEMO_HAVE_NO_MEMOS); + source.Reply(MEMO_HAVE_NO_MEMOS); } else { if (!param.empty() && isdigit(param[0])) { - MemoListCallback list(u, ci, mi, param); + MemoListCallback list(source, ci, mi, param); list.Process(); } else @@ -109,9 +111,9 @@ class CommandMSList : public Command if (i == end) { if (!chan.empty()) - u->SendMessage(MemoServ, MEMO_X_HAS_NO_NEW_MEMOS, chan.c_str()); + source.Reply(MEMO_X_HAS_NO_NEW_MEMOS, chan.c_str()); else - u->SendMessage(MemoServ, MEMO_HAVE_NO_NEW_MEMOS); + source.Reply(MEMO_HAVE_NO_NEW_MEMOS); return MOD_CONT; } } @@ -127,13 +129,13 @@ class CommandMSList : public Command { SentHeader = true; if (ci) - u->SendMessage(MemoServ, !param.empty() ? MEMO_LIST_CHAN_NEW_MEMOS : MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config->s_MemoServ.c_str(), ci->name.c_str()); + source.Reply(!param.empty() ? MEMO_LIST_CHAN_NEW_MEMOS : MEMO_LIST_CHAN_MEMOS, ci->name.c_str(), Config->s_MemoServ.c_str(), ci->name.c_str()); else - u->SendMessage(MemoServ, !param.empty() ? MEMO_LIST_NEW_MEMOS : MEMO_LIST_MEMOS, u->nick.c_str(), Config->s_MemoServ.c_str()); - u->SendMessage(MemoServ, MEMO_LIST_HEADER); + source.Reply(!param.empty() ? MEMO_LIST_NEW_MEMOS : MEMO_LIST_MEMOS, u->nick.c_str(), Config->s_MemoServ.c_str()); + source.Reply(MEMO_LIST_HEADER); } - MemoListCallback::DoList(u, ci, mi, i); + MemoListCallback::DoList(source, mi, i); } } } diff --git a/modules/core/ms_read.cpp b/modules/core/ms_read.cpp index 2f743cb30..785755fec 100644 --- a/modules/core/ms_read.cpp +++ b/modules/core/ms_read.cpp @@ -15,10 +15,10 @@ class MemoListCallback : public NumberList { - User *u; + CommandSource &source; MemoInfo *mi; public: - MemoListCallback(User *_u, MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), u(_u), mi(_mi) + MemoListCallback(CommandSource &_source, MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), source(_source), mi(_mi) { } @@ -27,11 +27,12 @@ class MemoListCallback : public NumberList if (!Number || Number > mi->memos.size()) return; - MemoListCallback::DoRead(u, mi, NULL, Number - 1); + MemoListCallback::DoRead(source, mi, NULL, Number - 1); } - static void DoRead(User *u, MemoInfo *mi, ChannelInfo *ci, unsigned index) + static void DoRead(CommandSource &source, MemoInfo *mi, ChannelInfo *ci, unsigned index) { + User *u = source.u; Memo *m = mi->memos[index]; if (ci) u->SendMessage(MemoServ, MEMO_CHAN_HEADER, index + 1, m->sender.c_str(), do_strftime(m->time).c_str(), Config->s_MemoServ.c_str(), ci->name.c_str(), index + 1); @@ -53,8 +54,10 @@ class CommandMSRead : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + MemoInfo *mi; ChannelInfo *ci = NULL; Anope::string numstr = !params.empty() ? params[0] : "", chan; @@ -67,12 +70,12 @@ class CommandMSRead : public Command if (!(ci = cs_findchan(chan))) { - u->SendMessage(MemoServ, CHAN_X_NOT_REGISTERED, chan.c_str()); + source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); return MOD_CONT; } else if (!check_access(u, ci, CA_MEMO)) { - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } mi = &ci->memos; @@ -85,9 +88,9 @@ class CommandMSRead : public Command else if (mi->memos.empty()) { if (!chan.empty()) - u->SendMessage(MemoServ, MEMO_X_HAS_NO_MEMOS, chan.c_str()); + source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str()); else - u->SendMessage(MemoServ, MEMO_HAVE_NO_MEMOS); + source.Reply(MEMO_HAVE_NO_MEMOS); } else { int i, end; @@ -98,25 +101,25 @@ class CommandMSRead : public Command for (i = 0, end = mi->memos.size(); i < end; ++i) if (mi->memos[i]->HasFlag(MF_UNREAD)) { - MemoListCallback::DoRead(u, mi, ci, i); + MemoListCallback::DoRead(source, mi, ci, i); ++readcount; } if (!readcount) { if (!chan.empty()) - u->SendMessage(MemoServ, MEMO_X_HAS_NO_NEW_MEMOS, chan.c_str()); + source.Reply(MEMO_X_HAS_NO_NEW_MEMOS, chan.c_str()); else - u->SendMessage(MemoServ, MEMO_HAVE_NO_NEW_MEMOS); + source.Reply(MEMO_HAVE_NO_NEW_MEMOS); } } else if (numstr.equals_ci("LAST")) { for (i = 0, end = mi->memos.size() - 1; i < end; ++i); - MemoListCallback::DoRead(u, mi, ci, i); + MemoListCallback::DoRead(source, mi, ci, i); } else /* number[s] */ { - MemoListCallback list(u, mi, numstr); + MemoListCallback list(source, mi, numstr); list.Process(); } } diff --git a/modules/core/ms_rsend.cpp b/modules/core/ms_rsend.cpp index 01b46fbe7..ea1351db5 100644 --- a/modules/core/ms_rsend.cpp +++ b/modules/core/ms_rsend.cpp @@ -20,16 +20,18 @@ class CommandMSRSend : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - Anope::string text = params[1]; + User *u = source.u; + + const Anope::string &nick = params[0]; + const Anope::string &text = params[1]; NickAlias *na = NULL; /* prevent user from rsend to themselves */ if ((na = findnick(nick)) && na->nc == u->Account()) { - u->SendMessage(MemoServ, MEMO_NO_RSEND_SELF); + source.Reply(MEMO_NO_RSEND_SELF); return MOD_CONT; } @@ -39,7 +41,7 @@ class CommandMSRSend : public Command if (u->Account()->IsServicesOper()) memo_send(u, nick, text, 3); else - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); } else if (Config->MSMemoReceipt == 2) /* Everybody can use rsend */ @@ -48,7 +50,7 @@ class CommandMSRSend : public Command { /* rsend has been disabled */ Log() << "MSMemoReceipt is set misconfigured to " << Config->MSMemoReceipt; - u->SendMessage(MemoServ, MEMO_RSEND_DISABLED); + source.Reply(MEMO_RSEND_DISABLED); } return MOD_CONT; diff --git a/modules/core/ms_send.cpp b/modules/core/ms_send.cpp index 9cc361f4e..ad1072d95 100644 --- a/modules/core/ms_send.cpp +++ b/modules/core/ms_send.cpp @@ -20,10 +20,11 @@ class CommandMSSend : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - Anope::string text = params[1]; + User *u = source.u; + const Anope::string &nick = params[0]; + const Anope::string &text = params[1]; memo_send(u, nick, text, 0); return MOD_CONT; } diff --git a/modules/core/ms_sendall.cpp b/modules/core/ms_sendall.cpp index 33730f590..7285154ea 100644 --- a/modules/core/ms_sendall.cpp +++ b/modules/core/ms_sendall.cpp @@ -20,13 +20,14 @@ class CommandMSSendAll : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string text = params[0]; + User *u = source.u; + const Anope::string &text = params[0]; if (readonly) { - u->SendMessage(MemoServ, MEMO_SEND_DISABLED); + source.Reply(MEMO_SEND_DISABLED); return MOD_CONT; } diff --git a/modules/core/ms_set.cpp b/modules/core/ms_set.cpp index 302cf120b..d17956a59 100644 --- a/modules/core/ms_set.cpp +++ b/modules/core/ms_set.cpp @@ -16,57 +16,61 @@ class CommandMSSet : public Command { private: - CommandReturn DoNotify(User *u, const std::vector<Anope::string> ¶ms, MemoInfo *mi) + CommandReturn DoNotify(CommandSource &source, const std::vector<Anope::string> ¶ms, MemoInfo *mi) { - Anope::string param = params[1]; + User *u = source.u; + const Anope::string ¶m = params[1]; if (param.equals_ci("ON")) { u->Account()->SetFlag(NI_MEMO_SIGNON); u->Account()->SetFlag(NI_MEMO_RECEIVE); - u->SendMessage(MemoServ, MEMO_SET_NOTIFY_ON, Config->s_MemoServ.c_str()); + source.Reply(MEMO_SET_NOTIFY_ON, Config->s_MemoServ.c_str()); } else if (param.equals_ci("LOGON")) { u->Account()->SetFlag(NI_MEMO_SIGNON); u->Account()->UnsetFlag(NI_MEMO_RECEIVE); - u->SendMessage(MemoServ, MEMO_SET_NOTIFY_LOGON, Config->s_MemoServ.c_str()); + source.Reply(MEMO_SET_NOTIFY_LOGON, Config->s_MemoServ.c_str()); } else if (param.equals_ci("NEW")) { u->Account()->UnsetFlag(NI_MEMO_SIGNON); u->Account()->SetFlag(NI_MEMO_RECEIVE); - u->SendMessage(MemoServ, MEMO_SET_NOTIFY_NEW, Config->s_MemoServ.c_str()); + source.Reply(MEMO_SET_NOTIFY_NEW, Config->s_MemoServ.c_str()); } else if (param.equals_ci("MAIL")) { if (!u->Account()->email.empty()) { u->Account()->SetFlag(NI_MEMO_MAIL); - u->SendMessage(MemoServ, MEMO_SET_NOTIFY_MAIL); + source.Reply(MEMO_SET_NOTIFY_MAIL); } else - u->SendMessage(MemoServ, MEMO_SET_NOTIFY_INVALIDMAIL); + source.Reply(MEMO_SET_NOTIFY_INVALIDMAIL); } else if (param.equals_ci("NOMAIL")) { u->Account()->UnsetFlag(NI_MEMO_MAIL); - u->SendMessage(MemoServ, MEMO_SET_NOTIFY_NOMAIL); + source.Reply(MEMO_SET_NOTIFY_NOMAIL); } else if (param.equals_ci("OFF")) { u->Account()->UnsetFlag(NI_MEMO_SIGNON); u->Account()->UnsetFlag(NI_MEMO_RECEIVE); u->Account()->UnsetFlag(NI_MEMO_MAIL); - u->SendMessage(MemoServ, MEMO_SET_NOTIFY_OFF, Config->s_MemoServ.c_str()); + source.Reply(MEMO_SET_NOTIFY_OFF, Config->s_MemoServ.c_str()); } else SyntaxError(MemoServ, u, "SET NOTIFY", MEMO_SET_NOTIFY_SYNTAX); + return MOD_CONT; } - CommandReturn DoLimit(User *u, const std::vector<Anope::string> ¶ms, MemoInfo *mi) + CommandReturn DoLimit(CommandSource &source, const std::vector<Anope::string> ¶ms, MemoInfo *mi) { + User *u = source.u; + Anope::string p1 = params[1]; Anope::string p2 = params.size() > 2 ? params[2] : ""; Anope::string p3 = params.size() > 3 ? params[3] : ""; @@ -84,12 +88,12 @@ class CommandMSSet : public Command p3 = params.size() > 4 ? params[4] : ""; if (!(ci = cs_findchan(chan))) { - u->SendMessage(MemoServ, CHAN_X_NOT_REGISTERED, chan.c_str()); + source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); return MOD_CONT; } else if (!is_servadmin && !check_access(u, ci, CA_MEMO)) { - u->SendMessage(MemoServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } mi = &ci->memos; @@ -101,7 +105,7 @@ class CommandMSSet : public Command NickAlias *na; if (!(na = findnick(p1))) { - u->SendMessage(MemoServ, NICK_X_NOT_REGISTERED, p1.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, p1.c_str()); return MOD_CONT; } user = p1; @@ -137,7 +141,7 @@ class CommandMSSet : public Command limit = p1.is_pos_number_only() ? convertTo<int32>(p1) : -1; if (limit < 0 || limit > 32767) { - u->SendMessage(MemoServ, MEMO_SET_LIMIT_OVERFLOW, 32767); + source.Reply(MEMO_SET_LIMIT_OVERFLOW, 32767); limit = 32767; } if (p1.equals_ci("NONE")) @@ -152,12 +156,12 @@ class CommandMSSet : public Command } if (!chan.empty() && ci->HasFlag(CI_MEMO_HARDMAX)) { - u->SendMessage(MemoServ, MEMO_SET_LIMIT_FORBIDDEN, chan.c_str()); + source.Reply(MEMO_SET_LIMIT_FORBIDDEN, chan.c_str()); return MOD_CONT; } else if (chan.empty() && nc->HasFlag(NI_MEMO_HARDMAX)) { - u->SendMessage(MemoServ, MEMO_SET_YOUR_LIMIT_FORBIDDEN); + source.Reply(MEMO_SET_YOUR_LIMIT_FORBIDDEN); return MOD_CONT; } limit = p1.is_pos_number_only() ? convertTo<int32>(p1) : -1; @@ -166,14 +170,14 @@ class CommandMSSet : public Command if (limit < 0 || (Config->MSMaxMemos > 0 && static_cast<unsigned>(limit) > Config->MSMaxMemos)) { if (!chan.empty()) - u->SendMessage(MemoServ, MEMO_SET_LIMIT_TOO_HIGH, chan.c_str(), Config->MSMaxMemos); + source.Reply(MEMO_SET_LIMIT_TOO_HIGH, chan.c_str(), Config->MSMaxMemos); else - u->SendMessage(MemoServ, MEMO_SET_YOUR_LIMIT_TOO_HIGH, Config->MSMaxMemos); + source.Reply(MEMO_SET_YOUR_LIMIT_TOO_HIGH, Config->MSMaxMemos); return MOD_CONT; } else if (limit > 32767) { - u->SendMessage(MemoServ, MEMO_SET_LIMIT_OVERFLOW, 32767); + source.Reply(MEMO_SET_LIMIT_OVERFLOW, 32767); limit = 32767; } } @@ -181,23 +185,23 @@ class CommandMSSet : public Command if (limit > 0) { if (chan.empty() && nc == u->Account()) - u->SendMessage(MemoServ, MEMO_SET_YOUR_LIMIT, limit); + source.Reply(MEMO_SET_YOUR_LIMIT, limit); else - u->SendMessage(MemoServ, MEMO_SET_LIMIT, !chan.empty() ? chan.c_str() : user.c_str(), limit); + source.Reply(MEMO_SET_LIMIT, !chan.empty() ? chan.c_str() : user.c_str(), limit); } else if (!limit) { if (chan.empty() && nc == u->Account()) - u->SendMessage(MemoServ, MEMO_SET_YOUR_LIMIT_ZERO); + source.Reply(MEMO_SET_YOUR_LIMIT_ZERO); else - u->SendMessage(MemoServ, MEMO_SET_LIMIT_ZERO, !chan.empty() ? chan.c_str() : user.c_str()); + source.Reply(MEMO_SET_LIMIT_ZERO, !chan.empty() ? chan.c_str() : user.c_str()); } else { if (chan.empty() && nc == u->Account()) - u->SendMessage(MemoServ, MEMO_UNSET_YOUR_LIMIT); + source.Reply(MEMO_UNSET_YOUR_LIMIT); else - u->SendMessage(MemoServ, MEMO_UNSET_LIMIT, !chan.empty() ? chan.c_str() : user.c_str()); + source.Reply(MEMO_UNSET_LIMIT, !chan.empty() ? chan.c_str() : user.c_str()); } return MOD_CONT; } @@ -206,25 +210,24 @@ class CommandMSSet : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; MemoInfo *mi = &u->Account()->memos; if (readonly) - { - u->SendMessage(MemoServ, MEMO_SET_DISABLED); - return MOD_CONT; - } + source.Reply(MEMO_SET_DISABLED); else if (cmd.equals_ci("NOTIFY")) - return this->DoNotify(u, params, mi); + return this->DoNotify(source, params, mi); else if (cmd.equals_ci("LIMIT")) - return this->DoLimit(u, params, mi); + return this->DoLimit(source, params, mi); else { - u->SendMessage(MemoServ, NICK_SET_UNKNOWN_OPTION, cmd.c_str()); - u->SendMessage(MemoServ, MORE_INFO, Config->s_MemoServ.c_str(), "SET"); + source.Reply(NICK_SET_UNKNOWN_OPTION, cmd.c_str()); + source.Reply(MORE_INFO, Config->s_MemoServ.c_str(), "SET"); } + return MOD_CONT; } diff --git a/modules/core/ms_staff.cpp b/modules/core/ms_staff.cpp index 7acebfe2e..e64f53ff2 100644 --- a/modules/core/ms_staff.cpp +++ b/modules/core/ms_staff.cpp @@ -20,13 +20,14 @@ class CommandMSStaff : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string text = params[0]; + User *u = source.u; + const Anope::string &text = params[0]; if (readonly) { - u->SendMessage(MemoServ, MEMO_SEND_DISABLED); + source.Reply(MEMO_SEND_DISABLED); return MOD_CONT; } diff --git a/modules/core/ns_access.cpp b/modules/core/ns_access.cpp index 946a1fa8f..62f544f64 100644 --- a/modules/core/ns_access.cpp +++ b/modules/core/ns_access.cpp @@ -16,37 +16,39 @@ class CommandNSAccess : public Command { private: - CommandReturn DoServAdminList(User *u, const std::vector<Anope::string> ¶ms, NickCore *nc) + CommandReturn DoServAdminList(CommandSource &source, const std::vector<Anope::string> ¶ms, NickCore *nc) { Anope::string mask = params.size() > 2 ? params[2] : ""; unsigned i, end; if (nc->access.empty()) { - u->SendMessage(NickServ, NICK_ACCESS_LIST_X_EMPTY, nc->display.c_str()); + source.Reply(NICK_ACCESS_LIST_X_EMPTY, nc->display.c_str()); return MOD_CONT; } if (nc->HasFlag(NI_SUSPENDED)) { - u->SendMessage(NickServ, NICK_X_SUSPENDED, nc->display.c_str()); + source.Reply(NICK_X_SUSPENDED, nc->display.c_str()); return MOD_CONT; } - u->SendMessage(NickServ, NICK_ACCESS_LIST_X, params[1].c_str()); + source.Reply(NICK_ACCESS_LIST_X, params[1].c_str()); for (i = 0, end = nc->access.size(); i < end; ++i) { Anope::string access = nc->GetAccess(i); if (!mask.empty() && !Anope::Match(access, mask)) continue; - u->SendMessage(Config->s_NickServ, " %s", access.c_str()); + source.Reply(" %s", access.c_str()); } return MOD_CONT; } - CommandReturn DoAdd(User *u, NickCore *nc, const Anope::string &mask) + CommandReturn DoAdd(CommandSource &source, NickCore *nc, const Anope::string &mask) { + User *u = source.u; + if (mask.empty()) { this->OnSyntaxError(u, "ADD"); @@ -55,24 +57,26 @@ class CommandNSAccess : public Command if (nc->access.size() >= Config->NSAccessMax) { - u->SendMessage(NickServ, NICK_ACCESS_REACHED_LIMIT, Config->NSAccessMax); + source.Reply(NICK_ACCESS_REACHED_LIMIT, Config->NSAccessMax); return MOD_CONT; } if (nc->FindAccess(mask)) { - u->SendMessage(NickServ, NICK_ACCESS_ALREADY_PRESENT, mask.c_str()); + source.Reply(NICK_ACCESS_ALREADY_PRESENT, mask.c_str()); return MOD_CONT; } nc->AddAccess(mask); - u->SendMessage(NickServ, NICK_ACCESS_ADDED, mask.c_str()); + source.Reply(NICK_ACCESS_ADDED, mask.c_str()); return MOD_CONT; } - CommandReturn DoDel(User *u, NickCore *nc, const Anope::string &mask) + CommandReturn DoDel(CommandSource &source, NickCore *nc, const Anope::string &mask) { + User *u = source.u; + if (mask.empty()) { this->OnSyntaxError(u, "DEL"); @@ -81,33 +85,34 @@ class CommandNSAccess : public Command if (!nc->FindAccess(mask)) { - u->SendMessage(NickServ, NICK_ACCESS_NOT_FOUND, mask.c_str()); + source.Reply(NICK_ACCESS_NOT_FOUND, mask.c_str()); return MOD_CONT; } - u->SendMessage(NickServ, NICK_ACCESS_DELETED, mask.c_str()); + source.Reply(NICK_ACCESS_DELETED, mask.c_str()); nc->EraseAccess(mask); return MOD_CONT; } - CommandReturn DoList(User *u, NickCore *nc, const Anope::string &mask) + CommandReturn DoList(CommandSource &source, NickCore *nc, const Anope::string &mask) { + User *u = source.u; unsigned i, end; if (nc->access.empty()) { - u->SendMessage(NickServ, NICK_ACCESS_LIST_EMPTY, u->nick.c_str()); + source.Reply(NICK_ACCESS_LIST_EMPTY, u->nick.c_str()); return MOD_CONT; } - u->SendMessage(NickServ, NICK_ACCESS_LIST); + source.Reply(NICK_ACCESS_LIST); for (i = 0, end = nc->access.size(); i < end; ++i) { Anope::string access = nc->GetAccess(i); if (!mask.empty() && !Anope::Match(access, mask)) continue; - u->SendMessage(Config->s_NickServ, " %s", access.c_str()); + source.Reply(" %s", access.c_str()); } return MOD_CONT; @@ -117,34 +122,32 @@ class CommandNSAccess : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; - Anope::string mask = params.size() > 1 ? params[1] : ""; - NickAlias *na; + User *u = source.u; + const Anope::string &cmd = params[0]; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; + NickAlias *na; if (cmd.equals_ci("LIST") && u->Account()->IsServicesOper() && !mask.empty() && (na = findnick(params[1]))) - return this->DoServAdminList(u, params, na->nc); + return this->DoServAdminList(source, params, na->nc); if (!mask.empty() && mask.find('@') == Anope::string::npos) { - u->SendMessage(NickServ, BAD_USERHOST_MASK); - u->SendMessage(NickServ, MORE_INFO, Config->s_NickServ.c_str(), "ACCESS"); + source.Reply(BAD_USERHOST_MASK); + source.Reply(MORE_INFO, Config->s_NickServ.c_str(), "ACCESS"); } - /* - else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick); - */ else if (u->Account()->HasFlag(NI_SUSPENDED)) - u->SendMessage(NickServ, NICK_X_SUSPENDED, u->Account()->display.c_str()); + source.Reply(NICK_X_SUSPENDED, u->Account()->display.c_str()); else if (cmd.equals_ci("ADD")) - return this->DoAdd(u, u->Account(), mask); + return this->DoAdd(source, u->Account(), mask); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, u->Account(), mask); + return this->DoDel(source, u->Account(), mask); else if (cmd.equals_ci("LIST")) - return this->DoList(u, u->Account(), mask); + return this->DoList(source, u->Account(), mask); else this->OnSyntaxError(u, ""); + return MOD_CONT; } diff --git a/modules/core/ns_alist.cpp b/modules/core/ns_alist.cpp index 16a30726d..4a51b287a 100644 --- a/modules/core/ns_alist.cpp +++ b/modules/core/ns_alist.cpp @@ -20,7 +20,7 @@ class CommandNSAList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { /* * List the channels that the given nickname has access on @@ -31,8 +31,8 @@ class CommandNSAList : public Command * -jester */ + User *u = source.u; Anope::string nick; - NickAlias *na; int min_level = 0; @@ -77,18 +77,18 @@ class CommandNSAList : public Command } if (!na) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else if (min_level <= ACCESS_INVALID || min_level > ACCESS_FOUNDER) - u->SendMessage(NickServ, CHAN_ACCESS_LEVEL_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); + source.Reply(CHAN_ACCESS_LEVEL_RANGE, ACCESS_INVALID + 1, ACCESS_FOUNDER - 1); else { int level; int chan_count = 0; int match_count = 0; - u->SendMessage(NickServ, is_servadmin ? NICK_ALIST_HEADER_X : NICK_ALIST_HEADER, na->nick.c_str()); + source.Reply(is_servadmin ? NICK_ALIST_HEADER_X : NICK_ALIST_HEADER, na->nick.c_str()); for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { @@ -107,14 +107,14 @@ class CommandNSAList : public Command { Anope::string xop = get_xop_level(level); - u->SendMessage(NickServ, NICK_ALIST_XOP_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), xop.c_str(), !ci->desc.empty() ? ci->desc.c_str() : ""); + source.Reply(NICK_ALIST_XOP_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), xop.c_str(), !ci->desc.empty() ? ci->desc.c_str() : ""); } else - u->SendMessage(NickServ, NICK_ALIST_ACCESS_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), level, !ci->desc.empty() ? ci->desc.c_str() : ""); + source.Reply(NICK_ALIST_ACCESS_FORMAT, match_count, ci->HasFlag(CI_NO_EXPIRE) ? '!' : ' ', ci->name.c_str(), level, !ci->desc.empty() ? ci->desc.c_str() : ""); } } - u->SendMessage(NickServ, NICK_ALIST_FOOTER, match_count, chan_count); + source.Reply(NICK_ALIST_FOOTER, match_count, chan_count); } return MOD_CONT; } diff --git a/modules/core/ns_drop.cpp b/modules/core/ns_drop.cpp index a3e292df1..b2dba8944 100644 --- a/modules/core/ns_drop.cpp +++ b/modules/core/ns_drop.cpp @@ -21,13 +21,14 @@ class CommandNSDrop : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; Anope::string nick = !params.empty() ? params[0] : ""; if (readonly) { - u->SendMessage(NickServ, NICK_DROP_DISABLED); + source.Reply(NICK_DROP_DISABLED); return MOD_CONT; } @@ -42,7 +43,7 @@ class CommandNSDrop : public Command Log(LOG_ADMIN, u, this) << "to drop nickname " << nr->nick << " (email: " << nr->email << ")"; delete nr; - u->SendMessage(NickServ, NICK_X_DROPPED, nick.c_str()); + source.Reply(NICK_X_DROPPED, nick.c_str()); } else if (nr && !nick.empty()) { @@ -50,23 +51,23 @@ class CommandNSDrop : public Command if (res) { Log(LOG_COMMAND, u, this) << "to drop nick request " << nr->nick; - u->SendMessage(NickServ, NICK_X_DROPPED, nr->nick.c_str()); + source.Reply(NICK_X_DROPPED, nr->nick.c_str()); delete nr; } else if (bad_password(u)) return MOD_STOP; else - u->SendMessage(NickServ, PASSWORD_INCORRECT); + source.Reply(PASSWORD_INCORRECT); } else - u->SendMessage(NickServ, NICK_NOT_REGISTERED); + source.Reply(NICK_NOT_REGISTERED); return MOD_CONT; } if (!u->Account()) { - u->SendMessage(NickServ, NICK_IDENTIFY_REQUIRED, Config->s_NickServ.c_str()); + source.Reply(NICK_IDENTIFY_REQUIRED, Config->s_NickServ.c_str()); return MOD_CONT; } @@ -76,13 +77,13 @@ class CommandNSDrop : public Command my_nick = na->nick; if (!is_mine && !u->Account()->HasPriv("nickserv/drop")) - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (Config->NSSecureAdmins && !is_mine && na->nc->IsServicesOper()) - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { if (readonly) - u->SendMessage(NickServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); if (ircd->sqline && na->HasFlag(NS_FORBIDDEN)) { @@ -99,14 +100,14 @@ class CommandNSDrop : public Command { if (Config->WallDrop) ircdproto->SendGlobops(NickServ, "\2%s\2 used DROP on \2%s\2", u->nick.c_str(), nick.c_str()); - u->SendMessage(NickServ, NICK_X_DROPPED, nick.c_str()); + source.Reply(NICK_X_DROPPED, nick.c_str()); } else { if (!nick.empty()) - u->SendMessage(NickServ, NICK_X_DROPPED, nick.c_str()); + source.Reply(NICK_X_DROPPED, nick.c_str()); else - u->SendMessage(NickServ, NICK_DROPPED); + source.Reply(NICK_DROPPED); } } diff --git a/modules/core/ns_forbid.cpp b/modules/core/ns_forbid.cpp index ab401b1a8..12871bda6 100644 --- a/modules/core/ns_forbid.cpp +++ b/modules/core/ns_forbid.cpp @@ -20,11 +20,11 @@ class CommandNSForbid : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - NickAlias *na; - Anope::string nick = params[0]; - Anope::string reason = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &nick = params[0]; + const Anope::string &reason = params.size() > 1 ? params[1] : ""; /* Assumes that permission checking has already been done. */ if (Config->ForceForbidReason && reason.empty()) @@ -34,17 +34,19 @@ class CommandNSForbid : public Command } if (readonly) - u->SendMessage(NickServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); if (!ircdproto->IsNickValid(nick)) { - u->SendMessage(NickServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); return MOD_CONT; } - if ((na = findnick(nick))) + + NickAlias *na = findnick(nick); + if (na) { if (Config->NSSecureAdmins && na->nc->IsServicesOper()) { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } delete na; diff --git a/modules/core/ns_getemail.cpp b/modules/core/ns_getemail.cpp index 14626ea97..ea61ac6ac 100644 --- a/modules/core/ns_getemail.cpp +++ b/modules/core/ns_getemail.cpp @@ -24,9 +24,10 @@ class CommandNSGetEMail : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string email = params[0]; + User *u = source.u; + const Anope::string &email = params[0]; int j = 0; Log(LOG_ADMIN, u, this) << "on " << email; @@ -38,13 +39,13 @@ class CommandNSGetEMail : public Command if (!nc->email.empty() && nc->email.equals_ci(email)) { ++j; - u->SendMessage(NickServ, NICK_GETEMAIL_EMAILS_ARE, nc->display.c_str(), email.c_str()); + source.Reply(NICK_GETEMAIL_EMAILS_ARE, nc->display.c_str(), email.c_str()); } } if (j <= 0) { - u->SendMessage(NickServ, NICK_GETEMAIL_NOT_USED, email.c_str()); + source.Reply(NICK_GETEMAIL_NOT_USED, email.c_str()); return MOD_CONT; } diff --git a/modules/core/ns_getpass.cpp b/modules/core/ns_getpass.cpp index 4bfd9fe91..8282dd7d3 100644 --- a/modules/core/ns_getpass.cpp +++ b/modules/core/ns_getpass.cpp @@ -20,9 +20,10 @@ class CommandNSGetPass : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + User *u = source.u; + const Anope::string &nick = params[0]; Anope::string tmp_pass; NickAlias *na; NickRequest *nr = NULL; @@ -34,15 +35,15 @@ class CommandNSGetPass : public Command Log(LOG_ADMIN, u, this) << "for " << nr->nick; if (Config->WallGetpass) ircdproto->SendGlobops(NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick.c_str(), nick.c_str()); - u->SendMessage(NickServ, NICK_GETPASS_PASSCODE_IS, nick.c_str(), nr->passcode.c_str()); + source.Reply(NICK_GETPASS_PASSCODE_IS, nick.c_str(), nr->passcode.c_str()); } else - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); } else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else if (Config->NSSecureAdmins && na->nc->IsServicesOper()) - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else { if (enc_decrypt(na->nc->pass, tmp_pass) == 1) @@ -50,10 +51,10 @@ class CommandNSGetPass : public Command Log(LOG_ADMIN, u, this) << "for " << nick; if (Config->WallGetpass) ircdproto->SendGlobops(NickServ, "\2%s\2 used GETPASS on \2%s\2", u->nick.c_str(), nick.c_str()); - u->SendMessage(NickServ, NICK_GETPASS_PASSWORD_IS, nick.c_str(), tmp_pass.c_str()); + source.Reply(NICK_GETPASS_PASSWORD_IS, nick.c_str(), tmp_pass.c_str()); } else - u->SendMessage(NickServ, NICK_GETPASS_UNAVAILABLE); + source.Reply(NICK_GETPASS_UNAVAILABLE); } return MOD_CONT; } diff --git a/modules/core/ns_ghost.cpp b/modules/core/ns_ghost.cpp index a350a5b1d..8009c85f4 100644 --- a/modules/core/ns_ghost.cpp +++ b/modules/core/ns_ghost.cpp @@ -21,39 +21,41 @@ class CommandNSGhost : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + const Anope::string &nick = params[0]; Anope::string pass = params.size() > 1 ? params[1] : ""; + + User *u = source.u; User *user = finduser(nick); NickAlias *na = findnick(nick); if (!user) - u->SendMessage(NickServ, NICK_X_NOT_IN_USE, nick.c_str()); + source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); else if (!na) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - u->SendMessage(NickServ, NICK_X_SUSPENDED, na->nick.c_str()); + source.Reply(NICK_X_SUSPENDED, na->nick.c_str()); else if (nick.equals_ci(u->nick)) - u->SendMessage(NickServ, NICK_NO_GHOST_SELF); + source.Reply(NICK_NO_GHOST_SELF); else if ((u->Account() == na->nc || (!na->nc->HasFlag(NI_SECURE) && is_on_access(u, na->nc))) || (!pass.empty() && enc_check_password(pass, na->nc->pass) == 1)) { if (!user->IsIdentified() && FindCommand(NickServ, "RECOVER")) - u->SendMessage(NickServ, NICK_GHOST_UNIDENTIFIED); + source.Reply(NICK_GHOST_UNIDENTIFIED); else { Log(LOG_COMMAND, u, this) << "for " << nick; Anope::string buf = "GHOST command used by " + u->nick; kill_user(Config->s_NickServ, nick, buf); - u->SendMessage(NickServ, NICK_GHOST_KILLED, nick.c_str()); + source.Reply(NICK_GHOST_KILLED, nick.c_str()); } } else { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); if (!pass.empty()) { Log(LOG_COMMAND, u, this) << "with an invalid password for " << nick; diff --git a/modules/core/ns_group.cpp b/modules/core/ns_group.cpp index 59d7ac8e7..cd945167b 100644 --- a/modules/core/ns_group.cpp +++ b/modules/core/ns_group.cpp @@ -21,71 +21,71 @@ class CommandNSGroup : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - NickAlias *na, *target; - Anope::string nick = params[0]; + User *u = source.u; + + const Anope::string &nick = params[0]; Anope::string pass = params[1]; - std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end; if (Config->NSEmailReg && findrequestnick(u->nick)) { - u->SendMessage(NickServ, NICK_REQUESTED); + source.Reply(NICK_REQUESTED); return MOD_CONT; } if (readonly) { - u->SendMessage(NickServ, NICK_GROUP_DISABLED); + source.Reply(NICK_GROUP_DISABLED); return MOD_CONT; } if (!ircdproto->IsNickValid(u->nick)) { - u->SendMessage(NickServ, NICK_X_FORBIDDEN, u->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, u->nick.c_str()); return MOD_CONT; } if (Config->RestrictOperNicks) - for (it = Config->Opers.begin(), it_end = Config->Opers.end(); it != it_end; ++it) + for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = Config->Opers.begin(), it_end = Config->Opers.end(); it != it_end; ++it) if (!is_oper(u) && u->nick.find_ci(it->first) != Anope::string::npos) { - u->SendMessage(NickServ, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); + source.Reply(NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); return MOD_CONT; } - na = findnick(u->nick); + NickAlias *target, *na = findnick(u->nick); if (!(target = findnick(nick))) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (Anope::CurTime < u->lastnickreg + Config->NSRegDelay) - u->SendMessage(NickServ, NICK_GROUP_PLEASE_WAIT, (Config->NSRegDelay + u->lastnickreg) - Anope::CurTime); + source.Reply(NICK_GROUP_PLEASE_WAIT, (Config->NSRegDelay + u->lastnickreg) - Anope::CurTime); else if (u->Account() && u->Account()->HasFlag(NI_SUSPENDED)) { Log(NickServ) << NickServ << u->GetMask() << " tried to use GROUP from SUSPENDED nick " << target->nick; - u->SendMessage(NickServ, NICK_X_SUSPENDED, u->nick.c_str()); + source.Reply(NICK_X_SUSPENDED, u->nick.c_str()); } else if (target && target->nc->HasFlag(NI_SUSPENDED)) { Log(LOG_COMMAND, u, this) << "tried to use GROUP for SUSPENDED nick " << target->nick; - u->SendMessage(NickServ, NICK_X_SUSPENDED, target->nick.c_str()); + source.Reply(NICK_X_SUSPENDED, target->nick.c_str()); } else if (target->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); else if (na && target->nc == na->nc) - u->SendMessage(NickServ, NICK_GROUP_SAME, target->nick.c_str()); + source.Reply(NICK_GROUP_SAME, target->nick.c_str()); else if (na && na->nc != u->Account()) - u->SendMessage(NickServ, NICK_IDENTIFY_REQUIRED, Config->s_NickServ.c_str()); + source.Reply(NICK_IDENTIFY_REQUIRED, Config->s_NickServ.c_str()); else if (na && Config->NSNoGroupChange) - u->SendMessage(NickServ, NICK_GROUP_CHANGE_DISABLED, Config->s_NickServ.c_str()); + source.Reply(NICK_GROUP_CHANGE_DISABLED, Config->s_NickServ.c_str()); else if (Config->NSMaxAliases && (target->nc->aliases.size() >= Config->NSMaxAliases) && !target->nc->IsServicesOper()) - u->SendMessage(NickServ, NICK_GROUP_TOO_MANY, target->nick.c_str(), Config->s_NickServ.c_str(), Config->s_NickServ.c_str()); + source.Reply(NICK_GROUP_TOO_MANY, target->nick.c_str(), Config->s_NickServ.c_str(), Config->s_NickServ.c_str()); else { int res = enc_check_password(pass, target->nc->pass); if (res == -1) { Log(LOG_COMMAND, u, this) << "failed group for " << na->nick << " (invalid password)"; - u->SendMessage(NickServ, PASSWORD_INCORRECT); + source.Reply(PASSWORD_INCORRECT); if (bad_password(u)) return MOD_STOP; } @@ -103,7 +103,7 @@ class CommandNSGroup : public Command if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && !u->nick.find_ci(Config->NSGuestNickPrefix) && !u->nick.substr(prefixlen).find_first_not_of("1234567890")) { - u->SendMessage(NickServ, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); + source.Reply(NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); return MOD_CONT; } } @@ -121,7 +121,7 @@ class CommandNSGroup : public Command u->SetMode(NickServ, UMODE_REGISTERED); Log(LOG_COMMAND, u, this) << "makes " << u->nick << " join group of " << target->nick << " (" << target->nc->display << ") (email: " << (!target->nc->email.empty() ? target->nc->email : "none") << ")"; - u->SendMessage(NickServ, NICK_GROUP_JOINED, target->nick.c_str()); + source.Reply(NICK_GROUP_JOINED, target->nick.c_str()); u->lastnickreg = Anope::CurTime; @@ -155,17 +155,18 @@ class CommandNSUngroup : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; Anope::string nick = !params.empty() ? params[0] : ""; NickAlias *na = findnick(!nick.empty() ? nick : u->nick); if (u->Account()->aliases.size() == 1) - u->SendMessage(NickServ, NICK_UNGROUP_ONE_NICK); + source.Reply(NICK_UNGROUP_ONE_NICK); else if (!na) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, !nick.empty() ? nick.c_str() : u->nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, !nick.empty() ? nick.c_str() : u->nick.c_str()); else if (na->nc != u->Account()) - u->SendMessage(NickServ, NICK_UNGROUP_NOT_IN_GROUP, na->nick.c_str()); + source.Reply(NICK_UNGROUP_NOT_IN_GROUP, na->nick.c_str()); else { NickCore *oldcore = na->nc; @@ -187,7 +188,7 @@ class CommandNSUngroup : public Command na->nc->greet = oldcore->greet; na->nc->language = oldcore->language; - u->SendMessage(NickServ, NICK_UNGROUP_SUCCESSFUL, na->nick.c_str(), oldcore->display.c_str()); + source.Reply(NICK_UNGROUP_SUCCESSFUL, na->nick.c_str(), oldcore->display.c_str()); User *user = finduser(na->nick); if (user) @@ -217,26 +218,27 @@ class CommandNSGList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; Anope::string nick = !params.empty() ? params[0] : ""; const NickCore *nc = u->Account(); if (!nick.empty() && (!nick.equals_ci(u->nick) && !u->Account()->IsServicesOper())) - u->SendMessage(NickServ, ACCESS_DENIED, Config->s_NickServ.c_str()); + source.Reply(ACCESS_DENIED, Config->s_NickServ.c_str()); else if (!nick.empty() && (!findnick(nick) || !(nc = findnick(nick)->nc))) - u->SendMessage(NickServ, nick.empty() ? NICK_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(nick.empty() ? NICK_NOT_REGISTERED : NICK_X_NOT_REGISTERED, nick.c_str()); else { - u->SendMessage(NickServ, !nick.empty() ? NICK_GLIST_HEADER_X : NICK_GLIST_HEADER, nc->display.c_str()); + source.Reply(!nick.empty() ? NICK_GLIST_HEADER_X : NICK_GLIST_HEADER, nc->display.c_str()); for (std::list<NickAlias *>::const_iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it) { NickAlias *na2 = *it; - u->SendMessage(NickServ, na2->HasFlag(NS_NO_EXPIRE) ? NICK_GLIST_REPLY_NOEXPIRE : NICK_GLIST_REPLY, na2->nick.c_str(), do_strftime(na2->last_seen + Config->NSExpire).c_str()); + source.Reply(na2->HasFlag(NS_NO_EXPIRE) ? NICK_GLIST_REPLY_NOEXPIRE : NICK_GLIST_REPLY, na2->nick.c_str(), do_strftime(na2->last_seen + Config->NSExpire).c_str()); } - u->SendMessage(NickServ, NICK_GLIST_FOOTER, nc->aliases.size()); + source.Reply(NICK_GLIST_FOOTER, nc->aliases.size()); } return MOD_CONT; } diff --git a/modules/core/ns_help.cpp b/modules/core/ns_help.cpp index 8bd062f6a..07ba58a07 100644 --- a/modules/core/ns_help.cpp +++ b/modules/core/ns_help.cpp @@ -21,9 +21,9 @@ class CommandNSHelp : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(NickServ, u, params[0]); + mod_help_cmd(NickServ, source.u, params[0]); return MOD_CONT; } diff --git a/modules/core/ns_identify.cpp b/modules/core/ns_identify.cpp index c7748e82c..bfb05ecc8 100644 --- a/modules/core/ns_identify.cpp +++ b/modules/core/ns_identify.cpp @@ -21,9 +21,11 @@ class CommandNSIdentify : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params.size() == 2 ? params[0] : u->nick; + User *u = source.u; + + const Anope::string &nick = params.size() == 2 ? params[0] : u->nick; Anope::string pass = params[params.size() - 1]; NickAlias *na = findnick(nick), *this_na = findnick(u->nick); @@ -31,32 +33,32 @@ class CommandNSIdentify : public Command { NickRequest *nr = findrequestnick(nick); if (nr) - u->SendMessage(NickServ, NICK_IS_PREREG); + source.Reply(NICK_IS_PREREG); else - u->SendMessage(NickServ, NICK_NOT_REGISTERED); + source.Reply(NICK_NOT_REGISTERED); } else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - u->SendMessage(NickServ, NICK_X_SUSPENDED, na->nick.c_str()); + source.Reply(NICK_X_SUSPENDED, na->nick.c_str()); /* You can now identify for other nicks without logging out first, * however you can not identify again for the group you're already * identified as */ else if (u->Account() && u->Account() == na->nc) - u->SendMessage(NickServ, NICK_ALREADY_IDENTIFIED); + source.Reply(NICK_ALREADY_IDENTIFIED); else { int res = enc_check_password(pass, na->nc->pass); if (!res) { Log(LOG_COMMAND, u, this) << "and failed to identify"; - u->SendMessage(NickServ, PASSWORD_INCORRECT); + source.Reply(PASSWORD_INCORRECT); if (bad_password(u)) return MOD_STOP; } else if (res == -1) - u->SendMessage(NickServ, NICK_IDENTIFY_FAILED); + source.Reply(NICK_IDENTIFY_FAILED); else { if (u->IsIdentified()) @@ -77,7 +79,7 @@ class CommandNSIdentify : public Command FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u)); Log(LOG_COMMAND, u, this) << "and identified for account " << u->Account()->display; - u->SendMessage(NickServ, NICK_IDENTIFY_SUCCEEDED); + source.Reply(NICK_IDENTIFY_SUCCEEDED); if (ircd->vhost) do_on_id(u); if (Config->NSModeOnID) @@ -85,8 +87,8 @@ class CommandNSIdentify : public Command if (Config->NSForceEmail && u->Account() && u->Account()->email.empty()) { - u->SendMessage(NickServ, NICK_IDENTIFY_EMAIL_REQUIRED); - u->SendMessage(NickServ, NICK_IDENTIFY_EMAIL_HOWTO); + source.Reply(NICK_IDENTIFY_EMAIL_REQUIRED); + source.Reply(NICK_IDENTIFY_EMAIL_HOWTO); } if (u->IsIdentified()) diff --git a/modules/core/ns_info.cpp b/modules/core/ns_info.cpp index 6f77874a5..ed60362f8 100644 --- a/modules/core/ns_info.cpp +++ b/modules/core/ns_info.cpp @@ -33,10 +33,11 @@ class CommandNSInfo : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + User *u = source.u; + const Anope::string &nick = params[0]; NickAlias *na = findnick(nick); bool has_auspex = u->IsIdentified() && u->Account()->HasPriv("nickserv/auspex"); @@ -45,21 +46,21 @@ class CommandNSInfo : public Command NickRequest *nr = findrequestnick(nick); if (nr) { - u->SendMessage(NickServ, NICK_IS_PREREG); + source.Reply(NICK_IS_PREREG); if (has_auspex) - u->SendMessage(NickServ, NICK_INFO_EMAIL, nr->email.c_str()); + source.Reply(NICK_INFO_EMAIL, nr->email.c_str()); } else if (nickIsServices(nick, true)) - u->SendMessage(NickServ, NICK_X_IS_SERVICES, nick.c_str()); + source.Reply(NICK_X_IS_SERVICES, nick.c_str()); else - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); } else if (na->HasFlag(NS_FORBIDDEN)) { if (is_oper(u) && !na->last_usermask.empty()) - u->SendMessage(NickServ, NICK_X_FORBIDDEN_OPER, nick.c_str(), na->last_usermask.c_str(), !na->last_realname.empty() ? na->last_realname.c_str() : GetString(u, NO_REASON).c_str()); + source.Reply(NICK_X_FORBIDDEN_OPER, nick.c_str(), na->last_usermask.c_str(), !na->last_realname.empty() ? na->last_realname.c_str() : GetString(u, NO_REASON).c_str()); else - u->SendMessage(NickServ, NICK_X_FORBIDDEN, nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, nick.c_str()); } else { @@ -73,48 +74,48 @@ class CommandNSInfo : public Command if (has_auspex || (u->Account() && na->nc == u->Account())) show_hidden = true; - u->SendMessage(NickServ, NICK_INFO_REALNAME, na->nick.c_str(), na->last_realname.c_str()); + source.Reply(NICK_INFO_REALNAME, na->nick.c_str(), na->last_realname.c_str()); if (na->nc->IsServicesOper() && (show_hidden || !na->nc->HasFlag(NI_HIDE_STATUS))) - u->SendMessage(NickServ, NICK_INFO_SERVICES_OPERTYPE, na->nick.c_str(), na->nc->ot->GetName().c_str()); + source.Reply(NICK_INFO_SERVICES_OPERTYPE, na->nick.c_str(), na->nc->ot->GetName().c_str()); if (nick_online) { if (show_hidden || !na->nc->HasFlag(NI_HIDE_MASK)) - u->SendMessage(NickServ, NICK_INFO_ADDRESS_ONLINE, na->last_usermask.c_str()); + source.Reply(NICK_INFO_ADDRESS_ONLINE, na->last_usermask.c_str()); else - u->SendMessage(NickServ, NICK_INFO_ADDRESS_ONLINE_NOHOST, na->nick.c_str()); + source.Reply(NICK_INFO_ADDRESS_ONLINE_NOHOST, na->nick.c_str()); } else { if (show_hidden || !na->nc->HasFlag(NI_HIDE_MASK)) - u->SendMessage(NickServ, NICK_INFO_ADDRESS, na->last_usermask.c_str()); + source.Reply(NICK_INFO_ADDRESS, na->last_usermask.c_str()); } - u->SendMessage(NickServ, NICK_INFO_TIME_REGGED, do_strftime(na->time_registered).c_str()); + source.Reply(NICK_INFO_TIME_REGGED, do_strftime(na->time_registered).c_str()); if (!nick_online) { - u->SendMessage(NickServ, NICK_INFO_LAST_SEEN, do_strftime(na->last_seen).c_str()); + source.Reply(NICK_INFO_LAST_SEEN, do_strftime(na->last_seen).c_str()); } if (!na->last_quit.empty() && (show_hidden || !na->nc->HasFlag(NI_HIDE_QUIT))) - u->SendMessage(NickServ, NICK_INFO_LAST_QUIT, na->last_quit.c_str()); + source.Reply(NICK_INFO_LAST_QUIT, na->last_quit.c_str()); if (!na->nc->email.empty() && (show_hidden || !na->nc->HasFlag(NI_HIDE_EMAIL))) - u->SendMessage(NickServ, NICK_INFO_EMAIL, na->nc->email.c_str()); + source.Reply(NICK_INFO_EMAIL, na->nc->email.c_str()); if (show_hidden) { if (!Config->s_HostServ.empty() && ircd->vhost && na->hostinfo.HasVhost()) { if (ircd->vident && !na->hostinfo.GetIdent().empty()) - u->SendMessage(NickServ, NICK_INFO_VHOST2, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); + source.Reply(NICK_INFO_VHOST2, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else - u->SendMessage(NickServ, NICK_INFO_VHOST, na->hostinfo.GetHost().c_str()); + source.Reply(NICK_INFO_VHOST, na->hostinfo.GetHost().c_str()); } if (!na->nc->greet.empty()) - u->SendMessage(NickServ, NICK_INFO_GREET, na->nc->greet.c_str()); + source.Reply(NICK_INFO_GREET, na->nc->greet.c_str()); Anope::string optbuf; @@ -124,20 +125,20 @@ class CommandNSInfo : public Command CheckOptStr(optbuf, NI_MSG, GetString(u, NICK_INFO_OPT_MSG).c_str(), na->nc); CheckOptStr(optbuf, NI_AUTOOP, GetString(u, NICK_INFO_OPT_AUTOOP).c_str(), na->nc); - u->SendMessage(NickServ, NICK_INFO_OPTIONS, optbuf.empty() ? GetString(u, NICK_INFO_OPT_NONE).c_str() : optbuf.c_str()); + source.Reply(NICK_INFO_OPTIONS, optbuf.empty() ? GetString(u, NICK_INFO_OPT_NONE).c_str() : optbuf.c_str()); if (na->nc->HasFlag(NI_SUSPENDED)) { if (!na->last_quit.empty()) - u->SendMessage(NickServ, NICK_INFO_SUSPENDED, na->last_quit.c_str()); + source.Reply(NICK_INFO_SUSPENDED, na->last_quit.c_str()); else - u->SendMessage(NickServ, NICK_INFO_SUSPENDED_NO_REASON); + source.Reply(NICK_INFO_SUSPENDED_NO_REASON); } if (na->HasFlag(NS_NO_EXPIRE)) - u->SendMessage(NickServ, NICK_INFO_NO_EXPIRE); + source.Reply(NICK_INFO_NO_EXPIRE); else - u->SendMessage(NickServ, NICK_INFO_EXPIRE, do_strftime(na->last_seen + Config->NSExpire).c_str()); + source.Reply(NICK_INFO_EXPIRE, do_strftime(na->last_seen + Config->NSExpire).c_str()); } FOREACH_MOD(I_OnNickInfo, OnNickInfo(u, na, show_hidden)); diff --git a/modules/core/ns_list.cpp b/modules/core/ns_list.cpp index 347d21b9a..a02321272 100644 --- a/modules/core/ns_list.cpp +++ b/modules/core/ns_list.cpp @@ -21,7 +21,7 @@ class CommandNSList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { /* SADMINS can search for nicks based on their NS_FORBIDDEN and NS_NO_EXPIRE * status. The keywords FORBIDDEN and NOEXPIRE represent these two states @@ -36,6 +36,8 @@ class CommandNSList : public Command * * UPDATE: SUSPENDED keyword is now accepted as well. */ + User *u = source.u; + Anope::string pattern = params[0]; const NickCore *mync; unsigned nnicks; @@ -49,7 +51,7 @@ class CommandNSList : public Command if (Config->NSListOpersOnly && !is_oper(u)) /* reverse the help logic */ { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_STOP; } @@ -58,24 +60,24 @@ class CommandNSList : public Command Anope::string tmp = myStrGetToken(pattern.substr(1), '-', 0); /* Read FROM out */ if (tmp.empty()) { - u->SendMessage(NickServ, LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); return MOD_CONT; } if (!tmp.is_number_only()) { - u->SendMessage(NickServ, LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); return MOD_CONT; } from = convertTo<int>(tmp); tmp = myStrGetTokenRemainder(pattern, '-', 1); /* Read TO out */ if (tmp.empty()) { - u->SendMessage(NickServ, LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); return MOD_CONT; } if (!tmp.is_number_only()) { - u->SendMessage(NickServ, LIST_INCORRECT_RANGE); + source.Reply(LIST_INCORRECT_RANGE); return MOD_CONT; } to = convertTo<int>(tmp); @@ -142,7 +144,7 @@ class CommandNSList : public Command snprintf(buf, sizeof(buf), "%-20s [Suspended]", na->nick.c_str()); else snprintf(buf, sizeof(buf), "%-20s %s", na->nick.c_str(), na->last_usermask.c_str()); - u->SendMessage(Config->s_NickServ, " %c%s", noexpire_char, buf); + source.Reply(" %c%s", noexpire_char, buf); } ++count; } @@ -161,7 +163,7 @@ class CommandNSList : public Command if ((nr->nick.equals_ci(pattern) || Anope::Match(buf, pattern)) && ++nnicks <= Config->NSListMax) { snprintf(buf, sizeof(buf), "%-20s [UNCONFIRMED]", nr->nick.c_str()); - u->SendMessage(Config->s_NickServ, " %c%s", noexpire_char, buf); + source.Reply(" %c%s", noexpire_char, buf); } } } diff --git a/modules/core/ns_logout.cpp b/modules/core/ns_logout.cpp index 252fe1d0d..c6e04c8c8 100644 --- a/modules/core/ns_logout.cpp +++ b/modules/core/ns_logout.cpp @@ -20,18 +20,20 @@ class CommandNSLogout : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = !params.empty() ? params[0] : ""; - Anope::string param = params.size() > 1 ? params[1] : ""; - User *u2; + User *u = source.u; + + const Anope::string &nick = !params.empty() ? params[0] : ""; + const Anope::string ¶m = params.size() > 1 ? params[1] : ""; + User *u2; if (!u->Account()->IsServicesOper() && !nick.empty()) this->OnSyntaxError(u, ""); else if (!(u2 = (!nick.empty() ? finduser(nick) : u))) - u->SendMessage(NickServ, NICK_X_NOT_IN_USE, nick.c_str()); + source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); else if (!nick.empty() && u2->Account() && !u2->Account()->IsServicesOper()) - u->SendMessage(NickServ, NICK_LOGOUT_SERVICESADMIN, nick.c_str()); + source.Reply(NICK_LOGOUT_SERVICESADMIN, nick.c_str()); else { if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE")) @@ -42,9 +44,9 @@ class CommandNSLogout : public Command /* Remove founder status from this user in all channels */ if (!nick.empty()) - u->SendMessage(NickServ, NICK_LOGOUT_X_SUCCEEDED, nick.c_str()); + source.Reply(NICK_LOGOUT_X_SUCCEEDED, nick.c_str()); else - u->SendMessage(NickServ, NICK_LOGOUT_SUCCEEDED); + source.Reply(NICK_LOGOUT_SUCCEEDED); ircdproto->SendAccountLogout(u2, u2->Account()); u2->RemoveMode(NickServ, UMODE_REGISTERED); diff --git a/modules/core/ns_recover.cpp b/modules/core/ns_recover.cpp index 73d65f966..137bcb092 100644 --- a/modules/core/ns_recover.cpp +++ b/modules/core/ns_recover.cpp @@ -21,23 +21,25 @@ class CommandNSRecover : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + User *u = source.u; + + const Anope::string &nick = params[0]; Anope::string pass = params.size() > 1 ? params[1] : ""; + NickAlias *na; User *u2; - if (!(u2 = finduser(nick))) - u->SendMessage(NickServ, NICK_X_NOT_IN_USE, nick.c_str()); + source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); else if (!(na = findnick(u2->nick))) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - u->SendMessage(NickServ, NICK_X_SUSPENDED, na->nick.c_str()); + source.Reply(NICK_X_SUSPENDED, na->nick.c_str()); else if (nick.equals_ci(u->nick)) - u->SendMessage(NickServ, NICK_NO_RECOVER_SELF); + source.Reply(NICK_NO_RECOVER_SELF); else if (!pass.empty()) { int res = enc_check_password(pass, na->nc->pass); @@ -50,11 +52,11 @@ class CommandNSRecover : public Command /* Convert Config->NSReleaseTimeout seconds to string format */ Anope::string relstr = duration(na->nc, Config->NSReleaseTimeout); - u->SendMessage(NickServ, NICK_RECOVERED, Config->s_NickServ.c_str(), nick.c_str(), relstr.c_str()); + source.Reply(NICK_RECOVERED, Config->s_NickServ.c_str(), nick.c_str(), relstr.c_str()); } else { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); if (!res) { Log(LOG_COMMAND, u, this) << "with invalid password for " << nick; @@ -73,10 +75,10 @@ class CommandNSRecover : public Command /* Convert Config->NSReleaseTimeout seconds to string format */ Anope::string relstr = duration(na->nc, Config->NSReleaseTimeout); - u->SendMessage(NickServ, NICK_RECOVERED, Config->s_NickServ.c_str(), nick.c_str(), relstr.c_str()); + source.Reply(NICK_RECOVERED, Config->s_NickServ.c_str(), nick.c_str(), relstr.c_str()); } else - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); } return MOD_CONT; } diff --git a/modules/core/ns_register.cpp b/modules/core/ns_register.cpp index f0304d119..b820e6318 100644 --- a/modules/core/ns_register.cpp +++ b/modules/core/ns_register.cpp @@ -18,8 +18,9 @@ static bool SendRegmail(User *u, NickRequest *nr); class CommandNSConfirm : public Command { protected: - CommandReturn ActuallyConfirmNick(User *u, NickRequest *nr, bool force) + CommandReturn ActuallyConfirmNick(CommandSource &source, NickRequest *nr, bool force) { + User *u = source.u; NickAlias *na = new NickAlias(nr->nick, new NickCore(nr->nick)); Anope::string tmp_pass; @@ -51,23 +52,23 @@ class CommandNSConfirm : public Command u->Login(na->nc); Log(LOG_COMMAND, u, this) << "to register " << u->nick << " (email: " << (!nr->email.empty() ? nr->email : "none") << ")"; if (Config->NSAddAccessOnReg) - u->SendMessage(NickServ, NICK_REGISTERED, u->nick.c_str(), na->nc->GetAccess(0).c_str()); + source.Reply(NICK_REGISTERED, u->nick.c_str(), na->nc->GetAccess(0).c_str()); else - u->SendMessage(NickServ, NICK_REGISTERED_NO_MASK, u->nick.c_str()); + source.Reply(NICK_REGISTERED_NO_MASK, u->nick.c_str()); delete nr; ircdproto->SendAccountLogin(u, u->Account()); ircdproto->SetAutoIdentificationToken(u); if (enc_decrypt(na->nc->pass, tmp_pass) == 1) - u->SendMessage(NickServ, NICK_PASSWORD_IS, tmp_pass.c_str()); + source.Reply(NICK_PASSWORD_IS, tmp_pass.c_str()); u->lastnickreg = Anope::CurTime; } else { Log(LOG_COMMAND, u, this) << "to confirm " << u->nick << " (email: " << (!nr->email.empty() ? nr->email : "none") << ")"; - u->SendMessage(NickServ, NICK_FORCE_REG, nr->nick.c_str()); + source.Reply(NICK_FORCE_REG, nr->nick.c_str()); User *user = finduser(nr->nick); /* Delrequest must be called before validate_user */ delete nr; @@ -80,8 +81,9 @@ class CommandNSConfirm : public Command return MOD_CONT; } - CommandReturn DoConfirm(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoConfirm(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; Anope::string passcode = !params.empty() ? params[0] : ""; NickRequest *nr = findrequestnick(u->nick); @@ -103,29 +105,29 @@ class CommandNSConfirm : public Command nr = findrequestnick(passcode); if (nr) { - ActuallyConfirmNick(u, nr, true); + ActuallyConfirmNick(source, nr, true); return MOD_CONT; } } - u->SendMessage(NickServ, NICK_CONFIRM_NOT_FOUND, Config->s_NickServ.c_str()); + source.Reply(NICK_CONFIRM_NOT_FOUND, Config->s_NickServ.c_str()); return MOD_CONT; } if (!nr->passcode.equals_cs(passcode)) { - u->SendMessage(NickServ, NICK_CONFIRM_INVALID); + source.Reply(NICK_CONFIRM_INVALID); return MOD_CONT; } } if (!nr) { - u->SendMessage(NickServ, NICK_REGISTRATION_FAILED); + source.Reply(NICK_REGISTRATION_FAILED); return MOD_CONT; } - ActuallyConfirmNick(u, nr, false); + ActuallyConfirmNick(source, nr, false); return MOD_CONT; } @@ -135,9 +137,9 @@ class CommandNSConfirm : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoConfirm(u, params); + return this->DoConfirm(source, params); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -167,8 +169,9 @@ class CommandNSRegister : public CommandNSConfirm this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickRequest *nr = NULL, *anr = NULL; NickAlias *na; size_t prefixlen = Config->NSGuestNickPrefix.length(); @@ -188,19 +191,19 @@ class CommandNSRegister : public CommandNSConfirm if (readonly) { - u->SendMessage(NickServ, NICK_REGISTRATION_DISABLED); + source.Reply(NICK_REGISTRATION_DISABLED); return MOD_CONT; } if (!is_oper(u) && Config->NickRegDelay && Anope::CurTime - u->my_signon < Config->NickRegDelay) { - u->SendMessage(NickServ, NICK_REG_DELAY, Config->NickRegDelay); + source.Reply(NICK_REG_DELAY, Config->NickRegDelay); return MOD_CONT; } if ((anr = findrequestnick(u->nick))) { - u->SendMessage(NickServ, NICK_REQUESTED); + source.Reply(NICK_REQUESTED); return MOD_CONT; } @@ -211,13 +214,13 @@ class CommandNSRegister : public CommandNSConfirm */ if (nicklen <= prefixlen + 7 && nicklen >= prefixlen + 1 && !u->nick.find_ci(Config->NSGuestNickPrefix) && !u->nick.substr(prefixlen).find_first_not_of("1234567890")) { - u->SendMessage(NickServ, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); + source.Reply(NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); return MOD_CONT; } if (!ircdproto->IsNickValid(u->nick)) { - u->SendMessage(NickServ, NICK_X_FORBIDDEN, u->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, u->nick.c_str()); return MOD_CONT; } @@ -228,7 +231,7 @@ class CommandNSRegister : public CommandNSConfirm if (u->nick.find_ci(nick) != Anope::string::npos && !is_oper(u)) { - u->SendMessage(NickServ, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); + source.Reply(NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); return MOD_CONT; } } @@ -236,24 +239,24 @@ class CommandNSRegister : public CommandNSConfirm if (Config->NSForceEmail && email.empty()) this->OnSyntaxError(u, ""); else if (Anope::CurTime < u->lastnickreg + Config->NSRegDelay) - u->SendMessage(NickServ, NICK_REG_PLEASE_WAIT, (u->lastnickreg + Config->NSRegDelay) - Anope::CurTime); + source.Reply(NICK_REG_PLEASE_WAIT, (u->lastnickreg + Config->NSRegDelay) - Anope::CurTime); else if ((na = findnick(u->nick))) { /* i.e. there's already such a nick regged */ if (na->HasFlag(NS_FORBIDDEN)) { Log(NickServ) << u->GetMask() << " tried to register FORBIDden nick " << u->nick; - u->SendMessage(NickServ, NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); + source.Reply(NICK_CANNOT_BE_REGISTERED, u->nick.c_str()); } else - u->SendMessage(NickServ, NICK_ALREADY_REGISTERED, u->nick.c_str()); + source.Reply(NICK_ALREADY_REGISTERED, u->nick.c_str()); } else if (pass.equals_ci(u->nick) || (Config->StrictPasswords && pass.length() < 5)) - u->SendMessage(NickServ, MORE_OBSCURE_PASSWORD); + source.Reply(MORE_OBSCURE_PASSWORD); else if (pass.length() > Config->PassLen) - u->SendMessage(NickServ, PASSWORD_TOO_LONG); + source.Reply(PASSWORD_TOO_LONG); else if (!email.empty() && !MailValidate(email)) - u->SendMessage(NickServ, MAIL_X_INVALID, email.c_str()); + source.Reply(MAIL_X_INVALID, email.c_str()); else { for (idx = 0; idx < 9; ++idx) @@ -269,13 +272,13 @@ class CommandNSRegister : public CommandNSConfirm { if (SendRegmail(u, nr)) { - u->SendMessage(NickServ, NICK_ENTER_REG_CODE, email.c_str(), Config->s_NickServ.c_str(), Config->s_NickServ.c_str()); + source.Reply(NICK_ENTER_REG_CODE, email.c_str(), Config->s_NickServ.c_str(), Config->s_NickServ.c_str()); Log(LOG_COMMAND, u, this) << "send registration verification code to " << nr->email; } else { Log(LOG_COMMAND, u, this) << "unable to send registration verification mail"; - u->SendMessage(NickServ, NICK_REG_UNABLE); + source.Reply(NICK_REG_UNABLE); delete nr; return MOD_CONT; } @@ -283,7 +286,7 @@ class CommandNSRegister : public CommandNSConfirm else { std::vector<Anope::string> empty_params; - return this->DoConfirm(u, empty_params); + return this->DoConfirm(source, empty_params); } } @@ -318,8 +321,9 @@ class CommandNSResend : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickRequest *nr = NULL; if (Config->NSEmailReg) { @@ -327,13 +331,13 @@ class CommandNSResend : public Command { if (Anope::CurTime < nr->lastmail + Config->NSResendDelay) { - u->SendMessage(NickServ, MAIL_LATER); + source.Reply(MAIL_LATER); return MOD_CONT; } if (!SendRegmail(u, nr)) { nr->lastmail = Anope::CurTime; - u->SendMessage(NickServ, NICK_REG_RESENT, nr->email.c_str()); + source.Reply(NICK_REG_RESENT, nr->email.c_str()); Log(LOG_COMMAND, u, this) << "resend registration verification code for " << nr->nick; } else diff --git a/modules/core/ns_release.cpp b/modules/core/ns_release.cpp index b8b517e36..743b7a2ec 100644 --- a/modules/core/ns_release.cpp +++ b/modules/core/ns_release.cpp @@ -21,31 +21,32 @@ class CommandNSRelease : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + User *u = source.u; + const Anope::string &nick = params[0]; Anope::string pass = params.size() > 1 ? params[1] : ""; NickAlias *na; if (!(na = findnick(nick))) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - u->SendMessage(NickServ, NICK_X_SUSPENDED, na->nick.c_str()); + source.Reply(NICK_X_SUSPENDED, na->nick.c_str()); else if (!na->HasFlag(NS_HELD)) - u->SendMessage(NickServ, NICK_RELEASE_NOT_HELD, nick.c_str()); + source.Reply(NICK_RELEASE_NOT_HELD, nick.c_str()); else if (!pass.empty()) { int res = enc_check_password(pass, na->nc->pass); if (res == 1) { Log(LOG_COMMAND, u, this) << "released " << na->nick; - u->SendMessage(NickServ, NICK_RELEASED); + source.Reply(NICK_RELEASED); } else { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); if (!res) { Log(LOG_COMMAND, u, this) << "invalid password for " << nick; @@ -59,10 +60,10 @@ class CommandNSRelease : public Command if (u->Account() == na->nc || (!na->nc->HasFlag(NI_SECURE) && is_on_access(u, na->nc))) { na->Release(); - u->SendMessage(NickServ, NICK_RELEASED); + source.Reply(NICK_RELEASED); } else - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); } return MOD_CONT; } diff --git a/modules/core/ns_resetpass.cpp b/modules/core/ns_resetpass.cpp index 1c23c5010..ddff616a3 100644 --- a/modules/core/ns_resetpass.cpp +++ b/modules/core/ns_resetpass.cpp @@ -23,22 +23,23 @@ class CommandNSResetPass : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na; if (Config->RestrictMail && (!u->Account() || !u->Account()->HasCommand("nickserv/resetpass"))) - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); if (!(na = findnick(params[0]))) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, params[0].c_str()); + source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else { if (SendResetEmail(u, na)) { Log(LOG_COMMAND, u, this) << "for " << na->nick << " (group: " << na->nc->display << ")"; - u->SendMessage(NickServ, NICK_RESETPASS_COMPLETE, na->nick.c_str()); + source.Reply(NICK_RESETPASS_COMPLETE, na->nick.c_str()); } } @@ -82,7 +83,7 @@ class NSResetPass : public Module EventReturn OnPreCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { - if (service == findbot(Config->s_NickServ) && command.equals_ci("CONFIRM") && !params.empty()) + if (service == NickServ && command.equals_ci("CONFIRM") && !params.empty()) { NickAlias *na = findnick(u->nick); @@ -94,7 +95,7 @@ class NSResetPass : public Module { na->nc->Shrink("ns_resetpass_code"); na->nc->Shrink("ns_resetpass_time"); - u->SendMessage(NickServ, NICK_CONFIRM_EXPIRED); + u->SendMessage(service, NICK_CONFIRM_EXPIRED); return EVENT_STOP; } @@ -114,7 +115,7 @@ class NSResetPass : public Module FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(u)); Log(LOG_COMMAND, u, &commandnsresetpass) << "confirmed RESETPASS to forcefully identify to " << na->nick; - u->SendMessage(NickServ, NICK_CONFIRM_SUCCESS, Config->s_NickServ.c_str()); + u->SendMessage(service, NICK_CONFIRM_SUCCESS, Config->s_NickServ.c_str()); if (ircd->vhost) do_on_id(u); @@ -125,7 +126,7 @@ class NSResetPass : public Module else { Log(LOG_COMMAND, u, &commandnsresetpass) << "invalid confirm passcode for " << na->nick; - u->SendMessage(NickServ, NICK_CONFIRM_INVALID); + u->SendMessage(service, NICK_CONFIRM_INVALID); bad_password(u); } diff --git a/modules/core/ns_saset.cpp b/modules/core/ns_saset.cpp index d91bdd41d..df0e28eab 100644 --- a/modules/core/ns_saset.cpp +++ b/modules/core/ns_saset.cpp @@ -28,24 +28,25 @@ class CommandNSSASet : public Command this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - Anope::string cmd = params[1]; + User *u = source.u; + const Anope::string &nick = params[0]; + const Anope::string &cmd = params[1]; if (readonly) { - u->SendMessage(NickServ, NICK_SET_DISABLED); + source.Reply(NICK_SET_DISABLED); return MOD_CONT; } NickAlias *na = findnick(nick); if (!na) - u->SendMessage(NickServ, NICK_SASET_BAD_NICK, nick.c_str()); + source.Reply(NICK_SASET_BAD_NICK, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else if (na->nc->HasFlag(NI_SUSPENDED)) - u->SendMessage(NickServ, NICK_X_SUSPENDED, na->nick.c_str()); + source.Reply(NICK_X_SUSPENDED, na->nick.c_str()); else { Command *c = this->FindCommand(params[1]); @@ -63,7 +64,7 @@ class CommandNSSASet : public Command mod_run_cmd(NickServ, u, c, params[1], cmdparams, false); } else - u->SendMessage(NickServ, NICK_SASET_UNKNOWN_OPTION, cmd.c_str()); + source.Reply(NICK_SASET_UNKNOWN_OPTION, cmd.c_str()); } return MOD_CONT; @@ -128,8 +129,9 @@ class CommandNSSASetDisplay : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *setter_na = findnick(params[0]); if (!setter_na) throw CoreException("NULL na in CommandNSSASetDisplay"); @@ -138,7 +140,7 @@ class CommandNSSASetDisplay : public Command NickAlias *na = findnick(params[1]); if (!na || na->nc != nc) { - u->SendMessage(NickServ, NICK_SASET_DISPLAY_INVALID, nc->display.c_str()); + source.Reply(NICK_SASET_DISPLAY_INVALID, nc->display.c_str()); return MOD_CONT; } @@ -172,8 +174,9 @@ class CommandNSSASetPassword : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *setter_na = findnick(params[0]); if (!setter_na) throw CoreException("NULL na in CommandNSSASetPassword"); @@ -183,32 +186,32 @@ class CommandNSSASetPassword : public Command if (Config->NSSecureAdmins && u->Account() != nc && nc->IsServicesOper()) { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } else if (nc->display.equals_ci(params[1]) || (Config->StrictPasswords && len < 5)) { - u->SendMessage(NickServ, MORE_OBSCURE_PASSWORD); + source.Reply(MORE_OBSCURE_PASSWORD); return MOD_CONT; } else if (len > Config->PassLen) { - u->SendMessage(NickServ, PASSWORD_TOO_LONG); + source.Reply(PASSWORD_TOO_LONG); return MOD_CONT; } if (enc_encrypt(params[1], nc->pass)) { Log(NickServ) << "Failed to encrypt password for " << nc->display << " (saset)"; - u->SendMessage(NickServ, NICK_SASET_PASSWORD_FAILED, nc->display.c_str()); + source.Reply(NICK_SASET_PASSWORD_FAILED, nc->display.c_str()); return MOD_CONT; } Anope::string tmp_pass; if (enc_decrypt(nc->pass, tmp_pass) == 1) - u->SendMessage(NickServ, NICK_SASET_PASSWORD_CHANGED_TO, nc->display.c_str(), tmp_pass.c_str()); + source.Reply(NICK_SASET_PASSWORD_CHANGED_TO, nc->display.c_str(), tmp_pass.c_str()); else - u->SendMessage(NickServ, NICK_SASET_PASSWORD_CHANGED, nc->display.c_str()); + source.Reply(NICK_SASET_PASSWORD_CHANGED, nc->display.c_str()); if (Config->WallSetpass) ircdproto->SendGlobops(NickServ, "\2%s\2 used SASET PASSWORD on \2%s\2", u->nick.c_str(), nc->display.c_str()); diff --git a/modules/core/ns_saset_noexpire.cpp b/modules/core/ns_saset_noexpire.cpp index 3489dcd2e..21814e41c 100644 --- a/modules/core/ns_saset_noexpire.cpp +++ b/modules/core/ns_saset_noexpire.cpp @@ -20,8 +20,9 @@ class CommandNSSASetNoexpire : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSASsetNoexpire"); @@ -31,12 +32,12 @@ class CommandNSSASetNoexpire : public Command if (param.equals_ci("ON")) { na->SetFlag(NS_NO_EXPIRE); - u->SendMessage(NickServ, NICK_SASET_NOEXPIRE_ON, na->nick.c_str()); + source.Reply(NICK_SASET_NOEXPIRE_ON, na->nick.c_str()); } else if (param.equals_ci("OFF")) { na->UnsetFlag(NS_NO_EXPIRE); - u->SendMessage(NickServ, NICK_SASET_NOEXPIRE_OFF, na->nick.c_str()); + source.Reply(NICK_SASET_NOEXPIRE_OFF, na->nick.c_str()); } else this->OnSyntaxError(u, "NOEXPIRE"); diff --git a/modules/core/ns_sendpass.cpp b/modules/core/ns_sendpass.cpp index 488196cf8..9612073ac 100644 --- a/modules/core/ns_sendpass.cpp +++ b/modules/core/ns_sendpass.cpp @@ -23,17 +23,18 @@ class CommandNSSendPass : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + User *u = source.u; + const Anope::string &nick = params[0]; NickAlias *na; if (Config->RestrictMail && (!u->Account() || !u->Account()->HasCommand("nickserv/sendpass"))) - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); else if (!(na = findnick(nick))) - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); else if (na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); else { Anope::string tmp_pass; @@ -42,11 +43,11 @@ class CommandNSSendPass : public Command if (SendPassMail(u, na, tmp_pass)) { Log(Config->RestrictMail ? LOG_ADMIN : LOG_COMMAND, u, this) << "for " << na->nick; - u->SendMessage(NickServ, NICK_SENDPASS_OK, nick.c_str()); + source.Reply(NICK_SENDPASS_OK, nick.c_str()); } } else - u->SendMessage(NickServ, NICK_SENDPASS_UNAVAILABLE); + source.Reply(NICK_SENDPASS_UNAVAILABLE); } return MOD_CONT; diff --git a/modules/core/ns_set.cpp b/modules/core/ns_set.cpp index f5cc9a2d3..7d63119e9 100644 --- a/modules/core/ns_set.cpp +++ b/modules/core/ns_set.cpp @@ -28,17 +28,19 @@ class CommandNSSet : public Command this->subcommands.clear(); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + if (readonly) { - u->SendMessage(NickServ, NICK_SET_DISABLED); + source.Reply(NICK_SET_DISABLED); return MOD_CONT; } if (u->Account()->HasFlag(NI_SUSPENDED)) { - u->SendMessage(NickServ, NICK_X_SUSPENDED, u->Account()->display.c_str()); + source.Reply(NICK_X_SUSPENDED, u->Account()->display.c_str()); return MOD_CONT; } @@ -57,7 +59,7 @@ class CommandNSSet : public Command mod_run_cmd(NickServ, u, c, params[0], cmdparams, false); } else - u->SendMessage(NickServ, NICK_SET_UNKNOWN_OPTION, params[0].c_str()); + source.Reply(NICK_SET_UNKNOWN_OPTION, params[0].c_str()); return MOD_CONT; } @@ -121,13 +123,14 @@ class CommandNSSetDisplay : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[1]); if (!na || na->nc != u->Account()) { - u->SendMessage(NickServ, NICK_SASET_DISPLAY_INVALID, u->Account()->display.c_str()); + source.Reply(NICK_SASET_DISPLAY_INVALID, u->Account()->display.c_str()); return MOD_CONT; } @@ -161,35 +164,36 @@ class CommandNSSetPassword : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string param = params[1]; + User *u = source.u; + const Anope::string ¶m = params[1]; unsigned len = param.length(); if (u->Account()->display.equals_ci(param) || (Config->StrictPasswords && len < 5)) { - u->SendMessage(NickServ, MORE_OBSCURE_PASSWORD); + source.Reply(MORE_OBSCURE_PASSWORD); return MOD_CONT; } else if (len > Config->PassLen) { - u->SendMessage(NickServ, PASSWORD_TOO_LONG); + source.Reply(PASSWORD_TOO_LONG); return MOD_CONT; } if (enc_encrypt(param, u->Account()->pass) < 0) { Log(NickServ) << "Failed to encrypt password for " << u->Account()->display << " (set)"; - u->SendMessage(NickServ, NICK_SASET_PASSWORD_FAILED); + source.Reply(NICK_SASET_PASSWORD_FAILED); return MOD_CONT; } Anope::string tmp_pass; if (enc_decrypt(u->Account()->pass, tmp_pass) == 1) - u->SendMessage(NickServ, NICK_SASET_PASSWORD_CHANGED_TO, u->Account()->display.c_str(), tmp_pass.c_str()); + source.Reply(NICK_SASET_PASSWORD_CHANGED_TO, u->Account()->display.c_str(), tmp_pass.c_str()); else - u->SendMessage(NickServ, NICK_SASET_PASSWORD_CHANGED, u->Account()->display.c_str()); + source.Reply(NICK_SASET_PASSWORD_CHANGED, u->Account()->display.c_str()); return MOD_CONT; } diff --git a/modules/core/ns_set_autoop.cpp b/modules/core/ns_set_autoop.cpp index 7eef455b5..f99060fa6 100644 --- a/modules/core/ns_set_autoop.cpp +++ b/modules/core/ns_set_autoop.cpp @@ -20,8 +20,9 @@ class CommandNSSetAutoOp : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetAutoOp"); @@ -32,12 +33,12 @@ class CommandNSSetAutoOp : public Command if (param.equals_ci("ON")) { nc->SetFlag(NI_AUTOOP); - u->SendMessage(NickServ, NICK_SASET_AUTOOP_ON, nc->display.c_str()); + source.Reply(NICK_SASET_AUTOOP_ON, nc->display.c_str()); } else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_AUTOOP); - u->SendMessage(NickServ, NICK_SASET_AUTOOP_OFF, nc->display.c_str()); + source.Reply(NICK_SASET_AUTOOP_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "AUTOOP"); diff --git a/modules/core/ns_set_email.cpp b/modules/core/ns_set_email.cpp index fff93b633..4f1e67506 100644 --- a/modules/core/ns_set_email.cpp +++ b/modules/core/ns_set_email.cpp @@ -20,8 +20,9 @@ class CommandNSSetEmail : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetEmail"); @@ -31,29 +32,29 @@ class CommandNSSetEmail : public Command if (param.empty() && Config->NSForceEmail) { - u->SendMessage(NickServ, NICK_SET_EMAIL_UNSET_IMPOSSIBLE); + source.Reply(NICK_SET_EMAIL_UNSET_IMPOSSIBLE); return MOD_CONT; } else if (Config->NSSecureAdmins && u->Account() != nc && nc->IsServicesOper()) { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } else if (!param.empty() && !MailValidate(param)) { - u->SendMessage(NickServ, MAIL_X_INVALID, param.c_str()); + source.Reply(MAIL_X_INVALID, param.c_str()); return MOD_CONT; } if (!param.empty()) { nc->email = param; - u->SendMessage(NickServ, NICK_SASET_EMAIL_CHANGED, nc->display.c_str(), param.c_str()); + source.Reply(NICK_SASET_EMAIL_CHANGED, nc->display.c_str(), param.c_str()); } else { nc->email.clear(); - u->SendMessage(NickServ, NICK_SASET_EMAIL_UNSET, nc->display.c_str()); + source.Reply(NICK_SASET_EMAIL_UNSET, nc->display.c_str()); } return MOD_CONT; diff --git a/modules/core/ns_set_greet.cpp b/modules/core/ns_set_greet.cpp index e3fce8241..27bbf8655 100644 --- a/modules/core/ns_set_greet.cpp +++ b/modules/core/ns_set_greet.cpp @@ -20,7 +20,7 @@ class CommandNSSetGreet : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { NickAlias *na = findnick(params[0]); if (!na) @@ -32,12 +32,12 @@ class CommandNSSetGreet : public Command if (!param.empty()) { nc->greet = param; - u->SendMessage(NickServ, NICK_SASET_GREET_CHANGED, nc->display.c_str(), nc->greet.c_str()); + source.Reply(NICK_SASET_GREET_CHANGED, nc->display.c_str(), nc->greet.c_str()); } else { nc->greet.clear(); - u->SendMessage(NickServ, NICK_SASET_GREET_UNSET, nc->display.c_str()); + source.Reply(NICK_SASET_GREET_UNSET, nc->display.c_str()); } return MOD_CONT; diff --git a/modules/core/ns_set_hide.cpp b/modules/core/ns_set_hide.cpp index ef38c4345..2427c015b 100644 --- a/modules/core/ns_set_hide.cpp +++ b/modules/core/ns_set_hide.cpp @@ -20,8 +20,9 @@ class CommandNSSetHide : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetHide"); @@ -66,12 +67,12 @@ class CommandNSSetHide : public Command if (arg.equals_ci("ON")) { nc->SetFlag(flag); - u->SendMessage(NickServ, onmsg, nc->display.c_str(), Config->s_NickServ.c_str()); + source.Reply(onmsg, nc->display.c_str(), Config->s_NickServ.c_str()); } else if (arg.equals_ci("OFF")) { nc->UnsetFlag(flag); - u->SendMessage(NickServ, offmsg, nc->display.c_str(), Config->s_NickServ.c_str()); + source.Reply(offmsg, nc->display.c_str(), Config->s_NickServ.c_str()); } else this->OnSyntaxError(u, "HIDE"); diff --git a/modules/core/ns_set_kill.cpp b/modules/core/ns_set_kill.cpp index c0699799f..52696bf2b 100644 --- a/modules/core/ns_set_kill.cpp +++ b/modules/core/ns_set_kill.cpp @@ -20,8 +20,9 @@ class CommandNSSetKill : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetKill"); @@ -35,14 +36,14 @@ class CommandNSSetKill : public Command nc->SetFlag(NI_KILLPROTECT); nc->UnsetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - u->SendMessage(NickServ, NICK_SASET_KILL_ON, nc->display.c_str()); + source.Reply(NICK_SASET_KILL_ON, nc->display.c_str()); } else if (param.equals_ci("QUICK")) { nc->SetFlag(NI_KILLPROTECT); nc->SetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - u->SendMessage(NickServ, NICK_SASET_KILL_QUICK, nc->display.c_str()); + source.Reply(NICK_SASET_KILL_QUICK, nc->display.c_str()); } else if (param.equals_ci("IMMED")) { @@ -51,17 +52,17 @@ class CommandNSSetKill : public Command nc->SetFlag(NI_KILLPROTECT); nc->SetFlag(NI_KILL_IMMED); nc->UnsetFlag(NI_KILL_QUICK); - u->SendMessage(NickServ, NICK_SASET_KILL_IMMED, nc->display.c_str()); + source.Reply(NICK_SASET_KILL_IMMED, nc->display.c_str()); } else - u->SendMessage(NickServ, NICK_SET_KILL_IMMED_DISABLED); + source.Reply(NICK_SET_KILL_IMMED_DISABLED); } else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_KILLPROTECT); nc->UnsetFlag(NI_KILL_QUICK); nc->UnsetFlag(NI_KILL_IMMED); - u->SendMessage(NickServ, NICK_SASET_KILL_OFF, nc->display.c_str()); + source.Reply(NICK_SASET_KILL_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "KILL"); diff --git a/modules/core/ns_set_language.cpp b/modules/core/ns_set_language.cpp index 99229da62..2f6898aac 100644 --- a/modules/core/ns_set_language.cpp +++ b/modules/core/ns_set_language.cpp @@ -20,8 +20,9 @@ class CommandNSSetLanguage : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetLanguage"); @@ -55,7 +56,7 @@ class CommandNSSetLanguage : public Command const Anope::string &langname = GetString(languages[j], LANGUAGE_NAME); if (langname == "English") continue; - u->SendMessage(Config->s_NickServ, " %s (%s)", languages[j].c_str(), langname.c_str()); + u->SendMessage(" %s (%s)", languages[j].c_str(), langname.c_str()); } return true; diff --git a/modules/core/ns_set_message.cpp b/modules/core/ns_set_message.cpp index 781ab3901..be2e6d350 100644 --- a/modules/core/ns_set_message.cpp +++ b/modules/core/ns_set_message.cpp @@ -20,8 +20,9 @@ class CommandNSSetMessage : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetMessage"); @@ -29,21 +30,21 @@ class CommandNSSetMessage : public Command if (!Config->UsePrivmsg) { - u->SendMessage(NickServ, NICK_SET_OPTION_DISABLED, "MSG"); + source.Reply(NICK_SET_OPTION_DISABLED, "MSG"); return MOD_CONT; } - Anope::string param = params.size() > 1 ? params[1] : ""; + const Anope::string ¶m = params.size() > 1 ? params[1] : ""; if (param.equals_ci("ON")) { nc->SetFlag(NI_MSG); - u->SendMessage(NickServ, NICK_SASET_MSG_ON, nc->display.c_str()); + source.Reply(NICK_SASET_MSG_ON, nc->display.c_str()); } else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_MSG); - u->SendMessage(NickServ, NICK_SASET_MSG_OFF, nc->display.c_str()); + source.Reply(NICK_SASET_MSG_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "MSG"); diff --git a/modules/core/ns_set_private.cpp b/modules/core/ns_set_private.cpp index 8fddbe1c9..e14d3ad15 100644 --- a/modules/core/ns_set_private.cpp +++ b/modules/core/ns_set_private.cpp @@ -20,8 +20,9 @@ class CommandNSSetPrivate : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetPrivate"); @@ -32,12 +33,12 @@ class CommandNSSetPrivate : public Command if (param.equals_ci("ON")) { nc->SetFlag(NI_PRIVATE); - u->SendMessage(NickServ, NICK_SASET_PRIVATE_ON, nc->display.c_str()); + source.Reply(NICK_SASET_PRIVATE_ON, nc->display.c_str()); } else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_PRIVATE); - u->SendMessage(NickServ, NICK_SASET_PRIVATE_OFF, nc->display.c_str()); + source.Reply(NICK_SASET_PRIVATE_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "PRIVATE"); diff --git a/modules/core/ns_set_secure.cpp b/modules/core/ns_set_secure.cpp index e9ce159dc..54628a13c 100644 --- a/modules/core/ns_set_secure.cpp +++ b/modules/core/ns_set_secure.cpp @@ -20,8 +20,9 @@ class CommandNSSetSecure : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetSecure"); @@ -32,12 +33,12 @@ class CommandNSSetSecure : public Command if (param.equals_ci("ON")) { nc->SetFlag(NI_SECURE); - u->SendMessage(NickServ, NICK_SASET_SECURE_ON, nc->display.c_str()); + source.Reply(NICK_SASET_SECURE_ON, nc->display.c_str()); } else if (param.equals_ci("OFF")) { nc->UnsetFlag(NI_SECURE); - u->SendMessage(NickServ, NICK_SASET_SECURE_OFF, nc->display.c_str()); + source.Reply(NICK_SASET_SECURE_OFF, nc->display.c_str()); } else this->OnSyntaxError(u, "SECURE"); diff --git a/modules/core/ns_status.cpp b/modules/core/ns_status.cpp index dd18d58e6..c33ace94d 100644 --- a/modules/core/ns_status.cpp +++ b/modules/core/ns_status.cpp @@ -21,29 +21,30 @@ class CommandNSStatus : public Command this->SetFlag(CFLAG_ALLOW_UNREGISTERED); } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - User *u2; - Anope::string nick = !params.empty() ? params[0] : u->nick; + User *u = source.u; + const Anope::string &nick = !params.empty() ? params[0] : u->nick; NickAlias *na = findnick(nick); spacesepstream sep(nick); Anope::string nickbuf; while (sep.GetToken(nickbuf)) { - if (!(u2 = finduser(nickbuf))) /* Nick is not online */ - u->SendMessage(NickServ, NICK_STATUS_REPLY, nickbuf.c_str(), 0, ""); + User *u2 = finduser(nickbuf); + if (!u2) /* Nick is not online */ + source.Reply(NICK_STATUS_REPLY, nickbuf.c_str(), 0, ""); else if (u2->IsIdentified() && na && na->nc == u2->Account()) /* Nick is identified */ - u->SendMessage(NickServ, NICK_STATUS_REPLY, nickbuf.c_str(), 3, u2->Account()->display.c_str()); + source.Reply(NICK_STATUS_REPLY, nickbuf.c_str(), 3, u2->Account()->display.c_str()); else if (u2->IsRecognized()) /* Nick is recognised, but NOT identified */ - u->SendMessage(NickServ, NICK_STATUS_REPLY, nickbuf.c_str(), 2, u2->Account() ? u2->Account()->display.c_str() : ""); + source.Reply(NICK_STATUS_REPLY, nickbuf.c_str(), 2, u2->Account() ? u2->Account()->display.c_str() : ""); else if (!na) /* Nick is online, but NOT a registered */ - u->SendMessage(NickServ, NICK_STATUS_REPLY, nickbuf.c_str(), 0, ""); + source.Reply(NICK_STATUS_REPLY, nickbuf.c_str(), 0, ""); else /* Nick is not identified for the nick, but they could be logged into an account, * so we tell the user about it */ - u->SendMessage(NickServ, NICK_STATUS_REPLY, nickbuf.c_str(), 1, u2->Account() ? u2->Account()->display.c_str() : ""); + source.Reply(NICK_STATUS_REPLY, nickbuf.c_str(), 1, u2->Account() ? u2->Account()->display.c_str() : ""); } return MOD_CONT; } diff --git a/modules/core/ns_suspend.cpp b/modules/core/ns_suspend.cpp index 08c134870..9d636ac85 100644 --- a/modules/core/ns_suspend.cpp +++ b/modules/core/ns_suspend.cpp @@ -20,34 +20,35 @@ class CommandNSSuspend : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - NickAlias *na; - User *u2; - Anope::string nick = params[0]; - Anope::string reason = params[1]; + User *u = source.u; + + const Anope::string &nick = params[0]; + const Anope::string &reason = params[1]; if (readonly) { - u->SendMessage(NickServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - if (!(na = findnick(nick))) + NickAlias *na = findnick(nick); + if (!na) { - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } if (Config->NSSecureAdmins && na->nc->IsServicesOper()) { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } @@ -65,7 +66,8 @@ class CommandNSSuspend : public Command { na2->last_quit = reason; - if ((u2 = finduser(na2->nick))) + User *u2 = finduser(na2->nick); + if (u2) { u2->Logout(); u2->Collide(na2); @@ -108,32 +110,33 @@ class CommandNSUnSuspend : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - NickAlias *na; - Anope::string nick = params[0]; + User *u = source.u; + const Anope::string &nick = params[0]; if (readonly) { - u->SendMessage(NickServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - if (!(na = findnick(nick))) + NickAlias *na = findnick(nick); + if (!na) { - u->SendMessage(NickServ, NICK_X_NOT_REGISTERED, nick.c_str()); + source.Reply(NICK_X_NOT_REGISTERED, nick.c_str()); return MOD_CONT; } if (na->HasFlag(NS_FORBIDDEN)) { - u->SendMessage(NickServ, NICK_X_FORBIDDEN, na->nick.c_str()); + source.Reply(NICK_X_FORBIDDEN, na->nick.c_str()); return MOD_CONT; } if (Config->NSSecureAdmins && na->nc->IsServicesOper()) { - u->SendMessage(NickServ, ACCESS_DENIED); + source.Reply(ACCESS_DENIED); return MOD_CONT; } diff --git a/modules/core/ns_update.cpp b/modules/core/ns_update.cpp index bbfad2b45..0ce918be1 100644 --- a/modules/core/ns_update.cpp +++ b/modules/core/ns_update.cpp @@ -20,8 +20,9 @@ class CommandNSUpdate : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(u->nick); if (!na) diff --git a/modules/core/os_akill.cpp b/modules/core/os_akill.cpp index fa1dca356..e35c6264d 100644 --- a/modules/core/os_akill.cpp +++ b/modules/core/os_akill.cpp @@ -15,21 +15,21 @@ class AkillDelCallback : public NumberList { - User *u; + CommandSource &source; unsigned Deleted; public: - AkillDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + AkillDelCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), source(_source), Deleted(0) { } ~AkillDelCallback() { if (!Deleted) - u->SendMessage(OperServ, OPER_AKILL_NO_MATCH); + source.Reply(OPER_AKILL_NO_MATCH); else if (Deleted == 1) - u->SendMessage(OperServ, OPER_AKILL_DELETED_ONE); + source.Reply(OPER_AKILL_DELETED_ONE); else - u->SendMessage(OperServ, OPER_AKILL_DELETED_SEVERAL, Deleted); + source.Reply(OPER_AKILL_DELETED_SEVERAL, Deleted); } void HandleNumber(unsigned Number) @@ -43,10 +43,10 @@ class AkillDelCallback : public NumberList return; ++Deleted; - DoDel(u, x); + DoDel(source, x); } - static void DoDel(User *u, XLine *x) + static void DoDel(CommandSource &source, XLine *x) { SGLine->DelXLine(x); } @@ -55,19 +55,19 @@ class AkillDelCallback : public NumberList class AkillListCallback : public NumberList { protected: - User *u; + CommandSource &source; bool SentHeader; public: - AkillListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + AkillListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false) { } ~AkillListCallback() { if (!SentHeader) - u->SendMessage(OperServ, OPER_AKILL_NO_MATCH); + source.Reply(OPER_AKILL_NO_MATCH); else - u->SendMessage(OperServ, END_OF_ANY_LIST, "Akill"); + source.Reply(END_OF_ANY_LIST, "Akill"); } void HandleNumber(unsigned Number) @@ -83,22 +83,22 @@ class AkillListCallback : public NumberList if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_AKILL_LIST_HEADER); + source.Reply(OPER_AKILL_LIST_HEADER); } - DoList(u, x, Number); + DoList(source, x, Number); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - u->SendMessage(OperServ, OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); + source.Reply(OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); } }; class AkillViewCallback : public AkillListCallback { public: - AkillViewCallback(User *_u, const Anope::string &numlist) : AkillListCallback(_u, numlist) + AkillViewCallback(CommandSource &_source, const Anope::string &numlist) : AkillListCallback(_source, numlist) { } @@ -115,23 +115,24 @@ class AkillViewCallback : public AkillListCallback if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_AKILL_VIEW_HEADER); + source.Reply(OPER_AKILL_VIEW_HEADER); } - DoList(u, x, Number); + DoList(source, x, Number); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - u->SendMessage(OperServ, OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expire_left(u->Account(), x->Expires).c_str(), x->Reason.c_str()); + source.Reply(OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expire_left(source.u->Account(), x->Expires).c_str(), x->Reason.c_str()); } }; class CommandOSAKill : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; unsigned last_param = 2; Anope::string expiry, mask; time_t expires; @@ -153,7 +154,7 @@ class CommandOSAKill : public Command /* Do not allow less than a minute expiry time */ if (expires && expires < 60) { - u->SendMessage(OperServ, BAD_EXPIRY_TIME); + source.Reply(BAD_EXPIRY_TIME); return MOD_CONT; } else if (expires > 0) @@ -181,7 +182,7 @@ class CommandOSAKill : public Command if (percent > 95) { - u->SendMessage(OperServ, USERHOST_MASK_TOO_WIDE, mask.c_str()); + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); Log(LOG_ADMIN, u, this) << "tried to akill " << percent << "% of the network (" << affected << " users)"; return MOD_CONT; } @@ -191,7 +192,7 @@ class CommandOSAKill : public Command if (!x) return MOD_CONT; - u->SendMessage(OperServ, OPER_AKILL_ADDED, mask.c_str()); + source.Reply(OPER_AKILL_ADDED, mask.c_str()); if (Config->WallOSAkill) { @@ -227,7 +228,7 @@ class CommandOSAKill : public Command } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); } else this->OnSyntaxError(u, "ADD"); @@ -235,9 +236,10 @@ class CommandOSAKill : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mask = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (mask.empty()) { @@ -247,13 +249,13 @@ class CommandOSAKill : public Command if (SGLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_LIST_EMPTY); + source.Reply(OPER_LIST_EMPTY); return MOD_CONT; } if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkillDelCallback list(u, mask); + AkillDelCallback list(source, mask); list.Process(); } else @@ -262,35 +264,35 @@ class CommandOSAKill : public Command if (!x) { - u->SendMessage(OperServ, OPER_AKILL_NOT_FOUND, mask.c_str()); + source.Reply(OPER_AKILL_NOT_FOUND, mask.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnDelAkill, OnDelAkill(u, x)); - AkillDelCallback::DoDel(u, x); - u->SendMessage(OperServ, OPER_AKILL_DELETED, mask.c_str()); + AkillDelCallback::DoDel(source, x); + source.Reply(OPER_AKILL_DELETED, mask.c_str()); } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SGLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_LIST_EMPTY); + source.Reply(OPER_LIST_EMPTY); return MOD_CONT; } - Anope::string mask = params.size() > 1 ? params[1] : ""; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkillListCallback list(u, mask); + AkillListCallback list(source, mask); list.Process(); } else @@ -306,35 +308,35 @@ class CommandOSAKill : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_AKILL_LIST_HEADER); + source.Reply(OPER_AKILL_LIST_HEADER); } - AkillListCallback::DoList(u, x, i); + AkillListCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_AKILL_NO_MATCH); + source.Reply(OPER_AKILL_NO_MATCH); else - u->SendMessage(OperServ, END_OF_ANY_LIST, "Akill"); + source.Reply(END_OF_ANY_LIST, "Akill"); } return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoView(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SGLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_LIST_EMPTY); + source.Reply(OPER_LIST_EMPTY); return MOD_CONT; } - Anope::string mask = params.size() > 1 ? params[1] : ""; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - AkillViewCallback list(u, mask); + AkillViewCallback list(source, mask); list.Process(); } else @@ -350,22 +352,23 @@ class CommandOSAKill : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_AKILL_VIEW_HEADER); + source.Reply(OPER_AKILL_VIEW_HEADER); } - AkillViewCallback::DoList(u, x, i); + AkillViewCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_AKILL_NO_MATCH); + source.Reply(OPER_AKILL_NO_MATCH); } return MOD_CONT; } - CommandReturn DoClear(User *u) + CommandReturn DoClear(CommandSource &source) { + User *u = source.u; FOREACH_MOD(I_OnDelAkill, OnDelAkill(u, NULL)); SGLine->Clear(); u->SendMessage(OperServ, OPER_AKILL_CLEAR); @@ -377,22 +380,24 @@ class CommandOSAKill : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; if (cmd.equals_ci("ADD")) - return this->DoAdd(u, params); + return this->DoAdd(source, params); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, params); + return this->DoDel(source, params); else if (cmd.equals_ci("LIST")) - return this->DoList(u, params); + return this->DoList(source, params); else if (cmd.equals_ci("VIEW")) - return this->DoView(u, params); + return this->DoView(source, params); else if (cmd.equals_ci("CLEAR")) - return this->DoClear(u); + return this->DoClear(source); else this->OnSyntaxError(u, ""); + return MOD_CONT; } diff --git a/modules/core/os_chankill.cpp b/modules/core/os_chankill.cpp index 7bed3220e..ee4e1abc1 100644 --- a/modules/core/os_chankill.cpp +++ b/modules/core/os_chankill.cpp @@ -20,8 +20,9 @@ class CommandOSChanKill : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; Anope::string expiry, channel; time_t expires; unsigned last_param = 1; @@ -40,7 +41,7 @@ class CommandOSChanKill : public Command expires *= 86400; if (expires && expires < 60) { - u->SendMessage(OperServ, BAD_EXPIRY_TIME); + source.Reply(BAD_EXPIRY_TIME); return MOD_CONT; } else if (expires > 0) @@ -79,7 +80,7 @@ class CommandOSChanKill : public Command ircdproto->SendGlobops(OperServ, "%s used CHANKILL on %s (%s)", u->nick.c_str(), channel.c_str(), realreason.c_str()); } else - u->SendMessage(OperServ, CHAN_X_NOT_IN_USE, channel.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, channel.c_str()); } return MOD_CONT; } diff --git a/modules/core/os_chanlist.cpp b/modules/core/os_chanlist.cpp index a8527a9df..20be8b9db 100644 --- a/modules/core/os_chanlist.cpp +++ b/modules/core/os_chanlist.cpp @@ -20,10 +20,11 @@ class CommandOSChanList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string pattern = !params.empty() ? params[0] : ""; - Anope::string opt = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &pattern = !params.empty() ? params[0] : ""; + const Anope::string &opt = params.size() > 1 ? params[1] : ""; std::list<ChannelModeName> Modes; User *u2; @@ -35,7 +36,7 @@ class CommandOSChanList : public Command if (!pattern.empty() && (u2 = finduser(pattern))) { - u->SendMessage(OperServ, OPER_CHANLIST_HEADER_USER, u2->nick.c_str()); + source.Reply(OPER_CHANLIST_HEADER_USER, u2->nick.c_str()); for (UChannelList::iterator uit = u2->chans.begin(), uit_end = u2->chans.end(); uit != uit_end; ++uit) { @@ -46,12 +47,12 @@ class CommandOSChanList : public Command if (!cc->chan->HasMode(*it)) continue; - u->SendMessage(OperServ, OPER_CHANLIST_RECORD, cc->chan->name.c_str(), cc->chan->users.size(), cc->chan->GetModes(true, true).c_str(), !cc->chan->topic.empty() ? cc->chan->topic.c_str() : ""); + source.Reply(OPER_CHANLIST_RECORD, cc->chan->name.c_str(), cc->chan->users.size(), cc->chan->GetModes(true, true).c_str(), !cc->chan->topic.empty() ? cc->chan->topic.c_str() : ""); } } else { - u->SendMessage(OperServ, OPER_CHANLIST_HEADER); + source.Reply(OPER_CHANLIST_HEADER); for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) { @@ -64,7 +65,7 @@ class CommandOSChanList : public Command if (!c->HasMode(*it)) continue; - u->SendMessage(OperServ, OPER_CHANLIST_RECORD, c->name.c_str(), c->users.size(), c->GetModes(true, true).c_str(), !c->topic.empty() ? c->topic.c_str() : ""); + source.Reply(OPER_CHANLIST_RECORD, c->name.c_str(), c->users.size(), c->GetModes(true, true).c_str(), !c->topic.empty() ? c->topic.c_str() : ""); } } diff --git a/modules/core/os_defcon.cpp b/modules/core/os_defcon.cpp index cfc8ebe62..963326296 100644 --- a/modules/core/os_defcon.cpp +++ b/modules/core/os_defcon.cpp @@ -59,14 +59,15 @@ class CommandOSDefcon : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string lvl = params[0]; + User *u = source.u; + const Anope::string &lvl = params[0]; int newLevel = 0; if (lvl.empty()) { - u->SendMessage(OperServ, OPER_DEFCON_CHANGED, Config->DefConLevel); + source.Reply(OPER_DEFCON_CHANGED, Config->DefConLevel); defcon_sendlvls(u); return MOD_CONT; } @@ -210,7 +211,7 @@ class OSDefcon : public Module if (!is_oper(u) && (CheckDefCon(DEFCON_OPER_ONLY) || CheckDefCon(DEFCON_SILENT_OPER_ONLY))) { if (!CheckDefCon(DEFCON_SILENT_OPER_ONLY)) - u->SendMessage(bi, OPER_DEFCON_DENIED); + u->SendMessage(OperServ, OPER_DEFCON_DENIED); return EVENT_STOP; } @@ -226,7 +227,7 @@ class OSDefcon : public Module { if (CheckDefCon(DEFCON_NO_NEW_NICKS)) { - u->SendMessage(NickServ, OPER_DEFCON_DENIED); + u->SendMessage(service, OPER_DEFCON_DENIED); return EVENT_STOP; } } @@ -237,7 +238,7 @@ class OSDefcon : public Module { if (!params.empty() && params[0].equals_ci("MLOCK") && CheckDefCon(DEFCON_NO_MLOCK_CHANGE)) { - u->SendMessage(ChanServ, OPER_DEFCON_DENIED); + u->SendMessage(service, OPER_DEFCON_DENIED); return EVENT_STOP; } } @@ -245,7 +246,7 @@ class OSDefcon : public Module { if (CheckDefCon(DEFCON_NO_NEW_CHANNELS)) { - u->SendMessage(ChanServ, OPER_DEFCON_DENIED); + u->SendMessage(service, OPER_DEFCON_DENIED); return EVENT_STOP; } } @@ -256,7 +257,7 @@ class OSDefcon : public Module { if (CheckDefCon(DEFCON_NO_NEW_MEMOS)) { - u->SendMessage(MemoServ, OPER_DEFCON_DENIED); + u->SendMessage(service, OPER_DEFCON_DENIED); return EVENT_STOP; } } diff --git a/modules/core/os_global.cpp b/modules/core/os_global.cpp index a63e211cd..6a9bdee1d 100644 --- a/modules/core/os_global.cpp +++ b/modules/core/os_global.cpp @@ -20,9 +20,10 @@ class CommandOSGlobal : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string msg = params[0]; + User *u = source.u; + const Anope::string &msg = params[0]; if (Config->WallOSGlobal) ircdproto->SendGlobops(OperServ, "\2%s\2 just used GLOBAL command.", u->nick.c_str()); diff --git a/modules/core/os_help.cpp b/modules/core/os_help.cpp index a626ddf28..26aff62ea 100644 --- a/modules/core/os_help.cpp +++ b/modules/core/os_help.cpp @@ -20,9 +20,9 @@ class CommandOSHelp : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - mod_help_cmd(OperServ, u, params[0]); + mod_help_cmd(OperServ, source.u, params[0]); return MOD_CONT; } diff --git a/modules/core/os_ignore.cpp b/modules/core/os_ignore.cpp index 38fc716fd..0c2669179 100644 --- a/modules/core/os_ignore.cpp +++ b/modules/core/os_ignore.cpp @@ -16,11 +16,12 @@ class CommandOSIgnore : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string time = params.size() > 1 ? params[1] : ""; - Anope::string nick = params.size() > 2 ? params[2] : ""; - time_t t; + const Anope::string &time = params.size() > 1 ? params[1] : ""; + const Anope::string &nick = params.size() > 2 ? params[2] : ""; + + User *u = source.u; if (time.empty() || nick.empty()) { @@ -29,45 +30,48 @@ class CommandOSIgnore : public Command } else { - t = dotime(time); + time_t t = dotime(time); if (t <= -1) { - u->SendMessage(OperServ, OPER_IGNORE_VALID_TIME); + source.Reply(OPER_IGNORE_VALID_TIME); return MOD_CONT; } else if (!t) { add_ignore(nick, t); - u->SendMessage(OperServ, OPER_IGNORE_PERM_DONE, nick.c_str()); + source.Reply(OPER_IGNORE_PERM_DONE, nick.c_str()); } else { add_ignore(nick, t); - u->SendMessage(OperServ, OPER_IGNORE_TIME_DONE, nick.c_str(), time.c_str()); + source.Reply(OPER_IGNORE_TIME_DONE, nick.c_str(), time.c_str()); } } return MOD_CONT; } - CommandReturn DoList(User *u) + CommandReturn DoList(CommandSource &source) { if (ignore.empty()) { - u->SendMessage(OperServ, OPER_IGNORE_LIST_EMPTY); + source.Reply(OPER_IGNORE_LIST_EMPTY); return MOD_CONT; } + User *u = source.u; + u->SendMessage(OperServ, OPER_IGNORE_LIST); for (std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end(); ign != ign_end; ++ign) - u->SendMessage(Config->s_OperServ, "%s", (*ign)->mask.c_str()); + source.Reply("%s", (*ign)->mask.c_str()); return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; Anope::string nick = params.size() > 1 ? params[1] : ""; if (nick.empty()) this->OnSyntaxError(u, "DEL"); @@ -75,17 +79,18 @@ class CommandOSIgnore : public Command { if (delete_ignore(nick)) { - u->SendMessage(OperServ, OPER_IGNORE_DEL_DONE, nick.c_str()); + source.Reply(OPER_IGNORE_DEL_DONE, nick.c_str()); return MOD_CONT; } - u->SendMessage(OperServ, OPER_IGNORE_LIST_NOMATCH, nick.c_str()); + source.Reply(OPER_IGNORE_LIST_NOMATCH, nick.c_str()); } return MOD_CONT; } - CommandReturn DoClear(User *u) + CommandReturn DoClear(CommandSource &source) { + User *u = source.u; clear_ignores(); u->SendMessage(OperServ, OPER_IGNORE_LIST_CLEARED); @@ -96,18 +101,19 @@ class CommandOSIgnore : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; if (cmd.equals_ci("ADD")) - return this->DoAdd(u, params); + return this->DoAdd(source, params); else if (cmd.equals_ci("LIST")) - return this->DoList(u); + return this->DoList(source); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, params); + return this->DoDel(source, params); else if (cmd.equals_ci("CLEAR")) - return this->DoClear(u); + return this->DoClear(source); else this->OnSyntaxError(u, ""); diff --git a/modules/core/os_jupe.cpp b/modules/core/os_jupe.cpp index c12f6e754..333fbf35e 100644 --- a/modules/core/os_jupe.cpp +++ b/modules/core/os_jupe.cpp @@ -20,16 +20,17 @@ class CommandOSJupe : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string jserver = params[0]; - Anope::string reason = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &jserver = params[0]; + const Anope::string &reason = params.size() > 1 ? params[1] : ""; Server *server = Server::Find(jserver); if (!isValidHost(jserver, 3)) - u->SendMessage(OperServ, OPER_JUPE_HOST_ERROR); + source.Reply(OPER_JUPE_HOST_ERROR); else if (server && (server == Me || server == Me->GetLinks().front())) - u->SendMessage(OperServ, OPER_JUPE_INVALID_SERVER); + source.Reply(OPER_JUPE_INVALID_SERVER); else { Anope::string rbuf = "Juped by " + u->nick + (!reason.empty() ? ": " + reason : ""); diff --git a/modules/core/os_kick.cpp b/modules/core/os_kick.cpp index a1fc22d02..93acb3f52 100644 --- a/modules/core/os_kick.cpp +++ b/modules/core/os_kick.cpp @@ -20,25 +20,28 @@ class CommandOSKick : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0], nick = params[1], s = params[2]; + User *u = source.u; + const Anope::string &chan = params[0]; + const Anope::string &nick = params[1]; + const Anope::string &s = params[2]; Channel *c; User *u2; if (!(c = findchan(chan))) { - u->SendMessage(OperServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); return MOD_CONT; } else if (c->bouncy_modes) { - u->SendMessage(OperServ, OPER_BOUNCY_MODES_U_LINE); + source.Reply(OPER_BOUNCY_MODES_U_LINE); return MOD_CONT; } else if (!(u2 = finduser(nick))) { - u->SendMessage(OperServ, NICK_X_NOT_IN_USE, nick.c_str()); + source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); return MOD_CONT; } diff --git a/modules/core/os_mode.cpp b/modules/core/os_mode.cpp index 64f4a6329..046e31162 100644 --- a/modules/core/os_mode.cpp +++ b/modules/core/os_mode.cpp @@ -20,15 +20,17 @@ class CommandOSMode : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0], modes = params[1]; + User *u = source.u; + const Anope::string &chan = params[0]; + const Anope::string &modes = params[1]; Channel *c; if (!(c = findchan(chan))) - u->SendMessage(OperServ, CHAN_X_NOT_IN_USE, chan.c_str()); + source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); else if (c->bouncy_modes) - u->SendMessage(OperServ, OPER_BOUNCY_MODES_U_LINE); + source.Reply(OPER_BOUNCY_MODES_U_LINE); else { c->SetModes(OperServ, false, modes.c_str()); diff --git a/modules/core/os_modinfo.cpp b/modules/core/os_modinfo.cpp index 218599f47..464519d1b 100644 --- a/modules/core/os_modinfo.cpp +++ b/modules/core/os_modinfo.cpp @@ -13,33 +13,53 @@ #include "module.h" -static int showModuleCmdLoaded(BotInfo *bi, const Anope::string &mod_name, User *u); class CommandOSModInfo : public Command { + int showModuleCmdLoaded(BotInfo *bi, const Anope::string &mod_name, CommandSource &source) + { + if (!bi) + return 0; + + int display = 0; + + for (CommandMap::iterator it = bi->Commands.begin(), it_end = bi->Commands.end(); it != it_end; ++it) + { + Command *c = it->second; + + if (c->module && c->module->name.equals_ci(mod_name) && c->service) + { + source.Reply(OPER_MODULE_CMD_LIST, c->service->nick.c_str(), c->name.c_str()); + ++display; + } + } + + return display; + } + public: CommandOSModInfo() : Command("MODINFO", 1, 1) { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string file = params[0]; + const Anope::string &file = params[0]; Module *m = FindModule(file); if (m) { - u->SendMessage(OperServ, OPER_MODULE_INFO_LIST, m->name.c_str(), !m->version.empty() ? m->version.c_str() : "?", !m->author.empty() ? m->author.c_str() : "?", do_strftime(m->created).c_str()); - - showModuleCmdLoaded(HostServ, m->name, u); - showModuleCmdLoaded(OperServ, m->name, u); - showModuleCmdLoaded(NickServ, m->name, u); - showModuleCmdLoaded(ChanServ, m->name, u); - showModuleCmdLoaded(BotServ, m->name, u); - showModuleCmdLoaded(MemoServ, m->name, u); + source.Reply(OPER_MODULE_INFO_LIST, m->name.c_str(), !m->version.empty() ? m->version.c_str() : "?", !m->author.empty() ? m->author.c_str() : "?", do_strftime(m->created).c_str()); + + showModuleCmdLoaded(HostServ, m->name, source); + showModuleCmdLoaded(OperServ, m->name, source); + showModuleCmdLoaded(NickServ, m->name, source); + showModuleCmdLoaded(ChanServ, m->name, source); + showModuleCmdLoaded(BotServ, m->name, source); + showModuleCmdLoaded(MemoServ, m->name, source); } else - u->SendMessage(OperServ, OPER_MODULE_NO_INFO, file.c_str()); + source.Reply(OPER_MODULE_NO_INFO, file.c_str()); return MOD_CONT; } @@ -75,24 +95,4 @@ class OSModInfo : public Module } }; -static int showModuleCmdLoaded(BotInfo *bi, const Anope::string &mod_name, User *u) -{ - if (!bi) - return 0; - - int display = 0; - - for (CommandMap::iterator it = bi->Commands.begin(), it_end = bi->Commands.end(); it != it_end; ++it) - { - Command *c = it->second; - - if (c->module && c->module->name.equals_ci(mod_name) && c->service) - { - u->SendMessage(OperServ, OPER_MODULE_CMD_LIST, c->service->nick.c_str(), c->name.c_str()); - ++display; - } - } - return display; -} - MODULE_INIT(OSModInfo) diff --git a/modules/core/os_modlist.cpp b/modules/core/os_modlist.cpp index 78c777a7a..9071e1052 100644 --- a/modules/core/os_modlist.cpp +++ b/modules/core/os_modlist.cpp @@ -20,8 +20,11 @@ class CommandOSModList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + const Anope::string ¶m = !params.empty() ? params[0] : ""; + int count = 0; int showCore = 0; int showThird = 1; @@ -32,8 +35,6 @@ class CommandOSModList : public Command int showDB = 1; int showSocketEngine = 1; - Anope::string param = !params.empty() ? params[0] : ""; - char core[] = "Core"; char third[] = "3rd"; char proto[] = "Protocol"; @@ -140,56 +141,56 @@ class CommandOSModList : public Command case CORE: if (showCore) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), core); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), core); ++count; } break; case THIRD: if (showThird) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), third); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), third); ++count; } break; case PROTOCOL: if (showProto) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), proto); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), proto); ++count; } break; case SUPPORTED: if (showSupported) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), supported); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), supported); ++count; } break; case QATESTED: if (showQA) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), qa); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), qa); ++count; } break; case ENCRYPTION: if (showEnc) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), enc); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), enc); ++count; } break; case DATABASE: if (showDB) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), db); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), db); ++count; } break; case SOCKETENGINE: if (showSocketEngine) { - u->SendMessage(OperServ, OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), socketengine); + source.Reply(OPER_MODULE_LIST, m->name.c_str(), m->version.c_str(), socketengine); ++count; } break; @@ -198,9 +199,9 @@ class CommandOSModList : public Command } } if (!count) - u->SendMessage(OperServ, OPER_MODULE_NO_LIST); + source.Reply(OPER_MODULE_NO_LIST); else - u->SendMessage(OperServ, OPER_MODULE_LIST_FOOTER, count); + source.Reply(OPER_MODULE_LIST_FOOTER, count); return MOD_CONT; } diff --git a/modules/core/os_modload.cpp b/modules/core/os_modload.cpp index 385353993..bec69bf36 100644 --- a/modules/core/os_modload.cpp +++ b/modules/core/os_modload.cpp @@ -20,14 +20,15 @@ class CommandOSModLoad : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mname = params[0]; + User *u = source.u; + const Anope::string &mname = params[0]; Module *m = FindModule(mname); if (m) { - u->SendMessage(OperServ, OPER_MODULE_ALREADY_LOADED, mname.c_str()); + source.Reply(OPER_MODULE_ALREADY_LOADED, mname.c_str()); return MOD_CONT; } @@ -35,7 +36,7 @@ class CommandOSModLoad : public Command if (status == MOD_ERR_OK) { ircdproto->SendGlobops(OperServ, "%s loaded module %s", u->nick.c_str(), mname.c_str()); - u->SendMessage(OperServ, OPER_MODULE_LOADED, mname.c_str()); + source.Reply(OPER_MODULE_LOADED, mname.c_str()); /* If a user is loading this module, then the core databases have already been loaded * so trigger the event manually @@ -45,7 +46,7 @@ class CommandOSModLoad : public Command m->OnPostLoadDatabases(); } else - u->SendMessage(OperServ, OPER_MODULE_LOAD_FAIL, mname.c_str()); + source.Reply(OPER_MODULE_LOAD_FAIL, mname.c_str()); return MOD_CONT; } diff --git a/modules/core/os_modreload.cpp b/modules/core/os_modreload.cpp index efbc680af..e91391a2c 100644 --- a/modules/core/os_modreload.cpp +++ b/modules/core/os_modreload.cpp @@ -20,26 +20,27 @@ class CommandOSModReLoad : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mname = params[0]; + User *u = source.u; + const Anope::string &mname = params[0]; Module *m = FindModule(mname); if (!m) { - u->SendMessage(OperServ, OPER_MODULE_ISNT_LOADED, mname.c_str()); + source.Reply(OPER_MODULE_ISNT_LOADED, mname.c_str()); return MOD_CONT; } if (!m->handle) { - u->SendMessage(OperServ, OPER_MODULE_REMOVE_FAIL, m->name.c_str()); + source.Reply(OPER_MODULE_REMOVE_FAIL, m->name.c_str()); return MOD_CONT; } if (m->GetPermanent()) { - u->SendMessage(OperServ, OPER_MODULE_NO_UNLOAD); + source.Reply(OPER_MODULE_NO_UNLOAD); return MOD_CONT; } @@ -49,7 +50,7 @@ class CommandOSModReLoad : public Command if (status != MOD_ERR_OK) { - u->SendMessage(OperServ, OPER_MODULE_REMOVE_FAIL, mname.c_str()); + source.Reply(OPER_MODULE_REMOVE_FAIL, mname.c_str()); return MOD_CONT; } @@ -57,7 +58,7 @@ class CommandOSModReLoad : public Command if (status == MOD_ERR_OK) { ircdproto->SendGlobops(OperServ, "%s reloaded module %s", u->nick.c_str(), mname.c_str()); - u->SendMessage(OperServ, OPER_MODULE_RELOADED, mname.c_str()); + source.Reply(OPER_MODULE_RELOADED, mname.c_str()); /* If a user is loading this module, then the core databases have already been loaded * so trigger the event manually @@ -71,7 +72,7 @@ class CommandOSModReLoad : public Command if (fatal) throw FatalException("Unable to reload module " + mname); else - u->SendMessage(OperServ, OPER_MODULE_LOAD_FAIL, mname.c_str()); + source.Reply(OPER_MODULE_LOAD_FAIL, mname.c_str()); } return MOD_CONT; diff --git a/modules/core/os_modunload.cpp b/modules/core/os_modunload.cpp index f8bbe0461..b47ad5998 100644 --- a/modules/core/os_modunload.cpp +++ b/modules/core/os_modunload.cpp @@ -20,26 +20,27 @@ class CommandOSModUnLoad : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mname = params[0]; + User *u = source.u; + const Anope::string &mname = params[0]; Module *m = FindModule(mname); if (!m) { - u->SendMessage(OperServ, OPER_MODULE_ISNT_LOADED, mname.c_str()); + source.Reply(OPER_MODULE_ISNT_LOADED, mname.c_str()); return MOD_CONT; } if (!m->handle) { - u->SendMessage(OperServ, OPER_MODULE_REMOVE_FAIL, m->name.c_str()); + source.Reply(OPER_MODULE_REMOVE_FAIL, m->name.c_str()); return MOD_CONT; } if (m->GetPermanent() || m->type == PROTOCOL) { - u->SendMessage(OperServ, OPER_MODULE_NO_UNLOAD); + source.Reply(OPER_MODULE_NO_UNLOAD); return MOD_CONT; } @@ -49,11 +50,11 @@ class CommandOSModUnLoad : public Command if (status == MOD_ERR_OK) { - u->SendMessage(OperServ, OPER_MODULE_UNLOADED, mname.c_str()); + source.Reply(OPER_MODULE_UNLOADED, mname.c_str()); ircdproto->SendGlobops(OperServ, "%s unloaded module %s", u->nick.c_str(), mname.c_str()); } else - u->SendMessage(OperServ, OPER_MODULE_REMOVE_FAIL, mname.c_str()); + source.Reply(OPER_MODULE_REMOVE_FAIL, mname.c_str()); return MOD_CONT; } diff --git a/modules/core/os_news.cpp b/modules/core/os_news.cpp index 237d5c66b..d62904d3b 100644 --- a/modules/core/os_news.cpp +++ b/modules/core/os_news.cpp @@ -95,7 +95,7 @@ static void DisplayNews(User *u, NewsType Type) if (Type == NEWS_RANDOM && i == current_news) continue; - u->SendMessage(Global ? Global : NickServ, msg, do_strftime(News[i]->time).c_str(), News[i]->Text.c_str()); + u->SendMessage(OperServ, msg, do_strftime(News[i]->time).c_str(), News[i]->Text.c_str()); ++displayed; @@ -114,7 +114,7 @@ static void DisplayNews(User *u, NewsType Type) } } -static int add_newsitem(User *u, const Anope::string &text, NewsType type) +static int add_newsitem(CommandSource &source, const Anope::string &text, NewsType type) { int num = 0; @@ -130,7 +130,7 @@ static int add_newsitem(User *u, const Anope::string &text, NewsType type) news->num = num + 1; news->Text = text; news->time = Anope::CurTime; - news->who = u->nick; + news->who = source.u->nick; News.push_back(news); @@ -166,7 +166,7 @@ static LanguageString *findmsgs(NewsType type, Anope::string &type_name) class NewsBase : public Command { protected: - CommandReturn DoList(User *u, NewsType type, LanguageString *msgs) + CommandReturn DoList(CommandSource &source, NewsType type, LanguageString *msgs) { int count = 0; @@ -174,54 +174,54 @@ class NewsBase : public Command if (News[i]->type == type) { if (!count) - u->SendMessage(OperServ, msgs[MSG_LIST_HEADER]); - u->SendMessage(OperServ, NEWS_LIST_ENTRY, News[i]->num, do_strftime(News[i]->time).c_str(), !News[i]->who.empty() ? News[i]->who.c_str() : "<unknown>", News[i]->Text.c_str()); + source.Reply(msgs[MSG_LIST_HEADER]); + source.Reply(NEWS_LIST_ENTRY, News[i]->num, do_strftime(News[i]->time).c_str(), !News[i]->who.empty() ? News[i]->who.c_str() : "<unknown>", News[i]->Text.c_str()); ++count; } if (!count) - u->SendMessage(OperServ, msgs[MSG_LIST_NONE]); + source.Reply(msgs[MSG_LIST_NONE]); else - u->SendMessage(OperServ, END_OF_ANY_LIST, "News"); + source.Reply(END_OF_ANY_LIST, "News"); return MOD_CONT; } - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms, NewsType type, LanguageString *msgs) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms, NewsType type, LanguageString *msgs) { - Anope::string text = params.size() > 1 ? params[1] : ""; + const Anope::string text = params.size() > 1 ? params[1] : ""; int n; if (text.empty()) - this->OnSyntaxError(u, "ADD"); + this->OnSyntaxError(source.u, "ADD"); else { if (readonly) { - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - n = add_newsitem(u, text, type); + n = add_newsitem(source, text, type); if (n < 0) - u->SendMessage(OperServ, NEWS_ADD_FULL); + source.Reply(NEWS_ADD_FULL); else - u->SendMessage(OperServ, msgs[MSG_ADDED], n); + source.Reply(msgs[MSG_ADDED], n); } return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms, NewsType type, LanguageString *msgs) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms, NewsType type, LanguageString *msgs) { - Anope::string text = params.size() > 1 ? params[1] : ""; + const Anope::string &text = params.size() > 1 ? params[1] : ""; unsigned num; if (text.empty()) - this->OnSyntaxError(u, "DEL"); + this->OnSyntaxError(source.u, "DEL"); else { if (readonly) { - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } if (!text.equals_ci("ALL")) @@ -229,29 +229,29 @@ class NewsBase : public Command num = text.is_pos_number_only() ? convertTo<unsigned>(text) : 0; if (num > 0 && del_newsitem(num, type)) { - u->SendMessage(OperServ, msgs[MSG_DELETED], num); + source.Reply(msgs[MSG_DELETED], num); for (unsigned i = 0, end = News.size(); i < end; ++i) if (News[i]->type == type && News[i]->num > num) --News[i]->num; } else - u->SendMessage(OperServ, msgs[MSG_DEL_NOT_FOUND], num); + source.Reply(msgs[MSG_DEL_NOT_FOUND], num); } else { if (del_newsitem(0, type)) - u->SendMessage(OperServ, msgs[MSG_DELETED_ALL]); + source.Reply(msgs[MSG_DELETED_ALL]); else - u->SendMessage(OperServ, msgs[MSG_DEL_NONE]); + source.Reply(msgs[MSG_DEL_NONE]); } } return MOD_CONT; } - CommandReturn DoNews(User *u, const std::vector<Anope::string> ¶ms, NewsType type) + CommandReturn DoNews(CommandSource &source, const std::vector<Anope::string> ¶ms, NewsType type) { - Anope::string cmd = params[0]; + const Anope::string &cmd = params[0]; Anope::string type_name; LanguageString *msgs = findmsgs(type, type_name); @@ -259,13 +259,13 @@ class NewsBase : public Command throw CoreException("news: Invalid type to do_news()"); if (cmd.equals_ci("LIST")) - return this->DoList(u, type, msgs); + return this->DoList(source, type, msgs); else if (cmd.equals_ci("ADD")) - return this->DoAdd(u, params, type, msgs); + return this->DoAdd(source, params, type, msgs); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, params, type, msgs); + return this->DoDel(source, params, type, msgs); else - this->OnSyntaxError(u, ""); + this->OnSyntaxError(source.u, ""); return MOD_CONT; } @@ -278,7 +278,7 @@ class NewsBase : public Command { } - virtual CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) = 0; + virtual CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) = 0; virtual bool OnHelp(User *u, const Anope::string &subcommand) = 0; @@ -292,9 +292,9 @@ class CommandOSLogonNews : public NewsBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoNews(u, params, NEWS_LOGON); + return this->DoNews(source, params, NEWS_LOGON); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -321,9 +321,9 @@ class CommandOSOperNews : public NewsBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoNews(u, params, NEWS_OPER); + return this->DoNews(source, params, NEWS_OPER); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -350,9 +350,9 @@ class CommandOSRandomNews : public NewsBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoNews(u, params, NEWS_RANDOM); + return this->DoNews(source, params, NEWS_RANDOM); } bool OnHelp(User *u, const Anope::string &subcommand) diff --git a/modules/core/os_noop.cpp b/modules/core/os_noop.cpp index 32b03f63b..c6de2ddd2 100644 --- a/modules/core/os_noop.cpp +++ b/modules/core/os_noop.cpp @@ -20,10 +20,11 @@ class CommandOSNOOP : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; - Anope::string server = params[1]; + User *u = source.u; + const Anope::string &cmd = params[0]; + const Anope::string &server = params[1]; if (cmd.equals_ci("SET")) { @@ -35,7 +36,7 @@ class CommandOSNOOP : public Command reason = "NOOP command used by " + u->nick; if (Config->WallOSNoOp) ircdproto->SendGlobops(OperServ, "\2%s\2 used NOOP on \2%s\2", u->nick.c_str(), server.c_str()); - u->SendMessage(OperServ, OPER_NOOP_SET, server.c_str()); + source.Reply(OPER_NOOP_SET, server.c_str()); /* Kill all the IRCops of the server */ for (patricia_tree<User *>::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it) @@ -50,7 +51,7 @@ class CommandOSNOOP : public Command else if (cmd.equals_ci("REVOKE")) { ircdproto->SendSVSNOOP(server, 0); - u->SendMessage(OperServ, OPER_NOOP_REVOKE, server.c_str()); + source.Reply(OPER_NOOP_REVOKE, server.c_str()); } else this->OnSyntaxError(u, ""); diff --git a/modules/core/os_oline.cpp b/modules/core/os_oline.cpp index c7fd9b83d..c3d0e4cae 100644 --- a/modules/core/os_oline.cpp +++ b/modules/core/os_oline.cpp @@ -20,27 +20,28 @@ class CommandOSOLine : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - Anope::string flag = params[1]; + User *u = source.u; + const Anope::string &nick = params[0]; + const Anope::string &flag = params[1]; User *u2 = NULL; /* let's check whether the user is online */ if (!(u2 = finduser(nick))) - u->SendMessage(OperServ, NICK_X_NOT_IN_USE, nick.c_str()); + source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); else if (u2 && flag[0] == '+') { ircdproto->SendSVSO(Config->s_OperServ, nick, flag); u2->SetMode(OperServ, UMODE_OPER); u2->SendMessage(OperServ, OPER_OLINE_IRCOP); - u->SendMessage(OperServ, OPER_OLINE_SUCCESS, flag.c_str(), nick.c_str()); + source.Reply(OPER_OLINE_SUCCESS, flag.c_str(), nick.c_str()); ircdproto->SendGlobops(OperServ, "\2%s\2 used OLINE for %s", u->nick.c_str(), nick.c_str()); } else if (u2 && flag[0] == '-') { ircdproto->SendSVSO(Config->s_OperServ, nick, flag); - u->SendMessage(OperServ, OPER_OLINE_SUCCESS, flag.c_str(), nick.c_str()); + source.Reply(OPER_OLINE_SUCCESS, flag.c_str(), nick.c_str()); ircdproto->SendGlobops(OperServ, "\2%s\2 used OLINE for %s", u->nick.c_str(), nick.c_str()); } else diff --git a/modules/core/os_quit.cpp b/modules/core/os_quit.cpp index d133708a1..da02b2ed0 100644 --- a/modules/core/os_quit.cpp +++ b/modules/core/os_quit.cpp @@ -21,8 +21,9 @@ class CommandOSQuit : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; quitmsg = "QUIT command received from " + u->nick; if (Config->GlobalOnCycle) diff --git a/modules/core/os_reload.cpp b/modules/core/os_reload.cpp index a54e1c2ed..0c42a4955 100644 --- a/modules/core/os_reload.cpp +++ b/modules/core/os_reload.cpp @@ -20,8 +20,10 @@ class CommandOSReload : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + try { ServerConfig *newconfig = new ServerConfig(); diff --git a/modules/core/os_restart.cpp b/modules/core/os_restart.cpp index 62cfb0a37..77fba8a50 100644 --- a/modules/core/os_restart.cpp +++ b/modules/core/os_restart.cpp @@ -20,8 +20,9 @@ class CommandOSRestart : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; quitmsg = "RESTART command received from " + u->nick; if (Config->GlobalOnCycle) diff --git a/modules/core/os_session.cpp b/modules/core/os_session.cpp index ffaea047f..0e2b4fbfd 100644 --- a/modules/core/os_session.cpp +++ b/modules/core/os_session.cpp @@ -16,21 +16,22 @@ class ExceptionDelCallback : public NumberList { protected: + CommandSource &source; User *u; unsigned Deleted; public: - ExceptionDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + ExceptionDelCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), source(_source), Deleted(0) { } ~ExceptionDelCallback() { if (!Deleted) - u->SendMessage(OperServ, OPER_EXCEPTION_NO_MATCH); + source.Reply(OPER_EXCEPTION_NO_MATCH); else if (Deleted == 1) - u->SendMessage(OperServ, OPER_EXCEPTION_DELETED_ONE); + source.Reply(OPER_EXCEPTION_DELETED_ONE); else - u->SendMessage(OperServ, OPER_EXCEPTION_DELETED_SEVERAL, Deleted); + source.Reply(OPER_EXCEPTION_DELETED_SEVERAL, Deleted); } virtual void HandleNumber(unsigned Number) @@ -55,10 +56,10 @@ class ExceptionDelCallback : public NumberList class ExceptionListCallback : public NumberList { protected: - User *u; + CommandSource &source; bool SentHeader; public: - ExceptionListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + ExceptionListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false) { } @@ -70,11 +71,11 @@ class ExceptionListCallback : public NumberList if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_EXCEPTION_LIST_HEADER); - u->SendMessage(OperServ, OPER_EXCEPTION_LIST_COLHEAD); + source.Reply(OPER_EXCEPTION_LIST_HEADER); + source.Reply(OPER_EXCEPTION_LIST_COLHEAD); } - DoList(u, Number - 1); + DoList(source.u, Number - 1); } static void DoList(User *u, unsigned index) @@ -89,7 +90,7 @@ class ExceptionListCallback : public NumberList class ExceptionViewCallback : public ExceptionListCallback { public: - ExceptionViewCallback(User *_u, const Anope::string &numlist) : ExceptionListCallback(_u, numlist) + ExceptionViewCallback(CommandSource &_source, const Anope::string &numlist) : ExceptionListCallback(_source, numlist) { } @@ -101,10 +102,10 @@ class ExceptionViewCallback : public ExceptionListCallback if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_EXCEPTION_LIST_HEADER); + source.Reply(OPER_EXCEPTION_LIST_HEADER); } - DoList(u, Number - 1); + DoList(source.u, Number - 1); } static void DoList(User *u, unsigned index) @@ -121,42 +122,42 @@ class ExceptionViewCallback : public ExceptionListCallback class CommandOSSession : public Command { private: - CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { Anope::string param = params[1]; unsigned mincount = param.is_pos_number_only() ? convertTo<unsigned>(param) : 0; if (mincount <= 1) - u->SendMessage(OperServ, OPER_SESSION_INVALID_THRESHOLD); + source.Reply(OPER_SESSION_INVALID_THRESHOLD); else { - u->SendMessage(OperServ, OPER_SESSION_LIST_HEADER, mincount); - u->SendMessage(OperServ, OPER_SESSION_LIST_COLHEAD); + source.Reply(OPER_SESSION_LIST_HEADER, mincount); + source.Reply(OPER_SESSION_LIST_COLHEAD); for (patricia_tree<Session *>::const_iterator it = SessionList.begin(), it_end = SessionList.end(); it != it_end; ++it) { Session *session = *it; if (session->count >= mincount) - u->SendMessage(OperServ, OPER_SESSION_LIST_FORMAT, session->count, session->host.c_str()); + source.Reply(OPER_SESSION_LIST_FORMAT, session->count, session->host.c_str()); } } return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoView(CommandSource &source, const std::vector<Anope::string> ¶ms) { Anope::string param = params[1]; Session *session = findsession(param); if (!session) - u->SendMessage(OperServ, OPER_SESSION_NOT_FOUND, param.c_str()); + source.Reply(OPER_SESSION_NOT_FOUND, param.c_str()); else { Exception *exception = find_host_exception(param); - u->SendMessage(OperServ, OPER_SESSION_VIEW_FORMAT, param.c_str(), session->count, exception ? exception-> limit : Config->DefSessionLimit); + source.Reply(OPER_SESSION_VIEW_FORMAT, param.c_str(), session->count, exception ? exception-> limit : Config->DefSessionLimit); } return MOD_CONT; @@ -166,22 +167,24 @@ class CommandOSSession : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; if (!Config->LimitSessions) { - u->SendMessage(OperServ, OPER_EXCEPTION_DISABLED); + source.Reply(OPER_EXCEPTION_DISABLED); return MOD_CONT; } if (cmd.equals_ci("LIST")) - return this->DoList(u, params); + return this->DoList(source, params); else if (cmd.equals_ci("VIEW")) - return this->DoView(u, params); + return this->DoView(source, params); else this->OnSyntaxError(u, ""); + return MOD_CONT; } @@ -205,8 +208,9 @@ class CommandOSSession : public Command class CommandOSException : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; Anope::string mask, expiry, limitstr; unsigned last_param = 3; int x; @@ -239,7 +243,7 @@ class CommandOSException : public Command time_t expires = !expiry.empty() ? dotime(expiry) : Config->ExceptionExpiry; if (expires < 0) { - u->SendMessage(OperServ, BAD_EXPIRY_TIME); + source.Reply(BAD_EXPIRY_TIME); return MOD_CONT; } else if (expires > 0) @@ -249,32 +253,33 @@ class CommandOSException : public Command if (limit < 0 || limit > static_cast<int>(Config->MaxSessionLimit)) { - u->SendMessage(OperServ, OPER_EXCEPTION_INVALID_LIMIT, Config->MaxSessionLimit); + source.Reply(OPER_EXCEPTION_INVALID_LIMIT, Config->MaxSessionLimit); return MOD_CONT; } else { if (mask.find('!') == Anope::string::npos || mask.find('@') == Anope::string::npos) { - u->SendMessage(OperServ, OPER_EXCEPTION_INVALID_HOSTMASK); + source.Reply(OPER_EXCEPTION_INVALID_HOSTMASK); return MOD_CONT; } x = exception_add(u, mask, limit, reason, u->nick, expires); if (x == 1) - u->SendMessage(OperServ, OPER_EXCEPTION_ADDED, mask.c_str(), limit); + source.Reply(OPER_EXCEPTION_ADDED, mask.c_str(), limit); if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); } return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mask = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (mask.empty()) { @@ -284,7 +289,7 @@ class CommandOSException : public Command if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - ExceptionDelCallback list(u, mask); + ExceptionDelCallback list(source, mask); list.Process(); } else @@ -294,23 +299,25 @@ class CommandOSException : public Command if (mask.equals_ci(exceptions[i]->mask)) { ExceptionDelCallback::DoDel(u, i); - u->SendMessage(OperServ, OPER_EXCEPTION_DELETED, mask.c_str()); + source.Reply(OPER_EXCEPTION_DELETED, mask.c_str()); break; } if (i == end) - u->SendMessage(OperServ, OPER_EXCEPTION_NOT_FOUND, mask.c_str()); + source.Reply(OPER_EXCEPTION_NOT_FOUND, mask.c_str()); } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - CommandReturn DoMove(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoMove(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string n1str = params.size() > 1 ? params[1] : ""; /* From position */ - Anope::string n2str = params.size() > 2 ? params[2] : ""; /* To position */ + User *u = source.u; + + const Anope::string &n1str = params.size() > 1 ? params[1] : ""; /* From position */ + const Anope::string &n2str = params.size() > 2 ? params[2] : ""; /* To position */ int n1, n2; if (n2str.empty()) @@ -328,10 +335,10 @@ class CommandOSException : public Command exceptions[n1] = exceptions[n2]; exceptions[n2] = temp; - u->SendMessage(OperServ, OPER_EXCEPTION_MOVED, exceptions[n1]->mask.c_str(), n1 + 1, n2 + 1); + source.Reply(OPER_EXCEPTION_MOVED, exceptions[n1]->mask.c_str(), n1 + 1, n2 + 1); if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); } else this->OnSyntaxError(u, "MOVE"); @@ -339,14 +346,15 @@ class CommandOSException : public Command return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; expire_exceptions(); Anope::string mask = params.size() > 1 ? params[1] : ""; if (!mask.empty() && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - ExceptionListCallback list(u, mask); + ExceptionListCallback list(source, mask); list.Process(); } else @@ -359,28 +367,29 @@ class CommandOSException : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_EXCEPTION_LIST_HEADER); - u->SendMessage(OperServ, OPER_EXCEPTION_LIST_COLHEAD); + source.Reply(OPER_EXCEPTION_LIST_HEADER); + source.Reply(OPER_EXCEPTION_LIST_COLHEAD); } ExceptionListCallback::DoList(u, i); } if (!SentHeader) - u->SendMessage(OperServ, OPER_EXCEPTION_NO_MATCH); + source.Reply(OPER_EXCEPTION_NO_MATCH); } return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoView(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; expire_exceptions(); Anope::string mask = params.size() > 1 ? params[1] : ""; if (!mask.empty() && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - ExceptionViewCallback list(u, mask); + ExceptionViewCallback list(source, mask); list.Process(); } else @@ -393,14 +402,14 @@ class CommandOSException : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_EXCEPTION_LIST_HEADER); + source.Reply(OPER_EXCEPTION_LIST_HEADER); } ExceptionViewCallback::DoList(u, i); } if (!SentHeader) - u->SendMessage(OperServ, OPER_EXCEPTION_NO_MATCH); + source.Reply(OPER_EXCEPTION_NO_MATCH); } return MOD_CONT; @@ -410,28 +419,30 @@ class CommandOSException : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; if (!Config->LimitSessions) { - u->SendMessage(OperServ, OPER_EXCEPTION_DISABLED); + source.Reply(OPER_EXCEPTION_DISABLED); return MOD_CONT; } if (cmd.equals_ci("ADD")) - return this->DoAdd(u, params); + return this->DoAdd(source, params); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, params); + return this->DoDel(source, params); else if (cmd.equals_ci("MOVE")) - return this->DoMove(u, params); + return this->DoMove(source, params); else if (cmd.equals_ci("LIST")) - return this->DoList(u, params); + return this->DoList(source, params); else if (cmd.equals_ci("VIEW")) - return this->DoView(u, params); + return this->DoView(source, params); else this->OnSyntaxError(u, ""); + return MOD_CONT; } diff --git a/modules/core/os_set.cpp b/modules/core/os_set.cpp index db216b410..3c2a800b2 100644 --- a/modules/core/os_set.cpp +++ b/modules/core/os_set.cpp @@ -16,27 +16,28 @@ class CommandOSSet : public Command { private: - CommandReturn DoList(User *u) + CommandReturn DoList(CommandSource &source) { - Log(LOG_ADMIN, u, this); + Log(LOG_ADMIN, source.u, this); LanguageString index; index = allow_ignore ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF; - u->SendMessage(OperServ, index, "IGNORE"); + source.Reply(index, "IGNORE"); index = readonly ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF; - u->SendMessage(OperServ, index, "READONLY"); + source.Reply(index, "READONLY"); index = debug ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF; - u->SendMessage(OperServ, index, "DEBUG"); + source.Reply(index, "DEBUG"); index = noexpire ? OPER_SET_LIST_OPTION_ON : OPER_SET_LIST_OPTION_OFF; - u->SendMessage(OperServ, index, "NOEXPIRE"); + source.Reply(index, "NOEXPIRE"); return MOD_CONT; } - CommandReturn DoSetIgnore(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoSetIgnore(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string setting = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -46,25 +47,26 @@ class CommandOSSet : public Command if (setting.equals_ci("ON")) { - Log(LOG_ADMIN, u, this) << "IGNORE ON"; + Log(LOG_ADMIN, u, this) << "ON"; allow_ignore = 1; - u->SendMessage(OperServ, OPER_SET_IGNORE_ON); + source.Reply(OPER_SET_IGNORE_ON); } else if (setting.equals_ci("OFF")) { - Log(LOG_ADMIN, u, this) << "IGNORE OFF"; + Log(LOG_ADMIN, u, this) << "OFF"; allow_ignore = 0; - u->SendMessage(OperServ, OPER_SET_IGNORE_OFF); + source.Reply(OPER_SET_IGNORE_OFF); } else - u->SendMessage(OperServ, OPER_SET_IGNORE_ERROR); + source.Reply(OPER_SET_IGNORE_ERROR); return MOD_CONT; } - CommandReturn DoSetReadOnly(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoSetReadOnly(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string setting = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -76,23 +78,24 @@ class CommandOSSet : public Command { readonly = true; Log(LOG_ADMIN, u, this) << "READONLY ON"; - u->SendMessage(OperServ, OPER_SET_READONLY_ON); + source.Reply(OPER_SET_READONLY_ON); } else if (setting.equals_ci("OFF")) { readonly = false; Log(LOG_ADMIN, u, this) << "READONLY OFF"; - u->SendMessage(OperServ, OPER_SET_READONLY_OFF); + source.Reply(OPER_SET_READONLY_OFF); } else - u->SendMessage(OperServ, OPER_SET_READONLY_ERROR); + source.Reply(OPER_SET_READONLY_ERROR); return MOD_CONT; } - CommandReturn DoSetSuperAdmin(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoSetSuperAdmin(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string setting = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -106,30 +109,31 @@ class CommandOSSet : public Command * Rob **/ if (!Config->SuperAdmin) - u->SendMessage(OperServ, OPER_SUPER_ADMIN_NOT_ENABLED); + source.Reply(OPER_SUPER_ADMIN_NOT_ENABLED); else if (setting.equals_ci("ON")) { u->isSuperAdmin = 1; - u->SendMessage(OperServ, OPER_SUPER_ADMIN_ON); + source.Reply(OPER_SUPER_ADMIN_ON); Log(LOG_ADMIN, u, this) << "SUPERADMIN ON"; ircdproto->SendGlobops(OperServ, GetString(OPER_SUPER_ADMIN_WALL_ON).c_str(), u->nick.c_str()); } else if (setting.equals_ci("OFF")) { u->isSuperAdmin = 0; - u->SendMessage(OperServ, OPER_SUPER_ADMIN_OFF); + source.Reply(OPER_SUPER_ADMIN_OFF); Log(LOG_ADMIN, u, this) << "SUPERADMIN OFF"; ircdproto->SendGlobops(OperServ, GetString(OPER_SUPER_ADMIN_WALL_OFF).c_str(), u->nick.c_str()); } else - u->SendMessage(OperServ, OPER_SUPER_ADMIN_SYNTAX); + source.Reply(OPER_SUPER_ADMIN_SYNTAX); return MOD_CONT; } - CommandReturn DoSetDebug(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoSetDebug(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string setting = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -141,29 +145,30 @@ class CommandOSSet : public Command { debug = 1; Log(LOG_ADMIN, u, this) << "DEBUG ON"; - u->SendMessage(OperServ, OPER_SET_DEBUG_ON); + source.Reply(OPER_SET_DEBUG_ON); } else if (setting.equals_ci("OFF") || (setting[0] == '0' && setting.is_number_only() && !convertTo<int>(setting))) { Log(LOG_ADMIN, u, this) << "DEBUG OFF"; debug = 0; - u->SendMessage(OperServ, OPER_SET_DEBUG_OFF); + source.Reply(OPER_SET_DEBUG_OFF); } else if (setting.is_number_only() && convertTo<int>(setting) > 0) { debug = convertTo<int>(setting); Log(LOG_ADMIN, u, this) << "DEBUG " << debug; - u->SendMessage(OperServ, OPER_SET_DEBUG_LEVEL, debug); + source.Reply(OPER_SET_DEBUG_LEVEL, debug); } else - u->SendMessage(OperServ, OPER_SET_DEBUG_ERROR); + source.Reply(OPER_SET_DEBUG_ERROR); return MOD_CONT; } - CommandReturn DoSetNoExpire(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoSetNoExpire(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string setting = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &setting = params.size() > 1 ? params[1] : ""; if (setting.empty()) { @@ -175,16 +180,16 @@ class CommandOSSet : public Command { noexpire = true; Log(LOG_ADMIN, u, this) << "NOEXPIRE ON"; - u->SendMessage(OperServ, OPER_SET_NOEXPIRE_ON); + source.Reply(OPER_SET_NOEXPIRE_ON); } else if (setting.equals_ci("OFF")) { noexpire = false; Log(LOG_ADMIN, u, this) << "NOEXPIRE OFF"; - u->SendMessage(OperServ, OPER_SET_NOEXPIRE_OFF); + source.Reply(OPER_SET_NOEXPIRE_OFF); } else - u->SendMessage(OperServ, OPER_SET_NOEXPIRE_ERROR); + source.Reply(OPER_SET_NOEXPIRE_ERROR); return MOD_CONT; } @@ -193,24 +198,25 @@ class CommandOSSet : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string option = params[0]; + const Anope::string &option = params[0]; if (option.equals_ci("LIST")) - return this->DoList(u); + return this->DoList(source); else if (option.equals_ci("IGNORE")) - return this->DoSetIgnore(u, params); + return this->DoSetIgnore(source, params); else if (option.equals_ci("READONLY")) - return this->DoSetReadOnly(u, params); + return this->DoSetReadOnly(source, params); else if (option.equals_ci("SUPERADMIN")) - return this->DoSetSuperAdmin(u, params); + return this->DoSetSuperAdmin(source, params); else if (option.equals_ci("DEBUG")) - return this->DoSetDebug(u, params); + return this->DoSetDebug(source, params); else if (option.equals_ci("NOEXPIRE")) - return this->DoSetNoExpire(u, params); + return this->DoSetNoExpire(source, params); else - u->SendMessage(OperServ, OPER_SET_UNKNOWN_OPTION, option.c_str()); + source.Reply(OPER_SET_UNKNOWN_OPTION, option.c_str()); + return MOD_CONT; } @@ -222,12 +228,10 @@ class CommandOSSet : public Command u->SendMessage(OperServ, OPER_HELP_SET_LIST); else if (subcommand.equals_ci("READONLY")) u->SendMessage(OperServ, OPER_HELP_SET_READONLY); - else if (subcommand.equals_ci("DEBUG")) - u->SendMessage(OperServ, OPER_HELP_SET_DEBUG); else if (subcommand.equals_ci("NOEXPIRE")) u->SendMessage(OperServ, OPER_HELP_SET_NOEXPIRE); else if (subcommand.equals_ci("IGNORE")) - u->SendMessage(OperServ, OPER_HELP_SET_IGNORE); + u->SendMessage(OperServ,OPER_HELP_SET_IGNORE); else if (subcommand.equals_ci("SUPERADMIN")) u->SendMessage(OperServ, OPER_HELP_SET_SUPERADMIN); else diff --git a/modules/core/os_shutdown.cpp b/modules/core/os_shutdown.cpp index ab12a02eb..b177678aa 100644 --- a/modules/core/os_shutdown.cpp +++ b/modules/core/os_shutdown.cpp @@ -20,8 +20,9 @@ class CommandOSShutdown : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; quitmsg = "SHUTDOWN command received from " + u->nick; if (Config->GlobalOnCycle) diff --git a/modules/core/os_snline.cpp b/modules/core/os_snline.cpp index 3a28b9427..214a8ee68 100644 --- a/modules/core/os_snline.cpp +++ b/modules/core/os_snline.cpp @@ -16,21 +16,21 @@ class SNLineDelCallback : public NumberList { - User *u; + CommandSource &source; unsigned Deleted; public: - SNLineDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + SNLineDelCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), source(_source), Deleted(0) { } ~SNLineDelCallback() { if (!Deleted) - u->SendMessage(OperServ, OPER_SNLINE_NO_MATCH); + source.Reply(OPER_SNLINE_NO_MATCH); else if (Deleted == 1) - u->SendMessage(OperServ, OPER_SNLINE_DELETED_ONE); + source.Reply(OPER_SNLINE_DELETED_ONE); else - u->SendMessage(OperServ, OPER_SNLINE_DELETED_SEVERAL, Deleted); + source.Reply(OPER_SNLINE_DELETED_SEVERAL, Deleted); } void HandleNumber(unsigned Number) @@ -44,10 +44,10 @@ class SNLineDelCallback : public NumberList return; ++Deleted; - DoDel(u, x); + DoDel(source, x); } - static void DoDel(User *u, XLine *x) + static void DoDel(CommandSource &source, XLine *x) { SNLine->DelXLine(x); } @@ -56,17 +56,17 @@ class SNLineDelCallback : public NumberList class SNLineListCallback : public NumberList { protected: - User *u; + CommandSource &source; bool SentHeader; public: - SNLineListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + SNLineListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false) { } ~SNLineListCallback() { if (!SentHeader) - u->SendMessage(OperServ, OPER_SNLINE_NO_MATCH); + source.Reply(OPER_SNLINE_NO_MATCH); } virtual void HandleNumber(unsigned Number) @@ -82,22 +82,22 @@ class SNLineListCallback : public NumberList if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SNLINE_LIST_HEADER); + source.Reply(OPER_SNLINE_LIST_HEADER); } - DoList(u, x, Number - 1); + DoList(source, x, Number - 1); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - u->SendMessage(OperServ, OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); + source.Reply(OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); } }; class SNLineViewCallback : public SNLineListCallback { public: - SNLineViewCallback(User *_u, const Anope::string &numlist) : SNLineListCallback(_u, numlist) + SNLineViewCallback(CommandSource &_source, const Anope::string &numlist) : SNLineListCallback(_source, numlist) { } @@ -114,24 +114,25 @@ class SNLineViewCallback : public SNLineListCallback if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SNLINE_VIEW_HEADER); + source.Reply(OPER_SNLINE_VIEW_HEADER); } - DoList(u, x, Number - 1); + DoList(source, x, Number - 1); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - Anope::string expirebuf = expire_left(u->Account(), x->Expires); - u->SendMessage(OperServ, OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expirebuf.c_str(), x->Reason.c_str()); + Anope::string expirebuf = expire_left(source.u->Account(), x->Expires); + source.Reply(OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expirebuf.c_str(), x->Reason.c_str()); } }; class CommandOSSNLine : public Command { private: - CommandReturn OnAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn OnAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; unsigned last_param = 2; Anope::string param, expiry; time_t expires; @@ -153,7 +154,7 @@ class CommandOSSNLine : public Command /* Do not allow less than a minute expiry time */ if (expires && expires < 60) { - u->SendMessage(OperServ, BAD_EXPIRY_TIME); + source.Reply(BAD_EXPIRY_TIME); return MOD_CONT; } else if (expires > 0) @@ -196,7 +197,7 @@ class CommandOSSNLine : public Command if (percent > 95) { - u->SendMessage(OperServ, USERHOST_MASK_TOO_WIDE, mask.c_str()); + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); Log(LOG_ADMIN, u, this) << "tried to SNLine " << percent << "% of the network (" << affected << " users)"; return MOD_CONT; } @@ -206,7 +207,7 @@ class CommandOSSNLine : public Command if (!x) return MOD_CONT; - u->SendMessage(OperServ, OPER_SNLINE_ADDED, mask.c_str()); + source.Reply(OPER_SNLINE_ADDED, mask.c_str()); if (Config->WallOSSNLine) { @@ -242,7 +243,7 @@ class CommandOSSNLine : public Command } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); } else @@ -251,15 +252,17 @@ class CommandOSSNLine : public Command return MOD_CONT; } - CommandReturn OnDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn OnDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + if (SNLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SNLINE_LIST_EMPTY); + source.Reply(OPER_SNLINE_LIST_EMPTY); return MOD_CONT; } - Anope::string mask = params.size() > 1 ? params[1] : ""; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (mask.empty()) { @@ -269,7 +272,7 @@ class CommandOSSNLine : public Command if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SNLineDelCallback list(u, mask); + SNLineDelCallback list(source, mask); list.Process(); } else @@ -278,35 +281,35 @@ class CommandOSSNLine : public Command if (!x) { - u->SendMessage(OperServ, OPER_SNLINE_NOT_FOUND, mask.c_str()); + source.Reply(OPER_SNLINE_NOT_FOUND, mask.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, X_SNLINE)); - SNLineDelCallback::DoDel(u, x); - u->SendMessage(OperServ, OPER_SNLINE_DELETED, mask.c_str()); + SNLineDelCallback::DoDel(source, x); + source.Reply(OPER_SNLINE_DELETED, mask.c_str()); } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - CommandReturn OnList(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn OnList(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SNLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SNLINE_LIST_EMPTY); + source.Reply(OPER_SNLINE_LIST_EMPTY); return MOD_CONT; } - Anope::string mask = params.size() > 1 ? params[1] : ""; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SNLineListCallback list(u, mask); + SNLineListCallback list(source, mask); list.Process(); } else @@ -322,35 +325,35 @@ class CommandOSSNLine : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SNLINE_LIST_HEADER); + source.Reply(OPER_SNLINE_LIST_HEADER); } - SNLineListCallback::DoList(u, x, i); + SNLineListCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_SNLINE_NO_MATCH); + source.Reply(OPER_SNLINE_NO_MATCH); else - u->SendMessage(OperServ, END_OF_ANY_LIST, "SNLine"); + source.Reply(END_OF_ANY_LIST, "SNLine"); } return MOD_CONT; } - CommandReturn OnView(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn OnView(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SNLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SNLINE_LIST_EMPTY); + source.Reply(OPER_SNLINE_LIST_EMPTY); return MOD_CONT; } - Anope::string mask = params.size() > 1 ? params[1] : ""; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SNLineViewCallback list(u, mask); + SNLineViewCallback list(source, mask); list.Process(); } else @@ -366,25 +369,26 @@ class CommandOSSNLine : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SNLINE_VIEW_HEADER); + source.Reply(OPER_SNLINE_VIEW_HEADER); } - SNLineViewCallback::DoList(u, x, i); + SNLineViewCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_SNLINE_NO_MATCH); + source.Reply(OPER_SNLINE_NO_MATCH); } return MOD_CONT; } - CommandReturn OnClear(User *u) + CommandReturn OnClear(CommandSource &source) { + User *u = source.u; FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, NULL, X_SNLINE)); SNLine->Clear(); - u->SendMessage(OperServ, OPER_SNLINE_CLEAR); + source.Reply(OPER_SNLINE_CLEAR); return MOD_CONT; } @@ -393,22 +397,24 @@ class CommandOSSNLine : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; if (cmd.equals_ci("ADD")) - return this->OnAdd(u, params); + return this->OnAdd(source, params); else if (cmd.equals_ci("DEL")) - return this->OnDel(u, params); + return this->OnDel(source, params); else if (cmd.equals_ci("LIST")) - return this->OnList(u, params); + return this->OnList(source, params); else if (cmd.equals_ci("VIEW")) - return this->OnView(u, params); + return this->OnView(source, params); else if (cmd.equals_ci("CLEAR")) - return this->OnClear(u); + return this->OnClear(source); else this->OnSyntaxError(u, ""); + return MOD_CONT; } diff --git a/modules/core/os_sqline.cpp b/modules/core/os_sqline.cpp index eb90f26d4..8d1e99634 100644 --- a/modules/core/os_sqline.cpp +++ b/modules/core/os_sqline.cpp @@ -15,21 +15,21 @@ class SQLineDelCallback : public NumberList { - User *u; + CommandSource &source; unsigned Deleted; public: - SQLineDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + SQLineDelCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), source(_source), Deleted(0) { } ~SQLineDelCallback() { if (!Deleted) - u->SendMessage(OperServ, OPER_SQLINE_NO_MATCH); + source.Reply(OPER_SQLINE_NO_MATCH); else if (Deleted == 1) - u->SendMessage(OperServ, OPER_SQLINE_DELETED_ONE); + source.Reply(OPER_SQLINE_DELETED_ONE); else - u->SendMessage(OperServ, OPER_SQLINE_DELETED_SEVERAL, Deleted); + source.Reply(OPER_SQLINE_DELETED_SEVERAL, Deleted); } void HandleNumber(unsigned Number) @@ -43,10 +43,10 @@ class SQLineDelCallback : public NumberList return; ++Deleted; - DoDel(u, x - 1); + DoDel(source, x - 1); } - static void DoDel(User *u, XLine *x) + static void DoDel(CommandSource &source, XLine *x) { SQLine->DelXLine(x); } @@ -55,17 +55,17 @@ class SQLineDelCallback : public NumberList class SQLineListCallback : public NumberList { protected: - User *u; + CommandSource &source; bool SentHeader; public: - SQLineListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + SQLineListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false) { } ~SQLineListCallback() { if (!SentHeader) - u->SendMessage(OperServ, OPER_SQLINE_NO_MATCH); + source.Reply(OPER_SQLINE_NO_MATCH); } virtual void HandleNumber(unsigned Number) @@ -81,22 +81,22 @@ class SQLineListCallback : public NumberList if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SQLINE_LIST_HEADER); + source.Reply(OPER_SQLINE_LIST_HEADER); } - DoList(u, x, Number - 1); + DoList(source, x, Number - 1); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - u->SendMessage(OperServ, OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); + source.Reply(OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); } }; class SQLineViewCallback : public SQLineListCallback { public: - SQLineViewCallback(User *_u, const Anope::string &numlist) : SQLineListCallback(_u, numlist) + SQLineViewCallback(CommandSource &_source, const Anope::string &numlist) : SQLineListCallback(_source, numlist) { } @@ -113,24 +113,25 @@ class SQLineViewCallback : public SQLineListCallback if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SQLINE_VIEW_HEADER); + source.Reply(OPER_SQLINE_VIEW_HEADER); } - DoList(u, x, Number); + DoList(source, x, Number); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - Anope::string expirebuf = expire_left(u->Account(), x->Expires); - u->SendMessage(OperServ, OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expirebuf.c_str(), x->Reason.c_str()); + Anope::string expirebuf = expire_left(source.u->Account(), x->Expires); + source.Reply(OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expirebuf.c_str(), x->Reason.c_str()); } }; class CommandOSSQLine : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; unsigned last_param = 2; Anope::string expiry, mask; time_t expires; @@ -152,7 +153,7 @@ class CommandOSSQLine : public Command /* Do not allow less than a minute expiry time */ if (expires && expires < 60) { - u->SendMessage(OperServ, BAD_EXPIRY_TIME); + source.Reply(BAD_EXPIRY_TIME); return MOD_CONT; } else if (expires > 0) @@ -180,7 +181,7 @@ class CommandOSSQLine : public Command if (percent > 95) { - u->SendMessage(OperServ, USERHOST_MASK_TOO_WIDE, mask.c_str()); + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); Log(LOG_ADMIN, u, this) << "tried to SQLine " << percent << "% of the network (" << affected << " users)"; return MOD_CONT; } @@ -189,7 +190,7 @@ class CommandOSSQLine : public Command if (!x) return MOD_CONT; - u->SendMessage(OperServ, OPER_SQLINE_ADDED, mask.c_str()); + source.Reply(OPER_SQLINE_ADDED, mask.c_str()); if (Config->WallOSSQLine) { @@ -225,7 +226,7 @@ class CommandOSSQLine : public Command } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); } else @@ -234,15 +235,17 @@ class CommandOSSQLine : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + if (SQLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SQLINE_LIST_EMPTY); + source.Reply(OPER_SQLINE_LIST_EMPTY); return MOD_CONT; } - Anope::string mask = params.size() > 1 ? params[1] : ""; + const Anope::string &mask = params.size() > 1 ? params[1] : ""; if (mask.empty()) { @@ -252,7 +255,7 @@ class CommandOSSQLine : public Command if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SQLineDelCallback list(u, mask); + SQLineDelCallback list(source, mask); list.Process(); } else @@ -261,27 +264,27 @@ class CommandOSSQLine : public Command if (!x) { - u->SendMessage(OperServ, OPER_SQLINE_NOT_FOUND, mask.c_str()); + source.Reply(OPER_SQLINE_NOT_FOUND, mask.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, X_SQLINE)); - SQLineDelCallback::DoDel(u, x); - u->SendMessage(OperServ, OPER_SQLINE_DELETED, mask.c_str()); + SQLineDelCallback::DoDel(source, x); + source.Reply(OPER_SQLINE_DELETED, mask.c_str()); } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SQLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SQLINE_LIST_EMPTY); + source.Reply(OPER_SQLINE_LIST_EMPTY); return MOD_CONT; } @@ -289,7 +292,7 @@ class CommandOSSQLine : public Command if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SQLineListCallback list(u, mask); + SQLineListCallback list(source, mask); list.Process(); } else @@ -305,27 +308,27 @@ class CommandOSSQLine : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SQLINE_LIST_HEADER); + source.Reply(OPER_SQLINE_LIST_HEADER); } - SQLineListCallback::DoList(u, x, i); + SQLineListCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_SQLINE_NO_MATCH); + source.Reply(OPER_SQLINE_NO_MATCH); else - u->SendMessage(OperServ, END_OF_ANY_LIST, "SQLine"); + source.Reply(END_OF_ANY_LIST, "SQLine"); } return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoView(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SQLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SQLINE_LIST_EMPTY); + source.Reply(OPER_SQLINE_LIST_EMPTY); return MOD_CONT; } @@ -333,7 +336,7 @@ class CommandOSSQLine : public Command if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SQLineViewCallback list(u, mask); + SQLineViewCallback list(source, mask); list.Process(); } else @@ -349,22 +352,23 @@ class CommandOSSQLine : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SQLINE_VIEW_HEADER); + source.Reply(OPER_SQLINE_VIEW_HEADER); } - SQLineViewCallback::DoList(u, x, i); + SQLineViewCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_SQLINE_NO_MATCH); + source.Reply(OPER_SQLINE_NO_MATCH); } return MOD_CONT; } - CommandReturn DoClear(User *u) + CommandReturn DoClear(CommandSource &source) { + User *u = source.u; FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, NULL, X_SQLINE)); SGLine->Clear(); u->SendMessage(OperServ, OPER_SQLINE_CLEAR); @@ -376,20 +380,21 @@ class CommandOSSQLine : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; if (cmd.equals_ci("ADD")) - return this->DoAdd(u, params); + return this->DoAdd(source, params); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, params); + return this->DoDel(source, params); else if (cmd.equals_ci("LIST")) - return this->DoList(u, params); + return this->DoList(source, params); else if (cmd.equals_ci("VIEW")) - return this->DoView(u, params); + return this->DoView(source, params); else if (cmd.equals_ci("CLEAR")) - return this->DoClear(u); + return this->DoClear(source); else this->OnSyntaxError(u, ""); return MOD_CONT; diff --git a/modules/core/os_staff.cpp b/modules/core/os_staff.cpp index 136e2ba4f..f938f2207 100644 --- a/modules/core/os_staff.cpp +++ b/modules/core/os_staff.cpp @@ -20,8 +20,9 @@ class CommandOSStaff : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; u->SendMessage(OperServ, OPER_STAFF_LIST_HEADER); for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = Config->Opers.begin(), it_end = Config->Opers.end(); it != it_end; ++it) @@ -41,13 +42,13 @@ class CommandOSStaff : public Command { found = 1; if (na->nick.equals_ci(u2->nick)) - u->SendMessage(OperServ, OPER_STAFF_FORMAT, '*', type.c_str(), u2->nick.c_str()); + source.Reply(OPER_STAFF_FORMAT, '*', type.c_str(), u2->nick.c_str()); else - u->SendMessage(OperServ, OPER_STAFF_AFORMAT, '*', type.c_str(), na->nick.c_str(), u2->nick.c_str()); + source.Reply(OPER_STAFF_AFORMAT, '*', type.c_str(), na->nick.c_str(), u2->nick.c_str()); } } if (!found) - u->SendMessage(OperServ, OPER_STAFF_FORMAT, ' ', type.c_str(), na->nick.c_str()); + source.Reply(OPER_STAFF_FORMAT, ' ', type.c_str(), na->nick.c_str()); } } diff --git a/modules/core/os_stats.cpp b/modules/core/os_stats.cpp index 295ec95f5..0e425c8ae 100644 --- a/modules/core/os_stats.cpp +++ b/modules/core/os_stats.cpp @@ -37,137 +37,139 @@ static int stats_count_servers(Server *s) class CommandOSStats : public Command { private: - CommandReturn DoStatsAkill(User *u) + CommandReturn DoStatsAkill(CommandSource &source) { int timeout; /* AKILLs */ - u->SendMessage(OperServ, OPER_STATS_AKILL_COUNT, SGLine->GetCount()); + source.Reply(OPER_STATS_AKILL_COUNT, SGLine->GetCount()); timeout = Config->AutokillExpiry + 59; if (timeout >= 172800) - u->SendMessage(OperServ, OPER_STATS_AKILL_EXPIRE_DAYS, timeout / 86400); + source.Reply(OPER_STATS_AKILL_EXPIRE_DAYS, timeout / 86400); else if (timeout >= 86400) - u->SendMessage(OperServ, OPER_STATS_AKILL_EXPIRE_DAY); + source.Reply(OPER_STATS_AKILL_EXPIRE_DAY); else if (timeout >= 7200) - u->SendMessage(OperServ, OPER_STATS_AKILL_EXPIRE_HOURS, timeout / 3600); + source.Reply(OPER_STATS_AKILL_EXPIRE_HOURS, timeout / 3600); else if (timeout >= 3600) - u->SendMessage(OperServ, OPER_STATS_AKILL_EXPIRE_HOUR); + source.Reply(OPER_STATS_AKILL_EXPIRE_HOUR); else if (timeout >= 120) - u->SendMessage(OperServ, OPER_STATS_AKILL_EXPIRE_MINS, timeout / 60); + source.Reply(OPER_STATS_AKILL_EXPIRE_MINS, timeout / 60); else if (timeout >= 60) - u->SendMessage(OperServ, OPER_STATS_AKILL_EXPIRE_MIN); + source.Reply(OPER_STATS_AKILL_EXPIRE_MIN); else - u->SendMessage(OperServ, OPER_STATS_AKILL_EXPIRE_NONE); + source.Reply(OPER_STATS_AKILL_EXPIRE_NONE); if (ircd->snline) { /* SNLINEs */ - u->SendMessage(OperServ, OPER_STATS_SNLINE_COUNT, SNLine->GetCount()); + source.Reply(OPER_STATS_SNLINE_COUNT, SNLine->GetCount()); timeout = Config->SNLineExpiry + 59; if (timeout >= 172800) - u->SendMessage(OperServ, OPER_STATS_SNLINE_EXPIRE_DAYS, timeout / 86400); + source.Reply(OPER_STATS_SNLINE_EXPIRE_DAYS, timeout / 86400); else if (timeout >= 86400) - u->SendMessage(OperServ, OPER_STATS_SNLINE_EXPIRE_DAY); + source.Reply(OPER_STATS_SNLINE_EXPIRE_DAY); else if (timeout >= 7200) - u->SendMessage(OperServ, OPER_STATS_SNLINE_EXPIRE_HOURS, timeout / 3600); + source.Reply(OPER_STATS_SNLINE_EXPIRE_HOURS, timeout / 3600); else if (timeout >= 3600) - u->SendMessage(OperServ, OPER_STATS_SNLINE_EXPIRE_HOUR); + source.Reply(OPER_STATS_SNLINE_EXPIRE_HOUR); else if (timeout >= 120) - u->SendMessage(OperServ, OPER_STATS_SNLINE_EXPIRE_MINS, timeout / 60); + source.Reply(OPER_STATS_SNLINE_EXPIRE_MINS, timeout / 60); else if (timeout >= 60) - u->SendMessage(OperServ, OPER_STATS_SNLINE_EXPIRE_MIN); + source.Reply(OPER_STATS_SNLINE_EXPIRE_MIN); else - u->SendMessage(OperServ, OPER_STATS_SNLINE_EXPIRE_NONE); + source.Reply(OPER_STATS_SNLINE_EXPIRE_NONE); } if (ircd->sqline) { /* SQLINEs */ - u->SendMessage(OperServ, OPER_STATS_SQLINE_COUNT, SQLine->GetCount()); + source.Reply(OPER_STATS_SQLINE_COUNT, SQLine->GetCount()); timeout = Config->SQLineExpiry + 59; if (timeout >= 172800) - u->SendMessage(OperServ, OPER_STATS_SQLINE_EXPIRE_DAYS, timeout / 86400); + source.Reply(OPER_STATS_SQLINE_EXPIRE_DAYS, timeout / 86400); else if (timeout >= 86400) - u->SendMessage(OperServ, OPER_STATS_SQLINE_EXPIRE_DAY); + source.Reply(OPER_STATS_SQLINE_EXPIRE_DAY); else if (timeout >= 7200) - u->SendMessage(OperServ, OPER_STATS_SQLINE_EXPIRE_HOURS, timeout / 3600); + source.Reply(OPER_STATS_SQLINE_EXPIRE_HOURS, timeout / 3600); else if (timeout >= 3600) - u->SendMessage(OperServ, OPER_STATS_SQLINE_EXPIRE_HOUR); + source.Reply(OPER_STATS_SQLINE_EXPIRE_HOUR); else if (timeout >= 120) - u->SendMessage(OperServ, OPER_STATS_SQLINE_EXPIRE_MINS, timeout / 60); + source.Reply(OPER_STATS_SQLINE_EXPIRE_MINS, timeout / 60); else if (timeout >= 60) - u->SendMessage(OperServ, OPER_STATS_SQLINE_EXPIRE_MIN); + source.Reply(OPER_STATS_SQLINE_EXPIRE_MIN); else - u->SendMessage(OperServ, OPER_STATS_SQLINE_EXPIRE_NONE); + source.Reply(OPER_STATS_SQLINE_EXPIRE_NONE); } if (ircd->szline) { /* SZLINEs */ - u->SendMessage(OperServ, OPER_STATS_SZLINE_COUNT, SZLine->GetCount()); + source.Reply(OPER_STATS_SZLINE_COUNT, SZLine->GetCount()); timeout = Config->SZLineExpiry + 59; if (timeout >= 172800) - u->SendMessage(OperServ, OPER_STATS_SZLINE_EXPIRE_DAYS, timeout / 86400); + source.Reply(OPER_STATS_SZLINE_EXPIRE_DAYS, timeout / 86400); else if (timeout >= 86400) - u->SendMessage(OperServ, OPER_STATS_SZLINE_EXPIRE_DAY); + source.Reply(OPER_STATS_SZLINE_EXPIRE_DAY); else if (timeout >= 7200) - u->SendMessage(OperServ, OPER_STATS_SZLINE_EXPIRE_HOURS, timeout / 3600); + source.Reply(OPER_STATS_SZLINE_EXPIRE_HOURS, timeout / 3600); else if (timeout >= 3600) - u->SendMessage(OperServ, OPER_STATS_SZLINE_EXPIRE_HOUR); + source.Reply(OPER_STATS_SZLINE_EXPIRE_HOUR); else if (timeout >= 120) - u->SendMessage(OperServ, OPER_STATS_SZLINE_EXPIRE_MINS, timeout / 60); + source.Reply(OPER_STATS_SZLINE_EXPIRE_MINS, timeout / 60); else if (timeout >= 60) - u->SendMessage(OperServ, OPER_STATS_SZLINE_EXPIRE_MIN); + source.Reply(OPER_STATS_SZLINE_EXPIRE_MIN); else - u->SendMessage(OperServ, OPER_STATS_SZLINE_EXPIRE_NONE); + source.Reply(OPER_STATS_SZLINE_EXPIRE_NONE); } return MOD_CONT; } - CommandReturn DoStatsReset(User *u) + CommandReturn DoStatsReset(CommandSource &source) { + User *u = source.u; maxusercnt = usercnt; u->SendMessage(OperServ, OPER_STATS_RESET); return MOD_CONT; } - CommandReturn DoStatsUptime(User *u) + CommandReturn DoStatsUptime(CommandSource &source) { + User *u = source.u; time_t uptime = Anope::CurTime - start_time; int days = uptime / 86400, hours = (uptime / 3600) % 24, mins = (uptime / 60) % 60, secs = uptime % 60; u->SendMessage(OperServ, OPER_STATS_CURRENT_USERS, usercnt, opcnt); u->SendMessage(OperServ, OPER_STATS_MAX_USERS, maxusercnt, do_strftime(maxusertime).c_str()); if (days > 1) - u->SendMessage(OperServ, OPER_STATS_UPTIME_DHMS, days, hours, mins, secs); + source.Reply(OPER_STATS_UPTIME_DHMS, days, hours, mins, secs); else if (days == 1) - u->SendMessage(OperServ, OPER_STATS_UPTIME_1DHMS, days, hours, mins, secs); + source.Reply(OPER_STATS_UPTIME_1DHMS, days, hours, mins, secs); else { if (hours > 1) { if (mins != 1) - u->SendMessage(OperServ, OPER_STATS_UPTIME_HMS, hours, mins); + source.Reply(OPER_STATS_UPTIME_HMS, hours, mins); else - u->SendMessage(OperServ, OPER_STATS_UPTIME_H1MS, hours, mins, secs); + source.Reply(OPER_STATS_UPTIME_H1MS, hours, mins, secs); } else if (hours == 1) { if (mins != 1) - u->SendMessage(OperServ, OPER_STATS_UPTIME_1HMS, hours, mins, secs); + source.Reply(OPER_STATS_UPTIME_1HMS, hours, mins, secs); else - u->SendMessage(OperServ, OPER_STATS_UPTIME_1H1MS, hours, mins, secs); + source.Reply(OPER_STATS_UPTIME_1H1MS, hours, mins, secs); } else { if (mins != 1) { if (secs != 1) - u->SendMessage(OperServ, OPER_STATS_UPTIME_MS, mins, secs); + source.Reply(OPER_STATS_UPTIME_MS, mins, secs); else - u->SendMessage(OperServ, OPER_STATS_UPTIME_M1S, mins, secs); + source.Reply(OPER_STATS_UPTIME_M1S, mins, secs); } else { if (secs != 1) - u->SendMessage(OperServ, OPER_STATS_UPTIME_1MS, mins, secs); + source.Reply(OPER_STATS_UPTIME_1MS, mins, secs); else - u->SendMessage(OperServ, OPER_STATS_UPTIME_1M1S, mins, secs); + source.Reply(OPER_STATS_UPTIME_1M1S, mins, secs); } } } @@ -175,7 +177,7 @@ class CommandOSStats : public Command return MOD_CONT; } - CommandReturn DoStatsUplink(User *u) + CommandReturn DoStatsUplink(CommandSource &source) { Anope::string buf; @@ -186,43 +188,43 @@ class CommandOSStats : public Command if (!buf.empty()) buf.erase(buf.begin()); - u->SendMessage(OperServ, OPER_STATS_UPLINK_SERVER, Me->GetLinks().front()->GetName().c_str()); - u->SendMessage(OperServ, OPER_STATS_UPLINK_CAPAB, buf.c_str()); - u->SendMessage(OperServ, OPER_STATS_UPLINK_SERVER_COUNT, stats_count_servers(Me->GetLinks().front())); + source.Reply(OPER_STATS_UPLINK_SERVER, Me->GetLinks().front()->GetName().c_str()); + source.Reply(OPER_STATS_UPLINK_CAPAB, buf.c_str()); + source.Reply(OPER_STATS_UPLINK_SERVER_COUNT, stats_count_servers(Me->GetLinks().front())); return MOD_CONT; } - CommandReturn DoStatsMemory(User *u) + CommandReturn DoStatsMemory(CommandSource &source) { long count, mem; - u->SendMessage(OperServ, OPER_STATS_BYTES_READ, TotalRead / 1024); - u->SendMessage(OperServ, OPER_STATS_BYTES_WRITTEN, TotalWritten / 1024); + source.Reply(OPER_STATS_BYTES_READ, TotalRead / 1024); + source.Reply(OPER_STATS_BYTES_WRITTEN, TotalWritten / 1024); get_user_stats(count, mem); - u->SendMessage(OperServ, OPER_STATS_USER_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_USER_MEM, count, (mem + 512) / 1024); get_channel_stats(&count, &mem); - u->SendMessage(OperServ, OPER_STATS_CHANNEL_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_CHANNEL_MEM, count, (mem + 512) / 1024); get_core_stats(count, mem); - u->SendMessage(OperServ, OPER_STATS_GROUPS_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_GROUPS_MEM, count, (mem + 512) / 1024); get_aliases_stats(count, mem); - u->SendMessage(OperServ, OPER_STATS_ALIASES_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_ALIASES_MEM, count, (mem + 512) / 1024); get_chanserv_stats(&count, &mem); - u->SendMessage(OperServ, OPER_STATS_CHANSERV_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_CHANSERV_MEM, count, (mem + 512) / 1024); if (!Config->s_BotServ.empty()) { get_botserv_stats(&count, &mem); - u->SendMessage(OperServ, OPER_STATS_BOTSERV_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_BOTSERV_MEM, count, (mem + 512) / 1024); } if (!Config->s_HostServ.empty()) { get_hostserv_stats(&count, &mem); - u->SendMessage(OperServ, OPER_STATS_HOSTSERV_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_HOSTSERV_MEM, count, (mem + 512) / 1024); } get_operserv_stats(&count, &mem); - u->SendMessage(OperServ, OPER_STATS_OPERSERV_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_OPERSERV_MEM, count, (mem + 512) / 1024); get_session_stats(count, mem); - u->SendMessage(OperServ, OPER_STATS_SESSIONS_MEM, count, (mem + 512) / 1024); + source.Reply(OPER_STATS_SESSIONS_MEM, count, (mem + 512) / 1024); return MOD_CONT; } @@ -231,28 +233,28 @@ class CommandOSStats : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string extra = !params.empty() ? params[0] : ""; + const Anope::string &extra = !params.empty() ? params[0] : ""; if (!extra.empty() && !extra.equals_ci("ALL")) { if (extra.equals_ci("AKILL")) - return this->DoStatsAkill(u); + return this->DoStatsAkill(source); else if (extra.equals_ci("RESET")) - return this->DoStatsReset(u); + return this->DoStatsReset(source); else if (!extra.equals_ci("MEMORY") && !extra.equals_ci("UPLINK")) - u->SendMessage(OperServ, OPER_STATS_UNKNOWN_OPTION, extra.c_str()); + source.Reply(OPER_STATS_UNKNOWN_OPTION, extra.c_str()); } if (extra.empty() || (!extra.equals_ci("MEMORY") && !extra.equals_ci("UPLINK"))) - this->DoStatsUptime(u); + this->DoStatsUptime(source); if (!extra.empty() && (extra.equals_ci("ALL") || extra.equals_ci("UPLINK"))) - this->DoStatsUplink(u); + this->DoStatsUplink(source); if (!extra.empty() && (extra.equals_ci("ALL") || extra.equals_ci("MEMORY"))) - this->DoStatsMemory(u); + this->DoStatsMemory(source); return MOD_CONT; } diff --git a/modules/core/os_svsnick.cpp b/modules/core/os_svsnick.cpp index cc50f83b3..51e0c06b8 100644 --- a/modules/core/os_svsnick.cpp +++ b/modules/core/os_svsnick.cpp @@ -20,9 +20,10 @@ class CommandOSSVSNick : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; + User *u = source.u; + const Anope::string &nick = params[0]; Anope::string newnick = params[1]; User *u2; @@ -31,33 +32,33 @@ class CommandOSSVSNick : public Command /* Truncate long nicknames to NICKMAX-2 characters */ if (newnick.length() > Config->NickLen) { - u->SendMessage(OperServ, NICK_X_TRUNCATED, newnick.c_str(), Config->NickLen, newnick.c_str()); + source.Reply(NICK_X_TRUNCATED, newnick.c_str(), Config->NickLen, newnick.c_str()); newnick = params[1].substr(0, Config->NickLen); } /* Check for valid characters */ if (newnick[0] == '-' || isdigit(newnick[0])) { - u->SendMessage(OperServ, NICK_X_ILLEGAL, newnick.c_str()); + source.Reply(NICK_X_ILLEGAL, newnick.c_str()); return MOD_CONT; } for (unsigned i = 0, end = newnick.length(); i < end; ++i) if (!isvalidnick(newnick[i])) { - u->SendMessage(OperServ, NICK_X_ILLEGAL, newnick.c_str()); + source.Reply(NICK_X_ILLEGAL, newnick.c_str()); return MOD_CONT; } /* Check for a nick in use or a forbidden/suspended nick */ if (!(u2 = finduser(nick))) - u->SendMessage(OperServ, NICK_X_NOT_IN_USE, nick.c_str()); + source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); else if (finduser(newnick)) - u->SendMessage(OperServ, NICK_X_IN_USE, newnick.c_str()); + source.Reply(NICK_X_IN_USE, newnick.c_str()); else if ((na = findnick(newnick)) && na->HasFlag(NS_FORBIDDEN)) - u->SendMessage(OperServ, NICK_X_FORBIDDEN, newnick.c_str()); + source.Reply(NICK_X_FORBIDDEN, newnick.c_str()); else { - u->SendMessage(OperServ, OPER_SVSNICK_NEWNICK, nick.c_str(), newnick.c_str()); + source.Reply(OPER_SVSNICK_NEWNICK, nick.c_str(), newnick.c_str()); ircdproto->SendGlobops(OperServ, "%s used SVSNICK to change %s to %s", u->nick.c_str(), nick.c_str(), newnick.c_str()); ircdproto->SendForceNickChange(u2, newnick, Anope::CurTime); } diff --git a/modules/core/os_szline.cpp b/modules/core/os_szline.cpp index 21facdde8..030bb5387 100644 --- a/modules/core/os_szline.cpp +++ b/modules/core/os_szline.cpp @@ -15,21 +15,21 @@ class SZLineDelCallback : public NumberList { - User *u; + CommandSource &source; unsigned Deleted; public: - SZLineDelCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, true), u(_u), Deleted(0) + SZLineDelCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, true), source(_source), Deleted(0) { } ~SZLineDelCallback() { if (!Deleted) - u->SendMessage(OperServ, OPER_SZLINE_NO_MATCH); + source.Reply(OPER_SZLINE_NO_MATCH); else if (Deleted == 1) - u->SendMessage(OperServ, OPER_SZLINE_DELETED_ONE); + source.Reply(OPER_SZLINE_DELETED_ONE); else - u->SendMessage(OperServ, OPER_SZLINE_DELETED_SEVERAL, Deleted); + source.Reply(OPER_SZLINE_DELETED_SEVERAL, Deleted); } void HandleNumber(unsigned Number) @@ -43,10 +43,10 @@ class SZLineDelCallback : public NumberList return; ++Deleted; - DoDel(u, x); + DoDel(source, x); } - static void DoDel(User *u, XLine *x) + static void DoDel(CommandSource &source, XLine *x) { SZLine->DelXLine(x); } @@ -55,17 +55,17 @@ class SZLineDelCallback : public NumberList class SZLineListCallback : public NumberList { protected: - User *u; + CommandSource &source; bool SentHeader; public: - SZLineListCallback(User *_u, const Anope::string &numlist) : NumberList(numlist, false), u(_u), SentHeader(false) + SZLineListCallback(CommandSource &_source, const Anope::string &numlist) : NumberList(numlist, false), source(_source), SentHeader(false) { } ~SZLineListCallback() { if (!SentHeader) - u->SendMessage(OperServ, OPER_SZLINE_NO_MATCH); + source.Reply(OPER_SZLINE_NO_MATCH); } virtual void HandleNumber(unsigned Number) @@ -81,22 +81,22 @@ class SZLineListCallback : public NumberList if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SZLINE_LIST_HEADER); + source.Reply(OPER_SZLINE_LIST_HEADER); } - DoList(u, x, Number - 1); + DoList(source, x, Number - 1); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - u->SendMessage(OperServ, OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); + source.Reply(OPER_LIST_FORMAT, Number + 1, x->Mask.c_str(), x->Reason.c_str()); } }; class SZLineViewCallback : public SZLineListCallback { public: - SZLineViewCallback(User *_u, const Anope::string &numlist) : SZLineListCallback(_u, numlist) + SZLineViewCallback(CommandSource &_source, const Anope::string &numlist) : SZLineListCallback(_source, numlist) { } @@ -113,24 +113,25 @@ class SZLineViewCallback : public SZLineListCallback if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SZLINE_VIEW_HEADER); + source.Reply(OPER_SZLINE_VIEW_HEADER); } - DoList(u, x, Number - 1); + DoList(source, x, Number - 1); } - static void DoList(User *u, XLine *x, unsigned Number) + static void DoList(CommandSource &source, XLine *x, unsigned Number) { - Anope::string expirebuf = expire_left(u->Account(), x->Expires); - u->SendMessage(OperServ, OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expirebuf.c_str(), x->Reason.c_str()); + Anope::string expirebuf = expire_left(source.u->Account(), x->Expires); + source.Reply(OPER_VIEW_FORMAT, Number + 1, x->Mask.c_str(), x->By.c_str(), do_strftime(x->Created).c_str(), expirebuf.c_str(), x->Reason.c_str()); } }; class CommandOSSZLine : public Command { private: - CommandReturn DoAdd(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; unsigned last_param = 2; Anope::string expiry, mask; time_t expires; @@ -152,7 +153,7 @@ class CommandOSSZLine : public Command /* Do not allow less than a minute expiry time */ if (expires && expires < 60) { - u->SendMessage(OperServ, BAD_EXPIRY_TIME); + source.Reply(BAD_EXPIRY_TIME); return MOD_CONT; } else if (expires > 0) @@ -180,7 +181,7 @@ class CommandOSSZLine : public Command if (percent > 95) { - u->SendMessage(OperServ, USERHOST_MASK_TOO_WIDE, mask.c_str()); + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); Log(LOG_ADMIN, u, this) << "tried to SZLine " << percent << "% of the network (" << affected << " users)"; return MOD_CONT; } @@ -190,7 +191,7 @@ class CommandOSSZLine : public Command if (!x) return MOD_CONT; - u->SendMessage(OperServ, OPER_SZLINE_ADDED, mask.c_str()); + source.Reply(OPER_SZLINE_ADDED, mask.c_str()); if (Config->WallOSSZLine) { @@ -226,7 +227,7 @@ class CommandOSSZLine : public Command } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); } else @@ -235,11 +236,13 @@ class CommandOSSZLine : public Command return MOD_CONT; } - CommandReturn DoDel(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + if (SZLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SZLINE_LIST_EMPTY); + source.Reply(OPER_SZLINE_LIST_EMPTY); return MOD_CONT; } @@ -253,7 +256,7 @@ class CommandOSSZLine : public Command if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SZLineDelCallback list(u, mask); + SZLineDelCallback list(source, mask); list.Process(); } else @@ -262,27 +265,27 @@ class CommandOSSZLine : public Command if (!x) { - u->SendMessage(OperServ, OPER_SZLINE_NOT_FOUND, mask.c_str()); + source.Reply(OPER_SZLINE_NOT_FOUND, mask.c_str()); return MOD_CONT; } FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, X_SZLINE)); - SZLineDelCallback::DoDel(u, x); - u->SendMessage(OperServ, OPER_SZLINE_DELETED, mask.c_str()); + SZLineDelCallback::DoDel(source, x); + source.Reply(OPER_SZLINE_DELETED, mask.c_str()); } if (readonly) - u->SendMessage(OperServ, READ_ONLY_MODE); + source.Reply(READ_ONLY_MODE); return MOD_CONT; } - CommandReturn DoList(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoList(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SZLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SZLINE_LIST_EMPTY); + source.Reply(OPER_SZLINE_LIST_EMPTY); return MOD_CONT; } @@ -290,7 +293,7 @@ class CommandOSSZLine : public Command if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SZLineListCallback list(u, mask); + SZLineListCallback list(source, mask); list.Process(); } else @@ -306,25 +309,25 @@ class CommandOSSZLine : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SZLINE_LIST_HEADER); + source.Reply(OPER_SZLINE_LIST_HEADER); } - SZLineListCallback::DoList(u, x, i); + SZLineListCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_SZLINE_NO_MATCH); + source.Reply(OPER_SZLINE_NO_MATCH); } return MOD_CONT; } - CommandReturn DoView(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn DoView(CommandSource &source, const std::vector<Anope::string> ¶ms) { if (SZLine->GetList().empty()) { - u->SendMessage(OperServ, OPER_SZLINE_LIST_EMPTY); + source.Reply(OPER_SZLINE_LIST_EMPTY); return MOD_CONT; } @@ -332,7 +335,7 @@ class CommandOSSZLine : public Command if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos) { - SZLineViewCallback list(u, mask); + SZLineViewCallback list(source, mask); list.Process(); } else @@ -348,22 +351,23 @@ class CommandOSSZLine : public Command if (!SentHeader) { SentHeader = true; - u->SendMessage(OperServ, OPER_SZLINE_VIEW_HEADER); + source.Reply(OPER_SZLINE_VIEW_HEADER); } - SZLineViewCallback::DoList(u, x, i); + SZLineViewCallback::DoList(source, x, i); } } if (!SentHeader) - u->SendMessage(OperServ, OPER_SZLINE_NO_MATCH); + source.Reply(OPER_SZLINE_NO_MATCH); } return MOD_CONT; } - CommandReturn DoClear(User *u) + CommandReturn DoClear(CommandSource &source) { + User *u = source.u; FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, NULL, X_SZLINE)); SZLine->Clear(); u->SendMessage(OperServ, OPER_SZLINE_CLEAR); @@ -375,22 +379,24 @@ class CommandOSSZLine : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string cmd = params[0]; + User *u = source.u; + const Anope::string &cmd = params[0]; if (cmd.equals_ci("ADD")) - return this->DoAdd(u, params); + return this->DoAdd(source, params); else if (cmd.equals_ci("DEL")) - return this->DoDel(u, params); + return this->DoDel(source, params); else if (cmd.equals_ci("LIST")) - return this->DoList(u, params); + return this->DoList(source, params); else if (cmd.equals_ci("VIEW")) - return this->DoView(u, params); + return this->DoView(source, params); else if (cmd.equals_ci("CLEAR")) - return this->DoClear(u); + return this->DoClear(source); else this->OnSyntaxError(u, ""); + return MOD_CONT; } diff --git a/modules/core/os_umode.cpp b/modules/core/os_umode.cpp index a2834edae..352896122 100644 --- a/modules/core/os_umode.cpp +++ b/modules/core/os_umode.cpp @@ -20,10 +20,11 @@ class CommandOSUMode : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - Anope::string modes = params[1]; + User *u = source.u; + const Anope::string &nick = params[0]; + const Anope::string &modes = params[1]; User *u2; @@ -37,12 +38,12 @@ class CommandOSUMode : public Command return MOD_CONT; } if (!(u2 = finduser(nick))) - u->SendMessage(OperServ, NICK_X_NOT_IN_USE, nick.c_str()); + source.Reply(NICK_X_NOT_IN_USE, nick.c_str()); else { u2->SetModes(OperServ, "%s", modes.c_str()); - u->SendMessage(OperServ, OPER_UMODE_SUCCESS, nick.c_str()); + source.Reply(OPER_UMODE_SUCCESS, nick.c_str()); u2->SendMessage(OperServ, OPER_UMODE_CHANGED, u->nick.c_str()); if (Config->WallOSMode) diff --git a/modules/core/os_update.cpp b/modules/core/os_update.cpp index 6a96ab855..2b9bc20b6 100644 --- a/modules/core/os_update.cpp +++ b/modules/core/os_update.cpp @@ -20,8 +20,9 @@ class CommandOSUpdate : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; u->SendMessage(OperServ, OPER_UPDATING); save_data = true; return MOD_CONT; diff --git a/modules/core/os_userlist.cpp b/modules/core/os_userlist.cpp index 436c073d6..8a56dea2e 100644 --- a/modules/core/os_userlist.cpp +++ b/modules/core/os_userlist.cpp @@ -20,10 +20,11 @@ class CommandOSUserList : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string pattern = !params.empty() ? params[0] : ""; - Anope::string opt = params.size() > 1 ? params[1] : ""; + User *u = source.u; + const Anope::string &pattern = !params.empty() ? params[0] : ""; + const Anope::string &opt = params.size() > 1 ? params[1] : ""; Channel *c; std::list<UserModeName> Modes; @@ -32,7 +33,7 @@ class CommandOSUserList : public Command if (!pattern.empty() && (c = findchan(pattern))) { - u->SendMessage(OperServ, OPER_USERLIST_HEADER_CHAN, pattern.c_str()); + source.Reply(OPER_USERLIST_HEADER_CHAN, pattern.c_str()); for (CUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit) { @@ -43,12 +44,12 @@ class CommandOSUserList : public Command if (!uc->user->HasMode(*it)) continue; - u->SendMessage(OperServ, OPER_USERLIST_RECORD, uc->user->nick.c_str(), uc->user->GetIdent().c_str(), uc->user->GetDisplayedHost().c_str()); + source.Reply(OPER_USERLIST_RECORD, uc->user->nick.c_str(), uc->user->GetIdent().c_str(), uc->user->GetDisplayedHost().c_str()); } } else { - u->SendMessage(OperServ, OPER_USERLIST_HEADER); + source.Reply(OPER_USERLIST_HEADER); for (patricia_tree<User *>::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it) { @@ -64,7 +65,7 @@ class CommandOSUserList : public Command if (!u2->HasMode(*mit)) continue; } - u->SendMessage(OperServ, OPER_USERLIST_RECORD, u2->nick.c_str(), u2->GetIdent().c_str(), u2->GetDisplayedHost().c_str()); + source.Reply(OPER_USERLIST_RECORD, u2->nick.c_str(), u2->GetIdent().c_str(), u2->GetDisplayedHost().c_str()); } } diff --git a/modules/core/ss_main.cpp b/modules/core/ss_main.cpp index 0e68a2795..b228ad33e 100644 --- a/modules/core/ss_main.cpp +++ b/modules/core/ss_main.cpp @@ -20,8 +20,9 @@ class CommandSSHelp : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; ircdproto->SendMessage(statserv, u->nick, "This is a test of the emergency StatServ system."); return MOD_CONT; } diff --git a/modules/extra/cs_appendtopic.cpp b/modules/extra/cs_appendtopic.cpp index e8ccde22b..b98efeed6 100644 --- a/modules/extra/cs_appendtopic.cpp +++ b/modules/extra/cs_appendtopic.cpp @@ -50,15 +50,16 @@ class CommandCSAppendTopic : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string newtopic = params[1]; - ChannelInfo *ci = cs_findchan(chan); - Channel *c = ci ? ci->c : NULL; + const Anope::string &newtopic = params[1]; + + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; if (!c) - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, ci->name.c_str()); else if (!check_access(u, ci, CA_TOPIC)) u->SendMessage(ChanServ, ACCESS_DENIED); else diff --git a/modules/extra/cs_enforce.cpp b/modules/extra/cs_enforce.cpp index 2d65422c6..4e21cf372 100644 --- a/modules/extra/cs_enforce.cpp +++ b/modules/extra/cs_enforce.cpp @@ -125,18 +125,16 @@ class CommandCSEnforce : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string chan = params[0]; - Anope::string what = params.size() > 1 ? params[1] : ""; - Channel *c = findchan(chan); - ChannelInfo *ci; + const Anope::string &what = params.size() > 1 ? params[1] : ""; - if (c) - ci = c->ci; + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; if (!c) - u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); + u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, ci->name.c_str()); else if (!check_access(u, ci, CA_AKICK)) u->SendMessage(ChanServ, ACCESS_DENIED); else diff --git a/modules/extra/cs_entrymsg.cpp b/modules/extra/cs_entrymsg.cpp index e2143f7d1..4c6dee644 100644 --- a/modules/extra/cs_entrymsg.cpp +++ b/modules/extra/cs_entrymsg.cpp @@ -94,9 +94,11 @@ class CommandEntryMessage : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; + if (ci && (IsFounder(u, ci) || u->Account()->HasCommand("chanserv/entrymsg"))) { bool success = true; diff --git a/modules/extra/cs_set_misc.cpp b/modules/extra/cs_set_misc.cpp index c5f11ca29..0ed913b69 100644 --- a/modules/extra/cs_set_misc.cpp +++ b/modules/extra/cs_set_misc.cpp @@ -20,9 +20,10 @@ class CommandCSSetMisc : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - ChannelInfo *ci = cs_findchan(params[0]); + User *u = source.u; + ChannelInfo *ci = source.ci; if (!ci) throw CoreException("NULL ci in CommandCSSetMisc"); diff --git a/modules/extra/cs_tban.cpp b/modules/extra/cs_tban.cpp index 444681262..a037c8243 100644 --- a/modules/extra/cs_tban.cpp +++ b/modules/extra/cs_tban.cpp @@ -58,23 +58,25 @@ class CommandCSTBan : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string mask; - Channel *c; - User *u2 = NULL; + User *u = source.u; + ChannelInfo *ci = source.ci; + Channel *c = ci->c; - Anope::string chan = params[0]; - Anope::string nick = params[1]; - Anope::string time = params[2]; + const Anope::string &chan = params[0]; + const Anope::string &nick = params[1]; + const Anope::string &time = params[2]; - if (!(c = findchan(chan))) + User *u2; + if (!c) u->SendMessage(ChanServ, CHAN_X_NOT_IN_USE, chan.c_str()); else if (!(u2 = finduser(nick))) u->SendMessage(ChanServ, NICK_X_NOT_IN_USE, nick.c_str()); else if (CanBanUser(c, u, u2)) { + Anope::string mask; get_idealban(c->ci, u2, mask); c->SetMode(NULL, CMODE_BAN, mask); new TempBan(dotime(time), c, mask); diff --git a/modules/extra/db_mysql.cpp b/modules/extra/db_mysql.cpp index bd1810f94..8298fcbdf 100644 --- a/modules/extra/db_mysql.cpp +++ b/modules/extra/db_mysql.cpp @@ -311,7 +311,7 @@ class CommandSQLSync : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms); + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms); bool OnHelp(User *u, const Anope::string &subcommand) { @@ -979,14 +979,18 @@ class DBMySQL : public Module return EVENT_CONTINUE; } - void OnPostCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) + void OnPostCommand(CommandSource &source, Command *command, const std::vector<Anope::string> ¶ms) { + User *u = source.u; + BotInfo *service = command->service; + ChannelInfo *ci = source.ci; + if (service == NickServ) { - if (u->Account() && ((command.equals_ci("SET") && !params.empty()) || (command.equals_ci("SASET") && u->Account()->HasCommand("nickserv/saset") && params.size() > 1))) + if (u->Account() && ((command->name.equals_ci("SET") && !params.empty()) || (command->name.equals_ci("SASET") && u->Account()->HasCommand("nickserv/saset") && params.size() > 1))) { - Anope::string cmd = (command == "SET" ? params[0] : params[1]); - NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0])); + Anope::string cmd = (command->name.equals_ci("SET") ? params[0] : params[1]); + NickCore *nc = (command->name.equals_ci("SET") ? u->Account() : findcore(params[0])); if (!nc) return; if (cmd.equals_ci("PASSWORD") && params.size() > 1) @@ -1013,9 +1017,8 @@ class DBMySQL : public Module } else if (service == ChanServ) { - if (command.equals_ci("SET") && u->Account() && params.size() > 1) + if (command->name.equals_ci("SET") && u->Account() && params.size() > 1) { - ChannelInfo *ci = cs_findchan(params[0]); if (!ci) return; if (!u->Account()->HasPriv("chanserv/set") && check_access(u, ci, CA_SET)) @@ -1051,9 +1054,8 @@ class DBMySQL : public Module } else if (service == BotServ) { - if (command.equals_ci("KICK") && params.size() > 2) + if (command->name.equals_ci("KICK") && params.size() > 2) { - ChannelInfo *ci = cs_findchan(params[0]); if (!ci) return; if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) @@ -1083,9 +1085,8 @@ class DBMySQL : public Module } } } - else if (command.equals_ci("SET") && params.size() > 2) + else if (command->name.equals_ci("SET") && params.size() > 2) { - ChannelInfo *ci = cs_findchan(params[0]); if (ci && !check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) return; BotInfo *bi = NULL; @@ -1105,11 +1106,11 @@ class DBMySQL : public Module } else if (service == MemoServ) { - if (command.equals_ci("IGNORE") && params.size() > 0) + if (command->name.equals_ci("IGNORE") && params.size() > 0) { Anope::string target = params[0]; NickCore *nc = NULL; - ChannelInfo *ci = NULL; + ci = NULL; if (target[0] != '#') { target = u->nick; @@ -1609,8 +1610,9 @@ static void SaveDatabases() me->OnExceptionAdd(NULL, exceptions[i]); } -CommandReturn CommandSQLSync::Execute(User *u, const std::vector<Anope::string> ¶ms) +CommandReturn CommandSQLSync::Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; SaveDatabases(); u->SendMessage(OperServ, OPER_SYNC_UPDATED); return MOD_CONT; diff --git a/modules/extra/hs_request.cpp b/modules/extra/hs_request.cpp index 9ae097d27..031fa72b7 100644 --- a/modules/extra/hs_request.cpp +++ b/modules/extra/hs_request.cpp @@ -49,12 +49,12 @@ class CommandHSRequest : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = u->nick; + User *u = source.u; + Anope::string rawhostmask = params[0]; Anope::string hostmask; - NickAlias *na; Anope::string vIdent = myStrGetToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ if (!vIdent.empty()) @@ -97,22 +97,17 @@ class CommandHSRequest : public Command return MOD_CONT; } - if ((na = findnick(nick))) + if (HSRequestMemoOper && Config->MSSendDelay > 0 && u && u->lastmemosend + Config->MSSendDelay > Anope::CurTime) { - if (HSRequestMemoOper && Config->MSSendDelay > 0 && u && u->lastmemosend + Config->MSSendDelay > Anope::CurTime) - { - me->SendMessage(HostServ, u, _("Please wait %d seconds before requesting a new vHost"), Config->MSSendDelay); - u->lastmemosend = Anope::CurTime; - return MOD_CONT; - } - my_add_host_request(nick, vIdent, hostmask, u->nick, Anope::CurTime); - - me->SendMessage(HostServ, u, _("Your vHost has been requested")); - req_send_memos(u, vIdent, hostmask); - Log(LOG_COMMAND, u, this, NULL) << "to request new vhost " << (!vIdent.empty() ? vIdent + "@" : "") << hostmask; + me->SendMessage(HostServ, u, _("Please wait %d seconds before requesting a new vHost"), Config->MSSendDelay); + u->lastmemosend = Anope::CurTime; + return MOD_CONT; } - else - u->SendMessage(HostServ, HOST_NOREG, nick.c_str()); + my_add_host_request(u->nick, vIdent, hostmask, u->nick, Anope::CurTime); + + me->SendMessage(HostServ, u, _("Your vHost has been requested")); + req_send_memos(u, vIdent, hostmask); + Log(LOG_COMMAND, u, this, NULL) << "to request new vhost " << (!vIdent.empty() ? vIdent + "@" : "") << hostmask; return MOD_CONT; } @@ -145,12 +140,14 @@ class CommandHSActivate : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - NickAlias *na; + User *u = source.u; - if ((na = findnick(nick))) + const Anope::string &nick = params[0]; + + NickAlias *na = findnick(nick); + if (na) { RequestMap::iterator it = Requests.find(na->nick); if (it != Requests.end()) @@ -205,10 +202,12 @@ class CommandHSReject : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - Anope::string nick = params[0]; - Anope::string reason = params.size() > 1 ? params[1] : ""; + User *u = source.u; + + const Anope::string &nick = params[0]; + const Anope::string &reason = params.size() > 1 ? params[1] : ""; RequestMap::iterator it = Requests.find(nick); if (it != Requests.end()) @@ -297,9 +296,9 @@ class CommandHSWaiting : public HSListBase { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { - return this->DoList(u); + return this->DoList(source.u); } bool OnHelp(User *u, const Anope::string &subcommand) @@ -351,7 +350,7 @@ class HSRequest : public Module EventReturn OnPreCommand(User *u, BotInfo *service, const Anope::string &command, const std::vector<Anope::string> ¶ms) { - if (!Config->s_HostServ.empty() && service == findbot(Config->s_HostServ)) + if (service == HostServ) { if (command.equals_ci("LIST")) { @@ -361,12 +360,20 @@ class HSRequest : public Module { std::vector<Anope::string> emptyParams; Command *c = FindCommand(HostServ, "WAITING"); - c->Execute(u, emptyParams); + if (!c) + throw CoreException("No waiting command?"); + CommandSource source; + source.u = u; + source.ci = NULL; + source.owner = service; + source.service = service; + source.fantasy = false; + c->Execute(source, emptyParams); return EVENT_STOP; } } } - else if (service == findbot(Config->s_NickServ)) + else if (service == NickServ) { if (command.equals_ci("DROP")) { diff --git a/modules/extra/m_dnsbl.cpp b/modules/extra/m_dnsbl.cpp index a9351d35e..b363d3503 100644 --- a/modules/extra/m_dnsbl.cpp +++ b/modules/extra/m_dnsbl.cpp @@ -7,6 +7,12 @@ #include "module.h" +struct FakeAkill : public Command +{ + FakeAkill() : Command("AKILL", 0, 0) { this->service = OperServ; } + CommandReturn Execute(CommandSource &, const std::vector<Anope::string> &) { return MOD_CONT; } +} fake_akill; + struct Blacklist { Anope::string name; @@ -56,9 +62,7 @@ class DNSBLResolver : public DNSRequest XLine *x = NULL; if (this->add_to_akill && SGLine && (x = SGLine->Add(NULL, NULL, Anope::string("*@") + user->host, Anope::CurTime + this->blacklist.bantime, reason))) { - static Command command_akill("AKILL", 0); - command_akill.service = OperServ; - Log(LOG_COMMAND, OperServ, &command_akill) << "for " << user->GetMask() << " (Listed in " << this->blacklist.name << ")"; + Log(LOG_COMMAND, OperServ, &fake_akill) << "for " << user->GetMask() << " (Listed in " << this->blacklist.name << ")"; /* If AkillOnAdd is disabled send it anyway, noone wants bots around... */ if (!Config->AkillOnAdd) ircdproto->SendAkill(x); diff --git a/modules/extra/ns_set_misc.cpp b/modules/extra/ns_set_misc.cpp index 71ba9834f..f7a2f815f 100644 --- a/modules/extra/ns_set_misc.cpp +++ b/modules/extra/ns_set_misc.cpp @@ -23,8 +23,9 @@ class CommandNSSetMisc : public Command { } - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { + User *u = source.u; NickAlias *na = findnick(params[0]); if (!na) throw CoreException("NULL na in CommandNSSetMisc"); |