ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  */
17 #ifndef _IRCSOCK_H
18 #define _IRCSOCK_H
20 #include <znc/zncconfig.h>
21 #include <znc/Socket.h>
22 #include <znc/Nick.h>
24 #include <deque>
26 // Forward Declarations
27 class CChan;
28 class CUser;
29 class CIRCNetwork;
30 class CClient;
31 // !Forward Declarations
33 class CIRCSock : public CZNCSock {
34 public:
35  CIRCSock(CIRCNetwork* pNetwork);
36  virtual ~CIRCSock();
38  typedef enum {
39  // These values must line up with their position in the CHANMODE argument to raw 005
40  ListArg = 0,
41  HasArg = 1,
43  NoArg = 3
44  } EChanModeArgs;
46  // Message Handlers
47  bool OnCTCPReply(CNick& Nick, CString& sMessage);
48  bool OnPrivCTCP(CNick& Nick, CString& sMessage);
49  bool OnChanCTCP(CNick& Nick, const CString& sChan, CString& sMessage);
50  bool OnGeneralCTCP(CNick& Nick, CString& sMessage);
51  bool OnPrivMsg(CNick& Nick, CString& sMessage);
52  bool OnChanMsg(CNick& Nick, const CString& sChan, CString& sMessage);
53  bool OnPrivNotice(CNick& Nick, CString& sMessage);
54  bool OnChanNotice(CNick& Nick, const CString& sChan, CString& sMessage);
55  bool OnServerCapAvailable(const CString& sCap);
56  // !Message Handlers
58  virtual void ReadLine(const CString& sData);
59  virtual void Connected();
60  virtual void Disconnected();
61  virtual void ConnectionRefused();
62  virtual void SockError(int iErrno, const CString& sDescription);
63  virtual void Timeout();
64  virtual void ReachedMaxBuffer();
66  void PutIRC(const CString& sLine);
67  void PutIRCQuick(const CString& sLine);
68  void ResetChans();
69  void Quit(const CString& sQuitMsg = "");
75  void PauseCap();
79  void ResumeCap();
81  // Setters
82  void SetPass(const CString& s) { m_sPass = s; }
83  // !Setters
85  // Getters
86  unsigned int GetMaxNickLen() const { return m_uMaxNickLen; }
87  EChanModeArgs GetModeType(unsigned char uMode) const;
88  unsigned char GetPermFromMode(unsigned char uMode) const;
89  const std::map<unsigned char, EChanModeArgs>& GetChanModes() const { return m_mueChanModes; }
90  bool IsPermChar(const char c) const { return (c != '\0' && GetPerms().find(c) != CString::npos); }
91  bool IsPermMode(const char c) const { return (c != '\0' && GetPermModes().find(c) != CString::npos); }
92  const CString& GetPerms() const { return m_sPerms; }
93  const CString& GetPermModes() const { return m_sPermModes; }
94  CString GetNickMask() const { return m_Nick.GetNickMask(); }
95  const CString& GetNick() const { return m_Nick.GetNick(); }
96  const CString& GetPass() const { return m_sPass; }
97  CIRCNetwork* GetNetwork() const { return m_pNetwork; }
98  bool HasNamesx() const { return m_bNamesx; }
99  bool HasUHNames() const { return m_bUHNames; }
100  const std::set<unsigned char>& GetUserModes() const { return m_scUserModes; }
101  // This is true if we are past raw 001
102  bool IsAuthed() const { return m_bAuthed; }
103  bool IsCapAccepted(const CString& sCap) { return 1 == m_ssAcceptedCaps.count(sCap); }
104  const MCString& GetISupport() const { return m_mISupport; }
105  CString GetISupport(const CString& sKey, const CString& sDefault = "") const;
106  // !Getters
108  // This handles NAMESX and UHNAMES in a raw 353 reply
109  void ForwardRaw353(const CString& sLine) const;
110  void ForwardRaw353(const CString& sLine, CClient* pClient) const;
112  // TODO move this function to CIRCNetwork and make it non-static?
113  static bool IsFloodProtected(double fRate);
114 private:
115  void SetNick(const CString& sNick);
116  void ParseISupport(const CString& sLine);
117  // This is called when we connect and the nick we want is already taken
118  void SendAltNick(const CString& sBadNick);
119  void SendNextCap();
120  void TrySend();
121 protected:
122  bool m_bAuthed;
123  bool m_bNamesx;
127  std::set<unsigned char> m_scUserModes;
128  std::map<unsigned char, EChanModeArgs> m_mueChanModes;
132  std::map<CString, CChan*> m_msChans;
133  unsigned int m_uMaxNickLen;
134  unsigned int m_uCapPaused;
137  time_t m_lastCTCP;
138  unsigned int m_uNumCTCP;
139  static const time_t m_uCTCPFloodTime;
140  static const unsigned int m_uCTCPFloodCount;
142  std::deque<CString> m_vsSendQueue;
143  short int m_iSendsAllowed;
144  unsigned short int m_uFloodBurst;
145  double m_fFloodRate;
148  friend class CIRCFloodTimer;
149 };
151 #endif // !_IRCSOCK_H
bool IsCapAccepted(const CString &sCap)
Definition: IRCSock.h:103
const CString & GetPermModes() const
Definition: IRCSock.h:93
bool OnServerCapAvailable(const CString &sCap)
Definition: User.h:37
void ResumeCap()
If you used PauseCap, call this when CAP negotiation and logging in should be resumed again...
CString GetNickMask() const
Definition: IRCSock.h:94
bool HasNamesx() const
Definition: IRCSock.h:98
CString m_sPass
Definition: IRCSock.h:131
CIRCNetwork * GetNetwork() const
Definition: IRCSock.h:97
virtual void ConnectionRefused()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
void ForwardRaw353(const CString &sLine) const
CString m_sPerms
Definition: IRCSock.h:125
bool OnPrivNotice(CNick &Nick, CString &sMessage)
const CString & GetNick() const
Definition: IRCSock.h:95
bool OnChanNotice(CNick &Nick, const CString &sChan, CString &sMessage)
MCString m_mISupport
Definition: IRCSock.h:141
bool IsPermMode(const char c) const
Definition: IRCSock.h:91
void PauseCap()
You can call this from CModule::OnServerCapResult to suspend sending other CAP requests and CAP END f...
void Quit(const CString &sQuitMsg="")
virtual void SockError(int iErrno, const CString &sDescription)
virtual void ReadLine(const CString &sData)
short int m_iSendsAllowed
Definition: IRCSock.h:143
bool IsPermChar(const char c) const
Definition: IRCSock.h:90
Definition: Client.h:84
EChanModeArgs GetModeType(unsigned char uMode) const
const CString & GetNick() const
Definition: IRCSock.h:40
unsigned short int m_uFloodBurst
Definition: IRCSock.h:144
Definition: Nick.h:29
bool OnChanMsg(CNick &Nick, const CString &sChan, CString &sMessage)
const std::set< unsigned char > & GetUserModes() const
Definition: IRCSock.h:100
CIRCSock(CIRCNetwork *pNetwork)
std::set< CString > SCString
Definition: ZNCString.h:34
Definition: IRCSock.h:43
CString GetNickMask() const
Definition: Socket.h:26
virtual ~CIRCSock()
virtual void ReachedMaxBuffer()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
CNick m_Nick
Definition: IRCSock.h:130
std::map< unsigned char, EChanModeArgs > m_mueChanModes
Definition: IRCSock.h:128
Definition: IRCNetwork.h:36
void PutIRC(const CString &sLine)
void ResetChans()
const std::map< unsigned char, EChanModeArgs > & GetChanModes() const
Definition: IRCSock.h:89
String class that is used inside ZNC.
Definition: ZNCString.h:67
bool OnChanCTCP(CNick &Nick, const CString &sChan, CString &sMessage)
virtual void Connected()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
std::deque< CString > m_vsSendQueue
Definition: IRCSock.h:142
SCString m_ssAcceptedCaps
Definition: IRCSock.h:135
static const unsigned int m_uCTCPFloodCount
Definition: IRCSock.h:140
unsigned int m_uMaxNickLen
Definition: IRCSock.h:133
unsigned char GetPermFromMode(unsigned char uMode) const
Definition: IRCSock.h:42
const CString & GetPass() const
Definition: IRCSock.h:96
bool IsAuthed() const
Definition: IRCSock.h:102
static const time_t m_uCTCPFloodTime
Definition: IRCSock.h:139
std::map< CString, CChan * > m_msChans
Definition: IRCSock.h:132
CString m_sPermModes
Definition: IRCSock.h:126
bool m_bAuthed
Definition: IRCSock.h:122
Definition: IRCSock.h:41
static bool IsFloodProtected(double fRate)
time_t m_lastCTCP
Definition: IRCSock.h:137
void SetPass(const CString &s)
Definition: IRCSock.h:82
CIRCNetwork * m_pNetwork
Definition: IRCSock.h:129
bool OnGeneralCTCP(CNick &Nick, CString &sMessage)
bool HasUHNames() const
Definition: IRCSock.h:99
A dictionary for strings.
Definition: ZNCString.h:538
unsigned int GetMaxNickLen() const
Definition: IRCSock.h:86
virtual void Disconnected()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
double m_fFloodRate
Definition: IRCSock.h:145
bool OnPrivCTCP(CNick &Nick, CString &sMessage)
const MCString & GetISupport() const
Definition: IRCSock.h:104
unsigned int m_uNumCTCP
Definition: IRCSock.h:138
bool OnCTCPReply(CNick &Nick, CString &sMessage)
Definition: IRCSock.h:38
const CString & GetPerms() const
Definition: IRCSock.h:92
friend class CIRCFloodTimer
Definition: IRCSock.h:148
SCString m_ssPendingCaps
Definition: IRCSock.h:136
bool m_bNamesx
Definition: IRCSock.h:123
unsigned int m_uCapPaused
Definition: IRCSock.h:134
bool m_bFloodProtection
Definition: IRCSock.h:146
bool m_bUHNames
Definition: IRCSock.h:124
Definition: IRCSock.h:33
bool OnPrivMsg(CNick &Nick, CString &sMessage)
Definition: Chan.h:34
virtual void Timeout()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
void PutIRCQuick(const CString &sLine)
Should be used for PONG only.
std::set< unsigned char > m_scUserModes
Definition: IRCSock.h:127