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 
93  MemberMap userlist;
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  long 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 WriteChannel(User* user, const char* text, ...) CUSTOM_PRINTF(3, 4);
241 
246  void WriteChannel(User* user, const std::string &text);
247 
253  void WriteChannelWithServ(const std::string& ServName, const char* text, ...) CUSTOM_PRINTF(3, 4);
254 
259  void WriteChannelWithServ(const std::string& ServName, const std::string &text);
260 
270  void WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...) CUSTOM_PRINTF(5, 6);
271 
281  void WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...) CUSTOM_PRINTF(6, 7);
282 
291  void WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text);
292 
301  void WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
303  void RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
304 
310  const char* ChanModes(bool showkey);
311 
323  unsigned int GetPrefixValue(User* user);
324 
329  bool IsBanned(User* user);
330 
333  bool CheckBan(User* user, const std::string& banmask);
334 
337  ModResult GetExtBanStatus(User *u, char type);
338 
342  void WriteNotice(const std::string& text);
343 };
344 
345 inline bool Channel::HasUser(User* user)
346 {
347  return (userlist.find(user) != userlist.end());
348 }
349 
350 inline std::string Channel::GetModeParameter(ChanModeReference& mode)
351 {
352  if (!mode)
353  return "";
354  return GetModeParameter(*mode);
355 }
356 
357 inline std::string Channel::GetModeParameter(ModeHandler* mh)
358 {
359  std::string out;
360  ParamModeBase* pm = mh->IsParameterMode();
361  if (pm && this->IsModeSet(pm))
362  pm->GetParameter(this, out);
363  return out;
364 }
365 
366 inline std::string Channel::GetModeParameter(ParamModeBase* pm)
367 {
368  std::string out;
369  if (this->IsModeSet(pm))
370  pm->GetParameter(this, out);
371  return out;
372 }
373 
374 inline bool Channel::IsModeSet(ChanModeReference& mode)
375 {
376  if (!mode)
377  return false;
378  return IsModeSet(*mode);
379 }
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:357
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:345
time_t age
Definition: channels.h:89
Definition: users.h:742
ParamModeBase * IsParameterMode()
Definition: mode.h:828
std::map< User *, insp::aligned_storage< Membership > > MemberMap
Definition: channels.h:42
Definition: membership.h:32
Definition: modules.h:72
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
Id GetId() const
Definition: mode.h:240
long GetUserCounter() const
Definition: channels.h:152
Definition: channels.h:37