InspIRCd  4.0
usermanager.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2015 Adam <[email protected]>
5  * Copyright (C) 2012-2016 Attila Molnar <[email protected]>
6  * Copyright (C) 2012-2013, 2017, 2019-2020 Sadie Powell <[email protected]>
7  * Copyright (C) 2012 Robby <[email protected]>
8  * Copyright (C) 2010 Craig Edwards <[email protected]>
9  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
10  * Copyright (C) 2008 Thomas Stagner <[email protected]>
11  * Copyright (C) 2008 Robin Burchell <[email protected]>
12  *
13  * This file is part of InspIRCd. InspIRCd is free software: you can
14  * redistribute it and/or modify it under the terms of the GNU General Public
15  * License as published by the Free Software Foundation, version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #pragma once
28 
29 #include <list>
30 
31 class CoreExport UserManager
32 {
33  public:
34  struct CloneCounts
35  {
36  unsigned int global = 0;
37  unsigned int local = 0;
38  };
39 
42  typedef std::map<irc::sockets::cidr_mask, CloneCounts> CloneMap;
43 
46  typedef std::vector<User*> OperList;
47 
49  typedef std::vector<User*> ServiceList;
50 
54 
55  private:
58  CloneMap clonemap;
59 
62  const CloneCounts zeroclonecounts;
63 
66  LocalList local_users;
67 
71  uint64_t already_sent_id;
72 
73  public:
76  UserManager();
77 
80  ~UserManager();
81 
84  user_hash clientlist;
85 
88  user_hash uuidlist;
89 
93 
96 
101 
105  void DoBackgroundUserStuff();
106 
118  void AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
119 
126  void QuitUser(User* user, const std::string& quitreason, const std::string* operreason = NULL);
127 
131  void AddClone(User* user);
132 
138  void RemoveCloneCounts(User *user);
139 
142  void RehashCloneCounts();
143 
150  const CloneCounts& GetCloneCounts(User* user) const;
151 
155  const CloneMap& GetCloneMap() const { return clonemap; }
156 
160  size_t RegisteredUserCount() { return this->clientlist.size() - this->UnregisteredUserCount() - this->ServiceCount(); }
161 
165  size_t UnregisteredUserCount() const { return this->unregistered_count; }
166 
170  size_t ServiceCount() const { return this->all_services.size(); }
171 
175  size_t LocalUserCount() const { return (this->local_users.size() - this->UnregisteredUserCount()); }
176 
180  user_hash& GetUsers() { return clientlist; }
181 
185  const LocalList& GetLocalUsers() const { return local_users; }
186 
191  void ServerNoticeAll(const char* text, ...) CUSTOM_PRINTF(2, 3);
192 
196  uint64_t NextAlreadySentId();
197 
203  User* Find(const std::string& nickuuid);
204 
209  User* FindNick(const std::string& nick);
210 
215  User* FindUUID(const std::string& uuid);
216 };
Definition: socket.h:173
Definition: users.h:238
Definition: usermanager.h:32
user_hash & GetUsers()
Definition: usermanager.h:180
size_t UnregisteredUserCount() const
Definition: usermanager.h:165
const CloneMap & GetCloneMap() const
Definition: usermanager.h:155
const LocalList & GetLocalUsers() const
Definition: usermanager.h:185
user_hash uuidlist
Definition: usermanager.h:88
user_hash clientlist
Definition: usermanager.h:84
OperList all_opers
Definition: usermanager.h:92
std::vector< User * > ServiceList
Definition: usermanager.h:49
size_t unregistered_count
Definition: usermanager.h:100
std::vector< User * > OperList
Definition: usermanager.h:46
size_t LocalUserCount() const
Definition: usermanager.h:175
insp::intrusive_list< LocalUser > LocalList
Definition: usermanager.h:53
size_t RegisteredUserCount()
Definition: usermanager.h:160
size_t ServiceCount() const
Definition: usermanager.h:170
ServiceList all_services
Definition: usermanager.h:95
std::map< irc::sockets::cidr_mask, CloneCounts > CloneMap
Definition: usermanager.h:42
Definition: usermanager.h:35
Definition: socket.h:63