]> jfr.im git - irc/rizon/znc.git/blame - User.h
Write forceserver and webircpassword to conf
[irc/rizon/znc.git] / User.h
CommitLineData
a09a7e79 1/*
b9b0fd4c 2 * Copyright (C) 2004-2011 See the AUTHORS file for details.
a09a7e79 3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
7 */
6dcacaa7 8
538d3ece 9#ifndef _USER_H
10#define _USER_H
11
3ecbf133 12#include "zncconfig.h"
e72c4456 13#include "Buffer.h"
538d3ece 14#include "Modules.h"
66389db9 15#include "Nick.h"
e72c4456 16#include <set>
17#include <vector>
538d3ece 18
538d3ece 19using std::set;
e72c4456 20using std::vector;
538d3ece 21
538d3ece 22class CChan;
a490f62d 23class CClient;
70c77458 24class CConfig;
3f24f287 25class CFile;
e72c4456 26class CIRCSock;
5fea8a69 27class CUserTimer;
e72c4456 28class CServer;
538d3ece 29
30class CUser {
31public:
89e5079c 32 CUser(const CString& sUserName);
acd854eb 33 ~CUser();
538d3ece 34
70c77458
US
35 bool ParseConfig(CConfig* Config, CString& sError);
36
cd63bae0 37 enum eHashType {
38 HASH_NONE,
39 HASH_MD5,
40 HASH_SHA256,
41
42 HASH_DEFAULT = HASH_SHA256
43 };
44
45 // If you change the default hash here and in HASH_DEFAULT,
46 // don't forget CUtils::sDefaultHash!
47 static CString SaltedHash(const CString& sPass, const CString& sSalt) {
48 return CUtils::SaltedSHA256Hash(sPass, sSalt);
49 }
50
86f3d7c7 51 bool PrintLine(CFile& File, CString sName, CString sValue) const;
4484999c 52 bool WriteConfig(CFile& File);
aabca275 53 CChan* FindChan(const CString& sName) const;
538d3ece 54 bool AddChan(CChan* pChan);
aabca275 55 bool AddChan(const CString& sName, bool bInConfig);
beb5b49b 56 bool DelChan(const CString& sName);
aabca275 57 void JoinChans();
86924339 58 CServer* FindServer(const CString& sName) const;
4d35bd48 59 bool DelServer(const CString& sName, unsigned short uPort, const CString& sPass);
d2542408 60 bool AddServer(const CString& sName);
61 bool AddServer(const CString& sName, unsigned short uPort, const CString& sPass = "", bool bSSL = false);
538d3ece 62 CServer* GetNextServer();
86924339 63 CServer* GetCurrentServer() const;
2becac12 64 bool SetNextServer(const CServer* pServer);
86924339 65 bool CheckPass(const CString& sPass) const;
beb5b49b 66 bool AddAllowedHost(const CString& sHostMask);
86924339 67 bool IsHostAllowed(const CString& sHostMask) const;
677f50d1 68 bool IsValid(CString& sErrMsg, bool bSkipPass = false) const;
beb5b49b 69 static bool IsValidUserName(const CString& sUserName);
49e98202 70 static CString MakeCleanUserName(const CString& sUserName);
86924339 71 bool IsLastServer() const;
538d3ece 72
3d7bf1fc 73 void DelClients();
f9d12fb8 74 void DelServers();
3d7bf1fc 75 void DelModules();
3d7bf1fc 76
c3e4a7a1 77 // Unloads a module on all users who have it loaded and loads it again.
78 static bool UpdateModule(const CString &sModule);
79
538d3ece 80 // Modules
3dde793e 81 CModules& GetModules() { return *m_pModules; }
94956090 82 const CModules& GetModules() const { return *m_pModules; }
538d3ece 83 // !Modules
538d3ece 84
aaec84a3 85 // Buffers
6a6ae0ed 86 void AddRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.AddLine(sPre, sPost, bIncNick); }
f601db2c 87 void UpdateRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.UpdateLine(sPre, sPost, bIncNick); }
94f64333 88 void UpdateExactRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.UpdateExactLine(sPre, sPost, bIncNick); }
aaec84a3 89 void ClearRawBuffer() { m_RawBuffer.Clear(); }
94f64333 90
91 void AddMotdBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_MotdBuffer.AddLine(sPre, sPost, bIncNick); }
92 void UpdateMotdBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_MotdBuffer.UpdateLine(sPre, sPost, bIncNick); }
aaec84a3 93 void ClearMotdBuffer() { m_MotdBuffer.Clear(); }
94f64333 94
95 void AddQueryBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_QueryBuffer.AddLine(sPre, sPost, bIncNick); }
96 void UpdateQueryBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_QueryBuffer.UpdateLine(sPre, sPost, bIncNick); }
aaec84a3 97 void ClearQueryBuffer() { m_QueryBuffer.Clear(); }
98 // !Buffers
538d3ece 99
beb5b49b 100 bool PutIRC(const CString& sLine);
a490f62d 101 bool PutUser(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
102 bool PutStatus(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
103 bool PutStatusNotice(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
104 bool PutModule(const CString& sModule, const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
6bc36d17 105 bool PutModNotice(const CString& sModule, const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
aaec84a3 106
aaaae4e5 107 bool IsUserAttached() const { return !m_vClients.empty(); }
a490f62d 108 void UserConnected(CClient* pClient);
109 void UserDisconnected(CClient* pClient);
538d3ece 110
beb5b49b 111 CString GetLocalIP();
ade1ee54 112 CString GetLocalDCCIP();
90f741d2
KF
113
114 /** This method will return whether the user is connected and authenticated to an IRC server.
115 */
b359f968 116 bool IsIRCConnected() const;
117 void SetIRCSocket(CIRCSock* pIRCSock);
aaec84a3 118 void IRCDisconnected();
e4006adc 119 void CheckIRCConnect();
538d3ece 120
70aafdee 121 CString ExpandString(const CString& sStr) const;
122 CString& ExpandString(const CString& sStr, CString& sRet) const;
123
f601db2c 124 CString AddTimestamp(const CString& sStr) const;
125 CString& AddTimestamp(const CString& sStr, CString& sRet) const;
126
0a622749 127 CString GetCurNick() const;
13ddd325 128 bool Clone(const CUser& User, CString& sErrorRet, bool bCloneChans = true);
e3b723de 129 void BounceAllClients();
538d3ece 130
b772e266 131 void AddBytesRead(unsigned long long u) { m_uBytesRead += u; }
132 void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; }
133
538d3ece 134 // Setters
beb5b49b 135 void SetNick(const CString& s);
136 void SetAltNick(const CString& s);
137 void SetIdent(const CString& s);
138 void SetRealName(const CString& s);
341263f9 139 void SetBindHost(const CString& s);
140 void SetDCCBindHost(const CString& s);
cd63bae0 141 void SetPass(const CString& s, eHashType eHash, const CString& sSalt = "");
e3b723de 142 void SetMultiClients(bool b);
538d3ece 143 void SetDenyLoadMod(bool b);
ef1c8de5 144 void SetAdmin(bool b);
341263f9 145 void SetDenySetBindHost(bool b);
beb5b49b 146 bool SetStatusPrefix(const CString& s);
147 void SetDefaultChanModes(const CString& s);
66389db9 148 void SetIRCNick(const CNick& n);
beb5b49b 149 void SetIRCServer(const CString& s);
150 void SetQuitMsg(const CString& s);
b1646030 151 bool AddCTCPReply(const CString& sCTCP, const CString& sReply);
c1bb18b9 152 bool DelCTCPReply(const CString& sCTCP);
e62ca411 153 bool SetBufferCount(unsigned int u, bool bForce = false);
c8f8285f 154 void SetKeepBuffer(bool b);
0afd0cf5 155 void SetChanPrefixes(const CString& s) { m_sChanPrefixes = s; }
0dd41818 156 void SetBeingDeleted(bool b) { m_bBeingDeleted = b; }
f601db2c 157 void SetTimestampFormat(const CString& s) { m_sTimestampFormat = s; }
158 void SetTimestampAppend(bool b) { m_bAppendTimestamp = b; }
1fa9187b 159 void SetTimestampPrepend(bool b) { m_bPrependTimestamp = b; }
160 void SetTimezoneOffset(float b) { m_fTimezoneOffset = b; }
c0e3f3bb 161 void SetJoinTries(unsigned int i) { m_uMaxJoinTries = i; }
da8c892d 162 void SetMaxJoins(unsigned int i) { m_uMaxJoins = i; }
ad92c58c 163 void SetSkinName(const CString& s) { m_sSkinName = s; }
d78369fe 164 void SetIRCConnectEnabled(bool b) { m_bIRCConnectEnabled = b; }
ff4e09c5 165 void SetIRCAway(bool b) { m_bIRCAway = b; }
538d3ece 166 // !Setters
167
168 // Getters
a490f62d 169 vector<CClient*>& GetClients() { return m_vClients; }
7059bf02 170 CIRCSock* GetIRCSock() { return m_pIRCSock; }
171 const CIRCSock* GetIRCSock() const { return m_pIRCSock; }
beb5b49b 172 const CString& GetUserName() const;
49e98202 173 const CString& GetCleanUserName() const;
174 const CString& GetNick(bool bAllowDefault = true) const;
175 const CString& GetAltNick(bool bAllowDefault = true) const;
176 const CString& GetIdent(bool bAllowDefault = true) const;
beb5b49b 177 const CString& GetRealName() const;
341263f9 178 const CString& GetBindHost() const;
179 const CString& GetDCCBindHost() const;
beb5b49b 180 const CString& GetPass() const;
cd63bae0 181 eHashType GetPassHashType() const;
4a62fca3 182 const CString& GetPassSalt() const;
b1646030 183 const set<CString>& GetAllowedHosts() const;
f601db2c 184 const CString& GetTimestampFormat() const;
185 bool GetTimestampAppend() const;
1fa9187b 186 bool GetTimestampPrepend() const;
d78369fe 187 bool GetIRCConnectEnabled() const { return m_bIRCConnectEnabled; }
beb5b49b 188
aaec84a3 189 const CString& GetChanPrefixes() const { return m_sChanPrefixes; }
0afd0cf5 190 bool IsChan(const CString& sChan) const;
aaec84a3 191
3f24f287 192 const CString& GetUserPath() const;
538d3ece 193
538d3ece 194 bool DenyLoadMod() const;
ef1c8de5 195 bool IsAdmin() const;
341263f9 196 bool DenySetBindHost() const;
e3b723de 197 bool MultiClients() const;
beb5b49b 198 const CString& GetStatusPrefix() const;
199 const CString& GetDefaultChanModes() const;
538d3ece 200 const vector<CChan*>& GetChans() const;
2640f169 201 const vector<CServer*>& GetServers() const;
66389db9 202 const CNick& GetIRCNick() const;
beb5b49b 203 const CString& GetIRCServer() const;
204 CString GetQuitMsg() const;
18b6b2e7 205 const MCString& GetCTCPReplies() const;
c8f8285f 206 unsigned int GetBufferCount() const;
207 bool KeepBuffer() const;
0dd41818 208 bool IsBeingDeleted() const { return m_bBeingDeleted; }
ab71a24b 209 bool HasServers() const { return !m_vServers.empty(); }
1fa9187b 210 float GetTimezoneOffset() const { return m_fTimezoneOffset; }
b772e266 211 unsigned long long BytesRead() const { return m_uBytesRead; }
212 unsigned long long BytesWritten() const { return m_uBytesWritten; }
c0e3f3bb 213 unsigned int JoinTries() const { return m_uMaxJoinTries; }
da8c892d 214 unsigned int MaxJoins() const { return m_uMaxJoins; }
86f3d7c7 215 bool IsIRCAway() const { return m_bIRCAway; }
ad92c58c 216 CString GetSkinName() const;
538d3ece 217 // !Getters
218private:
3327a974 219 bool JoinChan(CChan* pChan);
6a1d27d1 220 void JoinChans(set<CChan*>& sChans);
3327a974 221
538d3ece 222protected:
d44e5903
US
223 const CString m_sUserName;
224 const CString m_sCleanUserName;
f2d7ae1a 225 CString m_sNick;
226 CString m_sAltNick;
227 CString m_sIdent;
228 CString m_sRealName;
341263f9 229 CString m_sBindHost;
230 CString m_sDCCBindHost;
f2d7ae1a 231 CString m_sPass;
232 CString m_sPassSalt;
233 CString m_sStatusPrefix;
234 CString m_sDefaultChanModes;
235 CString m_sChanPrefixes;
236 CNick m_IRCNick;
237 bool m_bIRCAway;
238 CString m_sIRCServer;
239 CString m_sQuitMsg;
240 MCString m_mssCTCPReplies;
241 CString m_sTimestampFormat;
242 float m_fTimezoneOffset;
243 eHashType m_eHashType;
538d3ece 244
150d39e5 245 // Paths
f2d7ae1a 246 CString m_sUserPath;
150d39e5 247 // !Paths
248
f2d7ae1a 249 CBuffer m_RawBuffer;
250 CBuffer m_MotdBuffer;
251 CBuffer m_QueryBuffer;
252 bool m_bMultiClients;
f2d7ae1a 253 bool m_bDenyLoadMod;
254 bool m_bAdmin;
341263f9 255 bool m_bDenySetBindHost;
f2d7ae1a 256 bool m_bKeepBuffer;
257 bool m_bBeingDeleted;
258 bool m_bAppendTimestamp;
259 bool m_bPrependTimestamp;
260 bool m_bIRCConnectEnabled;
261 CIRCSock* m_pIRCSock;
262
263 CUserTimer* m_pUserTimer;
264
265 vector<CServer*> m_vServers;
266 vector<CChan*> m_vChans;
267 vector<CClient*> m_vClients;
f2d7ae1a 268 set<CString> m_ssAllowedHosts;
269 unsigned int m_uServerIdx; ///< Index in m_vServers of our current server + 1
270 unsigned int m_uBufferCount;
271 unsigned long long m_uBytesRead;
272 unsigned long long m_uBytesWritten;
273 unsigned int m_uMaxJoinTries;
274 unsigned int m_uMaxJoins;
275 CString m_sSkinName;
276
277 CModules* m_pModules;
538d3ece 278};
279
280#endif // !_USER_H