Anope IRC Services  Version 2.0
ns_info.cpp
Go to the documentation of this file.
1 /* NickServ core functions
2  *
3  * (C) 2003-2014 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);
44  if (u2 && u2->Account() == na->nc)
45  {
46  nick_online = true;
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  if (nick_online)
64  {
65  bool shown = false;
66  if (show_hidden && !na->last_realhost.empty())
67  {
68  info[_("Online from")] = na->last_realhost;
69  shown = true;
70  }
71  if ((show_hidden || !na->nc->HasExt("HIDE_MASK")) && (!shown || na->last_usermask != na->last_realhost))
72  info[_("Online from")] = na->last_usermask;
73  else
74  source.Reply(_("%s is currently online."), na->nick.c_str());
75  }
76  else
77  {
78  Anope::string shown;
79  if (show_hidden || !na->nc->HasExt("HIDE_MASK"))
80  {
81  info[_("Last seen address")] = na->last_usermask;
82  shown = na->last_usermask;
83  }
84 
85  if (show_hidden && !na->last_realhost.empty() && na->last_realhost != shown)
86  info[_("Last seen address")] = na->last_realhost;
87  }
88 
89  info[_("Registered")] = Anope::strftime(na->time_registered, source.GetAccount());
90 
91  if (!nick_online)
92  info[_("Last seen")] = Anope::strftime(na->last_seen, source.GetAccount());
93 
94  if (!na->last_quit.empty() && (show_hidden || !na->nc->HasExt("HIDE_QUIT")))
95  info[_("Last quit message")] = na->last_quit;
96 
97  if (!na->nc->email.empty() && (show_hidden || !na->nc->HasExt("HIDE_EMAIL")))
98  info[_("Email address")] = na->nc->email;
99 
100  if (show_hidden)
101  {
102  if (na->HasVhost())
103  {
104  if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
105  info[_("VHost")] = na->GetVhostIdent() + "@" + na->GetVhostHost();
106  else
107  info[_("VHost")] = na->GetVhostHost();
108  }
109  }
110 
111  FOREACH_MOD(OnNickInfo, (source, na, info, show_hidden));
112 
113  std::vector<Anope::string> replies;
114  info.Process(replies);
115 
116  for (unsigned i = 0; i < replies.size(); ++i)
117  source.Reply(replies[i]);
118  }
119  }
120 
121  bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
122  {
123  this->SendSyntax(source);
124  source.Reply(" ");
125  source.Reply(_("Displays information about the given nickname, such as\n"
126  "the nick's owner, last seen address and time, and nick\n"
127  "options. If no nick is given, and you are identified,\n"
128  "your account name is used, else your current nickname is\n"
129  "used."));
130 
131  return true;
132  }
133 };
134 
135 
136 class CommandNSSetHide : public Command
137 {
138  public:
139  CommandNSSetHide(Module *creator, const Anope::string &sname = "nickserv/set/hide", size_t min = 2) : Command(creator, sname, min, min + 1)
140  {
141  this->SetDesc(_("Hide certain pieces of nickname information"));
142  this->SetSyntax("{EMAIL | STATUS | USERMASK | QUIT} {ON | OFF}");
143  }
144 
145  void Run(CommandSource &source, const Anope::string &user, const Anope::string &param, const Anope::string &arg)
146  {
147  if (Anope::ReadOnly)
148  {
149  source.Reply(READ_ONLY_MODE);
150  return;
151  }
152 
153  const NickAlias *na = NickAlias::Find(user);
154  if (!na)
155  {
156  source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
157  return;
158  }
159  NickCore *nc = na->nc;
160 
161  EventReturn MOD_RESULT;
162  FOREACH_RESULT(OnSetNickOption, MOD_RESULT, (source, this, nc, param));
163  if (MOD_RESULT == EVENT_STOP)
164  return;
165 
166  Anope::string onmsg, offmsg, flag;
167 
168  if (param.equals_ci("EMAIL"))
169  {
170  flag = "HIDE_EMAIL";
171  onmsg = _("The E-mail address of \002%s\002 will now be hidden from %s INFO displays.");
172  offmsg = _("The E-mail address of \002%s\002 will now be shown in %s INFO displays.");
173  }
174  else if (param.equals_ci("USERMASK"))
175  {
176  flag = "HIDE_MASK";
177  onmsg = _("The last seen user@host mask of \002%s\002 will now be hidden from %s INFO displays.");
178  offmsg = _("The last seen user@host mask of \002%s\002 will now be shown in %s INFO displays.");
179  }
180  else if (param.equals_ci("STATUS"))
181  {
182  flag = "HIDE_STATUS";
183  onmsg = _("The services access status of \002%s\002 will now be hidden from %s INFO displays.");
184  offmsg = _("The services access status of \002%s\002 will now be shown in %s INFO displays.");
185  }
186  else if (param.equals_ci("QUIT"))
187  {
188  flag = "HIDE_QUIT";
189  onmsg = _("The last quit message of \002%s\002 will now be hidden from %s INFO displays.");
190  offmsg = _("The last quit message of \002%s\002 will now be shown in %s INFO displays.");
191  }
192  else
193  {
194  this->OnSyntaxError(source, "HIDE");
195  return;
196  }
197 
198  if (arg.equals_ci("ON"))
199  {
200  Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to change hide " << param.upper() << " to " << arg.upper() << " for " << nc->display;
201  nc->Extend<bool>(flag);
202  source.Reply(onmsg.c_str(), nc->display.c_str(), source.service->nick.c_str());
203  }
204  else if (arg.equals_ci("OFF"))
205  {
206  Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to change hide " << param.upper() << " to " << arg.upper() << " for " << nc->display;
207  nc->Shrink<bool>(flag);
208  source.Reply(offmsg.c_str(), nc->display.c_str(), source.service->nick.c_str());
209  }
210  else
211  this->OnSyntaxError(source, "HIDE");
212  }
213 
214  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
215  {
216  this->Run(source, source.nc->display, params[0], params[1]);
217  }
218 
220  {
221  this->SendSyntax(source);
222  source.Reply(" ");
223  source.Reply(_("Allows you to prevent certain pieces of information from\n"
224  "being displayed when someone does a %s \002INFO\002 on your\n"
225  "nick. You can hide your E-mail address (\002EMAIL\002), last seen\n"
226  "user@host mask (\002USERMASK\002), your services access status\n"
227  "(\002STATUS\002) and last quit message (\002QUIT\002).\n"
228  "The second parameter specifies whether the information should\n"
229  "be displayed (\002OFF\002) or hidden (\002ON\002)."), source.service->nick.c_str());
230  return true;
231  }
232 };
233 
235 {
236  public:
237  CommandNSSASetHide(Module *creator) : CommandNSSetHide(creator, "nickserv/saset/hide", 3)
238  {
239  this->SetSyntax(_("\037nickname\037 {EMAIL | STATUS | USERMASK | QUIT} {ON | OFF}"));
240  }
241 
242  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
243  {
244  this->ClearSyntax();
245  this->Run(source, params[0], params[1], params[2]);
246  }
247 
249  {
250  this->SendSyntax(source);
251  source.Reply(" ");
252  source.Reply(_("Allows you to prevent certain pieces of information from\n"
253  "being displayed when someone does a %s \002INFO\002 on the\n"
254  "nick. You can hide the E-mail address (\002EMAIL\002), last seen\n"
255  "user@host mask (\002USERMASK\002), the services access status\n"
256  "(\002STATUS\002) and last quit message (\002QUIT\002).\n"
257  "The second parameter specifies whether the information should\n"
258  "be displayed (\002OFF\002) or hidden (\002ON\002)."), source.service->nick.c_str());
259  return true;
260  }
261 };
262 
263 class NSInfo : public Module
264 {
266 
269 
271 
272  public:
273  NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
274  commandnsinfo(this), commandnssethide(this), commandnssasethide(this),
275  hide_email(this, "HIDE_EMAIL"), hide_usermask(this, "HIDE_MASK"), hide_status(this, "HIDE_STATUS"),
276  hide_quit(this, "HIDE_QUIT")
277  {
278 
279  }
280 };
281 
Serialize::Reference< NickCore > nc
Definition: account.h:47
CoreExport bool ReadOnly
Definition: main.cpp:28
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
SerializableExtensibleItem< bool > hide_usermask
Definition: ns_info.cpp:270
CommandNSSetHide(Module *creator, const Anope::string &sname="nickserv/set/hide", size_t min=2)
Definition: ns_info.cpp:139
bool OnHelp(CommandSource &source, const Anope::string &) anope_override
Definition: ns_info.cpp:219
Anope::string nick
Definition: account.h:37
const Anope::string & GetVhostHost() const
Definition: nickalias.cpp:106
Anope::string last_usermask
Definition: account.h:41
bool HasVhost() const
Definition: nickalias.cpp:96
Definition: users.h:34
CommandNSInfo(Module *creator)
Definition: ns_info.cpp:17
T * Extend(const Anope::string &name, const T &what)
Definition: extensible.h:224
#define NICK_X_NOT_REGISTERED
Definition: language.h:79
string upper() const
Definition: anope.h:266
void ClearSyntax()
Definition: command.cpp:135
#define READ_ONLY_MODE
Definition: language.h:71
void Process(std::vector< Anope::string > &)
Definition: misc.cpp:222
#define FOREACH_RESULT(ename, ret, args)
Definition: modules.h:95
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool equals_ci(const char *_str) const
Definition: anope.h:78
SerializableExtensibleItem< bool > hide_status
Definition: ns_info.cpp:270
bool OnHelp(CommandSource &source, const Anope::string &) anope_override
Definition: ns_info.cpp:248
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param, const Anope::string &arg)
Definition: ns_info.cpp:145
CoreExport time_t CurTime
Definition: main.cpp:41
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
bool CanSetVIdent
Definition: protocol.h:53
void Shrink(const Anope::string &name)
Definition: extensible.h:253
virtual void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
Definition: command.cpp:191
void Reply(const char *message,...)
Definition: command.cpp:96
CommandNSInfo commandnsinfo
Definition: ns_info.cpp:265
time_t time_registered
Definition: account.h:44
Reference< BotInfo > service
Definition: commands.h:67
CommandNSSASetHide(Module *creator)
Definition: ns_info.cpp:237
CommandNSSASetHide commandnssasethide
Definition: ns_info.cpp:268
Anope::string display
Definition: account.h:113
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
SerializableExtensibleItem< bool > hide_email
Definition: ns_info.cpp:270
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
EventReturn
Definition: modules.h:129
#define MODULE_INIT(x)
Definition: modules.h:45
bool AllowUnregistered() const
Definition: command.cpp:159
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ns_info.cpp:24
Anope::string nick
Definition: users.h:62
static User * Find(const Anope::string &name, bool nick_only=false)
Definition: users.cpp:815
time_t last_seen
Definition: account.h:45
NickCore * Account() const
Definition: users.cpp:422
void SendSyntax(CommandSource &)
Definition: command.cpp:145
Anope::string last_realname
Definition: account.h:39
NickCore * GetAccount()
Definition: command.cpp:36
SerializableExtensibleItem< bool > hide_quit
Definition: ns_info.cpp:270
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
Anope::string last_quit
Definition: account.h:38
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ns_info.cpp:242
CoreExport Anope::string strftime(time_t t, const NickCore *nc=NULL, bool short_output=false)
Definition: misc.cpp:356
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: ns_info.cpp:214
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: ns_info.cpp:121
CommandNSSetHide commandnssethide
Definition: ns_info.cpp:267
NSInfo(const Anope::string &modname, const Anope::string &creator)
Definition: ns_info.cpp:273
#define _(x)
Definition: services.h:50
static BotInfo * Find(const Anope::string &nick, bool nick_only=false)
Definition: bots.cpp:249
Anope::string last_realhost
Definition: account.h:43
const Anope::string & GetVhostIdent() const
Definition: nickalias.cpp:101