ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IRCNetwork.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2014 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 _IRCNETWORK_H
18 #define _IRCNETWORK_H
19 
20 #include <znc/zncconfig.h>
21 #include <znc/ZNCString.h>
22 #include <znc/Buffer.h>
23 #include <znc/Nick.h>
24 #include <znc/znc.h>
25 
26 class CModules;
27 class CUser;
28 class CFile;
29 class CConfig;
30 class CClient;
31 class CConfig;
32 class CChan;
33 class CServer;
34 class CIRCSock;
35 
36 class CIRCNetwork {
37 public:
38  static bool IsValidNetwork(const CString& sNetwork);
39 
40  CIRCNetwork(CUser *pUser, const CString& sName);
41  CIRCNetwork(CUser *pUser, const CIRCNetwork& Network);
42  ~CIRCNetwork();
43 
44  void Clone(const CIRCNetwork& Network, bool bCloneName = true);
45 
47 
48  void DelServers();
49 
50  bool ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade = false);
51  CConfig ToConfig();
52 
53  void BounceAllClients();
54 
55  bool IsUserAttached() const { return !m_vClients.empty(); }
56  bool IsUserOnline() const;
57  void ClientConnected(CClient *pClient);
58  void ClientDisconnected(CClient *pClient);
59 
60  CUser* GetUser();
61  const CString& GetName() const;
62  bool IsNetworkAttached() const { return !m_vClients.empty(); };
63  std::vector<CClient*>& GetClients() { return m_vClients; }
64 
65  void SetUser(CUser *pUser);
66  bool SetName(const CString& sName);
67 
68  // Modules
69  CModules& GetModules() { return *m_pModules; }
70  const CModules& GetModules() const { return *m_pModules; }
71  // !Modules
72 
73  bool PutUser(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
74  bool PutStatus(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
75  bool PutModule(const CString& sModule, const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
76 
77  const std::vector<CChan*>& GetChans() const;
78  CChan* FindChan(CString sName) const;
79  std::vector<CChan*> FindChans(const CString& sWild) const;
80  bool AddChan(CChan* pChan);
81  bool AddChan(const CString& sName, bool bInConfig);
82  bool DelChan(const CString& sName);
83  void JoinChans();
84  void JoinChans(std::set<CChan*>& sChans);
85 
86  const CString& GetChanPrefixes() const { return m_sChanPrefixes; };
87  void SetChanPrefixes(const CString& s) { m_sChanPrefixes = s; };
88  bool IsChan(const CString& sChan) const;
89 
90  const std::vector<CServer*>& GetServers() const;
91  bool HasServers() const { return !m_vServers.empty(); }
92  CServer* FindServer(const CString& sName) const;
93  bool DelServer(const CString& sName, unsigned short uPort, const CString& sPass);
94  bool AddServer(const CString& sName);
95  bool AddServer(const CString& sName, unsigned short uPort, const CString& sPass = "", bool bSSL = false);
97  CServer* GetCurrentServer() const;
98  void SetIRCServer(const CString& s);
99  bool SetNextServer(const CServer* pServer);
100  bool IsLastServer() const;
101 
102  void SetIRCConnectEnabled(bool b);
104 
106  const CIRCSock* GetIRCSock() const { return m_pIRCSock; }
107  const CString& GetIRCServer() const;
108  const CNick& GetIRCNick() const;
109  void SetIRCNick(const CNick& n);
110  CString GetCurNick() const;
111  bool IsIRCAway() const { return m_bIRCAway; }
112  void SetIRCAway(bool b) { m_bIRCAway = b; }
113 
114  bool Connect();
117  bool IsIRCConnected() const;
118  void SetIRCSocket(CIRCSock* pIRCSock);
119  void IRCDisconnected();
120  void CheckIRCConnect();
121 
122  bool PutIRC(const CString& sLine);
123 
124  // Buffers
125  void AddRawBuffer(const CString& sFormat, const CString& sText = "") { m_RawBuffer.AddLine(sFormat, sText); }
126  void UpdateRawBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_RawBuffer.UpdateLine(sMatch, sFormat, sText); }
127  void UpdateExactRawBuffer(const CString& sFormat, const CString& sText = "") { m_RawBuffer.UpdateExactLine(sFormat, sText); }
129 
130  void AddMotdBuffer(const CString& sFormat, const CString& sText = "") { m_MotdBuffer.AddLine(sFormat, sText); }
131  void UpdateMotdBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_MotdBuffer.UpdateLine(sMatch, sFormat, sText); }
133 
134  void AddQueryBuffer(const CString& sFormat, const CString& sText = "") { m_QueryBuffer.AddLine(sFormat, sText); }
135  void UpdateQueryBuffer(const CString& sMatch, const CString& sFormat, const CString& sText = "") { m_QueryBuffer.UpdateLine(sMatch, sFormat, sText); }
137  // !Buffers
138 
139  // la
140  const CString& GetNick(const bool bAllowDefault = true) const;
141  const CString& GetAltNick(const bool bAllowDefault = true) const;
142  const CString& GetIdent(const bool bAllowDefault = true) const;
143  const CString& GetRealName() const;
144  const CString& GetBindHost() const;
145  const CString& GetEncoding() const;
146 
147  void SetNick(const CString& s);
148  void SetAltNick(const CString& s);
149  void SetIdent(const CString& s);
150  void SetRealName(const CString& s);
151  void SetBindHost(const CString& s);
152  void SetEncoding(const CString& s);
153 
154  double GetFloodRate() const { return m_fFloodRate; }
155  unsigned short int GetFloodBurst() const { return m_uFloodBurst; }
156  void SetFloodRate(double fFloodRate) { m_fFloodRate = fFloodRate; }
157  void SetFloodBurst(unsigned short int uFloodBurst) { m_uFloodBurst = uFloodBurst; }
158 
159  CString ExpandString(const CString& sStr) const;
160  CString& ExpandString(const CString& sStr, CString& sRet) const;
161 private:
162  bool JoinChan(CChan* pChan);
163 
164 protected:
167 
174 
176 
177  std::vector<CClient*> m_vClients;
178 
180 
181  std::vector<CChan*> m_vChans;
182 
184 
187  std::vector<CServer*> m_vServers;
188  size_t m_uServerIdx;
189 
192 
193  double m_fFloodRate;
194  unsigned short int m_uFloodBurst;
195 
199 };
200 
201 #endif // !_IRCNETWORK_H
CString m_sNick
Definition: IRCNetwork.h:168
void SetIRCAway(bool b)
Definition: IRCNetwork.h:112
Definition: User.h:37
CBuffer m_QueryBuffer
Definition: IRCNetwork.h:198
const CString & GetIRCServer() const
CString m_sRealName
Definition: IRCNetwork.h:171
bool PutStatus(const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
size_type UpdateExactLine(const CString &sFormat, const CString &sText="")
Same as UpdateLine, but does nothing if this exact line already exists.
CUser * GetUser()
void SetBindHost(const CString &s)
double GetFloodRate() const
Definition: IRCNetwork.h:154
void SetFloodBurst(unsigned short int uFloodBurst)
Definition: IRCNetwork.h:157
bool SetNextServer(const CServer *pServer)
CBuffer m_MotdBuffer
Definition: IRCNetwork.h:197
bool IsIRCConnected() const
This method will return whether the user is connected and authenticated to an IRC server...
void ClientDisconnected(CClient *pClient)
const CIRCSock * GetIRCSock() const
Definition: IRCNetwork.h:106
CConfig ToConfig()
bool IsIRCAway() const
Definition: IRCNetwork.h:111
const CString & GetAltNick(const bool bAllowDefault=true) const
CString m_sEncoding
Definition: IRCNetwork.h:173
CModules * m_pModules
Definition: IRCNetwork.h:175
Definition: Client.h:84
void SetFloodRate(double fFloodRate)
Definition: IRCNetwork.h:156
unsigned short int m_uFloodBurst
Definition: IRCNetwork.h:194
void Clear()
Definition: Buffer.h:71
size_t m_uServerIdx
Index in m_vServers of our current server + 1.
Definition: IRCNetwork.h:188
CBuffer m_RawBuffer
Definition: IRCNetwork.h:196
const CString & GetIdent(const bool bAllowDefault=true) const
const CString & GetChanPrefixes() const
Definition: IRCNetwork.h:86
CString m_sBindHost
Definition: IRCNetwork.h:172
double m_fFloodRate
Set to -1 to disable protection.
Definition: IRCNetwork.h:193
std::vector< CChan * > m_vChans
Definition: IRCNetwork.h:181
const CString & GetRealName() const
void DelServers()
Definition: Modules.h:1066
void BounceAllClients()
Definition: Nick.h:29
CNick m_IRCNick
Definition: IRCNetwork.h:190
void AddMotdBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:130
const CModules & GetModules() const
Definition: IRCNetwork.h:70
void UpdateQueryBuffer(const CString &sMatch, const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:135
void UpdateExactRawBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:127
CString m_sIdent
Definition: IRCNetwork.h:170
std::vector< CChan * > FindChans(const CString &sWild) const
void AddQueryBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:134
void IRCDisconnected()
bool SetName(const CString &sName)
bool IsLastServer() const
CString GetNetworkPath()
CIRCSock * m_pIRCSock
Definition: IRCNetwork.h:179
void UpdateMotdBuffer(const CString &sMatch, const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:131
void SetEncoding(const CString &s)
void ClearQueryBuffer()
Definition: IRCNetwork.h:136
CString m_sIRCServer
Definition: IRCNetwork.h:186
CIRCSock * GetIRCSock()
Definition: IRCNetwork.h:105
CString m_sName
Definition: IRCNetwork.h:165
std::vector< CServer * > m_vServers
Definition: IRCNetwork.h:187
bool HasServers() const
Definition: IRCNetwork.h:91
Definition: FileUtils.h:30
Definition: IRCNetwork.h:36
bool PutIRC(const CString &sLine)
const CString & GetEncoding() const
bool IsNetworkAttached() const
Definition: IRCNetwork.h:62
bool GetIRCConnectEnabled() const
Definition: IRCNetwork.h:103
String class that is used inside ZNC.
Definition: ZNCString.h:67
CString m_sAltNick
Definition: IRCNetwork.h:169
void SetNick(const CString &s)
bool m_bIRCAway
Definition: IRCNetwork.h:191
CServer * FindServer(const CString &sName) const
CChan * FindChan(CString sName) const
size_type UpdateLine(const CString &sMatch, const CString &sFormat, const CString &sText="")
Same as AddLine, but replaces a line whose format string starts with sMatch if there is one...
void SetUser(CUser *pUser)
void SetChanPrefixes(const CString &s)
Definition: IRCNetwork.h:87
void SetIRCSocket(CIRCSock *pIRCSock)
bool IsUserOnline() const
CServer * GetCurrentServer() const
void ClearRawBuffer()
Definition: IRCNetwork.h:128
unsigned short int GetFloodBurst() const
Definition: IRCNetwork.h:155
bool IsChan(const CString &sChan) const
CModules & GetModules()
Definition: IRCNetwork.h:69
CString m_sChanPrefixes
Definition: IRCNetwork.h:183
const std::vector< CChan * > & GetChans() const
void SetAltNick(const CString &s)
Definition: Buffer.h:56
const CNick & GetIRCNick() const
CServer * GetNextServer()
const CString & GetName() const
bool DelServer(const CString &sName, unsigned short uPort, const CString &sPass)
void ClientConnected(CClient *pClient)
bool Connect()
CString ExpandString(const CString &sStr) const
bool IsUserAttached() const
Definition: IRCNetwork.h:55
void UpdateRawBuffer(const CString &sMatch, const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:126
void CheckIRCConnect()
void SetRealName(const CString &s)
void SetIRCNick(const CNick &n)
CIRCNetwork(CUser *pUser, const CString &sName)
bool AddServer(const CString &sName)
const std::vector< CServer * > & GetServers() const
void Clone(const CIRCNetwork &Network, bool bCloneName=true)
bool PutModule(const CString &sModule, const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
std::vector< CClient * > m_vClients
Definition: IRCNetwork.h:177
bool PutUser(const CString &sLine, CClient *pClient=NULL, CClient *pSkipClient=NULL)
size_type AddLine(const CString &sFormat, const CString &sText="", const timeval *ts=0)
CString GetCurNick() const
void SetIdent(const CString &s)
bool AddChan(CChan *pChan)
void ClearMotdBuffer()
Definition: IRCNetwork.h:132
Definition: Server.h:23
bool ParseConfig(CConfig *pConfig, CString &sError, bool bUpgrade=false)
std::vector< CClient * > & GetClients()
Definition: IRCNetwork.h:63
void SetIRCConnectEnabled(bool b)
void AddRawBuffer(const CString &sFormat, const CString &sText="")
Definition: IRCNetwork.h:125
const CString & GetNick(const bool bAllowDefault=true) const
bool m_bIRCConnectEnabled
Definition: IRCNetwork.h:185
void SetIRCServer(const CString &s)
Definition: IRCSock.h:33
bool DelChan(const CString &sName)
const CString & GetBindHost() const
Definition: Chan.h:34
Definition: Config.h:36
void JoinChans()
CUser * m_pUser
Definition: IRCNetwork.h:166
static bool IsValidNetwork(const CString &sNetwork)