summaryrefslogtreecommitdiff
path: root/src/memoserv.cpp
blob: bb168b939dde9bdf741940c8999408bf8a657fbb (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
/* MemoServ functions.
 *
 * (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 "memoserv.h"

Memo::Memo() : Flags<MemoFlag>(MemoFlagStrings) { }

Anope::string Memo::serialize_name() const
{
	return "Memo";
}

Serializable::serialized_data Memo::serialize()
{
	serialized_data data;	

	data["owner"] << this->owner;
	data["time"].setType(Serialize::DT_INT) << this->time;
	data["sender"] << this->sender;
	data["text"] << this->text;
	data["flags"] << this->ToString();

	return data;
}

void Memo::unserialize(serialized_data &data)
{
	if (!memoserv)
		return;
	
	bool ischan;
	MemoInfo *mi = memoserv->GetMemoInfo(data["owner"].astr(), ischan);
	if (!mi)
		return;

	Memo *m = new Memo();
	data["owner"] >> m->owner;
	data["time"] >> m->time;
	data["sender"] >> m->sender;
	data["text"] >> m->text;
	m->FromString(data["flags"].astr());

	mi->memos.push_back(m);
}

unsigned MemoInfo::GetIndex(Memo *m) const
{
	for (unsigned i = 0; i < this->memos.size(); ++i)
		if (this->memos[i] == m)
			return i;
	return -1;
}

void MemoInfo::Del(unsigned index)
{
	if (index >= this->memos.size())
		return;
	delete this->memos[index];
	this->memos.erase(this->memos.begin() + index);
}

void MemoInfo::Del(Memo *memo)
{
	std::vector<Memo *>::iterator it = std::find(this->memos.begin(), this->memos.end(), memo);

	if (it != this->memos.end())
	{
		delete memo;
		this->memos.erase(it);
	}
}

bool MemoInfo::HasIgnore(User *u)
{
	for (unsigned i = 0; i < this->ignores.size(); ++i)
		if (u->nick.equals_ci(this->ignores[i]) || (u->Account() && u->Account()->display.equals_ci(this->ignores[i])) || Anope::Match(u->GetMask(), Anope::string(this->ignores[i])))
			return true;
	return false;
}