InspIRCd  3.0
channels.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2013-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]>
9  * Copyright (C) 2007, 2009 Dennis Friis <[email protected]>
10  * Copyright (C) 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 
170  void DelUser(User* user);
171 
181  const MemberMap& GetUsers() const { return userlist; }
182 
187  bool HasUser(User* user);
188 
189  Membership* GetUser(User* user);
190 
196  void KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason);
197 
203  void KickUser(User* src, User* user, const std::string& reason)
204  {
205  MemberMap::iterator it = userlist.find(user);
206  if (it != userlist.end())
207  KickUser(src, it, reason);
208  }
209 
216  bool PartUser(User* user, std::string& reason);
217 
227  static Channel* JoinUser(LocalUser* user, std::string channame, bool override = false, const std::string& key = "");
228 
236  Membership* ForceJoin(User* user, const std::string* privs = NULL, bool bursting = false, bool created_by_local = false);
237 
243  void Write(ClientProtocol::Event& protoev, char status = 0, const CUList& except_list = CUList());
244 
251  void Write(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg, char status = 0, const CUList& except_list = CUList());
252 
258  const char* ChanModes(bool showsecret);
259 
271  unsigned int GetPrefixValue(User* user);
272 
277  bool IsBanned(User* user);
278 
281  bool CheckBan(User* user, const std::string& banmask);
282 
285  ModResult GetExtBanStatus(User *u, char type);
286 
291  void WriteNotice(const std::string& text, char status = 0);
292  void WriteRemoteNotice(const std::string& text, char status = 0);
293 };
294 
295 inline bool Channel::HasUser(User* user)
296 {
297  return (userlist.find(user) != userlist.end());
298 }
299 
300 inline std::string Channel::GetModeParameter(ChanModeReference& mode)
301 {
302  if (!mode)
303  return "";
304  return GetModeParameter(*mode);
305 }
306 
307 inline std::string Channel::GetModeParameter(ModeHandler* mh)
308 {
309  std::string out;
310  ParamModeBase* pm = mh->IsParameterMode();
311  if (pm && this->IsModeSet(pm))
312  pm->GetParameter(this, out);
313  return out;
314 }
315 
316 inline std::string Channel::GetModeParameter(ParamModeBase* pm)
317 {
318  std::string out;
319  if (this->IsModeSet(pm))
320  pm->GetParameter(this, out);
321  return out;
322 }
323 
324 inline bool Channel::IsModeSet(ChanModeReference& mode)
325 {
326  if (!mode)
327  return false;
328  return IsModeSet(*mode);
329 }
Channel::GetUsers
const MemberMap & GetUsers() const
Definition: channels.h:181
ClientProtocol::EventProvider
Definition: clientprotocol.h:625
Extensible
Definition: extensible.h:139
ModeHandler::IsParameterMode
ParamModeBase * IsParameterMode()
Definition: mode.h:842
Channel::name
std::string name
Definition: channels.h:88
Channel::MemberMap
std::map< User *, insp::aligned_storage< Membership > > MemberMap
Definition: channels.h:45
Channel::setby
std::string setby
Definition: channels.h:111
ClientProtocol::Event
Definition: clientprotocol.h:462
Channel::GetModeParameter
std::string GetModeParameter(ModeHandler *mode)
Definition: channels.h:307
Channel::IsModeSet
bool IsModeSet(ModeHandler *mode)
Definition: channels.h:123
ModResult
Definition: modules.h:70
Channel::HasUser
bool HasUser(User *user)
Definition: channels.h:295
ChanModeReference
Definition: dynref.h:123
Channel::topicset
time_t topicset
Definition: channels.h:106
Channel
Definition: channels.h:40
Channel::topic
std::string topic
Definition: channels.h:101
Channel::age
time_t age
Definition: channels.h:92
User
Definition: users.h:233
ClientProtocol::Message
Definition: clientprotocol.h:181
ParamModeBase
Definition: parammode.h:23
Channel::KickUser
void KickUser(User *src, User *user, const std::string &reason)
Definition: channels.h:203
Membership
Definition: membership.h:35
ModeParser::MODEID_MAX
static const ModeHandler::Id MODEID_MAX
Definition: mode.h:560
Channel::userlist
MemberMap userlist
Definition: channels.h:96
Channel::GetUserCounter
size_t GetUserCounter() const
Definition: channels.h:155
ModeHandler
Definition: mode.h:99
LocalUser
Definition: users.h:727