summaryrefslogtreecommitdiff
path: root/modules/core/ns_info.cpp
blob: a3ee2f70fbd23ffb030713fe6479301223f1e398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* NickServ core functions
 *
 * (C) 2003-2010 Anope Team
 * Contact us at team@anope.org
 *
 * Please read COPYING and README for further details.
 *
 * Based on the original code of Epona by Lara.
 * Based on the original code of Services by Andy Church.
 */

/*************************************************************************/

#include "module.h"

class CommandNSInfo : public Command
{
 private:
	// cannot be const, as it is modified
	void CheckOptStr(Anope::string &buf, NickCoreFlag opt, const Anope::string &str, NickCore *nc, bool reverse_logic = false)
	{
		if (reverse_logic ? !nc->HasFlag(opt) : nc->HasFlag(opt))
		{
			if (!buf.empty())
				buf += ", ";

			buf += str;
		}
	}
 public:
	CommandNSInfo() : Command("INFO", 1, 2)
	{
		this->SetFlag(CFLAG_ALLOW_UNREGISTERED);
	}

	CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> &params)
	{
		User *u = source.u;

		const Anope::string &nick = params[0];
		NickAlias *na = findnick(nick);
		bool has_auspex = u->IsIdentified() && u->Account()->HasPriv("nickserv/auspex");

		if (!na)
		{
			NickRequest *nr = findrequestnick(nick);
			if (nr)
			{
				source.Reply(NICK_IS_PREREG);
				if (has_auspex)
					source.Reply(NICK_INFO_EMAIL, nr->email.c_str());
			}
			else if (nickIsServices(nick, true))
				source.Reply(NICK_X_IS_SERVICES, nick.c_str());
			else
				source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
		}
		else if (na->HasFlag(NS_FORBIDDEN))
		{
			if (u->HasMode(UMODE_OPER) && !na->last_usermask.empty())
				source.Reply(NICK_X_FORBIDDEN_OPER, nick.c_str(), na->last_usermask.c_str(), !na->last_realname.empty() ? na->last_realname.c_str() : GetString(u, NO_REASON).c_str());
			else
				source.Reply(NICK_X_FORBIDDEN, nick.c_str());
		}
		else
		{
			bool nick_online = false, show_hidden = false;

			/* Is the real owner of the nick we're looking up online? -TheShadow */
			User *u2 = finduser(na->nick);
			if (u2 && u2->Account() == na->nc)
				nick_online = true;

			if (has_auspex || (u->Account() && na->nc == u->Account()))
				show_hidden = true;

			source.Reply(NICK_INFO_REALNAME, na->nick.c_str(), na->last_realname.c_str());

			if (na->nc->IsServicesOper() && (show_hidden || !na->nc->HasFlag(NI_HIDE_STATUS)))
				source.Reply(NICK_INFO_SERVICES_OPERTYPE, na->nick.c_str(), na->nc->ot->GetName().c_str());

			if (nick_online)
			{
				if (show_hidden || !na->nc->HasFlag(NI_HIDE_MASK))
					source.Reply(NICK_INFO_ADDRESS_ONLINE, na->last_usermask.c_str());
				else
					source.Reply(NICK_INFO_ADDRESS_ONLINE_NOHOST, na->nick.c_str());
			}
			else
			{
				if (show_hidden || !na->nc->HasFlag(NI_HIDE_MASK))
					source.Reply(NICK_INFO_ADDRESS, na->last_usermask.c_str());
			}

			source.Reply(NICK_INFO_TIME_REGGED, do_strftime(na->time_registered).c_str());

			if (!nick_online)
			{
				source.Reply(NICK_INFO_LAST_SEEN, do_strftime(na->last_seen).c_str());
			}

			if (!na->last_quit.empty() && (show_hidden || !na->nc->HasFlag(NI_HIDE_QUIT)))
				source.Reply(NICK_INFO_LAST_QUIT, na->last_quit.c_str());

			if (!na->nc->email.empty() && (show_hidden || !na->nc->HasFlag(NI_HIDE_EMAIL)))
				source.Reply(NICK_INFO_EMAIL, na->nc->email.c_str());

			if (show_hidden)
			{
				if (!Config->s_HostServ.empty() && ircd->vhost && na->hostinfo.HasVhost())
				{
					if (ircd->vident && !na->hostinfo.GetIdent().empty())
						source.Reply(NICK_INFO_VHOST2, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
					else
						source.Reply(NICK_INFO_VHOST, na->hostinfo.GetHost().c_str());
				}
				if (!na->nc->greet.empty())
					source.Reply(NICK_INFO_GREET, na->nc->greet.c_str());

				Anope::string optbuf;

				CheckOptStr(optbuf, NI_KILLPROTECT, GetString(u, NICK_INFO_OPT_KILL).c_str(), na->nc);
				CheckOptStr(optbuf, NI_SECURE, GetString(u, NICK_INFO_OPT_SECURE).c_str(), na->nc);
				CheckOptStr(optbuf, NI_PRIVATE, GetString(u, NICK_INFO_OPT_PRIVATE).c_str(), na->nc);
				CheckOptStr(optbuf, NI_MSG, GetString(u, NICK_INFO_OPT_MSG).c_str(), na->nc);
				CheckOptStr(optbuf, NI_AUTOOP, GetString(u, NICK_INFO_OPT_AUTOOP).c_str(), na->nc);

				source.Reply(NICK_INFO_OPTIONS, optbuf.empty() ? GetString(u, NICK_INFO_OPT_NONE).c_str() : optbuf.c_str());

				if (na->nc->HasFlag(NI_SUSPENDED))
				{
					if (!na->last_quit.empty())
						source.Reply(NICK_INFO_SUSPENDED, na->last_quit.c_str());
					else
						source.Reply(NICK_INFO_SUSPENDED_NO_REASON);
				}

				if (na->HasFlag(NS_NO_EXPIRE))
					source.Reply(NICK_INFO_NO_EXPIRE);
				else
					source.Reply(NICK_INFO_EXPIRE, do_strftime(na->last_seen + Config->NSExpire).c_str());
			}

			FOREACH_MOD(I_OnNickInfo, OnNickInfo(u, na, show_hidden));
		}
		return MOD_CONT;
	}

	bool OnHelp(CommandSource &source, const Anope::string &subcommand)
	{
		source.Reply(NICK_HELP_INFO);

		return true;
	}

	void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
	{
		SyntaxError(source, "INFO", NICK_INFO_SYNTAX);
	}

	void OnServHelp(CommandSource &source)
	{
		source.Reply(NICK_HELP_CMD_INFO);
	}
};

class NSInfo : public Module
{
	CommandNSInfo commandnsinfo;

 public:
	NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator)
	{
		this->SetAuthor("Anope");
		this->SetType(CORE);

		this->AddCommand(NickServ, &commandnsinfo);
	}
};

MODULE_INIT(NSInfo)