InspIRCd  3.0
channels.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2007 Robin Burchell <[email protected]>
6  * Copyright (C) 2007 Dennis Friis <[email protected]>
7  * Copyright (C) 2003-2007 Craig Edwards <[email protected]>
8  *
9  * This file is part of InspIRCd. InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #pragma once
24 
25 #include "membership.h"
26 #include "mode.h"
27 #include "parammode.h"
28 
37 class CoreExport Channel : public Extensible
38 {
39  public:
42  typedef std::map<User*, insp::aligned_storage<Membership> > MemberMap;
43 
44  private:
47  void SetDefaultModes();
48 
53  std::bitset<ModeParser::MODEID_MAX> modes;
54 
62  void DelUser(const MemberMap::iterator& membiter);
63 
64  public:
70  Channel(const std::string &name, time_t ts);
71 
81  void CheckDestroy();
82 
85  std::string name;
86 
89  time_t age;
90 
94 
98  std::string topic;
99 
103  time_t topicset;
104 
108  std::string setby; /* 128 */
109 
114  void SetMode(ModeHandler* mode, bool value);
115 
120  bool IsModeSet(ModeHandler* mode) { return ((mode->GetId() != ModeParser::MODEID_MAX) && (modes[mode->GetId()])); }
121  bool IsModeSet(ModeHandler& mode) { return IsModeSet(&mode); }
122  bool IsModeSet(ChanModeReference& mode);
123 
134  std::string GetModeParameter(ModeHandler* mode);
135  std::string GetModeParameter(ChanModeReference& mode);
136  std::string GetModeParameter(ParamModeBase* pm);
137 
145  void SetTopic(User* user, const std::string& topic, time_t topicts, const std::string* setter = NULL);
146 
152  size_t GetUserCounter() const { return userlist.size(); }
153 
161  Membership* AddUser(User* user);
162 
167  void DelUser(User* user);
168 
178  const MemberMap& GetUsers() const { return userlist; }
179 
184  bool HasUser(User* user);
185 
186  Membership* GetUser(User* user);
187 
193  void KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason);
194 
200  void KickUser(User* src, User* user, const std::string& reason)
201  {
202  MemberMap::iterator it = userlist.find(user);
203  if (it != userlist.end())
204  KickUser(src, it, reason);
205  }
206 
213  bool PartUser(User* user, std::string& reason);
214 
224  static Channel* JoinUser(LocalUser* user, std::string channame, bool override = false, const std::string& key = "");
225 
233  Membership* ForceJoin(User* user, const std::string* privs = NULL, bool bursting = false, bool created_by_local = false);
234 
240  void Write(ClientProtocol::Event& protoev, char status = 0, const CUList& except_list = CUList());
241 
248  void Write(ClientProtocol::EventProvider& protoevprov, ClientProtocol::Message& msg, char status = 0, const CUList& except_list = CUList());
249 
255  const char* ChanModes(bool showsecret);
256 
268  unsigned int GetPrefixValue(User* user);
269 
274  bool IsBanned(User* user);
275 
278  bool CheckBan(User* user, const std::string& banmask);
279 
282  ModResult GetExtBanStatus(User *u, char type);
283 
287  void WriteNotice(const std::string& text);
288 };
289 
290 inline bool Channel::HasUser(User* user)
291 {
292  return (userlist.find(user) != userlist.end());
293 }
294 
295 inline std::string Channel::GetModeParameter(ChanModeReference& mode)
296 {
297  if (!mode)
298  return "";
299  return GetModeParameter(*mode);
300 }
301 
302 inline std::string Channel::GetModeParameter(ModeHandler* mh)
303 {
304  std::string out;
305  ParamModeBase* pm = mh->IsParameterMode();
306  if (pm && this->IsModeSet(pm))
307  pm->GetParameter(this, out);
308  return out;
309 }
310 
311 inline std::string Channel::GetModeParameter(ParamModeBase* pm)
312 {
313  std::string out;
314  if (this->IsModeSet(pm))
315  pm->GetParameter(this, out);
316  return out;
317 }
318 
319 inline bool Channel::IsModeSet(ChanModeReference& mode)
320 {
321  if (!mode)
322  return false;
323  return IsModeSet(*mode);
324 }
std::string name
Definition: channels.h:85
MemberMap userlist
Definition: channels.h:93
Definition: mode.h:95
std::string GetModeParameter(ModeHandler *mode)
Definition: channels.h:302
std::string setby
Definition: channels.h:108
Definition: dynref.h:123
void KickUser(User *src, User *user, const std::string &reason)
Definition: channels.h:200
Definition: extensible.h:90
Definition: users.h:224
bool HasUser(User *user)
Definition: channels.h:290
time_t age
Definition: channels.h:89
Definition: users.h:708
ParamModeBase * IsParameterMode()
Definition: mode.h:820
std::map< User *, insp::aligned_storage< Membership > > MemberMap
Definition: channels.h:42
Definition: membership.h:32
Definition: clientprotocol.h:461
Definition: clientprotocol.h:180
Definition: modules.h:65
std::string topic
Definition: channels.h:98
Definition: parammode.h:22
bool IsModeSet(ModeHandler *mode)
Definition: channels.h:120
const MemberMap & GetUsers() const
Definition: channels.h:178
time_t topicset
Definition: channels.h:103
Definition: clientprotocol.h:614
Id GetId() const
Definition: mode.h:241
size_t GetUserCounter() const
Definition: channels.h:152
Definition: channels.h:37