ZNC  trunk
Chan.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2021 ZNC, see the NOTICE file for details.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ZNC_CHAN_H
18 #define ZNC_CHAN_H
19 
20 #include <znc/zncconfig.h>
21 #include <znc/Nick.h>
22 #include <znc/ZNCString.h>
23 #include <znc/Buffer.h>
24 #include <znc/Translation.h>
25 #include <map>
26 
27 // Forward Declarations
28 class CUser;
29 class CIRCNetwork;
30 class CClient;
31 class CConfig;
32 class CFile;
33 // !Forward Declarations
34 
35 class CChan : private CCoreTranslationMixin {
36  public:
37  typedef enum {
38  Voice = '+',
39  HalfOp = '%',
40  Op = '@',
41  Admin = '!',
42  Owner = '*'
43  } EUserPerms;
44 
45  typedef enum {
46  M_Private = 'p',
47  M_Secret = 's',
48  M_Moderated = 'm',
49  M_InviteOnly = 'i',
50  M_NoMessages = 'n',
51  M_OpTopic = 't',
52  M_Limit = 'l',
53  M_Key = 'k',
54  M_Op = 'o',
55  M_Voice = 'v',
56  M_Ban = 'b',
57  M_Except = 'e'
58  } EModes;
59 
60  CChan(const CString& sName, CIRCNetwork* pNetwork, bool bInConfig,
61  CConfig* pConfig = nullptr);
62  ~CChan();
63 
64  CChan(const CChan&) = delete;
65  CChan& operator=(const CChan&) = delete;
66 
67  void Reset();
68  CConfig ToConfig() const;
69  void Clone(CChan& chan);
70  void Cycle() const;
71  void JoinUser(const CString& sKey = "");
72  void AttachUser(CClient* pClient = nullptr);
73  void DetachUser();
74 
75  void OnWho(const CString& sNick, const CString& sIdent,
76  const CString& sHost);
77 
78  // Modes
80  void SetModes(const CString& s);
86  void SetModes(const CString& sModes, const VCString& vsModeParams);
88  void ModeChange(const CString& sModes, const CNick* OpNick = nullptr);
94  void ModeChange(const CString& sModes,const VCString& vsModeParams, const CNick* OpNick = nullptr);
95  bool AddMode(char cMode, const CString& sArg);
96  bool RemMode(char cMode);
97  CString GetModeString() const;
98  CString GetModeArg(CString& sArgs) const;
99  CString GetModeForNames() const;
100  // !Modes
101 
102  // Nicks
103  void ClearNicks();
104  const CNick* FindNick(const CString& sNick) const;
105  CNick* FindNick(const CString& sNick);
106  int AddNicks(const CString& sNicks);
107  bool AddNick(const CString& sNick);
108  bool RemNick(const CString& sNick);
109  bool ChangeNick(const CString& sOldNick, const CString& sNewNick);
110  // !Nicks
111 
112  // Buffer
113  const CBuffer& GetBuffer() const { return m_Buffer; }
114  unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); }
115  bool SetBufferCount(unsigned int u, bool bForce = false) {
116  m_bHasBufferCountSet = true;
117  return m_Buffer.SetLineCount(u, bForce);
118  }
119  void InheritBufferCount(unsigned int u, bool bForce = false) {
120  if (!m_bHasBufferCountSet) m_Buffer.SetLineCount(u, bForce);
121  }
122  void ResetBufferCount();
123  size_t AddBuffer(const CMessage& Format, const CString& sText = "") {
124  return m_Buffer.AddLine(Format, sText);
125  }
127  size_t AddBuffer(const CString& sFormat, const CString& sText = "",
128  const timeval* ts = nullptr,
129  const MCString& mssTags = MCString::EmptyMap) {
130  return m_Buffer.AddLine(sFormat, sText, ts, mssTags);
131  }
132  void ClearBuffer() { m_Buffer.Clear(); }
133  void SendBuffer(CClient* pClient);
134  void SendBuffer(CClient* pClient, const CBuffer& Buffer);
135  // !Buffer
136 
137  // m_Nick wrappers
139  CString GetPermStr() const { return m_Nick.GetPermStr(); }
141  bool HasPerm(char cPerm) const { return m_Nick.HasPerm(cPerm); }
143  bool AddPerm(char cPerm) { return m_Nick.AddPerm(cPerm); }
145  bool RemPerm(char cPerm) { return m_Nick.RemPerm(cPerm); }
146  // !wrappers
147 
148  // Setters
149  void SetModeKnown(bool b) { m_bModeKnown = b; }
150  void SetIsOn(bool b) {
151  m_bIsOn = b;
152  if (!b) {
153  Reset();
154  }
155  }
156  void SetKey(const CString& s);
157  void SetTopic(const CString& s) { m_sTopic = s; }
158  void SetTopicOwner(const CString& s) { m_sTopicOwner = s; }
159  void SetTopicDate(unsigned long u) { m_ulTopicDate = u; }
160  void SetDefaultModes(const CString& s) { m_sDefaultModes = s; }
161  void SetAutoClearChanBuffer(bool b);
162  void InheritAutoClearChanBuffer(bool b);
164  void SetDetached(bool b = true) { m_bDetached = b; }
165  void SetInConfig(bool b);
166  void SetCreationDate(unsigned long u) { m_ulCreationDate = u; }
167  void Disable() { m_bDisabled = true; }
168  void Enable();
170  void ResetJoinTries() { m_uJoinTries = 0; }
171  // !Setters
172 
173  // Getters
174  CIRCNetwork* GetNetwork() const { return m_pNetwork; }
175  bool IsModeKnown() const { return m_bModeKnown; }
176  bool HasMode(char cMode) const;
177  CString GetOptions() const;
178  CString GetModeArg(char cMode) const;
179  std::map<char, unsigned int> GetPermCounts() const;
180  bool IsOn() const { return m_bIsOn; }
181  const CString& GetName() const { return m_sName; }
182  const std::map<char, CString>& GetModes() const {
183  return m_mcsModes;
184  }
185  const CString& GetKey() const { return m_sKey; }
186  const CString& GetTopic() const { return m_sTopic; }
187  const CString& GetTopicOwner() const { return m_sTopicOwner; }
188  unsigned long GetTopicDate() const { return m_ulTopicDate; }
189  const CString& GetDefaultModes() const { return m_sDefaultModes; }
190  const std::map<CString, CNick>& GetNicks() const { return m_msNicks; }
191  size_t GetNickCount() const { return m_msNicks.size(); }
193  bool IsDetached() const { return m_bDetached; }
194  bool InConfig() const { return m_bInConfig; }
195  unsigned long GetCreationDate() const { return m_ulCreationDate; }
196  bool IsDisabled() const { return m_bDisabled; }
197  unsigned int GetJoinTries() const { return m_uJoinTries; }
198  bool HasBufferCountSet() const { return m_bHasBufferCountSet; }
201  }
202  // !Getters
203  private:
204  protected:
206  bool m_bIsOn;
216  unsigned long m_ulTopicDate;
217  unsigned long m_ulCreationDate;
220  unsigned int m_uJoinTries;
222  std::map<CString, CNick> m_msNicks; // Todo: make this caseless (irc style)
224 
226  std::map<char, CString> m_mcsModes;
227 };
228 
229 #endif // !ZNC_CHAN_H
CChan::HasAutoClearChanBufferSet
bool HasAutoClearChanBufferSet() const
Definition: Chan.h:199
CChan::FindNick
const CNick * FindNick(const CString &sNick) const
CChan::GetJoinTries
unsigned int GetJoinTries() const
Definition: Chan.h:197
CChan::M_Ban
@ M_Ban
Definition: Chan.h:56
CChan::AutoClearChanBuffer
bool AutoClearChanBuffer() const
Definition: Chan.h:192
CChan::CChan
CChan(const CString &sName, CIRCNetwork *pNetwork, bool bInConfig, CConfig *pConfig=nullptr)
CBuffer::AddLine
size_type AddLine(const CMessage &Format, const CString &sText="")
CChan::Clone
void Clone(CChan &chan)
CChan::m_sTopic
CString m_sTopic
Definition: Chan.h:214
Nick.h
CClient
Definition: Client.h:99
CChan::GetName
const CString & GetName() const
Definition: Chan.h:181
CChan::M_Private
@ M_Private
Definition: Chan.h:46
ZNCString.h
CChan::Owner
@ Owner
Definition: Chan.h:42
CChan::AddPerm
bool AddPerm(char cPerm)
e.g. '@' for chanop.
Definition: Chan.h:143
CChan::SetDefaultModes
void SetDefaultModes(const CString &s)
Definition: Chan.h:160
CChan::GetNicks
const std::map< CString, CNick > & GetNicks() const
Definition: Chan.h:190
CChan::HalfOp
@ HalfOp
Definition: Chan.h:39
CChan::AddBuffer
size_t AddBuffer(const CString &sFormat, const CString &sText="", const timeval *ts=nullptr, const MCString &mssTags=MCString::EmptyMap)
Definition: Chan.h:127
CChan::RemNick
bool RemNick(const CString &sNick)
CChan::m_bAutoClearChanBuffer
bool m_bAutoClearChanBuffer
Definition: Chan.h:207
CChan::SetTopicOwner
void SetTopicOwner(const CString &s)
Definition: Chan.h:158
CChan::GetModeString
CString GetModeString() const
MCString
A dictionary for strings.
Definition: ZNCString.h:595
CChan::SetInConfig
void SetInConfig(bool b)
CChan::SendBuffer
void SendBuffer(CClient *pClient)
CChan::OnWho
void OnWho(const CString &sNick, const CString &sIdent, const CString &sHost)
CChan::AddNick
bool AddNick(const CString &sNick)
CChan::GetOptions
CString GetOptions() const
CChan::GetCreationDate
unsigned long GetCreationDate() const
Definition: Chan.h:195
CChan::GetKey
const CString & GetKey() const
Definition: Chan.h:185
CChan::m_pNetwork
CIRCNetwork * m_pNetwork
Definition: Chan.h:218
CChan::IsDetached
bool IsDetached() const
Definition: Chan.h:193
CChan::m_ulTopicDate
unsigned long m_ulTopicDate
Definition: Chan.h:216
CChan::m_bInConfig
bool m_bInConfig
Definition: Chan.h:208
CChan::GetModeArg
CString GetModeArg(CString &sArgs) const
CChan::Voice
@ Voice
Definition: Chan.h:38
CChan::AttachUser
void AttachUser(CClient *pClient=nullptr)
CBuffer::GetLineCount
unsigned int GetLineCount() const
Definition: Buffer.h:107
CChan::HasBufferCountSet
bool HasBufferCountSet() const
Definition: Chan.h:198
CChan::m_uJoinTries
unsigned int m_uJoinTries
Definition: Chan.h:220
CChan::HasPerm
bool HasPerm(char cPerm) const
e.g. '@' for chanop.
Definition: Chan.h:141
CMessage
Here is a small explanation of how messages on IRC work, and how you can use this class to get useful...
Definition: Message.h:70
CChan::SetKey
void SetKey(const CString &s)
CChan::ClearBuffer
void ClearBuffer()
Definition: Chan.h:132
CChan::SetCreationDate
void SetCreationDate(unsigned long u)
Definition: Chan.h:166
CString
String class that is used inside ZNC.
Definition: ZNCString.h:68
CChan::M_Secret
@ M_Secret
Definition: Chan.h:47
CChan::M_Limit
@ M_Limit
Definition: Chan.h:52
CChan::GetBufferCount
unsigned int GetBufferCount() const
Definition: Chan.h:114
CChan::GetBuffer
const CBuffer & GetBuffer() const
Definition: Chan.h:113
CChan::SetModes
void SetModes(const CString &s)
CChan::M_OpTopic
@ M_OpTopic
Definition: Chan.h:51
CChan::M_Key
@ M_Key
Definition: Chan.h:53
CChan::m_Buffer
CBuffer m_Buffer
Definition: Chan.h:223
CChan::Cycle
void Cycle() const
CChan::ChangeNick
bool ChangeNick(const CString &sOldNick, const CString &sNewNick)
CChan::m_msNicks
std::map< CString, CNick > m_msNicks
Definition: Chan.h:222
CChan
Definition: Chan.h:35
CNick::RemPerm
bool RemPerm(char cPerm)
e.g. '@' for chanop.
CChan::GetPermCounts
std::map< char, unsigned int > GetPermCounts() const
CConfig
Definition: Config.h:36
CChan::M_InviteOnly
@ M_InviteOnly
Definition: Chan.h:49
CChan::ResetJoinTries
void ResetJoinTries()
Definition: Chan.h:170
CChan::SetIsOn
void SetIsOn(bool b)
Definition: Chan.h:150
CChan::~CChan
~CChan()
CChan::JoinUser
void JoinUser(const CString &sKey="")
CChan::m_bHasBufferCountSet
bool m_bHasBufferCountSet
Definition: Chan.h:210
CBuffer
Definition: Buffer.h:74
Buffer.h
CChan::GetModeForNames
CString GetModeForNames() const
CChan::GetTopicOwner
const CString & GetTopicOwner() const
Definition: Chan.h:187
CChan::m_bModeKnown
bool m_bModeKnown
Definition: Chan.h:225
CChan::m_sTopicOwner
CString m_sTopicOwner
Definition: Chan.h:215
CChan::m_ulCreationDate
unsigned long m_ulCreationDate
Definition: Chan.h:217
CChan::M_Moderated
@ M_Moderated
Definition: Chan.h:48
CChan::m_sName
CString m_sName
Definition: Chan.h:212
CChan::Reset
void Reset()
CChan::GetTopicDate
unsigned long GetTopicDate() const
Definition: Chan.h:188
CChan::SetBufferCount
bool SetBufferCount(unsigned int u, bool bForce=false)
Definition: Chan.h:115
CChan::AddMode
bool AddMode(char cMode, const CString &sArg)
CNick::HasPerm
bool HasPerm(char cPerm) const
e.g. '@' for chanop.
CChan::HasMode
bool HasMode(char cMode) const
CChan::IsModeKnown
bool IsModeKnown() const
Definition: Chan.h:175
CChan::m_sKey
CString m_sKey
Definition: Chan.h:213
CBuffer::Clear
void Clear()
Definition: Buffer.h:100
CChan::AddBuffer
size_t AddBuffer(const CMessage &Format, const CString &sText="")
Definition: Chan.h:123
CChan::SetTopic
void SetTopic(const CString &s)
Definition: Chan.h:157
CChan::m_bHasAutoClearChanBufferSet
bool m_bHasAutoClearChanBufferSet
Definition: Chan.h:211
CChan::IsDisabled
bool IsDisabled() const
Definition: Chan.h:196
CChan::EModes
EModes
Definition: Chan.h:45
CChan::M_Except
@ M_Except
Definition: Chan.h:57
Translation.h
CChan::InheritBufferCount
void InheritBufferCount(unsigned int u, bool bForce=false)
Definition: Chan.h:119
CUser
Definition: User.h:38
CChan::RemMode
bool RemMode(char cMode)
CChan::Disable
void Disable()
Definition: Chan.h:167
CChan::M_NoMessages
@ M_NoMessages
Definition: Chan.h:50
CChan::GetNetwork
CIRCNetwork * GetNetwork() const
Definition: Chan.h:174
CChan::GetDefaultModes
const CString & GetDefaultModes() const
Definition: Chan.h:189
CIRCNetwork
Definition: IRCNetwork.h:40
CChan::M_Voice
@ M_Voice
Definition: Chan.h:55
CNick::AddPerm
bool AddPerm(char cPerm)
e.g. '@' for chanop.
CChan::m_bDetached
bool m_bDetached
Definition: Chan.h:205
CChan::GetTopic
const CString & GetTopic() const
Definition: Chan.h:186
VCString
std::vector< CString > VCString
Definition: ZNCString.h:38
CChan::ModeChange
void ModeChange(const CString &sModes, const CNick *OpNick=nullptr)
CChan::GetNickCount
size_t GetNickCount() const
Definition: Chan.h:191
CNick
Definition: Nick.h:29
CChan::ResetAutoClearChanBuffer
void ResetAutoClearChanBuffer()
CChan::m_Nick
CNick m_Nick
Definition: Chan.h:219
MCString::EmptyMap
static const MCString EmptyMap
A static instance of an empty map.
Definition: ZNCString.h:606
CChan::SetDetached
void SetDetached(bool b=true)
Definition: Chan.h:164
CChan::Enable
void Enable()
CChan::SetTopicDate
void SetTopicDate(unsigned long u)
Definition: Chan.h:159
CCoreTranslationMixin
Definition: Translation.h:104
CChan::SetModeKnown
void SetModeKnown(bool b)
Definition: Chan.h:149
CNick::GetPermStr
CString GetPermStr() const
e.g. '@' for chanop.
CChan::ResetBufferCount
void ResetBufferCount()
CChan::InheritAutoClearChanBuffer
void InheritAutoClearChanBuffer(bool b)
CChan::m_bIsOn
bool m_bIsOn
Definition: Chan.h:206
CChan::GetModes
const std::map< char, CString > & GetModes() const
Definition: Chan.h:182
CChan::Op
@ Op
Definition: Chan.h:40
CChan::m_bDisabled
bool m_bDisabled
Definition: Chan.h:209
CChan::ToConfig
CConfig ToConfig() const
CChan::AddNicks
int AddNicks(const CString &sNicks)
CChan::IncJoinTries
void IncJoinTries()
Definition: Chan.h:169
CChan::EUserPerms
EUserPerms
Definition: Chan.h:37
CChan::Admin
@ Admin
Definition: Chan.h:41
CChan::InConfig
bool InConfig() const
Definition: Chan.h:194
CChan::m_sDefaultModes
CString m_sDefaultModes
Definition: Chan.h:221
CChan::GetPermStr
CString GetPermStr() const
e.g. '@' for chanop.
Definition: Chan.h:139
CChan::ClearNicks
void ClearNicks()
CBuffer::SetLineCount
bool SetLineCount(unsigned int u, bool bForce=false)
CChan::IsOn
bool IsOn() const
Definition: Chan.h:180
CChan::DetachUser
void DetachUser()
CFile
Definition: FileUtils.h:30
CChan::RemPerm
bool RemPerm(char cPerm)
e.g. '@' for chanop.
Definition: Chan.h:145
CChan::m_mcsModes
std::map< char, CString > m_mcsModes
Definition: Chan.h:226
CChan::operator=
CChan & operator=(const CChan &)=delete
CChan::M_Op
@ M_Op
Definition: Chan.h:54
CChan::SetAutoClearChanBuffer
void SetAutoClearChanBuffer(bool b)