blob: 1b01c3d5464f02ad0ff3f7951ded2fb971074592 (
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
|
#include "services.h"
#include "pseudo.h"
#define HASH(nick) ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31))
/** Default constructor
* @param display The display nick
*/
NickCore::NickCore(const std::string &coredisplay)
{
if (coredisplay.empty())
throw CoreException("Empty display passed to NickCore constructor");
next = prev = NULL;
display = email = greet = url = NULL;
ot = NULL;
icq = 0;
language = channelcount = 0;
lastmail = 0;
this->display = sstrdup(coredisplay.c_str());
slist_init(&this->aliases);
insert_core(this); // till hashing is redone..
/* Set default nick core flags */
for (size_t t = NI_BEGIN + 1; t != NI_END; ++t)
if (Config.NSDefFlags.HasFlag(static_cast<NickCoreFlag>(t)))
SetFlag(static_cast<NickCoreFlag>(t));
}
/** Default destructor
*/
NickCore::~NickCore()
{
FOREACH_MOD(I_OnDelCore, OnDelCore(this));
/* Clean up this nick core from any users online using it
* (ones that /nick but remain unidentified)
*/
for (std::list<User *>::iterator it = this->Users.begin(); it != this->Users.end(); ++it)
{
User *user = *it;
ircdproto->SendAccountLogout(user, user->Account());
ircdproto->SendUnregisteredNick(user);
user->Logout();
FOREACH_MOD(I_OnNickLogout, OnNickLogout(user));
}
this->Users.clear();
/* (Hopefully complete) cleanup */
cs_remove_nick(this);
/* Remove the core from the list */
if (this->next)
this->next->prev = this->prev;
if (this->prev)
this->prev->next = this->next;
else
nclists[HASH(this->display)] = this->next;
/* Log .. */
Alog() << Config.s_NickServ << ": deleting nickname group " << 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();
/* Now we can safely free it. */
delete [] this->display;
if (this->email)
delete [] this->email;
if (this->greet)
delete [] this->greet;
if (this->url)
delete [] this->url;
if (!this->memos.memos.empty())
{
for (unsigned i = 0; i < this->memos.memos.size(); ++i)
{
if (this->memos.memos[i]->text)
delete [] this->memos.memos[i]->text;
delete this->memos.memos[i];
}
this->memos.memos.clear();
}
}
bool NickCore::HasCommand(const std::string &cmdstr) const
{
if (!this->ot)
{
// No opertype.
return false;
}
return this->ot->HasCommand(cmdstr);
}
bool NickCore::IsServicesOper() const
{
if (this->ot)
return true;
return false;
}
bool NickCore::HasPriv(const std::string &privstr) const
{
if (!this->ot)
{
// No opertype.
return false;
}
return this->ot->HasPriv(privstr);
}
void NickCore::AddAccess(const std::string &entry)
{
access.push_back(entry);
FOREACH_MOD(I_OnNickAddAccess, OnNickAddAccess(this, entry));
}
std::string NickCore::GetAccess(unsigned entry)
{
if (access.empty() || entry >= access.size())
return "";
return access[entry];
}
bool NickCore::FindAccess(const std::string &entry)
{
for (unsigned i = 0; i < access.size(); ++i)
if (access[i] == entry)
return true;
return false;
}
void NickCore::EraseAccess(const std::string &entry)
{
for (unsigned i = 0; i < access.size(); ++i)
if (access[i] == entry)
{
FOREACH_MOD(I_OnNickEraseAccess, OnNickEraseAccess(this, entry));
access.erase(access.begin() + i);
break;
}
}
void NickCore::ClearAccess()
{
FOREACH_MOD(I_OnNickClearAccess, OnNickClearAccess(this));
access.clear();
}
|