ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Chan.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2018 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
79  void SetModes(const CString& s);
80  void ModeChange(const CString& sModes, const CNick* OpNick = nullptr);
81  bool AddMode(char cMode, const CString& sArg);
82  bool RemMode(char cMode);
83  CString GetModeString() const;
84  CString GetModeArg(CString& sArgs) const;
85  CString GetModeForNames() const;
86  // !Modes
87 
88  // Nicks
89  void ClearNicks();
90  const CNick* FindNick(const CString& sNick) const;
91  CNick* FindNick(const CString& sNick);
92  int AddNicks(const CString& sNicks);
93  bool AddNick(const CString& sNick);
94  bool RemNick(const CString& sNick);
95  bool ChangeNick(const CString& sOldNick, const CString& sNewNick);
96  // !Nicks
97 
98  // Buffer
99  const CBuffer& GetBuffer() const { return m_Buffer; }
100  unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); }
101  bool SetBufferCount(unsigned int u, bool bForce = false) {
102  m_bHasBufferCountSet = true;
103  return m_Buffer.SetLineCount(u, bForce);
104  }
105  void InheritBufferCount(unsigned int u, bool bForce = false) {
106  if (!m_bHasBufferCountSet) m_Buffer.SetLineCount(u, bForce);
107  }
108  void ResetBufferCount();
109  size_t AddBuffer(const CMessage& Format, const CString& sText = "") {
110  return m_Buffer.AddLine(Format, sText);
111  }
113  size_t AddBuffer(const CString& sFormat, const CString& sText = "",
114  const timeval* ts = nullptr,
115  const MCString& mssTags = MCString::EmptyMap) {
116  return m_Buffer.AddLine(sFormat, sText, ts, mssTags);
117  }
118  void ClearBuffer() { m_Buffer.Clear(); }
119  void SendBuffer(CClient* pClient);
120  void SendBuffer(CClient* pClient, const CBuffer& Buffer);
121  // !Buffer
122 
123  // m_Nick wrappers
125  CString GetPermStr() const { return m_Nick.GetPermStr(); }
127  bool HasPerm(char cPerm) const { return m_Nick.HasPerm(cPerm); }
129  bool AddPerm(char cPerm) { return m_Nick.AddPerm(cPerm); }
131  bool RemPerm(char cPerm) { return m_Nick.RemPerm(cPerm); }
132  // !wrappers
133 
134  // Setters
135  void SetModeKnown(bool b) { m_bModeKnown = b; }
136  void SetIsOn(bool b) {
137  m_bIsOn = b;
138  if (!b) {
139  Reset();
140  }
141  }
142  void SetKey(const CString& s);
143  void SetTopic(const CString& s) { m_sTopic = s; }
144  void SetTopicOwner(const CString& s) { m_sTopicOwner = s; }
145  void SetTopicDate(unsigned long u) { m_ulTopicDate = u; }
146  void SetDefaultModes(const CString& s) { m_sDefaultModes = s; }
147  void SetAutoClearChanBuffer(bool b);
148  void InheritAutoClearChanBuffer(bool b);
150  void SetDetached(bool b = true) { m_bDetached = b; }
151  void SetInConfig(bool b);
152  void SetCreationDate(unsigned long u) { m_ulCreationDate = u; }
153  void Disable() { m_bDisabled = true; }
154  void Enable();
156  void ResetJoinTries() { m_uJoinTries = 0; }
157  // !Setters
158 
159  // Getters
160  CIRCNetwork* GetNetwork() const { return m_pNetwork; }
161  bool IsModeKnown() const { return m_bModeKnown; }
162  bool HasMode(char cMode) const;
163  CString GetOptions() const;
164  CString GetModeArg(char cMode) const;
165  std::map<char, unsigned int> GetPermCounts() const;
166  bool IsOn() const { return m_bIsOn; }
167  const CString& GetName() const { return m_sName; }
168  const std::map<char, CString>& GetModes() const {
169  return m_mcsModes;
170  }
171  const CString& GetKey() const { return m_sKey; }
172  const CString& GetTopic() const { return m_sTopic; }
173  const CString& GetTopicOwner() const { return m_sTopicOwner; }
174  unsigned long GetTopicDate() const { return m_ulTopicDate; }
175  const CString& GetDefaultModes() const { return m_sDefaultModes; }
176  const std::map<CString, CNick>& GetNicks() const { return m_msNicks; }
177  size_t GetNickCount() const { return m_msNicks.size(); }
179  bool IsDetached() const { return m_bDetached; }
180  bool InConfig() const { return m_bInConfig; }
181  unsigned long GetCreationDate() const { return m_ulCreationDate; }
182  bool IsDisabled() const { return m_bDisabled; }
183  unsigned int GetJoinTries() const { return m_uJoinTries; }
184  bool HasBufferCountSet() const { return m_bHasBufferCountSet; }
187  }
188  // !Getters
189  private:
190  protected:
192  bool m_bIsOn;
202  unsigned long m_ulTopicDate;
203  unsigned long m_ulCreationDate;
206  unsigned int m_uJoinTries;
208  std::map<CString, CNick> m_msNicks; // Todo: make this caseless (irc style)
210 
212  std::map<char, CString> m_mcsModes;
213 };
214 
215 #endif // !ZNC_CHAN_H
void SetModeKnown(bool b)
Definition: Chan.h:135
bool RemPerm(char cPerm)
e.g. '@' for chanop.
Definition: Chan.h:131
Definition: Chan.h:38
void ResetBufferCount()
std::map< char, CString > m_mcsModes
Definition: Chan.h:212
void SendBuffer(CClient *pClient)
Definition: User.h:38
bool HasAutoClearChanBufferSet() const
Definition: Chan.h:185
void Clone(CChan &chan)
bool m_bDisabled
Definition: Chan.h:195
void SetDefaultModes(const CString &s)
Definition: Chan.h:146
int AddNicks(const CString &sNicks)
EUserPerms
Definition: Chan.h:37
size_t AddBuffer(const CString &sFormat, const CString &sText="", const timeval *ts=nullptr, const MCString &mssTags=MCString::EmptyMap)
Definition: Chan.h:113
bool m_bAutoClearChanBuffer
Definition: Chan.h:193
void SetTopicOwner(const CString &s)
Definition: Chan.h:144
CChan & operator=(const CChan &)=delete
CString m_sTopic
Definition: Chan.h:200
bool IsModeKnown() const
Definition: Chan.h:161
const CString & GetDefaultModes() const
Definition: Chan.h:175
CString GetPermStr() const
e.g. '@' for chanop.
Definition: Chan.h:125
Definition: Chan.h:54
Definition: Chan.h:53
const std::map< CString, CNick > & GetNicks() const
Definition: Chan.h:176
void SetKey(const CString &s)
Definition: Client.h:99
Definition: Chan.h:46
void SetInConfig(bool b)
const CBuffer & GetBuffer() const
Definition: Chan.h:99
Definition: Chan.h:52
void Clear()
Definition: Buffer.h:100
bool AddPerm(char cPerm)
e.g. '@' for chanop.
Definition: Chan.h:129
bool HasPerm(char cPerm) const
e.g. '@' for chanop.
Definition: Chan.h:127
void SetModes(const CString &s)
CConfig ToConfig() const
CIRCNetwork * m_pNetwork
Definition: Chan.h:204
unsigned long GetCreationDate() const
Definition: Chan.h:181
unsigned long m_ulTopicDate
Definition: Chan.h:202
CIRCNetwork * GetNetwork() const
Definition: Chan.h:160
bool RemNick(const CString &sNick)
const CString & GetName() const
Definition: Chan.h:167
Definition: Nick.h:29
bool m_bInConfig
Definition: Chan.h:194
std::map< CString, CNick > m_msNicks
Definition: Chan.h:208
const CNick * FindNick(const CString &sNick) const
unsigned int GetJoinTries() const
Definition: Chan.h:183
void AttachUser(CClient *pClient=nullptr)
Definition: Chan.h:49
unsigned long GetTopicDate() const
Definition: Chan.h:174
std::map< char, unsigned int > GetPermCounts() const
void OnWho(const CString &sNick, const CString &sIdent, const CString &sHost)
bool HasPerm(char cPerm) const
e.g. '@' for chanop.
void SetIsOn(bool b)
Definition: Chan.h:136
bool AddNick(const CString &sNick)
Definition: Chan.h:48
unsigned int m_uJoinTries
Definition: Chan.h:206
bool InConfig() const
Definition: Chan.h:180
void ClearBuffer()
Definition: Chan.h:118
CString GetOptions() const
Definition: FileUtils.h:30
const CString & GetTopic() const
Definition: Chan.h:172
CString m_sName
Definition: Chan.h:198
Definition: IRCNetwork.h:40
bool AddMode(char cMode, const CString &sArg)
void JoinUser(const CString &sKey="")
CBuffer m_Buffer
Definition: Chan.h:209
String class that is used inside ZNC.
Definition: ZNCString.h:68
Definition: Chan.h:47
Definition: Chan.h:55
void SetCreationDate(unsigned long u)
Definition: Chan.h:152
bool SetLineCount(unsigned int u, bool bForce=false)
bool IsDisabled() const
Definition: Chan.h:182
CString m_sTopicOwner
Definition: Chan.h:201
bool AutoClearChanBuffer() const
Definition: Chan.h:178
void ResetJoinTries()
Definition: Chan.h:156
size_t GetNickCount() const
Definition: Chan.h:177
bool ChangeNick(const CString &sOldNick, const CString &sNewNick)
CString GetModeForNames() const
static const MCString EmptyMap
A static instance of an empty map.
Definition: ZNCString.h:606
bool RemPerm(char cPerm)
e.g. '@' for chanop.
void SetTopic(const CString &s)
Definition: Chan.h:143
bool m_bDetached
Definition: Chan.h:191
CString GetModeArg(CString &sArgs) const
bool IsDetached() const
Definition: Chan.h:179
bool m_bModeKnown
Definition: Chan.h:211
EModes
Definition: Chan.h:45
unsigned long m_ulCreationDate
Definition: Chan.h:203
CNick m_Nick
Definition: Chan.h:205
void Reset()
Definition: Buffer.h:74
void Disable()
Definition: Chan.h:153
Definition: Chan.h:51
void SetDetached(bool b=true)
Definition: Chan.h:150
bool HasBufferCountSet() const
Definition: Chan.h:184
bool m_bHasBufferCountSet
Definition: Chan.h:196
CString m_sKey
Definition: Chan.h:199
A dictionary for strings.
Definition: ZNCString.h:595
size_t AddBuffer(const CMessage &Format, const CString &sText="")
Definition: Chan.h:109
bool AddPerm(char cPerm)
e.g. '@' for chanop.
bool RemMode(char cMode)
bool SetBufferCount(unsigned int u, bool bForce=false)
Definition: Chan.h:101
void Enable()
CString m_sDefaultModes
Definition: Chan.h:207
void DetachUser()
const CString & GetKey() const
Definition: Chan.h:171
Definition: Chan.h:57
void Cycle() const
const CString & GetTopicOwner() const
Definition: Chan.h:173
bool m_bHasAutoClearChanBufferSet
Definition: Chan.h:197
CString GetPermStr() const
e.g. '@' for chanop.
const std::map< char, CString > & GetModes() const
Definition: Chan.h:168
void ModeChange(const CString &sModes, const CNick *OpNick=nullptr)
void ResetAutoClearChanBuffer()
Definition: Chan.h:40
void InheritBufferCount(unsigned int u, bool bForce=false)
Definition: Chan.h:105
bool IsOn() const
Definition: Chan.h:166
Definition: Chan.h:39
unsigned int GetLineCount() const
Definition: Buffer.h:107
void SetTopicDate(unsigned long u)
Definition: Chan.h:145
Definition: Chan.h:41
CChan(const CString &sName, CIRCNetwork *pNetwork, bool bInConfig, CConfig *pConfig=nullptr)
void InheritAutoClearChanBuffer(bool b)
Definition: Chan.h:56
bool m_bIsOn
Definition: Chan.h:192
unsigned int GetBufferCount() const
Definition: Chan.h:100
Definition: Chan.h:42
bool HasMode(char cMode) const
size_type AddLine(const CMessage &Format, const CString &sText="")
void SetAutoClearChanBuffer(bool b)
Definition: Chan.h:35
void IncJoinTries()
Definition: Chan.h:155
Definition: Config.h:36
Definition: Chan.h:50
Here is a small explanation of how messages on IRC work, and how you can use this class to get useful...
Definition: Message.h:63
CString GetModeString() const
Definition: Translation.h:104
void ClearNicks()