anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

ns_info.cpp (9152B)

      1 /* NickServ core functions
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #include "module.h"
     13 
     14 class CommandNSInfo : public Command
     15 {
     16  public:
     17 	CommandNSInfo(Module *creator) : Command(creator, "nickserv/info", 0, 2)
     18 	{
     19 		this->SetDesc(_("Displays information about a given nickname"));
     20 		this->SetSyntax(_("[\037nickname\037]"));
     21 		this->AllowUnregistered(true);
     22 	}
     23 
     24 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     25 	{
     26 
     27 		const Anope::string &nick = params.size() ? params[0] : (source.nc ? source.nc->display : source.GetNick());
     28 		NickAlias *na = NickAlias::Find(nick);
     29 		bool has_auspex = source.HasPriv("nickserv/auspex");
     30 
     31 		if (!na)
     32 		{
     33 			if (BotInfo::Find(nick, true))
     34 				source.Reply(_("Nick \002%s\002 is part of this Network's Services."), nick.c_str());
     35 			else
     36 				source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
     37 		}
     38 		else
     39 		{
     40 			bool nick_online = false, show_hidden = false;
     41 
     42 			/* Is the real owner of the nick we're looking up online? -TheShadow */
     43 			User *u2 = User::Find(na->nick, true);
     44 			if (u2 && u2->Account() == na->nc)
     45 			{
     46 				nick_online = true;
     47 				na->last_seen = Anope::CurTime;
     48 			}
     49 
     50 			if (has_auspex || na->nc == source.GetAccount())
     51 				show_hidden = true;
     52 
     53 			source.Reply(_("%s is %s"), na->nick.c_str(), na->last_realname.c_str());
     54 
     55 			if (na->nc->HasExt("UNCONFIRMED"))
     56 				source.Reply(_("%s is an unconfirmed nickname."), na->nick.c_str());
     57 
     58 			if (na->nc->IsServicesOper() && (show_hidden || !na->nc->HasExt("HIDE_STATUS")))
     59 				source.Reply(_("%s is a Services Operator of type %s."), na->nick.c_str(), na->nc->o->ot->GetName().c_str());
     60 
     61 			InfoFormatter info(source.nc);
     62 
     63 			info[_("Account")] = na->nc->display;
     64 			if (nick_online)
     65 			{
     66 				bool shown = false;
     67 				if (show_hidden && !na->last_realhost.empty())
     68 				{
     69 					info[_("Online from")] = na->last_realhost;
     70 					shown = true;
     71 				}
     72 				if ((show_hidden || !na->nc->HasExt("HIDE_MASK")) && (!shown || na->last_usermask != na->last_realhost))
     73 					info[_("Online from")] = na->last_usermask;
     74 				else
     75 					source.Reply(_("%s is currently online."), na->nick.c_str());
     76 			}
     77 			else
     78 			{
     79 				Anope::string shown;
     80 				if (show_hidden || !na->nc->HasExt("HIDE_MASK"))
     81 				{
     82 					info[_("Last seen address")] = na->last_usermask;
     83 					shown = na->last_usermask;
     84 				}
     85 
     86 				if (show_hidden && !na->last_realhost.empty() && na->last_realhost != shown)
     87 					info[_("Last seen address")] = na->last_realhost;
     88 			}
     89 
     90 			info[_("Registered")] = Anope::strftime(na->time_registered, source.GetAccount());
     91 
     92 			if (!nick_online)
     93 				info[_("Last seen")] = Anope::strftime(na->last_seen, source.GetAccount());
     94 
     95 			if (!na->last_quit.empty() && (show_hidden || !na->nc->HasExt("HIDE_QUIT")))
     96 				info[_("Last quit message")] = na->last_quit;
     97 
     98 			if (!na->nc->email.empty() && (show_hidden || !na->nc->HasExt("HIDE_EMAIL")))
     99 				info[_("Email address")] = na->nc->email;
    100 
    101 			if (show_hidden)
    102 			{
    103 				if (na->HasVhost())
    104 				{
    105 					if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
    106 						info[_("VHost")] = na->GetVhostIdent() + "@" + na->GetVhostHost();
    107 					else
    108 						info[_("VHost")] = na->GetVhostHost();
    109 				}
    110 			}
    111 
    112 			FOREACH_MOD(OnNickInfo, (source, na, info, show_hidden));
    113 
    114 			std::vector<Anope::string> replies;
    115 			info.Process(replies);
    116 
    117 			for (unsigned i = 0; i < replies.size(); ++i)
    118 				source.Reply(replies[i]);
    119 		}
    120 	}
    121 
    122 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    123 	{
    124 		this->SendSyntax(source);
    125 		source.Reply(" ");
    126 		source.Reply(_("Displays information about the given nickname, such as\n"
    127 				"the nick's owner, last seen address and time, and nick\n"
    128 				"options. If no nick is given, and you are identified,\n"
    129 				"your account name is used, else your current nickname is\n"
    130 				"used."));
    131 
    132 		return true;
    133 	}
    134 };
    135 
    136 
    137 class CommandNSSetHide : public Command
    138 {
    139  public:
    140 	CommandNSSetHide(Module *creator, const Anope::string &sname = "nickserv/set/hide", size_t min = 2) : Command(creator, sname, min, min + 1)
    141 	{
    142 		this->SetDesc(_("Hide certain pieces of nickname information"));
    143 		this->SetSyntax("{EMAIL | STATUS | USERMASK | QUIT} {ON | OFF}");
    144 	}
    145 
    146 	void Run(CommandSource &source, const Anope::string &user, const Anope::string &param, const Anope::string &arg)
    147 	{
    148 		if (Anope::ReadOnly)
    149 		{
    150 			source.Reply(READ_ONLY_MODE);
    151 			return;
    152 		}
    153 
    154 		const NickAlias *na = NickAlias::Find(user);
    155 		if (!na)
    156 		{
    157 			source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
    158 			return;
    159 		}
    160 		NickCore *nc = na->nc;
    161 
    162 		EventReturn MOD_RESULT;
    163 		FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param));
    164 		if (MOD_RESULT == EVENT_STOP)
    165 			return;
    166 
    167 		Anope::string onmsg, offmsg, flag;
    168 
    169 		if (param.equals_ci("EMAIL"))
    170 		{
    171 			flag = "HIDE_EMAIL";
    172 			onmsg = _("The E-mail address of \002%s\002 will now be hidden from %s INFO displays.");
    173 			offmsg = _("The E-mail address of \002%s\002 will now be shown in %s INFO displays.");
    174 		}
    175 		else if (param.equals_ci("USERMASK"))
    176 		{
    177 			flag = "HIDE_MASK";
    178 			onmsg = _("The last seen user@host mask of \002%s\002 will now be hidden from %s INFO displays.");
    179 			offmsg = _("The last seen user@host mask of \002%s\002 will now be shown in %s INFO displays.");
    180 		}
    181 		else if (param.equals_ci("STATUS"))
    182 		{
    183 			flag = "HIDE_STATUS";
    184 			onmsg = _("The services access status of \002%s\002 will now be hidden from %s INFO displays.");
    185 			offmsg = _("The services access status of \002%s\002 will now be shown in %s INFO displays.");
    186 		}
    187 		else if (param.equals_ci("QUIT"))
    188 		{
    189 			flag = "HIDE_QUIT";
    190 			onmsg = _("The last quit message of \002%s\002 will now be hidden from %s INFO displays.");
    191 			offmsg = _("The last quit message of \002%s\002 will now be shown in %s INFO displays.");
    192 		}
    193 		else
    194 		{
    195 			this->OnSyntaxError(source, "HIDE");
    196 			return;
    197 		}
    198 
    199 		if (arg.equals_ci("ON"))
    200 		{
    201 			Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to change hide " << param.upper() << " to " << arg.upper() << " for " << nc->display;
    202 			nc->Extend<bool>(flag);
    203 			source.Reply(onmsg.c_str(), nc->display.c_str(), source.service->nick.c_str());
    204 		}
    205 		else if (arg.equals_ci("OFF"))
    206 		{
    207 			Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to change hide " << param.upper() << " to " << arg.upper() << " for " << nc->display;
    208 			nc->Shrink<bool>(flag);
    209 			source.Reply(offmsg.c_str(), nc->display.c_str(), source.service->nick.c_str());
    210 		}
    211 		else
    212 			this->OnSyntaxError(source, "HIDE");
    213 	}
    214 
    215 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
    216 	{
    217 		this->Run(source, source.nc->display, params[0], params[1]);
    218 	}
    219 
    220 	bool OnHelp(CommandSource &source, const Anope::string &) anope_override
    221 	{
    222 		this->SendSyntax(source);
    223 		source.Reply(" ");
    224 		source.Reply(_("Allows you to prevent certain pieces of information from\n"
    225 				"being displayed when someone does a %s \002INFO\002 on your\n"
    226 				"nick.  You can hide your E-mail address (\002EMAIL\002), last seen\n"
    227 				"user@host mask (\002USERMASK\002), your services access status\n"
    228 				"(\002STATUS\002) and last quit message (\002QUIT\002).\n"
    229 				"The second parameter specifies whether the information should\n"
    230 				"be displayed (\002OFF\002) or hidden (\002ON\002)."), source.service->nick.c_str());
    231 		return true;
    232 	}
    233 };
    234 
    235 class CommandNSSASetHide : public CommandNSSetHide
    236 {
    237  public:
    238 	CommandNSSASetHide(Module *creator) : CommandNSSetHide(creator, "nickserv/saset/hide", 3)
    239 	{
    240 		this->SetSyntax(_("\037nickname\037 {EMAIL | STATUS | USERMASK | QUIT} {ON | OFF}"));
    241 	}
    242 
    243 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
    244 	{
    245 		this->ClearSyntax();
    246 		this->Run(source, params[0], params[1], params[2]);
    247 	}
    248 
    249 	bool OnHelp(CommandSource &source, const Anope::string &) anope_override
    250 	{
    251 		this->SendSyntax(source);
    252 		source.Reply(" ");
    253 		source.Reply(_("Allows you to prevent certain pieces of information from\n"
    254 				"being displayed when someone does a %s \002INFO\002 on the\n"
    255 				"nick.  You can hide the E-mail address (\002EMAIL\002), last seen\n"
    256 				"user@host mask (\002USERMASK\002), the services access status\n"
    257 				"(\002STATUS\002) and last quit message (\002QUIT\002).\n"
    258 				"The second parameter specifies whether the information should\n"
    259 				"be displayed (\002OFF\002) or hidden (\002ON\002)."), source.service->nick.c_str());
    260 		return true;
    261 	}
    262 };
    263 
    264 class NSInfo : public Module
    265 {
    266 	CommandNSInfo commandnsinfo;
    267 
    268 	CommandNSSetHide commandnssethide;
    269 	CommandNSSASetHide commandnssasethide;
    270 
    271 	SerializableExtensibleItem<bool> hide_email, hide_usermask, hide_status, hide_quit;
    272 
    273  public:
    274 	NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    275 		commandnsinfo(this), commandnssethide(this), commandnssasethide(this),
    276 		 hide_email(this, "HIDE_EMAIL"), hide_usermask(this, "HIDE_MASK"), hide_status(this, "HIDE_STATUS"),
    277 		 hide_quit(this, "HIDE_QUIT")
    278 	{
    279 
    280 	}
    281 };
    282 
    283 MODULE_INIT(NSInfo)