diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/botserv.cpp | 4 | ||||
-rw-r--r-- | src/command.cpp | 6 | ||||
-rw-r--r-- | src/commands.cpp | 65 | ||||
-rw-r--r-- | src/language.cpp | 10 | ||||
-rw-r--r-- | src/memoserv.cpp | 42 | ||||
-rw-r--r-- | src/modules.cpp | 6 |
6 files changed, 70 insertions, 63 deletions
diff --git a/src/botserv.cpp b/src/botserv.cpp index 82826b489..1e7eb9551 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -332,7 +332,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) Anope::string message = sep.GetRemaining(); EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, ci->bi, command, message, true)); + FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, ci->bi, command, message, ci)); if (MOD_RESULT == EVENT_STOP) return; @@ -346,7 +346,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) message = ci->name + " " + message; message = command + " " + message; - mod_run_cmd(ChanServ, u, message, true); + mod_run_cmd(ChanServ, u, message, ci); } FOREACH_MOD(I_OnBotFantasy, OnBotFantasy(command, u, ci, sep.GetRemaining())); diff --git a/src/command.cpp b/src/command.cpp index d71685f4f..7c0a503fb 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -78,11 +78,11 @@ Command::~Command() this->module->DelCommand(this->service, this); } -void Command::OnServHelp(User *u) { } +void Command::OnServHelp(CommandSource &source) { } -bool Command::OnHelp(User *u, const Anope::string &subcommand) { return false; } +bool Command::OnHelp(CommandSource &source, const Anope::string &subcommand) { return false; } -void Command::OnSyntaxError(User *u, const Anope::string &subcommand) { } +void Command::OnSyntaxError(CommandSource &source, const Anope::string &subcommand) { } void Command::SetPermission(const Anope::string &reststr) { diff --git a/src/commands.cpp b/src/commands.cpp index 97078af09..e9671f3bd 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -26,7 +26,7 @@ Command *FindCommand(BotInfo *bi, const Anope::string &name) return NULL; } -void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &fullmessage, bool fantasy) +void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &fullmessage, ChannelInfo *ci) { if (!bi || !u) return; @@ -39,16 +39,16 @@ void mod_run_cmd(BotInfo *bi, User *u, const Anope::string &fullmessage, bool fa message = sep.GetRemaining(); EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, bi, command, message, fantasy)); + FOREACH_RESULT(I_OnPreCommandRun, OnPreCommandRun(u, bi, command, message, ci)); if (MOD_RESULT == EVENT_STOP) return; Command *c = FindCommand(bi, command); - mod_run_cmd(bi, u, c, command, message, fantasy); + mod_run_cmd(bi, u, c, command, message, ci); } -void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message, bool fantasy) +void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, const Anope::string &message, ChannelInfo *ci) { if (!bi || !u) return; @@ -88,18 +88,7 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, params.push_back(endparam); } - if (params.size() < c->MinParams) - { - c->OnSyntaxError(u, !params.empty() ? params[params.size() - 1] : ""); - return; - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreCommand, OnPreCommand(u, c->service, c->name, params)); - if (MOD_RESULT == EVENT_STOP) - return; - - ChannelInfo *ci = NULL; + bool fantasy = ci != NULL; if (params.size() > 0 && !c->HasFlag(CFLAG_STRIP_CHANNEL) && (bi == ChanServ || bi == BotServ)) { if (ircdproto->IsChannelValid(params[0])) @@ -134,6 +123,24 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, } } + CommandSource source; + source.u = u; + source.ci = ci; + source.owner = bi; + source.service = fantasy && ci ? ci->bi : c->service; + source.fantasy = fantasy; + + if (params.size() < c->MinParams) + { + c->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : ""); + return; + } + + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, c, params)); + if (MOD_RESULT == EVENT_STOP) + return; + // If the command requires a permission, and they aren't registered or don't have the required perm, DENIED if (!c->permission.empty() && !u->Account()->HasCommand(c->permission)) { @@ -142,13 +149,6 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, return; } - CommandSource source; - source.u = u; - source.ci = ci; - source.owner = bi; - source.service = fantasy && ci ? ci->bi : c->service; - source.fantasy = fantasy; - CommandReturn ret = c->Execute(source, params); if (ret == MOD_CONT) @@ -159,13 +159,12 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, /** * Prints the help message for a given command. - * @param services Services Client - * @param u User Struct - * @param Command Hash Table + * @param bi Client the command is on + * @param u User + * @param ci Optional channel the command was executed one (fantasy) * @param cmd Command - * @return void */ -void mod_help_cmd(BotInfo *bi, User *u, const Anope::string &cmd) +void mod_help_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &cmd) { if (!bi || !u || cmd.empty()) return; @@ -175,10 +174,16 @@ void mod_help_cmd(BotInfo *bi, User *u, const Anope::string &cmd) tokens.GetToken(token); Command *c = FindCommand(bi, token); - Anope::string subcommand = tokens.StreamEnd() ? "" : tokens.GetRemaining(); - if (!c || (Config->HidePrivilegedCommands && !c->permission.empty() && (!u->Account() || !u->Account()->HasCommand(c->permission))) || !c->OnHelp(u, subcommand)) + CommandSource source; + source.u = u; + source.ci = ci; + source.owner = bi; + source.service = ci ? ci->bi : bi; + source.fantasy = ci != NULL; + + if (!c || (Config->HidePrivilegedCommands && !c->permission.empty() && (!u->Account() || !u->Account()->HasCommand(c->permission))) || !c->OnHelp(source, subcommand)) u->SendMessage(bi, NO_HELP_AVAILABLE, cmd.c_str()); else { diff --git a/src/language.cpp b/src/language.cpp index ea6f37ee8..649398cb3 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -123,14 +123,14 @@ const Anope::string GetString(const char *domain, Anope::string language, const } #endif -void SyntaxError(BotInfo *bi, User *u, const Anope::string &command, LanguageString message) +void SyntaxError(CommandSource &source, const Anope::string &command, LanguageString message) { - if (!bi || !u || command.empty()) + if (command.empty()) return; - Anope::string str = GetString(u, message); - u->SendMessage(bi, SYNTAX_ERROR, str.c_str()); - u->SendMessage(bi, MORE_INFO, bi->nick.c_str(), command.c_str()); + Anope::string str = GetString(source.u, message); + source.Reply(SYNTAX_ERROR, str.c_str()); + source.Reply(MORE_INFO, source.owner->nick.c_str(), command.c_str()); } const char *const language_strings[LANG_STRING_COUNT] = { diff --git a/src/memoserv.cpp b/src/memoserv.cpp index eac54cc6d..ef6a9a5f8 100644 --- a/src/memoserv.cpp +++ b/src/memoserv.cpp @@ -145,7 +145,7 @@ MemoInfo *getmemoinfo(const Anope::string &name, bool &ischan, bool &isforbid) /** * Split from do_send, this way we can easily send a memo from any point - * @param u User Struct + * @param source Where replies should go * @param name Target of the memo * @param text Memo Text * @param z type see info @@ -155,71 +155,73 @@ MemoInfo *getmemoinfo(const Anope::string &name, bool &ischan, bool &isforbid) * 3 - reply to user and request read receipt * @return void */ -void memo_send(User *u, const Anope::string &name, const Anope::string &text, int z) +void memo_send(CommandSource &source, const Anope::string &name, const Anope::string &text, int z) { if (Config->s_MemoServ.empty()) return; + User *u = source.u; + bool ischan, isforbid; MemoInfo *mi; - Anope::string source = u->Account()->display; - int is_servoper = u->Account() && u->Account()->IsServicesOper(); + Anope::string sender = u && u->Account() ? u->Account()->display : ""; + int is_servoper = u && u->Account() && u->Account()->IsServicesOper(); if (readonly) u->SendMessage(MemoServ, MEMO_SEND_DISABLED); else if (text.empty()) { if (!z) - SyntaxError(MemoServ, u, "SEND", MEMO_SEND_SYNTAX); + SyntaxError(source, "SEND", MEMO_SEND_SYNTAX); if (z == 3) - SyntaxError(MemoServ, u, "RSEND", MEMO_RSEND_SYNTAX); + SyntaxError(source, "RSEND", MEMO_RSEND_SYNTAX); } else if (!u->IsIdentified() && !u->IsRecognized()) { if (!z || z == 3) - u->SendMessage(MemoServ, NICK_IDENTIFY_REQUIRED, Config->s_NickServ.c_str()); + source.Reply(NICK_IDENTIFY_REQUIRED, Config->s_NickServ.c_str()); } else if (!(mi = getmemoinfo(name, ischan, isforbid))) { if (!z || z == 3) { if (isforbid) - u->SendMessage(MemoServ, ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name.c_str()); + source.Reply(ischan ? CHAN_X_FORBIDDEN : NICK_X_FORBIDDEN, name.c_str()); else - u->SendMessage(MemoServ, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name.c_str()); + source.Reply(ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name.c_str()); } } else if (z != 2 && Config->MSSendDelay > 0 && u && u->lastmemosend + Config->MSSendDelay > Anope::CurTime) { u->lastmemosend = Anope::CurTime; if (!z) - u->SendMessage(MemoServ, MEMO_SEND_PLEASE_WAIT, Config->MSSendDelay); + source.Reply(MEMO_SEND_PLEASE_WAIT, Config->MSSendDelay); if (z == 3) - u->SendMessage(MemoServ, MEMO_RSEND_PLEASE_WAIT, Config->MSSendDelay); + source.Reply(MEMO_RSEND_PLEASE_WAIT, Config->MSSendDelay); } else if (!mi->memomax && !is_servoper) { if (!z || z == 3) - u->SendMessage(MemoServ, MEMO_X_GETS_NO_MEMOS, name.c_str()); + source.Reply(MEMO_X_GETS_NO_MEMOS, name.c_str()); } else if (mi->memomax > 0 && mi->memos.size() >= mi->memomax && !is_servoper) { if (!z || z == 3) - u->SendMessage(MemoServ, MEMO_X_HAS_TOO_MANY_MEMOS, name.c_str()); + source.Reply(MEMO_X_HAS_TOO_MANY_MEMOS, name.c_str()); } else { if (!z || z == 3) - u->SendMessage(MemoServ, MEMO_SENT, name.c_str()); + source.Reply(MEMO_SENT, name.c_str()); if ((!u->Account() || !u->Account()->IsServicesOper()) && mi->HasIgnore(u)) return; u->lastmemosend = Anope::CurTime; Memo *m = new Memo(); mi->memos.push_back(m); - m->sender = source; + m->sender = sender; m->time = Anope::CurTime; m->text = text; m->SetFlag(MF_UNREAD); @@ -244,13 +246,13 @@ void memo_send(User *u, const Anope::string &name, const Anope::string &text, in NickAlias *na = *it; User *user = finduser(na->nick); if (user && user->IsIdentified()) - user->SendMessage(MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->s_MemoServ.c_str(), mi->memos.size()); + source.Reply(MEMO_NEW_MEMO_ARRIVED, sender.c_str(), Config->s_MemoServ.c_str(), mi->memos.size()); } } else { if ((u = finduser(name)) && u->IsIdentified() && nc->HasFlag(NI_MEMO_RECEIVE)) - u->SendMessage(MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->s_MemoServ.c_str(), mi->memos.size()); + source.Reply(MEMO_NEW_MEMO_ARRIVED, sender.c_str(), Config->s_MemoServ.c_str(), mi->memos.size()); } /* if (flags & MEMO_RECEIVE) */ } /* if (MSNotifyAll) */ @@ -333,7 +335,7 @@ static bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m) /* Send receipt notification to sender. */ -void rsend_notify(User *u, Memo *m, const Anope::string &chan) +void rsend_notify(CommandSource &source, Memo *m, const Anope::string &chan) { /* Only send receipt if memos are allowed */ if (!readonly) @@ -359,11 +361,11 @@ void rsend_notify(User *u, Memo *m, const Anope::string &chan) snprintf(text, sizeof(text), "%s", GetString(na->nc, MEMO_RSEND_NICK_MEMO_TEXT).c_str()); /* Send notification */ - memo_send(u, m->sender, text, 2); + memo_send(source, m->sender, text, 2); /* Notify recepient of the memo that a notification has been sent to the sender */ - u->SendMessage(MemoServ, MEMO_RSEND_USER_NOTIFICATION, nc->display.c_str()); + source.Reply(MEMO_RSEND_USER_NOTIFICATION, nc->display.c_str()); } /* Remove receipt flag from the original memo */ diff --git a/src/modules.cpp b/src/modules.cpp index 1fc83c06e..63e6bcab3 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -282,9 +282,9 @@ Version Module::GetVersion() const return Version(VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); } -void Module::SendMessage(BotInfo *from, User *to, const char *fmt, ...) +void Module::SendMessage(CommandSource &source, const char *fmt, ...) { - Anope::string language = (to && to->Account() ? to->Account()->language : ""); + Anope::string language = (source.u && source.u->Account() ? source.u->Account()->language : ""); Anope::string message = GetString(this->name.c_str(), language, fmt); @@ -298,7 +298,7 @@ void Module::SendMessage(BotInfo *from, User *to, const char *fmt, ...) Anope::string token; while (sep.GetToken(token)) - to->SendMessage(from->nick, token); + source.Reply(token.c_str()); } Service::Service(Module *o, const Anope::string &n) : owner(o), name(n) |