-
Notifications
You must be signed in to change notification settings - Fork 1
/
IRCNetwork.h
170 lines (133 loc) · 5.62 KB
/
IRCNetwork.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright (C) 2004-2011 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#ifndef _IRCNETWORK_H
#define _IRCNETWORK_H
#include "zncconfig.h"
#include "ZNCString.h"
#include "Buffer.h"
#include "Nick.h"
#include "znc.h"
class CModules;
class CUser;
class CFile;
class CConfig;
class CClient;
class CConfig;
class CChan;
class CServer;
class CIRCSock;
class CIRCNetwork {
public:
static bool IsValidNetwork(const CString& sNetwork);
CIRCNetwork(CUser *pUser, const CString& sName);
CIRCNetwork(CUser *pUser, const CIRCNetwork *pNetwork, bool bCloneChans = true);
~CIRCNetwork();
CString GetNetworkPath();
void DelServers();
bool ParseConfig(CConfig *pConfig, CString& sError, bool bUpgrade = false);
CConfig ToConfig();
void BounceAllClients();
bool IsUserAttached() const { return !m_vClients.empty(); }
void ClientConnected(CClient *pClient);
void ClientDisconnected(CClient *pClient);
CUser* GetUser();
const CString& GetName() const;
bool IsNetworkAttached() const { return !m_vClients.empty(); };
vector<CClient*>& GetClients() { return m_vClients; }
void SetUser(CUser *pUser);
bool SetName(const CString& sName);
// Modules
CModules& GetModules() { return *m_pModules; }
const CModules& GetModules() const { return *m_pModules; }
// !Modules
bool PutUser(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
bool PutStatus(const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
bool PutModule(const CString& sModule, const CString& sLine, CClient* pClient = NULL, CClient* pSkipClient = NULL);
const vector<CChan*>& GetChans() const;
CChan* FindChan(const CString& sName) const;
bool AddChan(CChan* pChan);
bool AddChan(const CString& sName, bool bInConfig);
bool DelChan(const CString& sName);
void JoinChans();
const CString& GetChanPrefixes() const { return m_sChanPrefixes; };
void SetChanPrefixes(const CString& s) { m_sChanPrefixes = s; };
bool IsChan(const CString& sChan) const;
const vector<CServer*>& GetServers() const;
bool HasServers() const { return !m_vServers.empty(); }
CServer* FindServer(const CString& sName) const;
bool DelServer(const CString& sName, unsigned short uPort, const CString& sPass);
bool AddServer(const CString& sName);
bool AddServer(const CString& sName, unsigned short uPort, const CString& sPass = "", bool bSSL = false);
CServer* GetNextServer();
CServer* GetCurrentServer() const;
void SetIRCServer(const CString& s);
bool SetNextServer(const CServer* pServer);
bool IsLastServer() const;
CIRCSock* GetIRCSock() { return m_pIRCSock; }
const CIRCSock* GetIRCSock() const { return m_pIRCSock; }
const CString& GetIRCServer() const;
const CNick& GetIRCNick() const;
void SetIRCNick(const CNick& n);
CString GetCurNick() const;
bool IsIRCAway() const { return m_bIRCAway; }
void SetIRCAway(bool b) { m_bIRCAway = b; }
/** This method will return whether the user is connected and authenticated to an IRC server.
*/
bool IsIRCConnected() const;
void SetIRCSocket(CIRCSock* pIRCSock);
void IRCDisconnected();
void CheckIRCConnect();
bool PutIRC(const CString& sLine);
// Buffers
void AddRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.AddLine(sPre, sPost, bIncNick); }
void UpdateRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.UpdateLine(sPre, sPost, bIncNick); }
void UpdateExactRawBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_RawBuffer.UpdateExactLine(sPre, sPost, bIncNick); }
void ClearRawBuffer() { m_RawBuffer.Clear(); }
void AddMotdBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_MotdBuffer.AddLine(sPre, sPost, bIncNick); }
void UpdateMotdBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_MotdBuffer.UpdateLine(sPre, sPost, bIncNick); }
void ClearMotdBuffer() { m_MotdBuffer.Clear(); }
void AddQueryBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_QueryBuffer.AddLine(sPre, sPost, bIncNick); }
void UpdateQueryBuffer(const CString& sPre, const CString& sPost, bool bIncNick = true) { m_QueryBuffer.UpdateLine(sPre, sPost, bIncNick); }
void ClearQueryBuffer() { m_QueryBuffer.Clear(); }
// !Buffers
// la
const CString& GetNick(const bool bAllowDefault = true) const;
const CString& GetAltNick(const bool bAllowDefault = true) const;
const CString& GetIdent(const bool bAllowDefault = true) const;
const CString& GetRealName() const;
void SetNick(const CString& s);
void SetAltNick(const CString& s);
void SetIdent(const CString& s);
void SetRealName(const CString& s);
CString ExpandString(const CString& sStr) const;
CString& ExpandString(const CString& sStr, CString& sRet) const;
private:
bool JoinChan(CChan* pChan);
void JoinChans(set<CChan*>& sChans);
protected:
CString m_sName;
CUser* m_pUser;
CString m_sNick;
CString m_sAltNick;
CString m_sIdent;
CString m_sRealName;
CModules* m_pModules;
vector<CClient*> m_vClients;
CIRCSock* m_pIRCSock;
vector<CChan*> m_vChans;
CString m_sChanPrefixes;
CString m_sIRCServer;
vector<CServer*> m_vServers;
unsigned int m_uServerIdx; ///< Index in m_vServers of our current server + 1
CNick m_IRCNick;
bool m_bIRCAway;
CBuffer m_RawBuffer;
CBuffer m_MotdBuffer;
CBuffer m_QueryBuffer;
};
#endif // !_IRCNETWORK_H