Anope IRC Services  Version 2.0
memos.cpp
Go to the documentation of this file.
1 /* MemoServ functions.
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  */
12 
13 #include "services.h"
14 #include "modules.h"
15 #include "service.h"
16 #include "memo.h"
17 #include "users.h"
18 #include "account.h"
19 #include "regchannel.h"
20 
22 {
23  unread = receipt = false;
24 }
25 
27 {
28  bool ischan;
29  MemoInfo *mi = MemoInfo::GetMemoInfo(this->owner, ischan);
30  if (mi)
31  {
32  std::vector<Memo *>::iterator it = std::find(mi->memos->begin(), mi->memos->end(), this);
33 
34  if (it != mi->memos->end())
35  mi->memos->erase(it);
36  }
37 }
38 
40 {
41  data["owner"] << this->owner;
42  data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time;
43  data["sender"] << this->sender;
44  data["text"] << this->text;
45  data["unread"] << this->unread;
46  data["receipt"] << this->receipt;
47 }
48 
50 {
52 
53  data["owner"] >> owner;
54 
55  bool ischan;
56  MemoInfo *mi = MemoInfo::GetMemoInfo(owner, ischan);
57  if (!mi)
58  return NULL;
59 
60  Memo *m;
61  if (obj)
62  m = anope_dynamic_static_cast<Memo *>(obj);
63  else
64  m = new Memo();
65 
66  m->owner = owner;
67  data["time"] >> m->time;
68  data["sender"] >> m->sender;
69  data["text"] >> m->text;
70  data["unread"] >> m->unread;
71  data["receipt"] >> m->receipt;
72 
73  if (obj == NULL)
74  mi->memos->push_back(m);
75  return m;
76 }
77 
78 MemoInfo::MemoInfo() : memomax(0), memos("Memo")
79 {
80 }
81 
82 Memo *MemoInfo::GetMemo(unsigned index) const
83 {
84  if (index >= this->memos->size())
85  return NULL;
86  Memo *m = (*memos)[index];
87  m->QueueUpdate();
88  return m;
89 }
90 
91 unsigned MemoInfo::GetIndex(Memo *m) const
92 {
93  for (unsigned i = 0; i < this->memos->size(); ++i)
94  if (this->GetMemo(i) == m)
95  return i;
96  return -1;
97 }
98 
99 void MemoInfo::Del(unsigned index)
100 {
101  if (index >= this->memos->size())
102  return;
103  delete this->GetMemo(index);
104 }
105 
107 {
108  for (unsigned i = 0; i < this->ignores.size(); ++i)
109  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])))
110  return true;
111  return false;
112 }
113 
114 MemoInfo *MemoInfo::GetMemoInfo(const Anope::string &target, bool &ischan)
115 {
116  if (!target.empty() && target[0] == '#')
117  {
118  ischan = true;
119  ChannelInfo *ci = ChannelInfo::Find(target);
120  if (ci != NULL)
121  return &ci->memos;
122  }
123  else
124  {
125  ischan = false;
126  NickAlias *na = NickAlias::Find(target);
127  if (na != NULL)
128  return &na->nc->memos;
129  }
130 
131  return NULL;
132 }
133 
Serialize::Reference< NickCore > nc
Definition: account.h:47
static NickAlias * Find(const Anope::string &nick)
Definition: nickalias.cpp:121
Definition: hashcomp.h:84
Anope::string text
Definition: memo.h:34
~Memo()
Definition: memos.cpp:26
bool HasIgnore(User *u)
Definition: memos.cpp:106
unsigned GetIndex(Memo *m) const
Definition: memos.cpp:91
void QueueUpdate()
Definition: serialize.cpp:83
Anope::string sender
Definition: memo.h:33
Definition: users.h:34
static MemoInfo * GetMemoInfo(const Anope::string &targ, bool &is_chan)
Definition: memos.cpp:114
bool equals_ci(const char *_str) const
Definition: anope.h:78
virtual void SetType(const Anope::string &key, Type t)
Definition: serialize.h:38
bool receipt
Definition: memo.h:23
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
void Serialize(Serialize::Data &data) const anope_override
Definition: memos.cpp:39
CoreExport bool Match(const string &str, const string &mask, bool case_sensitive=false, bool use_regex=false)
Definition: misc.cpp:407
Definition: memo.h:40
std::vector< Anope::string > ignores
Definition: memo.h:44
Memo()
Definition: memos.cpp:21
static Serializable * Unserialize(Serializable *obj, Serialize::Data &)
Definition: memos.cpp:49
Definition: memo.h:19
Anope::string GetMask() const
Definition: users.cpp:269
Anope::string display
Definition: account.h:113
Memo * GetMemo(unsigned index) const
Definition: memos.cpp:82
bool empty() const
Definition: anope.h:126
MemoInfo memos
Definition: regchannel.h:77
std::basic_string< char, ci_char_traits, std::allocator< char > > string
Definition: hashcomp.h:133
Anope::string nick
Definition: users.h:62
Serialize::Checker< std::vector< Memo * > > memos
Definition: memo.h:43
NickCore * Account() const
Definition: users.cpp:422
MemoInfo()
Definition: memos.cpp:78
T anope_dynamic_static_cast(O ptr)
Definition: anope.h:774
time_t time
Definition: memo.h:32
void Del(unsigned index)
Definition: memos.cpp:99
bool unread
Definition: memo.h:22
Anope::string owner
Definition: memo.h:30