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
|
/*
* Anope IRC Services
*
* Copyright (C) 2011-2017 Anope Team <team@anope.org>
*
* This file is part of Anope. Anope is free software; you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software
* Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see see <http://www.gnu.org/licenses/>.
*/
#include "module.h"
#include "modules/help.h"
#include "modules/nickserv/update.h"
#include "modules/nickserv/info.h"
#include "modules/hostserv/del.h"
#include "vhosttype.h"
class HostServCore : public Module
, public EventHook<Event::UserLogin>
, public EventHook<Event::NickUpdate>
, public EventHook<Event::Help>
, public EventHook<Event::SetVhost>
, public EventHook<Event::DeleteVhost>
, public EventHook<Event::NickInfo>
{
Reference<ServiceBot> HostServ;
VHostType vhost_type;
public:
HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
, EventHook<Event::UserLogin>(this)
, EventHook<Event::NickUpdate>(this)
, EventHook<Event::Help>(this)
, EventHook<Event::SetVhost>(this)
, EventHook<Event::DeleteVhost>(this)
, EventHook<Event::NickInfo>(this)
, vhost_type(this)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
}
void OnReload(Configuration::Conf *conf) override
{
const Anope::string &hsnick = conf->GetModule(this)->Get<Anope::string>("client");
if (hsnick.empty())
throw ConfigException(Module::name + ": <client> must be defined");
ServiceBot *bi = ServiceBot::Find(hsnick, true);
if (!bi)
throw ConfigException(Module::name + ": no bot named " + hsnick);
HostServ = bi;
}
void OnUserLogin(User *u) override
{
if (!IRCD->CanSetVHost)
return;
HostServ::VHost *vhost = HostServ::FindVHost(u->Account());
if (vhost == nullptr)
return;
if (u->vhost.empty() || !u->vhost.equals_cs(vhost->GetHost()) || (!vhost->GetIdent().empty() && !u->GetVIdent().equals_cs(vhost->GetIdent())))
{
IRCD->Send<messages::VhostSet>(u, vhost->GetIdent(), vhost->GetHost());
u->vhost = vhost->GetHost();
u->UpdateHost();
if (IRCD->CanSetVIdent && !vhost->GetIdent().empty())
u->SetVIdent(vhost->GetIdent());
if (HostServ)
{
if (!vhost->GetIdent().empty())
u->SendMessage(*HostServ, _("Your vhost of \002{0}\002@\002{1}\002 is now activated."), vhost->GetIdent(), vhost->GetHost());
else
u->SendMessage(*HostServ, _("Your vhost of \002{0}\002 is now activated."), vhost->GetHost());
}
}
}
void OnNickUpdate(User *u) override
{
this->OnUserLogin(u);
}
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
if (!params.empty() || source.c || source.service != *HostServ)
return EVENT_CONTINUE;
source.Reply(_("{0} commands:"), HostServ->nick);
return EVENT_CONTINUE;
}
void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override
{
}
void OnSetVhost(NickServ::Nick *na) override
{
if (Config->GetModule(this)->Get<bool>("activate_on_set"))
{
User *u = User::Find(na->GetNick());
if (u && u->Account() == na->GetAccount())
{
HostServ::VHost *vhost = HostServ::FindVHost(u->Account());
if (vhost == nullptr)
return;
IRCD->Send<messages::VhostSet>(u, vhost->GetIdent(), vhost->GetHost());
u->vhost = vhost->GetHost();
u->UpdateHost();
if (IRCD->CanSetVIdent && !vhost->GetIdent().empty())
u->SetVIdent(vhost->GetIdent());
if (HostServ)
{
if (!vhost->GetIdent().empty())
u->SendMessage(*HostServ, _("Your vhost of \002{0}\002@\002{1}\002 is now activated."), vhost->GetIdent(), vhost->GetHost());
else
u->SendMessage(*HostServ, _("Your vhost of \002{0}\002 is now activated."), vhost->GetHost());
}
}
}
}
void OnDeleteVhost(NickServ::Nick *na) override
{
if (Config->GetModule(this)->Get<bool>("activate_on_set"))
{
User *u = User::Find(na->GetNick());
if (u && u->Account() == na->GetAccount())
IRCD->Send<messages::VhostDel>(u);
}
}
void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override
{
if (show_hidden || source.HasPriv("hostserv/auspex"))
{
for (HostServ::VHost *vhost : na->GetAccount()->GetRefs<HostServ::VHost *>())
{
info[_("VHost")] = vhost->Mask() + (vhost->IsDefault() ? " (default)" : "");
}
}
}
};
MODULE_INIT(HostServCore)
|