/src/znc/include/znc/Chan.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2004-2025 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 | | /// @deprecated Use SetModes(CString, VCString) |
80 | | void SetModes(const CString& s); |
81 | | /** |
82 | | * Set the current modes for this channel |
83 | | * @param sModes The mode characters being changed |
84 | | * @param vsModeParams The parameters for the modes to be set |
85 | | */ |
86 | | void SetModes(const CString& sModes, const VCString& vsModeParams); |
87 | | /// @deprecated Use ModeChange(CString, VCString, CNick*) |
88 | | void ModeChange(const CString& sModes, const CNick* OpNick = nullptr); |
89 | | /** |
90 | | * Handle changing the modes on a channel |
91 | | * @param sModes The mode string (eg. +ovbs-pbo) |
92 | | * @param vsModeParams The parameters for the mode string |
93 | | */ |
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 | 0 | const CBuffer& GetBuffer() const { return m_Buffer; } |
114 | 0 | unsigned int GetBufferCount() const { return m_Buffer.GetLineCount(); } |
115 | 0 | bool SetBufferCount(unsigned int u, bool bForce = false) { |
116 | 0 | m_bHasBufferCountSet = true; |
117 | 0 | return m_Buffer.SetLineCount(u, bForce); |
118 | 0 | } |
119 | 0 | void InheritBufferCount(unsigned int u, bool bForce = false) { |
120 | 0 | if (!m_bHasBufferCountSet) m_Buffer.SetLineCount(u, bForce); |
121 | 0 | } |
122 | | void ResetBufferCount(); |
123 | 0 | size_t AddBuffer(const CMessage& Format, const CString& sText = "") { |
124 | 0 | return m_Buffer.AddLine(Format, sText); |
125 | 0 | } |
126 | | /// @deprecated |
127 | | size_t AddBuffer(const CString& sFormat, const CString& sText = "", |
128 | | const timeval* ts = nullptr, |
129 | 0 | const MCString& mssTags = MCString::EmptyMap) { |
130 | 0 | return m_Buffer.AddLine(sFormat, sText, ts, mssTags); |
131 | 0 | } |
132 | 0 | 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 |
138 | | /// e.g. '@' for chanop. |
139 | 0 | CString GetPermStr() const { return m_Nick.GetPermStr(); } |
140 | | /// e.g. '@' for chanop. |
141 | 0 | bool HasPerm(char cPerm) const { return m_Nick.HasPerm(cPerm); } |
142 | | /// e.g. '@' for chanop. |
143 | 0 | bool AddPerm(char cPerm) { return m_Nick.AddPerm(cPerm); } |
144 | | /// e.g. '@' for chanop. |
145 | 0 | bool RemPerm(char cPerm) { return m_Nick.RemPerm(cPerm); } |
146 | | // !wrappers |
147 | | |
148 | | // Setters |
149 | 0 | void SetModeKnown(bool b) { m_bModeKnown = b; } |
150 | 0 | void SetIsOn(bool b) { |
151 | 0 | m_bIsOn = b; |
152 | 0 | if (!b) { |
153 | 0 | Reset(); |
154 | 0 | } |
155 | 0 | } |
156 | | void SetKey(const CString& s); |
157 | 0 | void SetTopic(const CString& s) { m_sTopic = s; } |
158 | 0 | void SetTopicOwner(const CString& s) { m_sTopicOwner = s; } |
159 | 0 | void SetTopicDate(unsigned long u) { m_ulTopicDate = u; } |
160 | 0 | void SetDefaultModes(const CString& s) { m_sDefaultModes = s; } |
161 | | void SetAutoClearChanBuffer(bool b); |
162 | | void InheritAutoClearChanBuffer(bool b); |
163 | | void ResetAutoClearChanBuffer(); |
164 | 0 | void SetDetached(bool b = true) { m_bDetached = b; } |
165 | | void SetInConfig(bool b); |
166 | 0 | void SetCreationDate(unsigned long u) { m_ulCreationDate = u; } |
167 | 0 | void Disable() { m_bDisabled = true; } |
168 | | void Enable(); |
169 | 0 | void IncJoinTries() { m_uJoinTries++; } |
170 | 0 | void ResetJoinTries() { m_uJoinTries = 0; } |
171 | | // !Setters |
172 | | |
173 | | // Getters |
174 | 0 | CIRCNetwork* GetNetwork() const { return m_pNetwork; } |
175 | 0 | 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 | 0 | bool IsOn() const { return m_bIsOn; } |
181 | 0 | const CString& GetName() const { return m_sName; } |
182 | 0 | const std::map<char, CString>& GetModes() const { |
183 | 0 | return m_mcsModes; |
184 | 0 | } |
185 | 0 | const CString& GetKey() const { return m_sKey; } |
186 | 0 | const CString& GetTopic() const { return m_sTopic; } |
187 | 0 | const CString& GetTopicOwner() const { return m_sTopicOwner; } |
188 | 0 | unsigned long GetTopicDate() const { return m_ulTopicDate; } |
189 | 0 | const CString& GetDefaultModes() const { return m_sDefaultModes; } |
190 | 0 | const std::map<CString, CNick>& GetNicks() const { return m_msNicks; } |
191 | 0 | size_t GetNickCount() const { return m_msNicks.size(); } |
192 | 0 | bool AutoClearChanBuffer() const { return m_bAutoClearChanBuffer; } |
193 | 0 | bool IsDetached() const { return m_bDetached; } |
194 | 0 | bool InConfig() const { return m_bInConfig; } |
195 | 0 | unsigned long GetCreationDate() const { return m_ulCreationDate; } |
196 | 0 | bool IsDisabled() const { return m_bDisabled; } |
197 | 0 | unsigned int GetJoinTries() const { return m_uJoinTries; } |
198 | 0 | bool HasBufferCountSet() const { return m_bHasBufferCountSet; } |
199 | 0 | bool HasAutoClearChanBufferSet() const { |
200 | 0 | return m_bHasAutoClearChanBufferSet; |
201 | 0 | } |
202 | | // !Getters |
203 | | private: |
204 | | protected: |
205 | | bool m_bDetached; |
206 | | bool m_bIsOn; |
207 | | bool m_bAutoClearChanBuffer; |
208 | | bool m_bInConfig; |
209 | | bool m_bDisabled; |
210 | | bool m_bHasBufferCountSet; |
211 | | bool m_bHasAutoClearChanBufferSet; |
212 | | CString m_sName; |
213 | | CString m_sKey; |
214 | | CString m_sTopic; |
215 | | CString m_sTopicOwner; |
216 | | unsigned long m_ulTopicDate; |
217 | | unsigned long m_ulCreationDate; |
218 | | CIRCNetwork* m_pNetwork; |
219 | | CNick m_Nick; |
220 | | unsigned int m_uJoinTries; |
221 | | CString m_sDefaultModes; |
222 | | std::map<CString, CNick> m_msNicks; // Todo: make this caseless (irc style) |
223 | | CBuffer m_Buffer; |
224 | | |
225 | | bool m_bModeKnown; |
226 | | std::map<char, CString> m_mcsModes; |
227 | | }; |
228 | | |
229 | | #endif // !ZNC_CHAN_H |