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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/*
*
* (C) 2003-2012 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 "account.h"
#include "config.h"
serialize_checker<nickcore_map> NickCoreList("NickCore");
/** Default constructor
* @param display The display nick
*/
NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), Flags<NickCoreFlag, NI_END>(NickCoreFlagStrings)
{
if (coredisplay.empty())
throw CoreException("Empty display passed to NickCore constructor");
this->o = NULL;
this->channelcount = 0;
this->lastmail = 0;
this->memos.memomax = Config->MSMaxMemos;
this->language = Config->NSDefLanguage;
this->display = coredisplay;
/* Set default nick core flags */
for (size_t t = NI_BEGIN + 1; t != NI_END; ++t)
if (Config->NSDefFlags.HasFlag(static_cast<NickCoreFlag>(t)))
this->SetFlag(static_cast<NickCoreFlag>(t));
size_t old = NickCoreList->size();
(*NickCoreList)[this->display] = this;
if (old == NickCoreList->size())
Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?";
}
/** Default destructor
*/
NickCore::~NickCore()
{
FOREACH_MOD(I_OnDelCore, OnDelCore(this));
/* Remove the core from the list */
NickCoreList->erase(this->display);
/* Clear access before deleting display name, we want to be able to use the display name in the clear access event */
this->ClearAccess();
if (!this->memos.memos->empty())
{
for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i)
this->memos.GetMemo(i)->destroy();
this->memos.memos->clear();
}
}
Serialize::Data NickCore::serialize() const
{
Serialize::Data data;
data["display"].setMax(Config->NickLen) << this->display;
data["pass"] << this->pass;
data["email"] << this->email;
data["greet"] << this->greet;
data["language"] << this->language;
data["flags"] << this->ToString();
for (unsigned i = 0; i < this->access.size(); ++i)
data["access"] << this->access[i] << " ";
for (unsigned i = 0; i < this->cert.size(); ++i)
data["cert"] << this->cert[i] << " ";
data["memomax"] << this->memos.memomax;
for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
data["memoignores"] << this->memos.ignores[i] << " ";
return data;
}
Serializable* NickCore::unserialize(Serializable *obj, Serialize::Data &data)
{
NickCore *nc;
if (obj)
nc = anope_dynamic_static_cast<NickCore *>(obj);
else
nc = new NickCore(data["display"].astr());
data["pass"] >> nc->pass;
data["email"] >> nc->email;
data["greet"] >> nc->greet;
data["language"] >> nc->language;
nc->FromString(data["flags"].astr());
{
Anope::string buf;
data["access"] >> buf;
spacesepstream sep(buf);
nc->access.clear();
while (sep.GetToken(buf))
nc->access.push_back(buf);
}
{
Anope::string buf;
data["cert"] >> buf;
spacesepstream sep(buf);
nc->cert.clear();
while (sep.GetToken(buf))
nc->cert.push_back(buf);
}
data["memomax"] >> nc->memos.memomax;
{
Anope::string buf;
data["memoignores"] >> buf;
spacesepstream sep(buf);
nc->memos.ignores.clear();
while (sep.GetToken(buf))
nc->memos.ignores.push_back(buf);
}
return nc;
}
bool NickCore::IsServicesOper() const
{
return this->o != NULL;
}
void NickCore::AddAccess(const Anope::string &entry)
{
this->access.push_back(entry);
FOREACH_MOD(I_OnNickAddAccess, OnNickAddAccess(this, entry));
}
Anope::string NickCore::GetAccess(unsigned entry) const
{
if (this->access.empty() || entry >= this->access.size())
return "";
return this->access[entry];
}
bool NickCore::FindAccess(const Anope::string &entry)
{
for (unsigned i = 0, end = this->access.size(); i < end; ++i)
if (this->access[i] == entry)
return true;
return false;
}
void NickCore::EraseAccess(const Anope::string &entry)
{
for (unsigned i = 0, end = this->access.size(); i < end; ++i)
if (this->access[i] == entry)
{
FOREACH_MOD(I_OnNickEraseAccess, OnNickEraseAccess(this, entry));
this->access.erase(this->access.begin() + i);
break;
}
}
void NickCore::ClearAccess()
{
FOREACH_MOD(I_OnNickClearAccess, OnNickClearAccess(this));
this->access.clear();
}
void NickCore::AddCert(const Anope::string &entry)
{
this->cert.push_back(entry);
FOREACH_MOD(I_OnNickAddCert, OnNickAddCert(this, entry));
}
Anope::string NickCore::GetCert(unsigned entry) const
{
if (this->cert.empty() || entry >= this->cert.size())
return "";
return this->cert[entry];
}
bool NickCore::FindCert(const Anope::string &entry) const
{
for (unsigned i = 0, end = this->cert.size(); i < end; ++i)
if (this->cert[i] == entry)
return true;
return false;
}
void NickCore::EraseCert(const Anope::string &entry)
{
for (unsigned i = 0, end = this->cert.size(); i < end; ++i)
if (this->cert[i] == entry)
{
FOREACH_MOD(I_OnNickEraseCert, OnNickEraseCert(this, entry));
this->cert.erase(this->cert.begin() + i);
break;
}
}
void NickCore::ClearCert()
{
FOREACH_MOD(I_OnNickClearCert, OnNickClearCert(this));
this->cert.clear();
}
|