summaryrefslogtreecommitdiff
path: root/modules/commands/os_forbid.h
blob: dcc5a9d6e4a781e9ae2690f262357d5ee7364250 (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
#ifndef OS_FORBID_H
#define OS_FORBID_H

enum ForbidType
{
	FT_NONE,
	FT_NICK,
	FT_CHAN,
	FT_EMAIL
};

struct ForbidData : Serializable
{
	Anope::string mask;
	Anope::string creator;
	Anope::string reason;
	time_t created;
	time_t expires;
	ForbidType type;

	const Anope::string serialize_name() const anope_override { return "ForbidData"; }
	Serialize::Data serialize() const anope_override;
	static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
};

class ForbidService : public Service
{
 public:
	ForbidService(Module *m) : Service(m, "ForbidService", "forbid") { }

	virtual void AddForbid(ForbidData *d) = 0;

	virtual void RemoveForbid(ForbidData *d) = 0;

	virtual ForbidData *FindForbid(const Anope::string &mask, ForbidType type) = 0;

	virtual const std::vector<ForbidData *> &GetForbids() = 0;
};

static service_reference<ForbidService> forbid_service("ForbidService", "forbid");

Serialize::Data ForbidData::serialize() const
{
	Serialize::Data data;
	
	data["mask"] << this->mask;
	data["creator"] << this->creator;
	data["reason"] << this->reason;
	data["created"] << this->created;
	data["expires"] << this->expires;
	data["type"] << this->type;

	return data;
}

Serializable* ForbidData::unserialize(Serializable *obj, Serialize::Data &data)
{
	if (!forbid_service)
		return NULL;

	ForbidData *fb;
	if (obj)
		fb = anope_dynamic_static_cast<ForbidData *>(obj);
	else
		fb = new ForbidData;

	data["mask"] >> fb->mask;
	data["creator"] >> fb->creator;
	data["reason"] >> fb->reason;
	data["created"] >> fb->created;
	data["expires"] >> fb->expires;
	unsigned int t;
	data["type"] >> t;
	fb->type = static_cast<ForbidType>(t);

	if (!obj)
		forbid_service->AddForbid(fb);
	return fb;
}

#endif