summaryrefslogtreecommitdiff
path: root/modules/nickserv/main/nick.cpp
blob: 4efaf5a45e01c4e09fed90c463a7573b53243757 (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
/*
 * Anope IRC Services
 *
 * Copyright (C) 2015-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 "nicktype.h"

NickImpl::~NickImpl()
{
	/* Remove us from the aliases list */
	NickServ::nickalias_map &map = NickServ::service->GetNickMap();
	map.erase(GetNick());
}

void NickImpl::Delete()
{
	EventManager::Get()->Dispatch(&Event::DelNick::OnDelNick, this);

	if (this->GetAccount())
	{
		/* Next: see if our core is still useful. */
		std::vector<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>();

		auto it = std::find(aliases.begin(), aliases.end(), this);
		if (it != aliases.end())
			aliases.erase(it);

		if (aliases.empty())
		{
			/* just me */
			this->GetAccount()->Delete();
		}
		else
		{
			/* Display updating stuff */
			if (GetNick().equals_ci(this->GetAccount()->GetDisplay()))
				this->GetAccount()->SetDisplay(aliases[0]);
		}
	}

	return Serialize::Object::Delete();
}

Anope::string NickImpl::GetNick()
{
	return Get<Anope::string>(&NickType::nick);
}

void NickImpl::SetNick(const Anope::string &n)
{
	Set(&NickType::nick, n);
}

Anope::string NickImpl::GetLastQuit()
{
	return Get(&NickType::last_quit);
}

void NickImpl::SetLastQuit(const Anope::string &lq)
{
	Set(&NickType::last_quit, lq);
}

Anope::string NickImpl::GetLastRealname()
{
	return Get(&NickType::last_realname);
}

void NickImpl::SetLastRealname(const Anope::string &lr)
{
	Set(&NickType::last_realname, lr);
}

Anope::string NickImpl::GetLastUsermask()
{
	return Get(&NickType::last_usermask);
}

void NickImpl::SetLastUsermask(const Anope::string &lu)
{
	Set(&NickType::last_usermask, lu);
}

Anope::string NickImpl::GetLastRealhost()
{
	return Get(&NickType::last_realhost);
}

void NickImpl::SetLastRealhost(const Anope::string &lr)
{
	Set(&NickType::last_realhost, lr);
}

time_t NickImpl::GetTimeRegistered()
{
	return Get(&NickType::time_registered);
}

void NickImpl::SetTimeRegistered(const time_t &tr)
{
	Set(&NickType::time_registered, tr);
}

time_t NickImpl::GetLastSeen()
{
	return Get(&NickType::last_seen);
}

void NickImpl::SetLastSeen(const time_t &ls)
{
	Set(&NickType::last_seen, ls);
}

NickServ::Account *NickImpl::GetAccount()
{
	return Get(&NickType::account);
}

void NickImpl::SetAccount(NickServ::Account *acc)
{
	Set(&NickType::account, acc);
}

bool NickImpl::IsNoExpire()
{
	return Get(&NickType::noexpire);
}

void NickImpl::SetNoExpire(bool n)
{
	Set(&NickType::noexpire, n);
}