From 2dec8e767a70def4b9b04a96ae4f75e4d1013038 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 18 Jun 2012 05:04:30 -0400 Subject: Allow userless command sources --- include/commands.h | 30 +++++- include/lists.h | 4 +- include/logger.h | 3 +- include/modules.h | 38 +++---- include/users.h | 9 +- modules/commands/bs_assign.cpp | 24 ++--- modules/commands/bs_badwords.cpp | 24 ++--- modules/commands/bs_bot.cpp | 13 ++- modules/commands/bs_botlist.cpp | 3 +- modules/commands/bs_control.cpp | 11 +- modules/commands/bs_info.cpp | 21 ++-- modules/commands/bs_kick.cpp | 7 +- modules/commands/bs_set_dontkickops.cpp | 12 +-- modules/commands/bs_set_dontkickvoices.cpp | 12 +-- modules/commands/bs_set_fantasy.cpp | 11 +- modules/commands/bs_set_greet.cpp | 11 +- modules/commands/bs_set_nobot.cpp | 13 ++- modules/commands/bs_set_private.cpp | 3 +- modules/commands/cs_access.cpp | 87 ++++++--------- modules/commands/cs_akick.cpp | 46 ++++---- modules/commands/cs_appendtopic.cpp | 9 +- modules/commands/cs_ban.cpp | 14 +-- modules/commands/cs_clearusers.cpp | 9 +- modules/commands/cs_clone.cpp | 10 +- modules/commands/cs_drop.cpp | 13 +-- modules/commands/cs_enforce.cpp | 3 +- modules/commands/cs_entrymsg.cpp | 19 +--- modules/commands/cs_fantasy_stats.cpp | 4 +- modules/commands/cs_fantasy_top.cpp | 4 +- modules/commands/cs_flags.cpp | 39 +++---- modules/commands/cs_getkey.cpp | 8 +- modules/commands/cs_info.cpp | 34 +++--- modules/commands/cs_invite.cpp | 20 ++-- modules/commands/cs_kick.cpp | 12 +-- modules/commands/cs_list.cpp | 4 +- modules/commands/cs_log.cpp | 13 ++- modules/commands/cs_mode.cpp | 39 ++++--- modules/commands/cs_modes.cpp | 16 ++- modules/commands/cs_register.cpp | 19 ++-- modules/commands/cs_saset_noexpire.cpp | 3 +- modules/commands/cs_seen.cpp | 13 ++- modules/commands/cs_set_bantype.cpp | 3 +- modules/commands/cs_set_chanstats.cpp | 3 +- modules/commands/cs_set_description.cpp | 3 +- modules/commands/cs_set_founder.cpp | 9 +- modules/commands/cs_set_keeptopic.cpp | 3 +- modules/commands/cs_set_misc.cpp | 2 +- modules/commands/cs_set_peace.cpp | 3 +- modules/commands/cs_set_persist.cpp | 3 +- modules/commands/cs_set_private.cpp | 3 +- modules/commands/cs_set_restricted.cpp | 3 +- modules/commands/cs_set_secure.cpp | 3 +- modules/commands/cs_set_securefounder.cpp | 3 +- modules/commands/cs_set_secureops.cpp | 3 +- modules/commands/cs_set_signkick.cpp | 3 +- modules/commands/cs_set_successor.cpp | 7 +- modules/commands/cs_set_topiclock.cpp | 3 +- modules/commands/cs_suspend.cpp | 8 +- modules/commands/cs_sync.cpp | 3 +- modules/commands/cs_tban.cpp | 2 +- modules/commands/cs_topic.cpp | 9 +- modules/commands/cs_unban.cpp | 10 +- modules/commands/cs_updown.cpp | 8 +- modules/commands/cs_xop.cpp | 44 ++++---- modules/commands/gl_global.cpp | 5 +- modules/commands/help.cpp | 9 +- modules/commands/hs_del.cpp | 6 +- modules/commands/hs_group.cpp | 9 +- modules/commands/hs_off.cpp | 7 +- modules/commands/hs_on.cpp | 7 +- modules/commands/hs_request.cpp | 24 ++--- modules/commands/hs_set.cpp | 10 +- modules/commands/ms_cancel.cpp | 3 +- modules/commands/ms_check.cpp | 3 +- modules/commands/ms_del.cpp | 11 +- modules/commands/ms_ignore.cpp | 5 +- modules/commands/ms_info.cpp | 25 +++-- modules/commands/ms_list.cpp | 7 +- modules/commands/ms_read.cpp | 9 +- modules/commands/ms_rsend.cpp | 7 +- modules/commands/ms_send.cpp | 2 +- modules/commands/ms_sendall.cpp | 7 +- modules/commands/ms_set.cpp | 22 ++-- modules/commands/ms_staff.cpp | 4 +- modules/commands/ns_access.cpp | 9 +- modules/commands/ns_ajoin.cpp | 14 +-- modules/commands/ns_alist.cpp | 5 +- modules/commands/ns_cert.cpp | 25 ++--- modules/commands/ns_drop.cpp | 21 ++-- modules/commands/ns_getemail.cpp | 3 +- modules/commands/ns_getpass.cpp | 3 +- modules/commands/ns_ghost.cpp | 18 ++-- modules/commands/ns_group.cpp | 24 +++-- modules/commands/ns_identify.cpp | 11 +- modules/commands/ns_info.cpp | 29 +++-- modules/commands/ns_list.cpp | 5 +- modules/commands/ns_logout.cpp | 9 +- modules/commands/ns_recover.cpp | 20 ++-- modules/commands/ns_register.cpp | 98 ++++++++--------- modules/commands/ns_release.cpp | 23 ++-- modules/commands/ns_resetpass.cpp | 18 ++-- modules/commands/ns_saset.cpp | 3 +- modules/commands/ns_sendpass.cpp | 7 +- modules/commands/ns_set.cpp | 11 +- modules/commands/ns_set_autoop.cpp | 2 +- modules/commands/ns_set_chanstats.cpp | 2 +- modules/commands/ns_set_display.cpp | 2 +- modules/commands/ns_set_email.cpp | 28 +++-- modules/commands/ns_set_greet.cpp | 2 +- modules/commands/ns_set_hide.cpp | 2 +- modules/commands/ns_set_kill.cpp | 2 +- modules/commands/ns_set_language.cpp | 2 +- modules/commands/ns_set_message.cpp | 2 +- modules/commands/ns_set_misc.cpp | 2 +- modules/commands/ns_set_private.cpp | 2 +- modules/commands/ns_set_secure.cpp | 2 +- modules/commands/ns_status.cpp | 3 +- modules/commands/ns_suspend.cpp | 6 +- modules/commands/ns_update.cpp | 15 ++- modules/commands/os_akill.cpp | 17 ++- modules/commands/os_chankill.cpp | 7 +- modules/commands/os_config.cpp | 4 +- modules/commands/os_defcon.cpp | 3 +- modules/commands/os_forbid.cpp | 8 +- modules/commands/os_ignore.cpp | 2 +- modules/commands/os_jupe.cpp | 5 +- modules/commands/os_kick.cpp | 5 +- modules/commands/os_kill.cpp | 5 +- modules/commands/os_login.cpp | 26 +++-- modules/commands/os_mode.cpp | 8 +- modules/commands/os_module.cpp | 17 ++- modules/commands/os_news.cpp | 2 +- modules/commands/os_noop.cpp | 7 +- modules/commands/os_oline.cpp | 5 +- modules/commands/os_oper.cpp | 4 +- modules/commands/os_session.cpp | 5 +- modules/commands/os_set.cpp | 31 +++--- modules/commands/os_shutdown.cpp | 9 +- modules/commands/os_svsnick.cpp | 3 +- modules/commands/os_sxline.cpp | 30 +++--- modules/extra/m_chanstats.cpp | 4 +- modules/extra/m_ldap_authentication.cpp | 5 +- modules/extra/m_statusupdate.cpp | 4 +- modules/extra/m_xmlrpc_main.cpp | 80 ++++---------- modules/extra/ns_maxemail.cpp | 6 +- modules/pseudoclients/chanserv.cpp | 2 +- modules/pseudoclients/nickserv.cpp | 2 +- src/bots.cpp | 86 +-------------- src/command.cpp | 167 ++++++++++++++++++++++++++++- src/logger.cpp | 38 ++++--- src/mail.cpp | 37 +++++-- src/misc.cpp | 6 +- src/users.cpp | 7 +- 153 files changed, 1028 insertions(+), 1059 deletions(-) diff --git a/include/commands.h b/include/commands.h index cfd46d644..d644ea8cb 100644 --- a/include/commands.h +++ b/include/commands.h @@ -33,11 +33,23 @@ struct CommandInfo Anope::string permission; }; +struct CommandReply +{ + virtual void SendMessage(const BotInfo *source, const Anope::string &msg) = 0; +}; + /* The source for a command */ -struct CoreExport CommandSource +class CoreExport CommandSource { - /* User executing the command */ + /* The nick executing the command */ + Anope::string nick; + /* User executing the command, may be NULL */ User *u; + public: + /* The account executing the command */ + NickCore *nc; + /* Where the reply should go */ + CommandReply *reply; /* Channel the command was executed on (fantasy) */ Channel *c; /* The service this command is on */ @@ -49,8 +61,20 @@ struct CoreExport CommandSource /* The permission of the command being executed */ Anope::string permission; + CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply); + + const Anope::string &GetNick() const; + User *GetUser() const; + AccessGroup AccessFor(ChannelInfo *ci) const; + bool IsFounder(ChannelInfo *ci) const; + void Reply(const char *message, ...); void Reply(const Anope::string &message); + + bool HasCommand(const Anope::string &cmd); + bool HasPriv(const Anope::string &cmd); + bool IsServicesOper() const; + bool IsOper() const; }; /** Every services command is a class, inheriting from Command. @@ -118,4 +142,6 @@ class CoreExport Command : public Service, public Flags virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand); }; +extern void RunCommand(CommandSource &source, const Anope::string &message); + #endif // COMMANDS_H diff --git a/include/lists.h b/include/lists.h index 308080c93..841faf7a9 100644 --- a/include/lists.h +++ b/include/lists.h @@ -81,11 +81,11 @@ class CoreExport ListFormatter */ class CoreExport InfoFormatter { - User *user; + NickCore *nc; std::vector > replies; unsigned longest; public: - InfoFormatter(User *u); + InfoFormatter(NickCore *nc); void Process(std::vector &); Anope::string &operator[](const Anope::string &key); }; diff --git a/include/logger.h b/include/logger.h index 8cb54a754..9364cfb7c 100644 --- a/include/logger.h +++ b/include/logger.h @@ -50,6 +50,7 @@ class CoreExport Log public: const BotInfo *bi; const User *u; + const NickCore *nc; Command *c; Channel *chan; const ChannelInfo *ci; @@ -63,7 +64,7 @@ class CoreExport Log Log(LogType type = LOG_NORMAL, const Anope::string &category = "", const BotInfo *bi = NULL); /* LOG_COMMAND/OVERRIDE/ADMIN */ - Log(LogType type, const User *u, Command *c, const ChannelInfo *ci = NULL); + Log(LogType type, const CommandSource &source, Command *c, const ChannelInfo *ci = NULL); /* LOG_CHANNEL */ Log(const User *u, Channel *c, const Anope::string &category = ""); diff --git a/include/modules.h b/include/modules.h index d44cbf8d9..ae7ab139a 100644 --- a/include/modules.h +++ b/include/modules.h @@ -499,25 +499,25 @@ class CoreExport Module : public Extensible virtual EventReturn OnExceptionAdd(Exception *ex) { return EVENT_CONTINUE; } /** Called before an exception is deleted - * @param u The user who is deleting it + * @param source The source deleting it * @param ex The exceotion */ - virtual void OnExceptionDel(User *u, Exception *ex) { } + virtual void OnExceptionDel(CommandSource &source, Exception *ex) { } /** Called before a XLine is added - * @param u The user adding the XLine + * @param source The source of the XLine * @param x The XLine * @param xlm The xline manager it was added to * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it */ - virtual EventReturn OnAddXLine(User *u, const XLine *x, XLineManager *xlm) { return EVENT_CONTINUE; } + virtual EventReturn OnAddXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { return EVENT_CONTINUE; } /** Called before a XLine is deleted - * @param u The user deleting the XLine + * @param source The source of the XLine * @param x The XLine * @param xlm The xline manager it was deleted from */ - virtual void OnDelXLine(User *u, const XLine *x, XLineManager *xlm) { } + virtual void OnDelXLine(CommandSource &source, const XLine *x, XLineManager *xlm) { } /** Called when a user is checked for whether they are a services oper * @param u The user @@ -558,31 +558,31 @@ class CoreExport Module : public Extensible /** Called when access is deleted from a channel * @param ci The channel - * @param u The user who removed the access + * @param source The source of the command * @param access The access entry being removed */ - virtual void OnAccessDel(ChannelInfo *ci, User *u, ChanAccess *access) { } + virtual void OnAccessDel(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { } /** Called when access is added * @param ci The channel - * @param u The user who added the access + * @param source The source of the command * @param access The access changed */ - virtual void OnAccessAdd(ChannelInfo *ci, User *u, ChanAccess *access) { } + virtual void OnAccessAdd(ChannelInfo *ci, CommandSource &source, ChanAccess *access) { } /** Called when the access list is cleared * @param ci The channel * @param u The user who cleared the access */ - virtual void OnAccessClear(ChannelInfo *ci, User *u) { } + virtual void OnAccessClear(ChannelInfo *ci, CommandSource &source) { } /** Called when a level for a channel is changed - * @param u The user changing the level + * @param source The source of the command * @param ci The channel the level was changed on * @param priv The privilege changed * @param what The new level */ - virtual void OnLevelChange(User *u, ChannelInfo *ci, const Anope::string &priv, int16_t what) { } + virtual void OnLevelChange(CommandSource &source, ChannelInfo *ci, const Anope::string &priv, int16_t what) { } /** Called right before a channel is dropped * @param ci The channel @@ -625,18 +625,18 @@ class CoreExport Module : public Extensible virtual void OnChannelDelete(Channel *c) { } /** Called after adding an akick to a channel - * @param u The user adding the akick + * @param source The source of the command * @param ci The channel * @param ak The akick */ - virtual void OnAkickAdd(User *u, ChannelInfo *ci, const AutoKick *ak) { } + virtual void OnAkickAdd(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) { } /** Called before removing an akick from a channel - * @param u The user removing the akick + * @param source The source of the command * @param ci The channel * @param ak The akick */ - virtual void OnAkickDel(User *u, ChannelInfo *ci, const AutoKick *ak) { } + virtual void OnAkickDel(CommandSource &source, ChannelInfo *ci, const AutoKick *ak) { } /** Called after a user join a channel when we decide whether to kick them or not * @param u The user @@ -669,10 +669,10 @@ class CoreExport Module : public Extensible virtual EventReturn OnGroupCheckPriv(const AccessGroup *group, const Anope::string &priv) { return EVENT_CONTINUE; } /** Called when a nick is dropped - * @param u The user dropping the nick + * @param source The source of the command * @param na The nick */ - virtual void OnNickDrop(User *u, NickAlias *na) { } + virtual void OnNickDrop(CommandSource &source, NickAlias *na) { } /** Called when a nick is forbidden * @param na The nick alias of the forbidden nick diff --git a/include/users.h b/include/users.h index e69c9d30b..d0b38025e 100644 --- a/include/users.h +++ b/include/users.h @@ -12,6 +12,7 @@ #include "modes.h" #include "extensible.h" #include "serialize.h" +#include "commands.h" extern CoreExport Anope::insensitive_map UserListByNick; extern CoreExport Anope::map UserListByUID; @@ -37,7 +38,7 @@ typedef std::list UChannelList; /* Online user and channel data. */ -class CoreExport User : public virtual Base, public Extensible +class CoreExport User : public virtual Base, public Extensible, public CommandReply { protected: Anope::string vident; @@ -161,7 +162,7 @@ class CoreExport User : public virtual Base, public Extensible * @param ... any number of parameters */ void SendMessage(const BotInfo *source, const char *fmt, ...); - virtual void SendMessage(const BotInfo *source, Anope::string msg); + void SendMessage(const BotInfo *source, const Anope::string &msg) anope_override; /** Collide a nick * See the comment in users.cpp @@ -194,13 +195,13 @@ class CoreExport User : public virtual Base, public Extensible * @param CheckNick True to check if the user is identified to the nickname they are on too * @return true or false */ - virtual bool IsIdentified(bool CheckNick = false) const; + bool IsIdentified(bool CheckNick = false) const; /** Check if the user is recognized for their nick (on the nicks access list) * @param CheckSecure Only returns true if the user has secure off * @return true or false */ - virtual bool IsRecognized(bool CheckSecure = true) const; + bool IsRecognized(bool CheckSecure = true) const; /** Check if the user is a services oper * @return true if they are an oper diff --git a/modules/commands/bs_assign.cpp b/modules/commands/bs_assign.cpp index 5c1691047..874c40015 100644 --- a/modules/commands/bs_assign.cpp +++ b/modules/commands/bs_assign.cpp @@ -27,8 +27,6 @@ class CommandBSAssign : public Command const Anope::string &chan = params[0]; const Anope::string &nick = params[1]; - User *u = source.u; - if (readonly) { source.Reply(BOT_ASSIGN_READONLY); @@ -49,13 +47,14 @@ class CommandBSAssign : public Command return; } - if (ci->botflags.HasFlag(BS_NOBOT) || (!ci->AccessFor(u).HasPriv("ASSIGN") && !u->HasPriv("botserv/administration"))) + AccessGroup access = source.AccessFor(ci); + if (ci->botflags.HasFlag(BS_NOBOT) || (!access.HasPriv("ASSIGN") && !source.HasPriv("botserv/administration"))) { source.Reply(ACCESS_DENIED); return; } - if (bi->HasFlag(BI_PRIVATE) && !u->HasCommand("botserv/assign/private")) + if (bi->HasFlag(BI_PRIVATE) && !source.HasCommand("botserv/assign/private")) { source.Reply(ACCESS_DENIED); return; @@ -67,10 +66,10 @@ class CommandBSAssign : public Command return; } - bool override = !ci->AccessFor(u).HasPriv("ASSIGN"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "for " << bi->nick; + bool override = !access.HasPriv("ASSIGN"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << bi->nick; - bi->Assign(u, ci); + bi->Assign(source.GetUser(), ci); source.Reply(_("Bot \002%s\002 has been assigned to %s."), bi->nick.c_str(), ci->name.c_str()); } @@ -96,8 +95,6 @@ class CommandBSUnassign : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; - if (readonly) { source.Reply(BOT_ASSIGN_READONLY); @@ -111,7 +108,8 @@ class CommandBSUnassign : public Command return; } - if (!u->HasPriv("botserv/administration") && !ci->AccessFor(u).HasPriv("ASSIGN")) + AccessGroup access = source.AccessFor(ci); + if (!source.HasPriv("botserv/administration") && !access.HasPriv("ASSIGN")) { source.Reply(ACCESS_DENIED); return; @@ -129,10 +127,10 @@ class CommandBSUnassign : public Command return; } - bool override = !ci->AccessFor(u).HasPriv("ASSIGN"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "for " << ci->bi->nick; + bool override = !access.HasPriv("ASSIGN"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << ci->bi->nick; - ci->bi->UnAssign(u, ci); + ci->bi->UnAssign(source.GetUser(), ci); source.Reply(_("There is no bot assigned to %s anymore."), ci->name.c_str()); } diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index eaf00d347..30de67d29 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -24,7 +24,7 @@ class BadwordsDelCallback : public NumberList public: BadwordsDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &list) : NumberList(list, true), source(_source), ci(_ci), c(_c), Deleted(0), override(false) { - if (!ci->AccessFor(source.u).HasPriv("BADWORDS") && source.u->HasPriv("botserv/administration")) + if (!source.AccessFor(ci).HasPriv("BADWORDS") && source.HasPriv("botserv/administration")) this->override = true; } @@ -43,7 +43,7 @@ class BadwordsDelCallback : public NumberList if (!Number || Number > ci->GetBadWordCount()) return; - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, ci) << "DEL " << ci->GetBadWord(Number - 1)->word; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, c, ci) << "DEL " << ci->GetBadWord(Number - 1)->word; ++Deleted; ci->EraseBadWord(Number - 1); } @@ -54,8 +54,8 @@ class CommandBSBadwords : public Command private: void DoList(CommandSource &source, ChannelInfo *ci, const Anope::string &word) { - bool override = !ci->AccessFor(source.u).HasPriv("BADWORDS"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "LIST"; + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "LIST"; ListFormatter list; list.addColumn("Number").addColumn("Word").addColumn("Type"); @@ -163,8 +163,8 @@ class CommandBSBadwords : public Command } } - bool override = !ci->AccessFor(source.u).HasPriv("BADWORDS"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "ADD " << realword; + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "ADD " << realword; ci->AddBadWord(realword, bwtype); source.Reply(_("\002%s\002 added to %s bad words list."), realword.c_str(), ci->name.c_str()); @@ -199,8 +199,8 @@ class CommandBSBadwords : public Command return; } - bool override = !ci->AccessFor(source.u).HasPriv("BADWORDS"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "DEL " << badword->word; + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "DEL " << badword->word; source.Reply(_("\002%s\002 deleted from %s bad words list."), badword->word.c_str(), ci->name.c_str()); @@ -212,8 +212,8 @@ class CommandBSBadwords : public Command void DoClear(CommandSource &source, ChannelInfo *ci) { - bool override = !ci->AccessFor(source.u).HasPriv("BADWORDS"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, this, ci) << "CLEAR"; + bool override = !source.AccessFor(ci).HasPriv("BADWORDS"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "CLEAR"; ci->ClearBadWords(); source.Reply(_("Bad words list is now empty.")); @@ -233,7 +233,6 @@ class CommandBSBadwords : public Command { const Anope::string &cmd = params[1]; const Anope::string &word = params.size() > 2 ? params[2] : ""; - User *u = source.u; bool need_args = cmd.equals_ci("LIST") || cmd.equals_ci("CLEAR"); if (!need_args && word.empty()) @@ -249,8 +248,7 @@ class CommandBSBadwords : public Command return; } - - if (!ci->AccessFor(u).HasPriv("BADWORDS") && (!need_args || !u->HasPriv("botserv/administration"))) + if (!source.AccessFor(ci).HasPriv("BADWORDS") && (!need_args || !source.HasPriv("botserv/administration"))) { source.Reply(ACCESS_DENIED); return; diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp index b1f22909f..0b45ee71c 100644 --- a/modules/commands/bs_bot.cpp +++ b/modules/commands/bs_bot.cpp @@ -94,7 +94,7 @@ class CommandBSBot : public Command BotInfo *bi = new BotInfo(nick, user, host, real); - Log(LOG_ADMIN, source.u, this) << "ADD " << bi->GetMask() << " " << bi->realname; + Log(LOG_ADMIN, source, this) << "ADD " << bi->GetMask() << " " << bi->realname; source.Reply(_("%s!%s@%s (%s) added to the bot list."), bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); @@ -253,7 +253,7 @@ class CommandBSBot : public Command } source.Reply(_("Bot \002%s\002 has been changed to %s!%s@%s (%s)"), 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; + Log(LOG_ADMIN, source, this) << "CHANGE " << oldnick << " to " << bi->GetMask() << " " << bi->realname; FOREACH_MOD(I_OnBotChange, OnBotChange(bi)); return; @@ -284,7 +284,7 @@ class CommandBSBot : public Command FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); - Log(LOG_ADMIN, source.u, this) << "DEL " << bi->nick; + Log(LOG_ADMIN, source, this) << "DEL " << bi->nick; source.Reply(_("Bot \002%s\002 has been deleted."), nick.c_str()); bi->destroy(); @@ -302,7 +302,6 @@ class CommandBSBot : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { const Anope::string &cmd = params[0]; - User *u = source.u; if (readonly) { @@ -313,7 +312,7 @@ class CommandBSBot : public Command if (cmd.equals_ci("ADD")) { // ADD nick user host real - 5 - if (!u->HasCommand("botserv/bot/add")) + if (!source.HasCommand("botserv/bot/add")) { source.Reply(ACCESS_DENIED); return; @@ -336,7 +335,7 @@ class CommandBSBot : public Command { // CHANGE oldn newn user host real - 6 // but only oldn and newn are required - if (!u->HasCommand("botserv/bot/change")) + if (!source.HasCommand("botserv/bot/change")) { source.Reply(ACCESS_DENIED); return; @@ -353,7 +352,7 @@ class CommandBSBot : public Command else if (cmd.equals_ci("DEL")) { // DEL nick - if (!u->HasCommand("botserv/bot/del")) + if (!source.HasCommand("botserv/bot/del")) { source.Reply(ACCESS_DENIED); return; diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp index 9fd8b81f7..176040b10 100644 --- a/modules/commands/bs_botlist.cpp +++ b/modules/commands/bs_botlist.cpp @@ -24,7 +24,6 @@ class CommandBSBotList : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; unsigned count = 0; ListFormatter list; @@ -34,7 +33,7 @@ class CommandBSBotList : public Command { BotInfo *bi = it->second; - if (u->HasCommand("botserv/botlist") || !bi->HasFlag(BI_PRIVATE)) + if (source.HasCommand("botserv/botlist") || !bi->HasFlag(BI_PRIVATE)) { ++count; ListFormatter::ListEntry entry; diff --git a/modules/commands/bs_control.cpp b/modules/commands/bs_control.cpp index 6ca435b37..6957d0a78 100644 --- a/modules/commands/bs_control.cpp +++ b/modules/commands/bs_control.cpp @@ -26,8 +26,6 @@ class CommandBSSay : public Command { const Anope::string &text = params[1]; - User *u = source.u; - ChannelInfo *ci = cs_findchan(params[0]); if (ci == NULL) { @@ -35,7 +33,7 @@ class CommandBSSay : public Command return; } - if (!ci->AccessFor(u).HasPriv("SAY")) + if (!source.AccessFor(ci).HasPriv("SAY")) { source.Reply(ACCESS_DENIED); return; @@ -63,7 +61,7 @@ class CommandBSSay : public Command ci->bi->lastmsg = Anope::CurTime; // XXX need a way to find if someone is overriding this - Log(LOG_COMMAND, u, this, ci) << text; + Log(LOG_COMMAND, source, this, ci) << text; return; } @@ -88,7 +86,6 @@ class CommandBSAct : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; Anope::string message = params[1]; ChannelInfo *ci = cs_findchan(params[0]); @@ -98,7 +95,7 @@ class CommandBSAct : public Command return; } - if (!ci->AccessFor(u).HasPriv("SAY")) + if (!source.AccessFor(ci).HasPriv("SAY")) { source.Reply(ACCESS_DENIED); return; @@ -124,7 +121,7 @@ class CommandBSAct : public Command ci->bi->lastmsg = Anope::CurTime; // XXX Need to be able to find if someone is overriding this. - Log(LOG_COMMAND, u, this, ci) << message; + Log(LOG_COMMAND, source, this, ci) << message; return; } diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp index 251bd84df..d5b2693ad 100644 --- a/modules/commands/bs_info.cpp +++ b/modules/commands/bs_info.cpp @@ -59,10 +59,9 @@ class CommandBSInfo : public Command { const Anope::string &query = params[0]; - User *u = source.u; const BotInfo *bi = findbot(query); ChannelInfo *ci; - InfoFormatter info(u); + InfoFormatter info(source.nc); if (bi) { @@ -79,7 +78,7 @@ class CommandBSInfo : public Command for (unsigned i = 0; i < replies.size(); ++i) source.Reply(replies[i]); - if (u->HasPriv("botserv/administration")) + if (source.HasPriv("botserv/administration")) { std::vector buf; this->send_bot_channels(buf, bi); @@ -90,7 +89,7 @@ class CommandBSInfo : public Command } else if ((ci = cs_findchan(query))) { - if (!ci->AccessFor(u).HasPriv("FOUNDER") && !u->HasPriv("botserv/administration")) + if (!source.AccessFor(ci).HasPriv("FOUNDER") && !source.HasPriv("botserv/administration")) { source.Reply(ACCESS_DENIED); return; @@ -99,8 +98,8 @@ class CommandBSInfo : public Command source.Reply(CHAN_INFO_HEADER, ci->name.c_str()); info[_("Bot nick")] = ci->bi ? ci->bi->nick : "not assigned yet"; - Anope::string enabled = translate(u, _("Enabled")); - Anope::string disabled = translate(u, _("Disabled")); + Anope::string enabled = translate(source.nc, _("Enabled")); + Anope::string disabled = translate(source.nc, _("Disabled")); if (ci->botflags.HasFlag(BS_KICK_BADWORDS)) { @@ -203,11 +202,11 @@ class CommandBSInfo : public Command info[_("AMSG kicker")] = disabled; Anope::string flags; - CheckOptStr(flags, BS_DONTKICKOPS, _("Ops protection"), ci->botflags, u->Account()); - CheckOptStr(flags, BS_DONTKICKVOICES, _("Voices protection"), ci->botflags, u->Account()); - CheckOptStr(flags, BS_FANTASY, _("Fantasy"), ci->botflags, u->Account()); - CheckOptStr(flags, BS_GREET, _("Greet"), ci->botflags, u->Account()); - CheckOptStr(flags, BS_NOBOT, _("No bot"), ci->botflags, u->Account()); + CheckOptStr(flags, BS_DONTKICKOPS, _("Ops protection"), ci->botflags, source.nc); + CheckOptStr(flags, BS_DONTKICKVOICES, _("Voices protection"), ci->botflags, source.nc); + CheckOptStr(flags, BS_FANTASY, _("Fantasy"), ci->botflags, source.nc); + CheckOptStr(flags, BS_GREET, _("Greet"), ci->botflags, source.nc); + CheckOptStr(flags, BS_NOBOT, _("No bot"), ci->botflags, source.nc); info[_("Options")] = flags.empty() ? _("None") : flags; diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index 819c5af74..32cfbe952 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -30,7 +30,6 @@ class CommandBSKick : public Command const Anope::string &value = params[2]; const Anope::string &ttb = params.size() > 3 ? params[3] : ""; - User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); if (readonly) @@ -41,14 +40,14 @@ class CommandBSKick : public Command this->OnSyntaxError(source, ""); else if (!value.equals_ci("ON") && !value.equals_ci("OFF")) this->OnSyntaxError(source, ""); - else if (!ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration")) + else if (!source.AccessFor(ci).HasPriv("SET") && !source.HasPriv("botserv/administration")) source.Reply(ACCESS_DENIED); else if (!ci->bi) source.Reply(BOT_NOT_ASSIGNED); else { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << option << " " << value; + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << option << " " << value; if (option.equals_ci("BADWORDS")) { diff --git a/modules/commands/bs_set_dontkickops.cpp b/modules/commands/bs_set_dontkickops.cpp index f05cb1a2c..598dfdcea 100644 --- a/modules/commands/bs_set_dontkickops.cpp +++ b/modules/commands/bs_set_dontkickops.cpp @@ -24,7 +24,6 @@ class CommandBSSetDontKickOps : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); if (ci == NULL) { @@ -32,7 +31,8 @@ class CommandBSSetDontKickOps : public Command return; } - if (!u->HasPriv("botserv/administration") && !ci->AccessFor(u).HasPriv("SET")) + AccessGroup access = source.AccessFor(ci); + if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) { source.Reply(ACCESS_DENIED); return; @@ -46,16 +46,16 @@ class CommandBSSetDontKickOps : public Command if (params[1].equals_ci("ON")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to enable dontkickops"; + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickops"; ci->botflags.SetFlag(BS_DONTKICKOPS); source.Reply(_("Bot \002won't kick ops\002 on channel %s."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to disable dontkickops"; + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickops"; ci->botflags.UnsetFlag(BS_DONTKICKOPS); source.Reply(_("Bot \002will kick ops\002 on channel %s."), ci->name.c_str()); diff --git a/modules/commands/bs_set_dontkickvoices.cpp b/modules/commands/bs_set_dontkickvoices.cpp index 2b477bbfe..05453296b 100644 --- a/modules/commands/bs_set_dontkickvoices.cpp +++ b/modules/commands/bs_set_dontkickvoices.cpp @@ -24,7 +24,6 @@ class CommandBSSetDontKickVoices : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); if (ci == NULL) { @@ -32,7 +31,8 @@ class CommandBSSetDontKickVoices : public Command return; } - if (!u->HasPriv("botserv/administration") && !ci->AccessFor(u).HasPriv("SET")) + AccessGroup access = source.AccessFor(ci); + if (!source.HasPriv("botserv/administration") && !access.HasPriv("SET")) { source.Reply(ACCESS_DENIED); return; @@ -46,16 +46,16 @@ class CommandBSSetDontKickVoices : public Command if (params[1].equals_ci("ON")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to enable dontkickvoices"; + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable dontkickvoices"; ci->botflags.SetFlag(BS_DONTKICKVOICES); source.Reply(_("Bot \002won't kick voices\002 on channel %s."), ci->name.c_str()); } else if (params[1].equals_ci("OFF")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to disable dontkickvoices"; + bool override = !access.HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable dontkickvoices"; ci->botflags.UnsetFlag(BS_DONTKICKVOICES); source.Reply(_("Bot \002will kick voices\002 on channel %s."), ci->name.c_str()); diff --git a/modules/commands/bs_set_fantasy.cpp b/modules/commands/bs_set_fantasy.cpp index 06df20fbc..03bd40c70 100644 --- a/modules/commands/bs_set_fantasy.cpp +++ b/modules/commands/bs_set_fantasy.cpp @@ -24,7 +24,6 @@ class CommandBSSetFantasy : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); const Anope::string &value = params[1]; @@ -34,7 +33,7 @@ class CommandBSSetFantasy : public Command return; } - if (!u->HasPriv("botserv/administration") && !ci->AccessFor(u).HasPriv("SET")) + if (!source.HasPriv("botserv/administration") && !source.AccessFor(ci).HasPriv("SET")) { source.Reply(ACCESS_DENIED); return; @@ -48,16 +47,16 @@ class CommandBSSetFantasy : public Command if (value.equals_ci("ON")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to enable fantasy"; + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable fantasy"; ci->botflags.SetFlag(BS_FANTASY); source.Reply(_("Fantasy mode is now \002on\002 on channel %s."), ci->name.c_str()); } else if (value.equals_ci("OFF")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to disable fantasy"; + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable fantasy"; ci->botflags.UnsetFlag(BS_FANTASY); source.Reply(_("Fantasy mode is now \002off\002 on channel %s."), ci->name.c_str()); diff --git a/modules/commands/bs_set_greet.cpp b/modules/commands/bs_set_greet.cpp index 806f62f29..b74b0e5dd 100644 --- a/modules/commands/bs_set_greet.cpp +++ b/modules/commands/bs_set_greet.cpp @@ -24,7 +24,6 @@ class CommandBSSetGreet : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); const Anope::string &value = params[1]; @@ -34,7 +33,7 @@ class CommandBSSetGreet : public Command return; } - if (!u->HasPriv("botserv/administration") && !ci->AccessFor(u).HasPriv("SET")) + if (!source.HasPriv("botserv/administration") && !source.AccessFor(ci).HasPriv("SET")) { source.Reply(ACCESS_DENIED); return; @@ -48,16 +47,16 @@ class CommandBSSetGreet : public Command if (value.equals_ci("ON")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to enable greets"; + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable greets"; ci->botflags.SetFlag(BS_GREET); source.Reply(_("Greet mode is now \002on\002 on channel %s."), ci->name.c_str()); } else if (value.equals_ci("OFF")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to disable greets"; + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable greets"; ci->botflags.UnsetFlag(BS_GREET); source.Reply(_("Greet mode is now \002off\002 on channel %s."), ci->name.c_str()); diff --git a/modules/commands/bs_set_nobot.cpp b/modules/commands/bs_set_nobot.cpp index 75c3a8286..246864953 100644 --- a/modules/commands/bs_set_nobot.cpp +++ b/modules/commands/bs_set_nobot.cpp @@ -24,7 +24,6 @@ class CommandBSSetNoBot : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); const Anope::string &value = params[1]; @@ -34,7 +33,7 @@ class CommandBSSetNoBot : public Command return; } - if (!u->HasCommand("botserv/set/nobot")) + if (!source.HasCommand("botserv/set/nobot")) { source.Reply(ACCESS_DENIED); return; @@ -42,18 +41,18 @@ class CommandBSSetNoBot : public Command if (value.equals_ci("ON")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_ADMIN : LOG_COMMAND, u, this, ci) << "to enable nobot"; + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_ADMIN : LOG_COMMAND, source, this, ci) << "to enable nobot"; ci->botflags.SetFlag(BS_NOBOT); if (ci->bi) - ci->bi->UnAssign(u, ci); + ci->bi->UnAssign(source.GetUser(), ci); source.Reply(_("No Bot mode is now \002on\002 on channel %s."), ci->name.c_str()); } else if (value.equals_ci("OFF")) { - bool override = !ci->AccessFor(u).HasPriv("SET"); - Log(override ? LOG_ADMIN : LOG_COMMAND, u, this, ci) << "to disable nobot"; + bool override = !source.AccessFor(ci).HasPriv("SET"); + Log(override ? LOG_ADMIN : LOG_COMMAND, source, this, ci) << "to disable nobot"; ci->botflags.UnsetFlag(BS_NOBOT); source.Reply(_("No Bot mode is now \002off\002 on channel %s."), ci->name.c_str()); diff --git a/modules/commands/bs_set_private.cpp b/modules/commands/bs_set_private.cpp index 5a1be8d45..0cd055d00 100644 --- a/modules/commands/bs_set_private.cpp +++ b/modules/commands/bs_set_private.cpp @@ -24,7 +24,6 @@ class CommandBSSetPrivate : public Command void Execute(CommandSource &source, const std::vector ¶ms) anope_override { - User *u = source.u; BotInfo *bi = findbot(params[0]); const Anope::string &value = params[1]; @@ -34,7 +33,7 @@ class CommandBSSetPrivate : public Command return; } - if (!u->HasCommand("botserv/set/private")) + if (!source.HasCommand("botserv/set/private")) { source.Reply(ACCESS_DENIED); return; diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index ff0ee067e..c482e3c66 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -90,8 +90,6 @@ class CommandCSAccess : public Command { void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector ¶ms) { - User *u = source.u; - Anope::string mask = params[2]; int level = ACCESS_INVALID; @@ -112,7 +110,7 @@ class CommandCSAccess : public Command return; } - AccessGroup u_access = ci->AccessFor(u); + AccessGroup u_access = source.AccessFor(ci); const ChanAccess *highest = u_access.Highest(); AccessChanAccess tmp_access(NULL); @@ -123,7 +121,7 @@ class CommandCSAccess : public Command if ((!highest || *highest <= tmp_access) && !u_access.Founder) { - if (u->HasPriv("chanserv/access/modify")) + if (source.HasPriv("chanserv/access/modify")) override = true; else { @@ -150,7 +148,7 @@ class CommandCSAccess : public Command if (mask.equals_ci(access->mask)) { /* Don't allow lowering from a level >= u_level */ - if ((!highest || *access >= *highest) && !u_access.Founder && !u->HasPriv("chanserv/access/modify")) + if ((!highest || *access >= *highest) && !u_access.Founder && !source.HasPriv("chanserv/access/modify")) { source.Reply(ACCESS_DENIED); return; @@ -172,15 +170,15 @@ class CommandCSAccess : public Command AccessChanAccess *access = anope_dynamic_static_cast(provider->Create()); access->ci = ci; access->mask = mask; - access->creator = u->nick; + access->creator = source.GetNick(); access->level = level; access->last_seen = 0; access->created = Anope::CurTime; ci->AddAccess(access); - FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, u, access)); + FOREACH_MOD(I_OnAccessAdd, OnAccessAdd(ci, source, access)); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to add " << mask << " with level " << level; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << " with level " << level; source.Reply(_("\002%s\002 added to %s access list at level \002%d\002."), access->mask.c_str(), ci->name.c_str(), level); return; @@ -188,8 +186,6 @@ class CommandCSAccess : public Command void DoDel(CommandSource &source, ChannelInfo *ci, const std::vector ¶ms) { - User *u = source.u; - const Anope::string &mask = params[2]; if (!ci->GetAccessCount()) @@ -208,7 +204,7 @@ class CommandCSAccess : public Command public: AccessDelCallback(CommandSource &_source, ChannelInfo *_ci, Command *_c, const Anope::string &numlist) : NumberList(numlist, true), source(_source), ci(_ci), c(_c), Deleted(0), Denied(false), override(false) { - if (!ci->AccessFor(source.u).HasPriv("ACCESS_CHANGE") && source.u->HasPriv("chanserv/access/modify")) + if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/access/modify")) this->override = true; } @@ -220,7 +216,7 @@ class CommandCSAccess : public Command source.Reply(_("No matching entries on %s access list."), ci->name.c_str()); else { - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, ci) << "to delete " << Nicks; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, c, ci) << "to delete " << Nicks; if (Deleted == 1) source.Reply(_("Deleted 1 entry from %s access list."), ci->name.c_str()); @@ -234,14 +230,12 @@ class CommandCSAccess : public Command if (!Number || Number > ci->GetAccessCount()) return; - User *user = source.u; - ChanAccess *access = ci->GetAccess(Number - 1); - AccessGroup u_access = ci->AccessFor(user); + AccessGroup u_access = source.AccessFor(ci); const ChanAccess *u_highest = u_access.Highest(); - if ((!u_highest || *u_highest <= *access) && !u_access.Founder && !this->override && !access->mask.equals_ci(user->Account()->display)) + if ((!u_highest || *u_highest <= *access) && !u_access.Founder && !this->override && !access->mask.equals_ci(source.nc->display)) { Denied = true; return; @@ -253,7 +247,7 @@ class CommandCSAccess : public Command else Nicks = access->mask; - FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, user, access)); + FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, source, access)); ci->EraseAccess(Number - 1); } @@ -263,7 +257,7 @@ class CommandCSAccess : public Command } else { - AccessGroup u_access = ci->AccessFor(u); + AccessGroup u_access = source.AccessFor(ci); const ChanAccess *highest = u_access.Highest(); for (unsigned i = ci->GetAccessCount(); i > 0; --i) @@ -271,15 +265,15 @@ class CommandCSAccess : public Command ChanAccess *access = ci->GetAccess(i - 1); if (mask.equals_ci(access->mask)) { - if (!access->mask.equals_ci(u->Account()->display) && !u_access.Founder && (!highest || *highest <= *access) && !u->HasPriv("chanserv/access/modify")) + if (!access->mask.equals_ci(source.nc->display) && !u_access.Founder && (!highest || *highest <= *access) && !source.HasPriv("chanserv/access/modify")) source.Reply(ACCESS_DENIED); else { source.Reply(_("\002%s\002 deleted from %s access list."), access->mask.c_str(), ci->name.c_str()); - bool override = !u_access.Founder && !u_access.HasPriv("ACCESS_CHANGE") && !access->mask.equals_ci(u->Account()->display); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to delete " << access->mask; + bool override = !u_access.Founder && !u_access.HasPriv("ACCESS_CHANGE") && !access->mask.equals_ci(source.nc->display); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << access->mask; - FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, u, access)); + FOREACH_MOD(I_OnAccessDel, OnAccessDel(ci, source, access)); ci->EraseAccess(access); } return; @@ -420,20 +414,18 @@ class CommandCSAccess : public Command void DoClear(CommandSource &source, ChannelInfo *ci) { - User *u = source.u; - - if (!IsFounder(u, ci) && !u->HasPriv("chanserv/access/modify")) + if (!source.IsFounder(ci) && !source.HasPriv("chanserv/access/modify")) source.Reply(ACCESS_DENIED); else { - FOREACH_MOD(I_OnAccessClear, OnAccessClear(ci, u)); + FOREACH_MOD(I_OnAccessClear, OnAccessClear(ci, source)); ci->ClearAccess(); source.Reply(_("Channel %s access list has been cleared."), ci->name.c_str()); - bool override = !IsFounder(u, ci); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to clear the access list"; + bool override = !source.IsFounder(ci); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clear the access list"; } return; @@ -456,7 +448,6 @@ class CommandCSAccess : public Command const Anope::string &nick = params.size() > 2 ? params[2] : ""; const Anope::string &s = params.size() > 3 ? params[3] : ""; - User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); if (ci == NULL) { @@ -469,16 +460,16 @@ class CommandCSAccess : public Command bool is_del = cmd.equals_ci("DEL"); bool has_access = false; - if (u->HasPriv("chanserv/access/modify")) + if (source.HasPriv("chanserv/access/modify")) has_access = true; - else if (is_list && ci->AccessFor(u).HasPriv("ACCESS_LIST")) + else if (is_list && source.AccessFor(ci).HasPriv("ACCESS_LIST")) has_access = true; - else if (ci->AccessFor(u).HasPriv("ACCESS_CHANGE")) + else if (source.AccessFor(ci).HasPriv("ACCESS_CHANGE")) has_access = true; else if (is_del) { const NickAlias *na = findnick(nick); - if (na && na->nc == u->Account()) + if (na && na->nc == source.nc) has_access = true; } @@ -575,8 +566,6 @@ class CommandCSLevels : public Command { void DoSet(CommandSource &source, ChannelInfo *ci, const std::vector ¶ms) { - User *u = source.u; - const Anope::string &what = params[2]; const Anope::string &lev = params[3]; @@ -607,10 +596,10 @@ class CommandCSLevels : public Command else { ci->SetLevel(p->name, level); - FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, p->name, level)); + FOREACH_MOD(I_OnLevelChange, OnLevelChange(source, ci, p->name, level)); - bool override = !ci->AccessFor(u).HasPriv("FOUNDER"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to set " << p->name << " to level " << level; + bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to set " << p->name << " to level " << level; if (level == ACCESS_FOUNDER) source.Reply(_("Level for %s on channel %s changed to founder only."), p->name.c_str(), ci->name.c_str()); @@ -622,8 +611,6 @@ class CommandCSLevels : public Command void DoDisable(CommandSource &source, ChannelInfo *ci, const std::vector ¶ms) { - User *u = source.u; - 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 */ @@ -633,10 +620,10 @@ class CommandCSLevels : public Command if (p != NULL) { ci->SetLevel(p->name, ACCESS_INVALID); - FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, p->name, ACCESS_INVALID)); + FOREACH_MOD(I_OnLevelChange, OnLevelChange(source, ci, p->name, ACCESS_INVALID)); - bool override = !ci->AccessFor(u).HasPriv("FOUNDER"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to disable " << p->name; + bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable " << p->name; source.Reply(_("\002%s\002 disabled on channel %s."), p->name.c_str(), ci->name.c_str()); return; @@ -684,13 +671,11 @@ class CommandCSLevels : public Command void DoReset(CommandSource &source, ChannelInfo *ci) { - User *u = source.u; - reset_levels(ci); - FOREACH_MOD(I_OnLevelChange, OnLevelChange(u, ci, "ALL", 0)); + FOREACH_MOD(I_OnLevelChange, OnLevelChange(source, ci, "ALL", 0)); - bool override = !ci->AccessFor(u).HasPriv("FOUNDER"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to reset all levels"; + bool override = !source.AccessFor(ci).HasPriv("FOUNDER"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to reset all levels"; source.Reply(_("Access levels for \002%s\002 reset to defaults."), ci->name.c_str()); return; @@ -712,8 +697,6 @@ class CommandCSLevels : public Command const Anope::string &what = params.size() > 2 ? params[2] : ""; const Anope::string &s = params.size() > 3 ? params[3] : ""; - User *u = source.u; - ChannelInfo *ci = cs_findchan(params[0]); if (ci == NULL) { @@ -726,7 +709,7 @@ 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(source, cmd); - else if (!ci->AccessFor(u).HasPriv("FOUNDER") && !u->HasPriv("chanserv/access/modify")) + else if (!source.AccessFor(ci).HasPriv("FOUNDER") && !source.HasPriv("chanserv/access/modify")) source.Reply(ACCESS_DENIED); else if (cmd.equals_ci("SET")) this->DoSet(source, ci, params); @@ -757,7 +740,7 @@ class CommandCSLevels : public Command const Privilege &p = privs[i]; ListFormatter::ListEntry entry; entry["Name"] = p.name; - entry["Description"] = translate(source.u, p.desc.c_str()); + entry["Description"] = translate(source.nc, p.desc.c_str()); list.addEntry(entry); } diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 107f97584..1ff67215c 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -50,8 +50,6 @@ class CommandCSAKick : public Command { void DoAdd(CommandSource &source, ChannelInfo *ci, const std::vector ¶ms) { - User *u = source.u; - Anope::string mask = params[2]; Anope::string reason = params.size() > 3 ? params[3] : ""; const NickAlias *na = findnick(mask); @@ -86,7 +84,7 @@ class CommandCSAKick : public Command * or whether the mask matches a user with higher/equal access - Viper */ if (ci->HasFlag(CI_PEACE) && nc) { - AccessGroup nc_access = ci->AccessFor(nc), u_access = ci->AccessFor(u); + AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); if (nc == ci->GetFounder() || nc_access >= u_access) { source.Reply(ACCESS_DENIED); @@ -101,7 +99,7 @@ class CommandCSAKick : public Command { User *u2 = it->second; - AccessGroup nc_access = ci->AccessFor(nc), u_access = ci->AccessFor(u); + AccessGroup nc_access = ci->AccessFor(nc), u_access = source.AccessFor(ci); Entry entry_mask(CMODE_BEGIN, mask); if ((ci->AccessFor(u2).HasPriv("FOUNDER") || nc_access >= u_access) && entry_mask.Matches(u2)) @@ -117,7 +115,7 @@ class CommandCSAKick : public Command { na = it->second; - AccessGroup nc_access = ci->AccessFor(na->nc), u_access = ci->AccessFor(u); + AccessGroup nc_access = ci->AccessFor(na->nc), u_access = source.AccessFor(ci); if (na->nc && (na->nc == ci->GetFounder() || nc_access >= u_access)) { Anope::string buf = na->nick + "!" + na->last_usermask; @@ -147,14 +145,14 @@ class CommandCSAKick : public Command } if (nc) - akick = ci->AddAkick(u->nick, nc, reason); + akick = ci->AddAkick(source.GetNick(), nc, reason); else - akick = ci->AddAkick(u->nick, mask, reason); + akick = ci->AddAkick(source.GetNick(), mask, reason); - bool override = !ci->AccessFor(u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to add " << mask << (reason == "" ? "" : ": ") << reason; + bool override = !source.AccessFor(ci).HasPriv("AKICK"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to add " << mask << (reason == "" ? "" : ": ") << reason; - FOREACH_MOD(I_OnAkickAdd, OnAkickAdd(u, ci, akick)); + FOREACH_MOD(I_OnAkickAdd, OnAkickAdd(source, ci, akick)); source.Reply(_("\002%s\002 added to %s autokick list."), mask.c_str(), ci->name.c_str()); @@ -163,8 +161,6 @@ class CommandCSAKick : public Command void DoDel(CommandSource &source, ChannelInfo *ci, const std::vector ¶ms) { - User *u = source.u; - const Anope::string &mask = params[2]; unsigned i, end; @@ -190,8 +186,8 @@ class CommandCSAKick : public Command ~AkickDelCallback() { - bool override = !ci->AccessFor(source.u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source.u, c, ci) << "to delete " << Deleted << (Deleted == 1 ? " entry" : " entries"); + bool override = !source.AccessFor(ci).HasPriv("AKICK"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, c, ci) << "to delete " << Deleted << (Deleted == 1 ? " entry" : " entries"); if (!Deleted) source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); @@ -206,7 +202,7 @@ class CommandCSAKick : public Command if (!Number || Number > ci->GetAkickCount()) return; - FOREACH_MOD(I_OnAkickDel, OnAkickDel(source.u, ci, ci->GetAkick(Number - 1))); + FOREACH_MOD(I_OnAkickDel, OnAkickDel(source, ci, ci->GetAkick(Number - 1))); ++Deleted; ci->EraseAkick(Number - 1); @@ -234,10 +230,10 @@ class CommandCSAKick : public Command return; } - bool override = !ci->AccessFor(u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to delete " << mask; + bool override = !source.AccessFor(ci).HasPriv("AKICK"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to delete " << mask; - FOREACH_MOD(I_OnAkickDel, OnAkickDel(u, ci, ci->GetAkick(i))); + FOREACH_MOD(I_OnAkickDel, OnAkickDel(source, ci, ci->GetAkick(i))); ci->EraseAkick(i); @@ -370,7 +366,6 @@ class CommandCSAKick : public Command void DoEnforce(CommandSource &source, ChannelInfo *ci) { - User *u = source.u; Channel *c = ci->c; int count = 0; @@ -388,17 +383,16 @@ class CommandCSAKick : public Command ++count; } - bool override = !ci->AccessFor(u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "ENFORCE, affects " << count << " users"; + bool override = !source.AccessFor(ci).HasPriv("AKICK"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "ENFORCE, affects " << count << " users"; source.Reply(_("AKICK ENFORCE for \002%s\002 complete; \002%d\002 users were affected."), ci->name.c_str(), count); } void DoClear(CommandSource &source, ChannelInfo *ci) { - User *u = source.u; - bool override = !ci->AccessFor(u).HasPriv("AKICK"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to clear the akick list"; + bool override = !source.AccessFor(ci).HasPriv("AKICK"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to clear the akick list"; ci->ClearAkick(); source.Reply(_("Channel %s akick list has been cleared."), ci->name.c_str()); @@ -422,8 +416,6 @@ class CommandCSAKick : public Command Anope::string cmd = params[1]; Anope::string mask = params.size() > 2 ? params[2] : ""; - User *u = source.u; - ChannelInfo *ci = cs_findchan(params[0]); if (ci == NULL) { @@ -433,7 +425,7 @@ class CommandCSAKick : public Command if (mask.empty() && (cmd.equals_ci("ADD") || cmd.equals_ci("DEL"))) this->OnSyntaxError(source, cmd); - else if (!ci->AccessFor(u).HasPriv("AKICK") && !u->HasPriv("chanserv/access/modify")) + else if (!source.AccessFor(ci).HasPriv("AKICK") && !source.HasPriv("chanserv/access/modify")) source.Reply(ACCESS_DENIED); else if (!cmd.equals_ci("LIST") && !cmd.equals_ci("VIEW") && !cmd.equals_ci("ENFORCE") && readonly) source.Reply(_("Sorry, channel autokick list modification is temporarily disabled.")); diff --git a/modules/commands/cs_appendtopic.cpp b/modules/commands/cs_appendtopic.cpp index fe1633b8a..70cde7b7b 100644 --- a/modules/commands/cs_appendtopic.cpp +++ b/modules/commands/cs_appendtopic.cpp @@ -52,14 +52,13 @@ class CommandCSAppendTopic : public Command { const Anope::string &newtopic = params[1]; - User *u = source.u; Channel *c = findchan(params[0]);; if (!c) source.Reply(CHAN_X_NOT_IN_USE, params[0].c_str()); else if (!c->ci) source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str()); - else if (!c->ci->AccessFor(u).HasPriv("TOPIC") && !u->HasCommand("chanserv/topic")) + else if (!source.AccessFor(c->ci).HasPriv("TOPIC") && !source.HasCommand("chanserv/topic")) source.Reply(ACCESS_DENIED); else { @@ -74,12 +73,12 @@ class CommandCSAppendTopic : public Command bool has_topiclock = c->ci->HasFlag(CI_TOPICLOCK); c->ci->UnsetFlag(CI_TOPICLOCK); - c->ChangeTopic(u->nick, topic, Anope::CurTime); + c->ChangeTopic(source.GetNick(), topic, Anope::CurTime); if (has_topiclock) c->ci->SetFlag(CI_TOPICLOCK); - bool override = !c->ci->AccessFor(u).HasPriv("TOPIC"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, c->ci) << "to append: " << topic; + bool override = !source.AccessFor(c->ci).HasPriv("TOPIC"); + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, c->ci) << "to append: " << topic; } return; } diff --git a/modules/commands/cs_ban.cpp b/modules/commands/cs_ban.cpp index 867d654c5..063d98ab5 100644 --- a/modules/commands/cs_ban.cpp +++ b/modules/commands/cs_ban.cpp @@ -36,11 +36,11 @@ class CommandCSBan : public Command return; } - User *u = source.u; Channel *c = ci->c; + User *u = source.GetUser(); User *u2 = finduser(target); - AccessGroup u_access = ci->AccessFor(u); + AccessGroup u_access = source.AccessFor(ci); if (!c) source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); @@ -66,7 +66,7 @@ class CommandCSBan : public Command get_idealban(ci, u2, mask); // XXX need a way to detect if someone is overriding - Log(LOG_COMMAND, u, this, ci) << "for " << mask; + Log(LOG_COMMAND, source, this, ci) << "for " << mask; c->SetMode(NULL, CMODE_BAN, mask); @@ -74,15 +74,15 @@ class CommandCSBan : public Command if (!c->FindUser(u2)) return; - if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !ci->AccessFor(u).HasPriv("SIGNKICK"))) - c->Kick(ci->WhoSends(), u2, "%s (%s)", reason.c_str(), u->nick.c_str()); + if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !source.AccessFor(ci).HasPriv("SIGNKICK"))) + c->Kick(ci->WhoSends(), u2, "%s (%s)", reason.c_str(), source.GetNick().c_str()); else c->Kick(ci->WhoSends(), u2, "%s", reason.c_str()); } } else if (u_access.HasPriv("FOUNDER")) { - Log(LOG_COMMAND, u, this, ci) << "for " << target; + Log(LOG_COMMAND, source, this, ci) << "for " << target; c->SetMode(NULL, CMODE_BAN, target); @@ -106,7 +106,7 @@ class CommandCSBan : public Command ++kicked; if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !u_access.HasPriv("SIGNKICK"))) - c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s) (%s)", reason.c_str(), target.c_str(), u->nick.c_str()); + c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s) (%s)", reason.c_str(), target.c_str(), source.GetNick().c_str()); else c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s)", reason.c_str(), target.c_str()); } diff --git a/modules/commands/cs_clearusers.cpp b/modules/commands/cs_clearusers.cpp index 58de57f5a..1c26fe382 100644 --- a/modules/commands/cs_clearusers.cpp +++ b/modules/commands/cs_clearusers.cpp @@ -26,7 +26,6 @@ class CommandCSClearUsers : public Command { const Anope::string &chan = params[0]; - User *u = source.u; Channel *c = findchan(chan); Anope::string modebuf; @@ -40,13 +39,13 @@ class CommandCSClearUsers : public Command source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str()); return; } - else if (!c->ci->AccessFor(u).HasPriv("FOUNDER") && !u->HasCommand("chanserv/clearusers")) + else if (!source.AccessFor(c->ci).HasPriv("FOUNDER") && !source.HasCommand("chanserv/clearusers")) { source.Reply(ACCESS_DENIED); return; } - Anope::string buf = "CLEARUSERS command from " +