From ee3289029d61da12013e0f5a3e4faf2d07543a0e Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 25 Jun 2014 11:02:19 -0400 Subject: Remove the rest of the 1.8 logic "let's write all of the command handler with no return statement!" Fix if (something) else if (!something) tests Remove returns at the bottom of void functions --- modules/commands/bs_badwords.cpp | 19 ++-- modules/commands/bs_bot.cpp | 4 +- modules/commands/bs_botlist.cpp | 15 +-- modules/commands/bs_info.cpp | 2 +- modules/commands/cs_access.cpp | 54 ++++++++--- modules/commands/cs_akick.cpp | 19 ++-- modules/commands/cs_enforce.cpp | 18 +++- modules/commands/cs_flags.cpp | 12 ++- modules/commands/cs_log.cpp | 44 +++++---- modules/commands/cs_register.cpp | 107 +++++++++++++-------- modules/commands/cs_updown.cpp | 8 +- modules/commands/cs_xop.cpp | 6 +- modules/commands/help.cpp | 14 +-- modules/commands/hs_del.cpp | 40 ++++---- modules/commands/hs_group.cpp | 21 ++-- modules/commands/hs_off.cpp | 13 +-- modules/commands/hs_on.cpp | 27 +++--- modules/commands/hs_request.cpp | 72 ++++++++------ modules/commands/ms_del.cpp | 52 +++++----- modules/commands/ms_list.cpp | 121 +++++++++++------------ modules/commands/ms_read.cpp | 57 +++++------ modules/commands/ms_rsend.cpp | 1 + modules/commands/ms_set.cpp | 2 +- modules/commands/ns_ajoin.cpp | 40 ++++---- modules/commands/ns_drop.cpp | 21 ++-- modules/commands/ns_getpass.cpp | 28 +++--- modules/commands/ns_group.cpp | 143 +++++++++++++++++---------- modules/commands/ns_identify.cpp | 54 ++++++----- modules/commands/ns_info.cpp | 117 +++++++++++----------- modules/commands/ns_logout.cpp | 47 +++++---- modules/commands/ns_register.cpp | 197 ++++++++++++++++++++++---------------- modules/commands/ns_resetpass.cpp | 23 +++-- modules/commands/ns_set.cpp | 38 +++----- modules/commands/os_akill.cpp | 6 +- modules/commands/os_chankill.cpp | 59 ++++++------ modules/commands/os_defcon.cpp | 1 - 36 files changed, 856 insertions(+), 646 deletions(-) (limited to 'modules') diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp index 5e9dd363a..a29209e31 100644 --- a/modules/commands/bs_badwords.cpp +++ b/modules/commands/bs_badwords.cpp @@ -245,19 +245,20 @@ class CommandBSBadwords : public Command } if (list.IsEmpty()) - source.Reply(_("No matching entries on the bad word list of \002{0}\002."), ci->name); - else { - std::vector replies; - list.Process(replies); + source.Reply(_("No matching entries on the bad word list of \002{0}\002."), ci->name); + return; + } - source.Reply(_("Bad words list for \002{0}\002:"), ci->name); + std::vector replies; + list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + source.Reply(_("Bad words list for \002{0}\002:"), ci->name); - source.Reply(_("End of bad words list.")); - } + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + + source.Reply(_("End of bad words list.")); } void DoAdd(CommandSource &source, ChanServ::Channel *ci, const Anope::string &word) diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp index f4beba6e6..79c23a764 100644 --- a/modules/commands/bs_bot.cpp +++ b/modules/commands/bs_bot.cpp @@ -76,7 +76,7 @@ class CommandBSBot : public Command NickServ::Nick *na = NickServ::FindNick(nick); if (na) { - source.Reply(_("Nickname \002{0}\002 is already registered!"), na->nick); + source.Reply(_("\002{0}\002 is already registered!"), na->nick); return; } @@ -188,7 +188,7 @@ class CommandBSBot : public Command NickServ::Nick *na = NickServ::FindNick(nick); if (na) { - source.Reply(_("Nickname \002{0}\002 is already registered."), na->nick); + source.Reply(_("\002{0}\002 is already registered."), na->nick); return; } diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp index 85855bb82..58b763d47 100644 --- a/modules/commands/bs_botlist.cpp +++ b/modules/commands/bs_botlist.cpp @@ -44,16 +44,17 @@ class CommandBSBotList : public Command list.Process(replies); if (!count) - source.Reply(_("There are no bots available at this time.")); - else { - source.Reply(_("Bot list:")); + source.Reply(_("There are no bots available")); + return; + } - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + source.Reply(_("Bot list:")); - source.Reply(_("{0} bots available."), count); - } + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + + source.Reply(_("{0} bots available."), count); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp index 677dfaaf6..4d7bc0765 100644 --- a/modules/commands/bs_info.cpp +++ b/modules/commands/bs_info.cpp @@ -81,7 +81,7 @@ class CommandBSInfo : public Command source.Reply(replies[i]); } else - source.Reply(_("\002{0}\002 is not a valid bot or registered channel."), query.c_str()); + source.Reply(_("\002{0}\002 is not a valid bot or registered channel."), query); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index a1153cac6..5f38dc09a 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -437,20 +437,20 @@ class CommandCSAccess : public Command } if (list.IsEmpty()) - source.Reply(_("No matching entries on the access list of \002{0}\002."), ci->name); - else { - std::vector replies; - list.Process(replies); + source.Reply(_("No matching entries on the access list of \002{0}\002."), ci->name); + return; + } - source.Reply(_("Access list for \002{0}\002:"), ci->name); + std::vector replies; + list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + source.Reply(_("Access list for \002{0}\002:"), ci->name); - source.Reply(_("End of access list")); - } + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + source.Reply(_("End of access list.")); } void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) @@ -546,12 +546,24 @@ class CommandCSAccess : public Command * If DEL, we require a nick and no level. * Else (ADD), we require a level (which implies a nick). */ if (is_list || is_clear ? 0 : (cmd.equals_ci("DEL") ? (nick.empty() || !s.empty()) : s.empty())) + { this->OnSyntaxError(source, cmd); - else if (!has_access) + return; + } + + if (!has_access) + { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), is_list ? "ACCESS_LIST" : "ACCESS_CHANGE", ci->name); - else if (Anope::ReadOnly && !is_list) + return; + } + + if (Anope::ReadOnly && !is_list) + { source.Reply(_("Sorry, channel access list modification is temporarily disabled.")); - else if (cmd.equals_ci("ADD")) + return; + } + + if (cmd.equals_ci("ADD")) this->DoAdd(source, ci, params); else if (cmd.equals_ci("DEL")) this->DoDel(source, ci, params); @@ -813,12 +825,24 @@ class CommandCSLevels : public Command * one; else, we want none. */ 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 (!source.AccessFor(ci).HasPriv("FOUNDER") && !source.HasPriv("chanserv/access/modify")) + return; + } + + if (!source.AccessFor(ci).HasPriv("FOUNDER") && !source.HasPriv("chanserv/access/modify")) + { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "FOUNDER", ci->name); - else if (Anope::ReadOnly && !cmd.equals_ci("LIST")) + return; + } + + if (Anope::ReadOnly && !cmd.equals_ci("LIST")) + { source.Reply(_("Services are in read-only mode.")); - else if (cmd.equals_ci("SET")) + return; + } + + if (cmd.equals_ci("SET")) this->DoSet(source, ci, params); else if (cmd.equals_ci("DIS") || cmd.equals_ci("DISABLE")) this->DoDisable(source, ci, params); diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 435373810..9f69810fc 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -418,19 +418,20 @@ class CommandCSAKick : public Command } if (list.IsEmpty()) - source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); - else { - std::vector replies; - list.Process(replies); + source.Reply(_("No matching entries on %s autokick list."), ci->name.c_str()); + return; + } - source.Reply(_("Autokick list for %s:"), ci->name.c_str()); + std::vector replies; + list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + source.Reply(_("Autokick list for %s:"), ci->name.c_str()); - source.Reply(_("End of autokick list")); - } + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + + source.Reply(_("End of autokick list")); } void DoList(CommandSource &source, ChanServ::Channel *ci, const std::vector ¶ms) diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp index 64ef9ab0d..80abed196 100644 --- a/modules/commands/cs_enforce.cpp +++ b/modules/commands/cs_enforce.cpp @@ -235,12 +235,24 @@ class CommandCSEnforce : public Command ChanServ::Channel *ci = ChanServ::Find(params[0]); if (!ci) + { source.Reply(_("Channel \002{0}\002 isn't registered."), params[0]); - else if (!ci->c) + return; + } + + if (!ci->c) + { source.Reply(_("Channel \002{0}\002 doesn't exist."), ci->name); - else if (!source.AccessFor(ci).HasPriv("AKICK") && !source.HasPriv("chanserv/access/modify")) + return; + } + + if (!source.AccessFor(ci).HasPriv("AKICK") && !source.HasPriv("chanserv/access/modify")) + { source.Reply("Access denied. You do not have the \002{0}\002 privilege on \002{1}\002.", "AKICK", ci->name); - else if (what.equals_ci("SECUREOPS")) + return; + } + + if (what.equals_ci("SECUREOPS")) this->DoSecureOps(source, ci); else if (what.equals_ci("RESTRICTED")) this->DoRestricted(source, ci); diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp index 7e17a1b47..ac03febb7 100644 --- a/modules/commands/cs_flags.cpp +++ b/modules/commands/cs_flags.cpp @@ -396,10 +396,18 @@ class CommandCSFlags : public Command has_access = true; if (!has_access) + { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), is_list ? "ACCESS_LIST" : "ACCESS_CHANGE", ci->name); - else if (Anope::ReadOnly && !is_list) + return; + } + + if (Anope::ReadOnly && !is_list) + { source.Reply(_("Sorry, channel access list modification is temporarily disabled.")); - else if (cmd.equals_ci("MODIFY")) + return; + } + + if (cmd.equals_ci("MODIFY")) this->DoModify(source, ci, params); else if (is_list) this->DoList(source, ci, params); diff --git a/modules/commands/cs_log.cpp b/modules/commands/cs_log.cpp index 9fd1a2fdf..5c80448c2 100644 --- a/modules/commands/cs_log.cpp +++ b/modules/commands/cs_log.cpp @@ -129,33 +129,35 @@ public: { LogSettings *ls = ci->Require("logsettings"); if (!ls || (*ls)->empty()) - source.Reply(_("There currently are no logging configurations for \002{0}\002."), ci->name); - else { - ListFormatter list(source.GetAccount()); - list.AddColumn(_("Number")).AddColumn(_("Service")).AddColumn(_("Command")).AddColumn(_("Method")).AddColumn(""); + source.Reply(_("There currently are no logging configurations for \002{0}\002."), ci->name); + return; + } - for (unsigned i = 0; i < (*ls)->size(); ++i) - { - const LogSetting *log = (*ls)->at(i); - - ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); - entry["Service"] = log->command_service; - entry["Command"] = !log->command_name.empty() ? log->command_name : log->service_name; - entry["Method"] = log->method; - entry[""] = log->extra; - list.AddEntry(entry); - } - source.Reply(_("Log list for \002{0}\002:"), ci->name); + ListFormatter list(source.GetAccount()); + list.AddColumn(_("Number")).AddColumn(_("Service")).AddColumn(_("Command")).AddColumn(_("Method")).AddColumn(""); - std::vector replies; - list.Process(replies); + for (unsigned i = 0; i < (*ls)->size(); ++i) + { + const LogSetting *log = (*ls)->at(i); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + ListFormatter::ListEntry entry; + entry["Number"] = stringify(i + 1); + entry["Service"] = log->command_service; + entry["Command"] = !log->command_name.empty() ? log->command_name : log->service_name; + entry["Method"] = log->method; + entry[""] = log->extra; + list.AddEntry(entry); } + + source.Reply(_("Log list for \002{0}\002:"), ci->name); + + std::vector replies; + list.Process(replies); + + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); } else if (params.size() > 2) { diff --git a/modules/commands/cs_register.cpp b/modules/commands/cs_register.cpp index 594babe2f..36803e608 100644 --- a/modules/commands/cs_register.cpp +++ b/modules/commands/cs_register.cpp @@ -24,66 +24,97 @@ class CommandCSRegister : public Command { const Anope::string &chan = params[0]; const Anope::string &chdesc = params.size() > 1 ? params[1] : ""; - unsigned maxregistered = Config->GetModule("chanserv")->Get("maxregistered"); User *u = source.GetUser(); NickServ::Account *nc = source.nc; - Channel *c = Channel::Find(params[0]); - ChanServ::Channel *ci = ChanServ::Find(params[0]); if (Anope::ReadOnly) + { source.Reply(_("Sorry, channel registration is temporarily disabled.")); - else if (nc->HasExt("UNCONFIRMED")) + return; + } + + if (nc->HasExt("UNCONFIRMED")) + { source.Reply(_("You must confirm your account before you can register a channel.")); - else if (chan[0] == '&') + return; + } + + if (chan[0] == '&') + { source.Reply(_("Local channels can not be registered.")); - else if (chan[0] != '#') + return; + } + + if (chan[0] != '#') + { source.Reply(_("Please use the symbol of \002#\002 when attempting to register.")); - else if (!IRCD->IsChannelValid(chan)) + return; + } + + if (!IRCD->IsChannelValid(chan)) + { source.Reply(_("Channel \002{0}\002 is not a valid channel."), chan); - else if (!c && u) + return; + } + + Channel *c = Channel::Find(params[0]); + if (!c && u) + { source.Reply(_("Channel \002{0}\002 doesn't exist."), chan); - else if (ci) - source.Reply(_("Channel \002%s\002 is already registered!"), chan.c_str()); - else if (c && !c->HasUserStatus(u, "OP")) + return; + } + + ChanServ::Channel *ci = ChanServ::Find(chan); + if (ci) + { + source.Reply(_("Channel \002{0}\002 is already registered!"), chan); + return; + } + + if (c && !c->HasUserStatus(u, "OP")) + { source.Reply(_("You must be a channel operator to register the channel.")); - else if (maxregistered && nc->channelcount >= maxregistered && !source.HasPriv("chanserv/no-register-limit")) + return; + } + + unsigned maxregistered = Config->GetModule("chanserv")->Get("maxregistered"); + if (maxregistered && nc->channelcount >= maxregistered && !source.HasPriv("chanserv/no-register-limit")) { if (nc->channelcount > maxregistered) source.Reply(_("Sorry, you have already exceeded your limit of \002{0}\002 channels."), maxregistered); else source.Reply(_("Sorry, you have already reached your limit of \002{0}\002 channels."), maxregistered); + return; } - else - { - if (!ChanServ::service) - return; - ci = ChanServ::service->Create(chan); - ci->SetFounder(nc); - ci->desc = chdesc; - - if (c && !c->topic.empty()) - { - ci->last_topic = c->topic; - ci->last_topic_setter = c->topic_setter; - ci->last_topic_time = c->topic_time; - } - else - ci->last_topic_setter = source.service->nick; - Log(LOG_COMMAND, source, this, ci); - source.Reply(_("Channel \002{0}\002 registered under your account: \002{1}\002"), chan, nc->display); + if (!ChanServ::service) + return; + ci = ChanServ::service->Create(chan); + ci->SetFounder(nc); + ci->desc = chdesc; - /* Implement new mode lock */ - if (c) - { - c->CheckModes(); - if (u) - c->SetCorrectModes(u, true); - } + if (c && !c->topic.empty()) + { + ci->last_topic = c->topic; + ci->last_topic_setter = c->topic_setter; + ci->last_topic_time = c->topic_time; + } + else + ci->last_topic_setter = source.service->nick; + + Log(LOG_COMMAND, source, this, ci); + source.Reply(_("Channel \002{0}\002 registered under your account: \002{1}\002"), chan, nc->display); - Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, ci); + /* Implement new mode lock */ + if (c) + { + c->CheckModes(); + if (u) + c->SetCorrectModes(u, true); } + + Event::OnChanRegistered(&Event::ChanRegistered::OnChanRegistered, ci); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index 0e487ff6c..5339d7f73 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -90,12 +90,14 @@ class CommandCSUp : public Command source.Reply(_("User \002{0}\002 isn't currently online."), nick); return; } + if (srcu && !srcu->FindChannel(c)) { source.Reply(_("You must be in \002%s\002 to use this command."), c->name.c_str()); return; } - else if (!u->FindChannel(c)) + + if (!u->FindChannel(c)) { source.Reply(_("You must be on channel \002{0}\002 to use this command."), c->name); return; @@ -201,12 +203,14 @@ class CommandCSDown : public Command source.Reply(_("You must be on channel \002{0}\002 to use this command."), c->name); return; } + if (srcu && !srcu->FindChannel(c)) { source.Reply(_("You must be in \002%s\002 to use this command."), c->name.c_str()); return; } - else if (!u->FindChannel(c)) + + if (!u->FindChannel(c)) { source.Reply(_("\002%s\002 is not on channel %s."), u->nick, c->name); return; diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp index c3b43cd3e..44af355ec 100644 --- a/modules/commands/cs_xop.cpp +++ b/modules/commands/cs_xop.cpp @@ -149,7 +149,8 @@ class CommandCSXOP : public Command source.Reply(_("Channel \002{0}\002 isn't registered."), mask); return; } - else if (ci == targ_ci) + + if (ci == targ_ci) { source.Reply(_("You can't add a channel to its own access list.")); return; @@ -165,7 +166,8 @@ class CommandCSXOP : public Command source.Reply(_("Masks and unregistered users may not be on access lists.")); return; } - else if (mask.find_first_of("!*@") == Anope::string::npos && !na) + + if (mask.find_first_of("!*@") == Anope::string::npos && !na) { User *targ = User::Find(mask, true); if (targ != NULL) diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp index 4d8ee27bb..fc367760b 100644 --- a/modules/commands/help.cpp +++ b/modules/commands/help.cpp @@ -14,8 +14,6 @@ class CommandHelp : public Command { - static const unsigned help_wrap_len = 40; - static CommandGroup *FindGroup(const Anope::string &name) { for (unsigned i = 0; i < Config->CommandGroups.size(); ++i) @@ -108,20 +106,10 @@ class CommandHelp : public Command for (std::list::iterator it2 = it->second.begin(), it2_end = it->second.end(); it2 != it2_end; ++it2) { const Anope::string &c_name = *it2; - buf += ", " + c_name; - - if (buf.length() > help_wrap_len) - { - source.Reply(" {0}", buf.substr(2)); - buf.clear(); - } } if (buf.length() > 2) - { source.Reply(" {0}", buf.substr(2)); - buf.clear(); - } } if (!groups.empty()) { @@ -156,6 +144,8 @@ class CommandHelp : public Command const Anope::string &subcommand = params.size() > max ? params[max] : ""; source.command = it->first; + + c->SendSyntax(source); if (!c->OnHelp(source, subcommand)) continue; diff --git a/modules/commands/hs_del.cpp b/modules/commands/hs_del.cpp index 02727185e..907b3e12c 100644 --- a/modules/commands/hs_del.cpp +++ b/modules/commands/hs_del.cpp @@ -30,15 +30,16 @@ class CommandHSDel : public Command const Anope::string &nick = params[0]; NickServ::Nick *na = NickServ::FindNick(nick); - if (na) + if (!na) { - Log(LOG_ADMIN, source, this) << "for user " << na->nick; - this->OnDeleteVhost(&Event::DeleteVhost::OnDeleteVhost, na); - na->RemoveVhost(); - source.Reply(_("Vhost for \002{0}\002 has been removed."), na->nick); - } - else source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } + + Log(LOG_ADMIN, source, this) << "for user " << na->nick; + this->OnDeleteVhost(&Event::DeleteVhost::OnDeleteVhost, na); + na->RemoveVhost(); + source.Reply(_("Vhost for \002{0}\002 has been removed."), na->nick); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -66,20 +67,21 @@ class CommandHSDelAll : public Command const Anope::string &nick = params[0]; NickServ::Nick *na = NickServ::FindNick(nick); - if (na) + if (!na) { - this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na); - const NickServ::Account *nc = na->nc; - for (unsigned i = 0; i < nc->aliases->size(); ++i) - { - na = nc->aliases->at(i); - na->RemoveVhost(); - } - Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->display; - source.Reply(_("Vhosts for group \002{0}\002 have been removed."), nc->display); - } - else source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } + + this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na); + const NickServ::Account *nc = na->nc; + for (unsigned i = 0; i < nc->aliases->size(); ++i) + { + na = nc->aliases->at(i); + na->RemoveVhost(); + } + Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->display; + source.Reply(_("Vhosts for group \002{0}\002 have been removed."), nc->display); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/hs_group.cpp b/modules/commands/hs_group.cpp index 8b84d0f65..a3d68844b 100644 --- a/modules/commands/hs_group.cpp +++ b/modules/commands/hs_group.cpp @@ -52,16 +52,23 @@ class CommandHSGroup : public Command } NickServ::Nick *na = NickServ::FindNick(source.GetNick()); - if (na && source.GetAccount() == na->nc && na->HasVhost()) + if (!na || na->nc != source.GetAccount()) { - this->Sync(na); - if (!na->GetVhostIdent().empty()) - source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002@\002{2}\002."), source.nc->display, na->GetVhostIdent(), na->GetVhostHost()); - else - source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002."), source.nc->display, na->GetVhostHost()); + source.Reply(_("Access denied.")); + return; } - else + + if (!na->HasVhost()) + { source.Reply(_("There is no vhost assigned to this nickname.")); + return; + } + + this->Sync(na); + if (!na->GetVhostIdent().empty()) + source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002@\002{2}\002."), source.nc->display, na->GetVhostIdent(), na->GetVhostHost()); + else + source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002."), source.nc->display, na->GetVhostHost()); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/hs_off.cpp b/modules/commands/hs_off.cpp index 2d8c23b80..e847963d6 100644 --- a/modules/commands/hs_off.cpp +++ b/modules/commands/hs_off.cpp @@ -25,14 +25,15 @@ class CommandHSOff : public Command User *u = source.GetUser(); const NickServ::Nick *na = NickServ::FindNick(u->nick); - if (!na || !na->HasVhost()) - source.Reply(_("There is no vhost assigned to this nickname.")); - else + if (!na || !na->HasVhost() || na->nc != source.GetAccount()) { - IRCD->SendVhostDel(u); - Log(LOG_COMMAND, source, this) << "to disable their vhost"; - source.Reply(_("Your vhost was removed and the normal cloaking restored.")); + source.Reply(_("There is no vhost assigned to this nickname.")); + return; } + + IRCD->SendVhostDel(u); + Log(LOG_COMMAND, source, this) << "to disable their vhost"; + source.Reply(_("Your vhost was removed and the normal cloaking restored.")); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/hs_on.cpp b/modules/commands/hs_on.cpp index c9e686131..8ec26f565 100644 --- a/modules/commands/hs_on.cpp +++ b/modules/commands/hs_on.cpp @@ -27,21 +27,24 @@ class CommandHSOn : public Command User *u = source.GetUser(); const NickServ::Nick *na = NickServ::FindNick(u->nick); - if (na && u->Account() == na->nc && na->HasVhost()) + + if (!na || !na->HasVhost() || na->nc != u->Account()) { - if (!na->GetVhostIdent().empty()) - source.Reply(_("Your vhost of \002{0}\002@\002{1}\002 is now activated."), na->GetVhostIdent(), na->GetVhostHost()); - else - source.Reply(_("Your vhost of \002{0}\002 is now activated."), na->GetVhostHost()); - Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!na->GetVhostIdent().empty() ? na->GetVhostIdent() + "@" : "") << na->GetVhostHost(); - IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost()); - u->vhost = na->GetVhostHost(); - if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) - u->SetVIdent(na->GetVhostIdent()); - u->UpdateHost(); + source.Reply(_("There is no vhost assigned to this nickname.")); + return; } + + if (!na->GetVhostIdent().empty()) + source.Reply(_("Your vhost of \002{0}\002@\002{1}\002 is now activated."), na->GetVhostIdent(), na->GetVhostHost()); else - source.Reply(_("There is no vhost assigned to this nickname.")); + source.Reply(_("Your vhost of \002{0}\002 is now activated."), na->GetVhostHost()); + + Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!na->GetVhostIdent().empty() ? na->GetVhostIdent() + "@" : "") << na->GetVhostHost(); + IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost()); + u->vhost = na->GetVhostHost(); + if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) + u->SetVIdent(na->GetVhostIdent()); + u->UpdateHost(); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp index 1d9207e05..d1fb0e640 100644 --- a/modules/commands/hs_request.cpp +++ b/modules/commands/hs_request.cpp @@ -185,23 +185,30 @@ class CommandHSActivate : public Command } const Anope::string &nick = params[0]; - NickServ::Nick *na = NickServ::FindNick(nick); - HostRequest *req = na ? na->GetExt("hostrequest") : NULL; - if (req) - { - na->SetVhost(req->ident, req->host, source.GetNick(), req->time); - Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); - if (Config->GetModule(this->owner)->Get("memouser") && MemoServ::service) - MemoServ::service->Send(source.service->nick, na->nick, _("[auto memo] Your requested vHost has been approved."), true); + if (!na) + { + source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } - source.Reply(_("Vhost for \002{0}\002 has been activated."), na->nick); - Log(LOG_COMMAND, source, this) << "for " << na->nick << " for vhost " << (!req->ident.empty() ? req->ident + "@" : "") << req->host; - na->Shrink("hostrequest"); + HostRequest *req = na->GetExt("hostrequest"); + if (!req) + { + source.Reply(_("\002{0}\002 does not have a pending vhost request."), na->nick); + return; } - else - source.Reply(_("\002{0}\002 does not have a pending vhost request."), nick); + + na->SetVhost(req->ident, req->host, source.GetNick(), req->time); + Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); + + if (Config->GetModule(this->owner)->Get("memouser") && MemoServ::service) + MemoServ::service->Send(source.service->nick, na->nick, _("[auto memo] Your requested vHost has been approved."), true); + + source.Reply(_("Vhost for \002{0}\002 has been activated."), na->nick); + Log(LOG_COMMAND, source, this) << "for " << na->nick << " for vhost " << (!req->ident.empty() ? req->ident + "@" : "") << req->host; + na->Shrink("hostrequest"); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -235,27 +242,34 @@ class CommandHSReject : public Command const Anope::string &reason = params.size() > 1 ? params[1] : ""; NickServ::Nick *na = NickServ::FindNick(nick); - HostRequest *req = na ? na->GetExt("hostrequest") : NULL; - if (req) + if (!na) { - na->Shrink("hostrequest"); + source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } - if (Config->GetModule(this->owner)->Get("memouser") && MemoServ::service) - { - Anope::string message; - if (!reason.empty()) - message = Anope::printf(_("[auto memo] Your requested vHost has been rejected. Reason: %s"), reason.c_str()); - else - message = _("[auto memo] Your requested vHost has been rejected."); + HostRequest *req = na->GetExt("hostrequest"); + if (!req) + { + source.Reply(_("\002{0}\002 does not have a pending vhost request."), na->nick); + return; + } - MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); - } + na->Shrink("hostrequest"); + + if (Config->GetModule(this->owner)->Get("memouser") && MemoServ::service) + { + Anope::string message; + if (!reason.empty()) + message = Anope::printf(_("[auto memo] Your requested vHost has been rejected. Reason: %s"), reason.c_str()); + else + message = _("[auto memo] Your requested vHost has been rejected."); - source.Reply(_("Vhost for \002{0}\002 has been rejected."), na->nick); - Log(LOG_COMMAND, source, this) << "to reject vhost for " << nick << " (" << (!reason.empty() ? reason : "no reason") << ")"; + MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); } - else - source.Reply(_("\002{0}\002 does not have a pending vhost request."), nick); + + source.Reply(_("Vhost for \002{0}\002 has been rejected."), na->nick); + Log(LOG_COMMAND, source, this) << "to reject vhost for " << nick << " (" << (!reason.empty() ? reason : "no reason") << ")"; } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ms_del.cpp b/modules/commands/ms_del.cpp index 4e4ca5ed4..17722d340 100644 --- a/modules/commands/ms_del.cpp +++ b/modules/commands/ms_del.cpp @@ -73,49 +73,53 @@ class CommandMSDel : public Command source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "MEMO", ci->name); return; } + mi = ci->memos; } else mi = source.nc->memos; if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST"))) + { this->OnSyntaxError(source, numstr); - else if (!mi || mi->memos->empty()) + return; + } + + if (!mi || mi->memos->empty()) { if (!chan.empty()) source.Reply(_("\002{0}\002 has no memos."), chan); else source.Reply(_("You have no memos.")); + return; + } + + if (isdigit(numstr[0])) + { + MemoDelCallback list(source, ci, mi, numstr); + list.Process(); + } + else if (numstr.equals_ci("LAST")) + { + /* Delete last memo. */ + if (MemoServ::Event::OnMemoDel) + MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->name : source.nc->display, mi, mi->GetMemo(mi->memos->size() - 1)); + mi->Del(mi->memos->size() - 1); + source.Reply(_("Memo \002{0}\002 has been deleted."), mi->memos->size() + 1); } else { - if (isdigit(numstr[0])) - { - MemoDelCallback list(source, ci, mi, numstr); - list.Process(); - } - else if (numstr.equals_ci("LAST")) + /* Delete all memos. */ + for (unsigned i = mi->memos->size(); i > 0; --i) { - /* Delete last memo. */ if (MemoServ::Event::OnMemoDel) - MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->name : source.nc->display, mi, mi->GetMemo(mi->memos->size() - 1)); - mi->Del(mi->memos->size() - 1); - source.Reply(_("Memo \002{0}\002 has been deleted."), mi->memos->size() + 1); + MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->name : source.nc->display, mi, mi->GetMemo(i)); + mi->Del(i - 1); } + if (!chan.empty()) + source.Reply(_("All memos for channel \002{0}\002 have been deleted."), chan); else - { - /* Delete all memos. */ - for (unsigned i = mi->memos->size(); i > 0; --i) - { - if (MemoServ::Event::OnMemoDel) - MemoServ::Event::OnMemoDel(&MemoServ::Event::MemoDel::OnMemoDel, ci ? ci->name : source.nc->display, mi, mi->GetMemo(i)); - mi->Del(i - 1); - } - if (!chan.empty()) - source.Reply(_("All memos for channel \002{0}\002 have been deleted."), chan); - else - source.Reply(_("All of your memos have been deleted.")); - } + source.Reply(_("All of your memos have been deleted.")); } } diff --git a/modules/commands/ms_list.cpp b/modules/commands/ms_list.cpp index 89f3dc7a5..543e132e3 100644 --- a/modules/commands/ms_list.cpp +++ b/modules/commands/ms_list.cpp @@ -51,89 +51,92 @@ class CommandMSList : public Command mi = source.nc->memos; if (!param.empty() && !isdigit(param[0]) && !param.equals_ci("NEW")) + { this->OnSyntaxError(source, param); - else if (!mi->memos->size()) + return; + } + + if (!mi->memos->size()) { if (!chan.empty()) source.Reply(_("\002{0}\002 has no memos."), chan); else source.Reply(_("You have no memos.")); + return; } - else - { - ListFormatter list(source.GetAccount()); - list.AddColumn(_("Number")).AddColumn(_("Sender")).AddColumn(_("Date/Time")); + ListFormatter list(source.GetAccount()); - if (!param.empty() && isdigit(param[0])) - { - class MemoListCallback : public NumberList - { - ListFormatter &list; - CommandSource &source; - const MemoServ::MemoInfo *mi; - public: - MemoListCallback(ListFormatter &_list, CommandSource &_source, const MemoServ::MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), list(_list), source(_source), mi(_mi) - { - } - - void HandleNumber(unsigned number) override - { - if (!number || number > mi->memos->size()) - return; - - const MemoServ::Memo *m = mi->GetMemo(number - 1); - - ListFormatter::ListEntry entry; - entry["Number"] = (m->unread ? "* " : " ") + stringify(number); - entry["Sender"] = m->sender; - entry["Date/Time"] = Anope::strftime(m->time, source.GetAccount()); - this->list.AddEntry(entry); - } - } - mlc(list, source, mi, param); - mlc.Process(); - } - else + list.AddColumn(_("Number")).AddColumn(_("Sender")).AddColumn(_("Date/Time")); + + if (!param.empty() && isdigit(param[0])) + { + class MemoListCallback : public NumberList { - if (!param.empty()) + ListFormatter &list; + CommandSource &source; + const MemoServ::MemoInfo *mi; + public: + MemoListCallback(ListFormatter &_list, CommandSource &_source, const MemoServ::MemoInfo *_mi, const Anope::string &numlist) : NumberList(numlist, false), list(_list), source(_source), mi(_mi) { - unsigned i, end; - for (i = 0, end = mi->memos->size(); i < end; ++i) - if (mi->GetMemo(i)->unread) - break; - if (i == end) - { - if (!chan.empty()) - source.Reply(_("\002{0}\002 has no new memos."), chan); - else - source.Reply(_("You have no new memos.")); - return; - } } - for (unsigned i = 0, end = mi->memos->size(); i < end; ++i) + void HandleNumber(unsigned number) override { - if (!param.empty() && !mi->GetMemo(i)->unread) - continue; + if (!number || number > mi->memos->size()) + return; - const MemoServ::Memo *m = mi->GetMemo(i); + const MemoServ::Memo *m = mi->GetMemo(number - 1); ListFormatter::ListEntry entry; - entry["Number"] = (m->unread ? "* " : " ") + stringify(i + 1); + entry["Number"] = (m->unread ? "* " : " ") + stringify(number); entry["Sender"] = m->sender; entry["Date/Time"] = Anope::strftime(m->time, source.GetAccount()); - list.AddEntry(entry); + this->list.AddEntry(entry); } } + mlc(list, source, mi, param); + mlc.Process(); + } + else + { + if (!param.empty()) + { + unsigned i, end; + for (i = 0, end = mi->memos->size(); i < end; ++i) + if (mi->GetMemo(i)->unread) + break; + if (i == end) + { + if (!chan.empty()) + source.Reply(_("\002{0}\002 has no new memos."), chan); + else + source.Reply(_("You have no new memos.")); + return; + } + } + + for (unsigned i = 0, end = mi->memos->size(); i < end; ++i) + { + if (!param.empty() && !mi->GetMemo(i)->unread) + continue; - std::vector replies; - list.Process(replies); + const MemoServ::Memo *m = mi->GetMemo(i); - source.Reply(_("Memos for \002{0}\002:"), ci ? ci->name.c_str() : source.GetNick().c_str()); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); + ListFormatter::ListEntry entry; + entry["Number"] = (m->unread ? "* " : " ") + stringify(i + 1); + entry["Sender"] = m->sender; + entry["Date/Time"] = Anope::strftime(m->time, source.GetAccount()); + list.AddEntry(entry); + } } + + std::vector replies; + list.Process(replies); + + source.Reply(_("Memos for \002{0}\002:"), ci ? ci->name.c_str() : source.GetNick().c_str()); + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ms_read.cpp b/modules/commands/ms_read.cpp index 2cbecf70b..d7e5a6ed1 100644 --- a/modules/commands/ms_read.cpp +++ b/modules/commands/ms_read.cpp @@ -134,46 +134,49 @@ class CommandMSRead : public Command mi = source.nc->memos; if (numstr.empty() || (!numstr.equals_ci("LAST") && !numstr.equals_ci("NEW") && !numstr.is_number_only())) + { this->OnSyntaxError(source, numstr); - else if (mi->memos->empty()) + return; + } + + if (mi->memos->empty()) { if (!chan.empty()) source.Reply(_("\002{0}\002 has no memos."), chan); else source.Reply(_("You have no memos.")); + return; } - else - { - int i, end; - if (numstr.equals_ci("NEW")) - { - int readcount = 0; - for (i = 0, end = mi->memos->size(); i < end; ++i) - if (mi->GetMemo(i)->unread) - { - MemoListCallback::DoRead(source, mi, ci, i); - ++readcount; - } - if (!readcount) + int i, end; + + if (numstr.equals_ci("NEW")) + { + int readcount = 0; + for (i = 0, end = mi->memos->size(); i < end; ++i) + if (mi->GetMemo(i)->unread) { - if (!chan.empty()) - source.Reply(_("\002{0}\002 has no new memos."), chan); - else - source.Reply(_("You have no new memos.")); + MemoListCallback::DoRead(source, mi, ci, i); + ++readcount; } - } - else if (numstr.equals_ci("LAST")) - { - for (i = 0, end = mi->memos->size() - 1; i < end; ++i); - MemoListCallback::DoRead(source, mi, ci, i); - } - else /* number[s] */ + if (!readcount) { - MemoListCallback list(source, mi, ci, numstr); - list.Process(); + if (!chan.empty()) + source.Reply(_("\002{0}\002 has no new memos."), chan); + else + source.Reply(_("You have no new memos.")); } } + else if (numstr.equals_ci("LAST")) + { + for (i = 0, end = mi->memos->size() - 1; i < end; ++i); + MemoListCallback::DoRead(source, mi, ci, i); + } + else /* number[s] */ + { + MemoListCallback list(source, mi, ci, numstr); + list.Process(); + } } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ms_rsend.cpp b/modules/commands/ms_rsend.cpp index 101a67816..80e5c5434 100644 --- a/modules/commands/ms_rsend.cpp +++ b/modules/commands/ms_rsend.cpp @@ -96,6 +96,7 @@ class MSRSend : public Module { if (!MemoServ::service) throw ModuleException("No MemoServ!"); + throw ModuleException("XXX"); } }; diff --git a/modules/commands/ms_set.cpp b/modules/commands/ms_set.cpp index 42bce16cf..462cc72a8 100644 --- a/modules/commands/ms_set.cpp +++ b/modules/commands/ms_set.cpp @@ -154,7 +154,7 @@ class CommandMSSet : public Command source.Reply(_("The memo limit for \002{0}\002 may not be changed."), chan); return; } - else if (chan.empty() && nc->HasExt("MEMO_HARDMAX")) + if (chan.empty() && nc->HasExt("MEMO_HARDMAX")) { source.Reply(_("You are not permitted to change your memo limit.")); return; diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp index 94df860d6..81015dc71 100644 --- a/modules/commands/ns_ajoin.cpp +++ b/modules/commands/ns_ajoin.cpp @@ -92,30 +92,32 @@ class CommandNSAJoin : public Command { AJoinList *channels = nc->Require("ajoinlist"); - if ((*channels)->empty()) + if ((*channels)->empty())\ + { source.Reply(_("The auto join list of \002{0}\002 is empty."), nc->display); - else + return; + } + + + ListFormatter list(source.GetAccount()); + list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Key")); + for (unsigned i = 0; i < (*channels)->size(); ++i) { - ListFormatter list(source.GetAccount()); - list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Key")); - for (unsigned i = 0; i < (*channels)->size(); ++i) - { - AJoinEntry *aj = (*channels)->at(i); - ListFormatter::ListEntry entry; - entry["Number"] = stringify(i + 1); - entry["Channel"] = aj->channel; - entry["Key"] = aj->key; - list.AddEntry(entry); - } + AJoinEntry *aj = (*channels)->at(i); + ListFormatter::ListEntry entry; + entry["Number"] = stringify(i + 1); + entry["Channel"] = aj->channel; + entry["Key"] = aj->key; + list.AddEntry(entry); + } - source.Reply(_("Auto join list of \002{0}\002:"), nc->display); + source.Reply(_("Auto join list of \002{0}\002:"), nc->display); - std::vector replies; - list.Process(replies); + std::vector replies; + list.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); - } + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); } void DoAdd(CommandSource &source, NickServ::Account *nc, const Anope::string &chans, const Anope::string &keys) diff --git a/modules/commands/ns_drop.cpp b/modules/commands/ns_drop.cpp index 345521504..deeee7170 100644 --- a/modules/commands/ns_drop.cpp +++ b/modules/commands/ns_drop.cpp @@ -43,18 +43,23 @@ class CommandNSDrop : public Command bool is_mine = source.GetAccount() == na->nc; if (!is_mine && !source.HasPriv("nickserv/drop")) + { source.Reply(_("Access denied. You do not have the correct operator privileges to drop other user's nicknames.")); - else if (Config->GetModule("nickserv")->Get("secureadmins", "yes") && !is_mine && na->nc->IsServicesOper()) - source.Reply(_("You may not drop other Services Operators' nicknames.")); - else + return; + } + + if (Config->GetModule("nickserv")->Get("secureadmins", "yes") && !is_mine && na->nc->IsServicesOper()) { - this->onnickdrop(&Event::NickDrop::OnNickDrop, source, na); + source.Reply(_("You may not drop other Services Operators' nicknames.")); + return; + } - Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; - delete na; + this->onnickdrop(&Event::NickDrop::OnNickDrop, source, na); - source.Reply(_("\002{0}\002 has been dropped."), nick); - } + Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; + delete na; + + source.Reply(_("\002{0}\002 has been dropped."), nick); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ns_getpass.cpp b/modules/commands/ns_getpass.cpp index 166dded78..09b7c72b7 100644 --- a/modules/commands/ns_getpass.cpp +++ b/modules/commands/ns_getpass.cpp @@ -24,22 +24,28 @@ class CommandNSGetPass : public Command { const Anope::string &nick = params[0]; Anope::string tmp_pass; - const NickServ::Nick *na; + const NickServ::Nick *na = NickServ::FindNick(nick); - if (!(na = NickServ::FindNick(nick))) + if (!na) + { source.Reply(_("\002{0}\002 isn't registered."), nick); - else if (Config->GetModule("nickserv")->Get("secureadmins", "yes") && na->nc->IsServicesOper()) + return; + } + + if (Config->GetModule("nickserv")->Get("secureadmins", "yes") && na->nc->IsServicesOper()) + { source.Reply(_("You may not get the password of other Services Operators.")); - else + return; + } + + if (!Anope::Decrypt(na->nc->pass, tmp_pass)) { - if (Anope::Decrypt(na->nc->pass, tmp_pass) == 1) - { - Log(LOG_ADMIN, source, this) << "for " << nick; - source.Reply(_("Password of \002{0}\02 is \002%s\002."), nick, tmp_pass); - } - else - source.Reply(_("The \002{0}\002 command is unavailable because encryption is in use."), source.command); + source.Reply(_("The \002{0}\002 command is unavailable because encryption is in use."), source.command); + return; } + + Log(LOG_ADMIN, source, this) << "for " << na->nick; + source.Reply(_("Password of \002{0}\02 is \002%s\002."), na->nick, tmp_pass); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ns_group.cpp b/modules/commands/ns_group.cpp index 7a67337f9..380fe4631 100644 --- a/modules/commands/ns_group.cpp +++ b/modules/commands/ns_group.cpp @@ -130,55 +130,84 @@ class CommandNSGroup : public Command time_t reg_delay = Config->GetModule("nickserv")->Get("regdelay"); unsigned maxaliases = Config->GetModule(this->owner)->Get("maxaliases"); if (!(target = NickServ::FindNick(nick))) + { source.Reply(_("\002{0}\002 isn't registered."), nick); - else if (Anope::CurTime < u->lastnickreg + reg_delay) + return; + } + + if (Anope::CurTime < u->lastnickreg + reg_delay) + { source.Reply(_("Please wait \002{0}\002 seconds before using the \002{1}\002 command again."), (reg_delay + u->lastnickreg) - Anope::CurTime, source.command); - else if (target->nc->HasExt("NS_SUSPENDED")) + return; + } + + if (target->nc->HasExt("NS_SUSPENDED")) { Log(LOG_COMMAND, source, this) << "and tried to group to suspended nick " << target->nick; source.Reply(_("\002{0}\002 is suspended."), target->nick); + return; } - else if (na && Config->GetModule(this->owner)->Get("nogroupchange")) + + if (na && Config->GetModule(this->owner)->Get("nogroupchange")) + { source.Reply(_("Your nick is already registered.")); - else if (na && *target->nc == *na->nc) + return; + } + + if (na && *target->nc == *na->nc) + { source.Reply(_("You are already a member of the group of \002{0}\002."), target->nick); - else if (na && na->nc != u->Account()) + return; + } + + if (na && na->nc != u->Account()) + { source.Reply(_("\002{0}\002 is already registered."), na->nick); - else if (na && Config->GetModule(this->owner)->Get("nogroupchange")) + return; + } + + if (na && Config->GetModule(this->owner)->Get("nogroupchange")) + { source.Reply(_("You are already registered.")); - else if (maxaliases && target->nc->aliases->size() >= maxaliases && !target->nc->IsServicesOper()) + return; + } + + if (maxaliases && target->nc->aliases->size() >= maxaliases && !target->nc->IsServicesOper()) + { source.Reply(_("There are too many nicknames in your group.")); - else if (u->nick.length() <= guestnick.length() + 7 && + return; + } + + if (u->nick.length() <= guestnick.length() + 7 && u->nick.length() >= guestnick.length() + 1 && !u->nick.find_ci(guestnick) && !u->nick.substr(guestnick.length()).find_first_not_of("1234567890")) { source.Reply(_("\002{0}\002 may not be registered."), u->nick); + return; + } + + bool ok = false; + if (!na && u->Account() == target->nc) + ok = true; + + NSCertList *cl = target->nc->GetExt("certificates"); + if (!u->fingerprint.empty() && cl && cl->FindCert(u->fingerprint)) + ok = true; + + if (ok == false && !pass.empty()) + { + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(onnickgroup, source, this, u->nick, target), owner, target->nc->display, pass); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); + req->Dispatch(); } else { - bool ok = false; - if (!na && u->Account() == target->nc) - ok = true; - - NSCertList *cl = target->nc->GetExt("certificates"); - if (!u->fingerprint.empty() && cl && cl->FindCert(u->fingerprint)) - ok = true; + NSGroupRequestListener req(onnickgroup, source, this, u->nick, target); - if (ok == false && !pass.empty()) - { - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(onnickgroup, source, this, u->nick, target), owner, target->nc->display, pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); - req->Dispatch(); - } + if (ok) + req.OnSuccess(nullptr); else - { - NSGroupRequestListener req(onnickgroup, source, this, u->nick, target); - - if (ok) - req.OnSuccess(nullptr); - else - req.OnFail(nullptr); - } + req.OnFail(nullptr); } } @@ -212,38 +241,48 @@ class CommandNSUngroup : public Command NickServ::Nick *na = NickServ::FindNick(!nick.empty() ? nick : u->nick); if (u->Account()->aliases->size() == 1) + { source.Reply(_("Your nickname is not grouped to anything, so you can't ungroup it.")); - else if (!na) + return; + } + + if (!na) + { source.Reply(_("\002{0}\002 isn't registered."), !nick.empty() ? nick : u->nick); - else if (na->nc != u->Account()) - source.Reply(_("\002{0}\002 is not in your group."), na->nick); - else + return; + } + + if (na->nc != u->Account()) { - NickServ::Account *oldcore = na->nc; + source.Reply(_("\002{0}\002 is not in your group."), na->nick); + return; + } - std::vector::iterator it = std::find(oldcore->aliases->begin(), oldcore->aliases->end(), na); - if (it != oldcore->aliases->end()) - oldcore->aliases->erase(it); - if (na->nick.equals_ci(oldcore->display)) - oldcore->SetDisplay(oldcore->aliases->front()); + NickServ::Account *oldcore = na->nc; - NickServ::Account *nc = NickServ::service->CreateAccount(na->nick); - na->nc = nc; - nc->aliases->push_back(na); + std::vector::iterator it = std::find(oldcore->aliases->begin(), oldcore->aliases->end(), na); + if (it != oldcore->aliases->end()) + oldcore->aliases->erase(it); - nc->pass = oldcore->pass; - if (!oldcore->email.empty()) - nc->email = oldcore->email; - nc->language = oldcore->language; + if (na->nick.equals_ci(oldcore->display)) + oldcore->SetDisplay(oldcore->aliases->front()); - source.Reply(_("\002{0}\002 has been ungrouped from \002{1}\002."), na->nick, oldcore->display); + NickServ::Account *nc = NickServ::service->CreateAccount(na->nick); + na->nc = nc; + nc->aliases->push_back(na); - User *user = User::Find(na->nick); - if (user) - /* The user on the nick who was ungrouped may be identified to the old group, set -r */ - user->RemoveMode(source.service, "REGISTERED"); - } + nc->pass = oldcore->pass; + if (!oldcore->email.empty()) + nc->email = oldcore->email; + nc->language = oldcore->language; + + source.Reply(_("\002{0}\002 has been ungrouped from \002{1}\002."), na->nick, oldcore->display); + + User *user = User::Find(na->nick); + if (user) + /* The user on the nick who was ungrouped may be identified to the old group, set -r */ + user->RemoveMode(source.service, "REGISTERED"); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ns_identify.cpp b/modules/commands/ns_identify.cpp index 07616635e..c8384d8a8 100644 --- a/modules/commands/ns_identify.cpp +++ b/modules/commands/ns_identify.cpp @@ -28,32 +28,33 @@ class NSIdentifyRequestListener : public NickServ::IdentifyRequestListener NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); if (!na) - source.Reply(_("\002{0}\002 isn't registered."), req->GetAccount()); - else { - if (u->IsIdentified()) - Log(LOG_COMMAND, source, cmd) << "to log out of account " << u->Account()->display; - - Log(LOG_COMMAND, source, cmd) << "and identified for account " << na->nc->display; - source.Reply(_("Password accepted - you are now recognized as \002{0}\002."), na->nc->display); - u->Identify(na); + source.Reply(_("\002{0}\002 isn't registered."), req->GetAccount()); + return; } + + if (u->IsIdentified()) + Log(LOG_COMMAND, source, cmd) << "to log out of account " << u->Account()->display; + + Log(LOG_COMMAND, source, cmd) << "and identified for account " << na->nc->display; + source.Reply(_("Password accepted - you are now recognized as \002{0}\002."), na->nc->display); + u->Identify(na); } void OnFail(NickServ::IdentifyRequest *req) override { - if (source.GetUser()) + if (!source.GetUser()) + return; + + bool accountexists = NickServ::FindNick(req->GetAccount()) != NULL; + Log(LOG_COMMAND, source, cmd) << "and failed to identify to" << (accountexists ? " " : " nonexistent ") << "account " << req->GetAccount(); + if (accountexists) { - bool accountexists = NickServ::FindNick(req->GetAccount()) != NULL; - Log(LOG_COMMAND, source, cmd) << "and failed to identify to" << (accountexists ? " " : " nonexistent ") << "account " << req->GetAccount(); - if (accountexists) - { - source.Reply(_("Password incorrect.")); - source.GetUser()->BadPassword(); - } - else - source.Reply("\002{0}\002 isn't registered.", req->GetAccount()); + source.Reply(_("Password incorrect.")); + source.GetUser()->BadPassword(); } + else + source.Reply("\002{0}\002 isn't registered.", req->GetAccount()); } }; @@ -77,15 +78,20 @@ class CommandNSIdentify : public Command NickServ::Nick *na = NickServ::FindNick(nick); if (na && na->nc->HasExt("NS_SUSPENDED")) + { source.Reply(_("\002{0}\002 is suspended."), na->nick); - else if (u->Account() && na && u->Account() == na->nc) - source.Reply(_("You are already identified.")); - else + return; + } + + if (u->Account() && na && u->Account() == na->nc) { - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), owner, na ? na->nc->display : nick, pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, u, req); - req->Dispatch(); + source.Reply(_("You are already identified.")); + return; } + + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), owner, na ? na->nc->display : nick, pass); + Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, u, req); + req->Dispatch(); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ns_info.cpp b/modules/commands/ns_info.cpp index bbec0fef0..9bbf5c418 100644 --- a/modules/commands/ns_info.cpp +++ b/modules/commands/ns_info.cpp @@ -38,88 +38,87 @@ class CommandNSInfo : public Command source.Reply(_("\002{0}\002 is part of this Network's Services."), nick); else source.Reply(_("\002{0}\002 isn't registered."), nick); + return; } - else - { - bool nick_online = false, show_hidden = false; - /* Is the real owner of the nick we're looking up online? -TheShadow */ - User *u2 = User::Find(na->nick); - if (u2 && u2->Account() == na->nc) - { - nick_online = true; - na->last_seen = Anope::CurTime; - } + bool nick_online = false, show_hidden = false; - if (has_auspex || na->nc == source.GetAccount()) - show_hidden = true; + /* Is the real owner of the nick we're looking up online? -TheShadow */ + User *u2 = User::Find(na->nick); + if (u2 && u2->Account() == na->nc) + { + nick_online = true; + na->last_seen = Anope::CurTime; + } + + if (has_auspex || na->nc == source.GetAccount()) + show_hidden = true; - source.Reply(_("\002{0}\002 is \002{1}\002"), na->nick, na->last_realname); + source.Reply(_("\002{0}\002 is \002{1}\002"), na->nick, na->last_realname); - if (na->nc->HasExt("UNCONFIRMED")) - source.Reply(_("\002{0}\002 has not confirmed their account."), na->nick); + if (na->nc->HasExt("UNCONFIRMED")) + source.Reply(_("\002{0}\002 has not confirmed their account."), na->nick); - if (na->nc->IsServicesOper() && (show_hidden || !na->nc->HasExt("HIDE_STATUS"))) - source.Reply(_("\002{0}\002 is a Services Operator of type \002{0}\002."), na->nick, na->nc->o->ot->GetName()); + if (na->nc->IsServicesOper() && (show_hidden || !na->nc->HasExt("HIDE_STATUS"))) + source.Reply(_("\002{0}\002 is a Services Operator of type \002{0}\002."), na->nick, na->nc->o->ot->GetName()); - InfoFormatter info(source.nc); + InfoFormatter info(source.nc); - if (nick_online) + if (nick_online) + { + bool shown = false; + if (show_hidden && !na->last_realhost.empty()) { - bool shown = false; - if (show_hidden && !na->last_realhost.empty()) - { - info[_("Online from")] = na->last_realhost; - shown = true; - } - if ((show_hidden || !na->nc->HasExt("HIDE_MASK")) && (!shown || na->last_usermask != na->last_realhost)) - info[_("Online from")] = na->last_usermask; - else - source.Reply(_("\002{0}\002 is currently online."), na->nick); + info[_("Online from")] = na->last_realhost; + shown = true; } + if ((show_hidden || !na->nc->HasExt("HIDE_MASK")) && (!shown || na->last_usermask != na->last_realhost)) + info[_("Online from")] = na->last_usermask; else + source.Reply(_("\002{0}\002 is currently online."), na->nick); + } + else + { + Anope::string shown; + if (show_hidden || !na->nc->HasExt("HIDE_MASK")) { - Anope::string shown; - if (show_hidden || !na->nc->HasExt("HIDE_MASK")) - { - info[_("Last seen address")] = na->last_usermask; - shown = na->last_usermask; - } - - if (show_hidden && !na->last_realhost.empty() && na->last_realhost != shown) - info[_("Last seen address")] = na->last_realhost; + info[_("Last seen address")] = na->last_usermask; + shown = na->last_usermask; } - info[_("Registered")] = Anope::strftime(na->time_registered, source.GetAccount()); + if (show_hidden && !na->last_realhost.empty() && na->last_realhost != shown) + info[_("Last seen address")] = na->last_realhost; + } + + info[_("Registered")] = Anope::strftime(na->time_registered, source.GetAccount()); - if (!nick_online) - info[_("Last seen")] = Anope::strftime(na->last_seen, source.GetAccount()); + if (!nick_online) + info[_("Last seen")] = Anope::strftime(na->last_seen, source.GetAccount()); - if (!na->last_quit.empty() && (show_hidden || !na->nc->HasExt("HIDE_QUIT"))) - info[_("Last quit message")] = na->last_quit; + if (!na->last_quit.empty() && (show_hidden || !na->nc->HasExt("HIDE_QUIT"))) + info[_("Last quit message")] = na->last_quit; - if (!na->nc->email.empty() && (show_hidden || !na->nc->HasExt("HIDE_EMAIL"))) - info[_("Email address")] = na->nc->email; + if (!na->nc->email.empty() && (show_hidden || !na->nc->HasExt("HIDE_EMAIL"))) + info[_("Email address")] = na->nc->email; - if (show_hidden) + if (show_hidden) + { + if (na->HasVhost()) { - if (na->HasVhost()) - { - if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) - info[_("VHost")] = na->GetVhostIdent() + "@" + na->GetVhostHost(); - else - info[_("VHost")] = na->GetVhostHost(); - } + if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) + info[_("VHost")] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + else + info[_("VHost")] = na->GetVhostHost(); } + } - this->onnickinfo(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden); + this->onnickinfo(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden); - std::vector replies; - info.Process(replies); + std::vector replies; + info.Process(replies); - for (unsigned i = 0; i < replies.size(); ++i) - source.Reply(replies[i]); - } + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ns_logout.cpp b/modules/commands/ns_logout.cpp index 70f2171af..f63086789 100644 --- a/modules/commands/ns_logout.cpp +++ b/modules/commands/ns_logout.cpp @@ -27,33 +27,42 @@ class CommandNSLogout : public Command const Anope::string &nick = !params.empty() ? params[0] : ""; const Anope::string ¶m = params.size() > 1 ? params[1] : ""; - User *u2; if (!source.IsServicesOper() && !nick.empty()) + { this->OnSyntaxError(source, ""); - else if (!(u2 = (!nick.empty() ? User::Find(nick, true) : source.GetUser()))) + return; + } + + User *u2 = !nick.empty() ? User::Find(nick, true) : source.GetUser(); + if (!u2) + { source.Reply(_("\002{0}\002 isn't currently online."), !nick.empty() ? nick : source.GetNick()); - else if (!nick.empty() && u2->IsServicesOper()) - source.Reply(_("You can't logout \002{0}\002, they are a Services Operator."), nick); - else + return; + } + + if (!nick.empty() && u2->IsServicesOper()) { - if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE") && NickServ::service) - NickServ::service->Validate(u2); + source.Reply(_("You can't logout \002{0}\002, they are a Services Operator."), nick); + return; + } - u2->super_admin = false; /* Dont let people logout and remain a SuperAdmin */ - Log(LOG_COMMAND, source, this) << "to logout " << u2->nick; + if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE") && NickServ::service) + NickServ::service->Validate(u2); - if (!nick.empty()) - source.Reply(_("\002{0}\002 has been logged out."), nick); - else - source.Reply(_("You have been logged out.")); + u2->super_admin = false; /* Dont let people logout and remain a SuperAdmin */ + Log(LOG_COMMAND, source, this) << "to logout " << u2->nick; - IRCD->SendLogout(u2); - u2->RemoveMode(source.service, "REGISTERED"); - u2->Logout(); + if (!nick.empty()) + source.Reply(_("\002{0}\002 has been logged out."), nick); + else + source.Reply(_("You have been logged out.")); - /* Send out an event */ - Event::OnNickLogout(&Event::NickLogout::OnNickLogout, u2); - } + IRCD->SendLogout(u2); + u2->RemoveMode(source.service, "REGISTERED"); + u2->Logout(); + + /* Send out an event */ + Event::OnNickLogout(&Event::NickLogout::OnNickLogout, u2); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp index c54ea3764..c464bc2f6 100644 --- a/modules/commands/