InspIRCd  3.0
cmd_whowas.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2013, 2018 Sadie Powell <[email protected]>
5  * Copyright (C) 2012, 2014-2015 Attila Molnar <[email protected]>
6  * Copyright (C) 2012 Robby <[email protected]>
7  * Copyright (C) 2010 Craig Edwards <[email protected]>
8  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
9  * Copyright (C) 2007 Robin Burchell <[email protected]>
10  * Copyright (C) 2007 Dennis Friis <[email protected]>
11  *
12  * This file is part of InspIRCd. InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 
26 #pragma once
27 
28 #include "modules.h"
29 
30 namespace WhoWas
31 {
34  struct Entry
35  {
38  const std::string host;
39 
42  const std::string dhost;
43 
46  const std::string ident;
47 
50  const std::string server;
51 
54  const std::string real;
55 
58  const time_t signon;
59 
62  Entry(User* user);
63  };
64 
67  struct Nick : public insp::intrusive_list_node<Nick>
68  {
71  typedef std::deque<Entry*> List;
72 
76 
79  const time_t addtime;
80 
83  const std::string nick;
84 
87  Nick(const std::string& nickname);
88 
91  ~Nick();
92  };
93 
94  class Manager
95  {
96  public:
97  struct Stats
98  {
101  size_t entrycount;
102  };
103 
107  void Add(User* user);
108 
112  Stats GetStats() const;
113 
116  void Maintain();
117 
125  void UpdateConfig(unsigned int NewGroupSize, unsigned int NewMaxGroups, unsigned int NewMaxKeep);
126 
131  const Nick* FindNick(const std::string& nick) const;
132 
136  bool IsEnabled() const;
137 
140  Manager();
141 
144  ~Manager();
145 
146  private:
150 
153  typedef TR1NS::unordered_map<std::string, WhoWas::Nick*, irc::insensitive, irc::StrHashComp> whowas_users;
154 
157  whowas_users whowas;
158 
161  FIFO whowas_fifo;
162 
165  unsigned int GroupSize;
166 
170  unsigned int MaxGroups;
171 
174  unsigned int MaxKeep;
175 
178  void Prune();
179 
183  void PurgeNick(whowas_users::iterator it);
184 
188  void PurgeNick(WhoWas::Nick* nick);
189  };
190 }
191 
197 class CommandWhowas : public Command
198 {
199  public:
203 
204  CommandWhowas(Module* parent);
210  CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
211 };
WhoWas::Entry::Entry
Entry(User *user)
CommandWhowas
Definition: cmd_whowas.h:197
WhoWas::Nick::Nick
Nick(const std::string &nickname)
WhoWas::Nick::entries
List entries
Definition: cmd_whowas.h:75
WhoWas::Manager::IsEnabled
bool IsEnabled() const
WhoWas::Manager
Definition: cmd_whowas.h:94
WhoWas::Nick::~Nick
~Nick()
WhoWas::Entry::ident
const std::string ident
Definition: cmd_whowas.h:46
WhoWas::Manager::~Manager
~Manager()
WhoWas::Manager::Stats
Definition: cmd_whowas.h:97
CommandWhowas::manager
WhoWas::Manager manager
Definition: cmd_whowas.h:202
WhoWas::Entry::server
const std::string server
Definition: cmd_whowas.h:50
WhoWas::Entry::real
const std::string real
Definition: cmd_whowas.h:54
WhoWas::Entry::dhost
const std::string dhost
Definition: cmd_whowas.h:42
WhoWas::Manager::Manager
Manager()
WhoWas::Manager::UpdateConfig
void UpdateConfig(unsigned int NewGroupSize, unsigned int NewMaxGroups, unsigned int NewMaxKeep)
WhoWas::Manager::GetStats
Stats GetStats() const
WhoWas::Entry::signon
const time_t signon
Definition: cmd_whowas.h:58
WhoWas::Entry::host
const std::string host
Definition: cmd_whowas.h:38
insp::intrusive_list_node
Definition: intrusive_list.h:33
Module
Definition: modules.h:247
User
Definition: users.h:233
Command
Definition: ctables.h:224
WhoWas::Nick::nick
const std::string nick
Definition: cmd_whowas.h:83
WhoWas::Manager::Stats::entrycount
size_t entrycount
Definition: cmd_whowas.h:101
WhoWas::Manager::Maintain
void Maintain()
WhoWas::Manager::FindNick
const Nick * FindNick(const std::string &nick) const
CommandWhowas::Handle
CmdResult Handle(User *user, const Params &parameters) CXX11_OVERRIDE
WhoWas::Manager::Add
void Add(User *user)
WhoWas::Nick::addtime
const time_t addtime
Definition: cmd_whowas.h:79
WhoWas::Nick
Definition: cmd_whowas.h:67
WhoWas::Nick::List
std::deque< Entry * > List
Definition: cmd_whowas.h:71
insp::intrusive_list_tail< Nick >
WhoWas::Entry
Definition: cmd_whowas.h:34
CommandBase::Params
Definition: ctables.h:117