InspIRCd  3.0
channels.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2013-2016, 2018 Attila Molnar <[email protected]>
5  * Copyright (C) 2012-2013, 2017-2020 Sadie Powell <[email protected]>
6  * Copyright (C) 2012 Robby <[email protected]>
7  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
8  * Copyright (C) 2007-2008 Robin Burchell <[email protected].net>
9  * Copyright (C) 2007, 2009 Dennis Friis <[email protected]>
10  * Copyright (C) 2003-2006, 2008, 2010 Craig Edwards <[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 "membership.h"
29 #include "mode.h"
30 #include "parammode.h"
31 
40 class CoreExport Channel : public Extensible
41 {
42  public:
45  typedef std::map<User*, insp::aligned_storage<Membership> > MemberMap;
46 
47  private:
50  void SetDefaultModes();
51 
56  std::bitset<ModeParser::MODEID_MAX> modes;
57 
65  void DelUser(const MemberMap::iterator& membiter);
66 
67  public:
73  Channel(const std::string &name, time_t ts);
74 
84  void CheckDestroy();
85 
88  std::string name;
89 
92  time_t age;
93 
97 
101  std::string topic;
102 
106  time_t topicset;
107 
111  std::string setby; /* 128 */
112 
117  void SetMode(ModeHandler* mode, bool value);
118 
123  bool IsModeSet(ModeHandler* mode) { return ((mode->GetId() != ModeParser::MODEID_MAX) && (modes[mode->GetId()])); }
124  bool IsModeSet(ModeHandler& mode) { return IsModeSet(&mode); }
125  bool IsModeSet(ChanModeReference& mode);
126 
137  std::string GetModeParameter(ModeHandler* mode);
138  std::string GetModeParameter(ChanModeReference& mode);
139  std::string GetModeParameter(ParamModeBase* pm);
140 
148  void SetTopic(User* user, const std::string& topic, time_t topicts, const std::string* setter = NULL);
149 
155  size_t GetUserCounter() const { return userlist.size(); }
156 
164  Membership* AddUser(User* user);
165 
169  void DelUser(User* user);
170 
180  const MemberMap& GetUsers() const { return userlist; }
181 
186  bool HasUser(User* user);
187 
188  Membership* GetUser(User* user);
189 
195  void KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason);
196 
202  void KickUser(User* src, User* user, const std::string& reason)
203  {
204  MemberMap::iterator it = userlist.find(user);
205  if (it != userlist.end())
206  KickUser(src, it, reason);
207  }
208 
215  bool PartUser(User* user, std::string& reason);
216 
226  static Channel* JoinUser(LocalUser* user, std::string channame, bool override = false, const std::string& key = "");
227 
235  Membership* ForceJoin(User* user, const std::string* privs = NULL, bool bursting = false, bool created_by_local = false);
236 
242  void Write(ClientProtocol::Event& protoev, char status = 0, const CUList& except_list = CUList());
243 
250  void Write(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg, char status = 0, const CUList& except_list = CUList());
251 
257  const char* ChanModes(bool showsecret);
258 
270  unsigned int GetPrefixValue(User* user);
271 
276  bool IsBanned(User* user);
277 
280  bool CheckBan(User* user, const std::string& banmask);
281 
284  ModResult GetExtBanStatus(User *u, char type);
285 
290  void WriteNotice(const std::string& text, char status = 0);
291  void WriteRemoteNotice(const std::string& text, char status = 0);
292 };
293 
294 inline bool Channel::HasUser(User* user)
295 {
296  return (userlist.find(user) != userlist.end());
297 }
298 
299 inline std::string Channel::GetModeParameter(ChanModeReference& mode)
300 {
301  if (!mode)
302  return "";
303  return GetModeParameter(*mode);
304 }
305 
306 inline std::string Channel::GetModeParameter(ModeHandler* mh)
307 {
308  std::string out;
309  ParamModeBase* pm = mh->IsParameterMode();
310  if (pm && this->IsModeSet(pm))
311  pm->GetParameter(this, out);
312  return out;
313 }
314 
315 inline std::string Channel::GetModeParameter(ParamModeBase* pm)
316 {
317  std::string out;
318  if (this->IsModeSet(pm))
319  pm->GetParameter(this, out);
320  return out;
321 }
322 
323 inline bool Channel::IsModeSet(ChanModeReference& mode)
324 {
325  if (!mode)
326  return false;
327  return IsModeSet(*mode);
328 }
Definition: dynref.h:124
Definition: channels.h:41
std::string setby
Definition: channels.h:111
std::string GetModeParameter(ModeHandler *mode)
Definition: channels.h:306
time_t topicset
Definition: channels.h:106
size_t GetUserCounter() const
Definition: channels.h:155
const MemberMap & GetUsers() const
Definition: channels.h:180
MemberMap userlist
Definition: channels.h:96
std::map< User *, insp::aligned_storage< Membership > > MemberMap
Definition: channels.h:45
bool HasUser(User *user)
Definition: channels.h:294
std::string topic
Definition: channels.h:101
time_t age
Definition: channels.h:92
void KickUser(User *src, User *user, const std::string &reason)
Definition: channels.h:202
bool IsModeSet(ModeHandler *mode)
Definition: channels.h:123
std::string name
Definition: channels.h:88
Definition: clientprotocol.h:465
Definition: clientprotocol.h:628
Definition: clientprotocol.h:182
Definition: extensible.h:142
Definition: users.h:745
Definition: membership.h:36
Definition: modules.h:72
Definition: mode.h:100
ParamModeBase * IsParameterMode()
Definition: mode.h:856
Id GetId() const
Definition: mode.h:248
static const ModeHandler::Id MODEID_MAX
Definition: mode.h:570
Definition: parammode.h:24
Definition: users.h:247