summaryrefslogtreecommitdiff
path: root/src/hostserv.cpp
blob: 31ff713f85756c91329c8cd705920cb83392e56c (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
/* HostServ 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 "services.h"
#include "modules.h"
#include "language.h"

E void moduleAddHostServCmds();

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

void moduleAddHostServCmds()
{
	ModuleManager::LoadModuleList(Config->HostServCoreModules);
}

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

/**
 * Return information on memory use.
 * Assumes pointers are valid.
 **/

void get_hostserv_stats(long *nrec, long *memuse)
{
	long count = 0, mem = 0;

	for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
	{
		NickAlias *na = it->second;

		if (!na->hostinfo.HasVhost())
			continue;

		if (!na->hostinfo.GetIdent().empty())
			mem += na->hostinfo.GetIdent().length();
		if (!na->hostinfo.GetHost().empty())
			mem += na->hostinfo.GetHost().length();
		if (!na->hostinfo.GetCreator().empty())
			mem += na->hostinfo.GetCreator().length();
		++count;
	}

	*nrec = count;
	*memuse = mem;
}

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

/**
 * HostServ initialization.
 * @return void
 */
void hostserv_init()
{
	if (!Config->s_HostServ.empty())
		moduleAddHostServCmds();
}

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

/** Set a vhost for the user
 * @param ident The ident
 * @param host The host
 * @param creator Who created the vhost
 * @param time When the vhost was craated
 */
void HostInfo::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created)
{
	Ident = ident;
	Host = host;
	Creator = creator;
	Time = created;
}

/** Remove a users vhost
 **/
void HostInfo::RemoveVhost()
{
	Ident.clear();
	Host.clear();
	Creator.clear();
	Time = 0;
}

/** Check if the user has a vhost
 * @return true or false
 */
bool HostInfo::HasVhost() const
{
	return !Host.empty();
}

/** Retrieve the vhost ident
 * @return the ident
 */
const Anope::string &HostInfo::GetIdent() const
{
	return Ident;
}

/** Retrieve the vhost host
 * @return the host
 */
const Anope::string &HostInfo::GetHost() const
{
	return Host;
}

/** Retrieve the vhost creator
 * @return the creator
 */
const Anope::string &HostInfo::GetCreator() const
{
	return Creator;
}

/** Retrieve when the vhost was crated
 * @return the time it was created
 */
const time_t HostInfo::GetTime() const
{
	return Time;
}

/*************************************************************************/
/* Start of Generic Functions */
/*************************************************************************/

/** Sync all vhosts in a group to the same thing
 * @param na The nick with the vhost wanting to by synced
 */
void HostServSyncVhosts(NickAlias *na)
{
	if (!na || !na->hostinfo.HasVhost())
		return;

	for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it)
	{
		NickAlias *nick = *it;
		nick->hostinfo.SetVhost(na->hostinfo.GetIdent(), na->hostinfo.GetHost(), na->hostinfo.GetCreator());
	}
}

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

void do_on_id(User *u)
{
	if (!u)
		return;
	NickAlias *na = findnick(u->nick);
	if (!na || !na->hostinfo.HasVhost())
		return;

	if (u->vhost.empty() || !u->vhost.equals_cs(na->hostinfo.GetHost()) || (!na->hostinfo.GetIdent().empty() && !u->GetVIdent().equals_cs(na->hostinfo.GetIdent())))
	{
		ircdproto->SendVhost(u, na->hostinfo.GetIdent(), na->hostinfo.GetHost());
		if (ircd->vhost)
			u->vhost = na->hostinfo.GetHost();
		if (ircd->vident && !na->hostinfo.GetIdent().empty())
			u->SetVIdent(na->hostinfo.GetIdent());
		u->UpdateHost();

		if (!na->hostinfo.GetIdent().empty())
			notice_lang(Config->s_HostServ, u, HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str());
		else
			notice_lang(Config->s_HostServ, u, HOST_ACTIVATED, na->hostinfo.GetHost().c_str());
	}
}