Anope IRC Services  Version 2.0
account.h
Go to the documentation of this file.
1 /*
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 #ifndef ACCOUNT_H
14 #define ACCOUNT_H
15 
16 #include "extensible.h"
17 #include "serialize.h"
18 #include "anope.h"
19 #include "memo.h"
20 #include "base.h"
21 
24 
27 
28 /* A registered nickname.
29  * It matters that Base is here before Extensible (it is inherited by Serializable)
30  */
32 {
33  Anope::string vhost_ident, vhost_host, vhost_creator;
34  time_t vhost_created;
35 
36  public:
40  /* Last usermask this nick was seen on, eg user@host */
42  /* Last uncloaked usermask, requires nickserv/auspex to see */
45  time_t last_seen;
46  /* Account this nick is tied to. Multiple nicks can be tied to a single account. */
48 
53  NickAlias(const Anope::string &nickname, NickCore *nickcore);
54  ~NickAlias();
55 
56  void Serialize(Serialize::Data &data) const anope_override;
57  static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
58 
65  void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime);
66 
69  void RemoveVhost();
70 
74  bool HasVhost() const;
75 
79  const Anope::string &GetVhostIdent() const;
80 
84  const Anope::string &GetVhostHost() const;
85 
89  const Anope::string &GetVhostCreator() const;
90 
94  time_t GetVhostCreated() const;
95 
100  static NickAlias *Find(const Anope::string &nick);
101 };
102 
103 /* A registered account. Each account must have a NickAlias with the same nick as the
104  * account's display.
105  * It matters that Base is here before Extensible (it is inherited by Serializable)
106  */
108 {
109  /* Channels which reference this core in some way (this is on their access list, akick list, is founder, successor, etc) */
111  public:
112  /* Name of the account. Find(display)->nc == this. */
114  /* User password in form of hashm:data */
117  /* Locale name of the language of the user. Empty means default language */
119  /* Access list, contains user@host masks of users who get certain privileges based
120  * on if NI_SECURE is set and what (if any) kill protection is enabled. */
121  std::vector<Anope::string> access;
123  std::map<Anope::string, Anope::string> last_modes;
124 
125  /* Nicknames registered that are grouped to this account.
126  * for n in aliases, n->nc == this.
127  */
129 
130  /* Set if this user is a services operattor. o->ot must exist. */
131  Oper *o;
132 
133  /* Unsaved data */
134 
135  /* Number of channels registered by this account */
136  uint16_t channelcount;
137  /* Last time an email was sent to this user */
138  time_t lastmail;
139  /* Users online now logged into this account */
140  std::list<User *> users;
141 
145  NickCore(const Anope::string &nickdisplay);
146  ~NickCore();
147 
148  void Serialize(Serialize::Data &data) const anope_override;
149  static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
150 
154  void SetDisplay(const NickAlias *na);
155 
159  virtual bool IsServicesOper() const;
160 
167  void AddAccess(const Anope::string &entry);
168 
176  Anope::string GetAccess(unsigned entry) const;
177 
180  unsigned GetAccessCount() const;
181 
189  bool FindAccess(const Anope::string &entry);
190 
197  void EraseAccess(const Anope::string &entry);
198 
203  void ClearAccess();
204 
211  bool IsOnAccess(const User *u) const;
212 
217  static NickCore* Find(const Anope::string &nick);
218 
219  void AddChannelReference(ChannelInfo *ci);
220  void RemoveChannelReference(ChannelInfo *ci);
221  void GetChannelReferences(std::deque<ChannelInfo *> &queue);
222 };
223 
224 /* A request to check if an account/password is valid. These can exist for
225  * extended periods due to the time some authentication modules take.
226  */
228 {
229  /* Owner of this request, used to cleanup requests if a module is unloaded
230  * while a reqyest us pending */
234 
235  std::set<Module *> holds;
237  bool success;
238 
239  static std::set<IdentifyRequest *> Requests;
240 
241  protected:
242  IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass);
243  virtual ~IdentifyRequest();
244 
245  public:
246  /* One of these is called when the request goes through */
247  virtual void OnSuccess() = 0;
248  virtual void OnFail() = 0;
249 
250  const Anope::string &GetAccount() const { return account; }
251  const Anope::string &GetPassword() const { return password; }
252 
253  /* Holds this request. When a request is held it must be Released later
254  * for the request to complete. Multiple modules may hold a request at any time,
255  * but the request is not complete until every module has released it. If you do not
256  * require holding this (eg, your password check is done in this thread and immediately)
257  * then you don't need to hold the request before Successing it.
258  * @param m The module holding this request
259  */
260  void Hold(Module *m);
261 
265  void Release(Module *m);
266 
271  void Success(Module *m);
272 
277  void Dispatch();
278 
279  static void ModuleUnload(Module *m);
280 };
281 
282 #endif // ACCOUNT_H
Serialize::Reference< NickCore > nc
Definition: account.h:47
Anope::string vhost_ident
Definition: account.h:33
Anope::string password
Definition: account.h:233
CoreExport Serialize::Checker< nickcore_map > NickCoreList
time_t vhost_created
Definition: account.h:34
Definition: hashcomp.h:84
Serialize::Checker< std::vector< NickAlias * > > aliases
Definition: account.h:128
Definition: opertype.h:18
Anope::string nick
Definition: account.h:37
Anope::string last_usermask
Definition: account.h:41
Definition: users.h:34
std::vector< Anope::string > access
Definition: account.h:121
uint16_t channelcount
Definition: account.h:136
CoreExport time_t CurTime
Definition: main.cpp:41
const Anope::string & GetPassword() const
Definition: account.h:251
Anope::string pass
Definition: account.h:115
MemoInfo memos
Definition: account.h:122
CoreExport Serialize::Checker< nickalias_map > NickAliasList
std::set< Module * > holds
Definition: account.h:235
Anope::hash_map< NickAlias * > nickalias_map
Definition: account.h:22
Definition: memo.h:40
time_t time_registered
Definition: account.h:44
Anope::string display
Definition: account.h:113
virtual void Serialize(Serialize::Data &data) const =0
Oper * o
Definition: account.h:131
#define anope_override
Definition: services.h:56
Serialize::Checker< std::map< ChannelInfo *, int > > chanaccess
Definition: account.h:110
std::map< Anope::string, Anope::string > last_modes
Definition: account.h:123
#define CoreExport
Definition: services.h:62
Anope::string account
Definition: account.h:232
time_t last_seen
Definition: account.h:45
time_t lastmail
Definition: account.h:138
Anope::string last_realname
Definition: account.h:39
Anope::string last_quit
Definition: account.h:38
Anope::hash_map< NickCore * > nickcore_map
Definition: account.h:23
bool dispatched
Definition: account.h:236
Module * owner
Definition: account.h:231
std::list< User * > users
Definition: account.h:140
static std::set< IdentifyRequest * > Requests
Definition: account.h:239
Anope::string email
Definition: account.h:116
Anope::string last_realhost
Definition: account.h:43
Anope::string language
Definition: account.h:118
const Anope::string & GetAccount() const
Definition: account.h:250