]> jfr.im git - irc/rizon/znc.git/blob - IRCSock.h
Write forceserver and webircpassword to conf
[irc/rizon/znc.git] / IRCSock.h
1 /*
2 * Copyright (C) 2004-2011 See the AUTHORS file for details.
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 */
8
9 #ifndef _IRCSOCK_H
10 #define _IRCSOCK_H
11
12 #include "zncconfig.h"
13 #include "Socket.h"
14 #include "Nick.h"
15
16 // Forward Declarations
17 class CChan;
18 class CUser;
19 class CClient;
20 // !Forward Declarations
21
22 class CIRCSock : public CZNCSock {
23 public:
24 CIRCSock(CUser* pUser);
25 virtual ~CIRCSock();
26
27 typedef enum {
28 // These values must line up with their position in the CHANMODE argument to raw 005
29 ListArg = 0,
30 HasArg = 1,
31 ArgWhenSet = 2,
32 NoArg = 3
33 } EChanModeArgs;
34
35 // Message Handlers
36 bool OnCTCPReply(CNick& Nick, CString& sMessage);
37 bool OnPrivCTCP(CNick& Nick, CString& sMessage);
38 bool OnChanCTCP(CNick& Nick, const CString& sChan, CString& sMessage);
39 bool OnGeneralCTCP(CNick& Nick, CString& sMessage);
40 bool OnPrivMsg(CNick& Nick, CString& sMessage);
41 bool OnChanMsg(CNick& Nick, const CString& sChan, CString& sMessage);
42 bool OnPrivNotice(CNick& Nick, CString& sMessage);
43 bool OnChanNotice(CNick& Nick, const CString& sChan, CString& sMessage);
44 bool OnServerCapAvailable(const CString& sCap);
45 // !Message Handlers
46
47 virtual void ReadLine(const CString& sData);
48 virtual void Connected();
49 virtual void Disconnected();
50 virtual void ConnectionRefused();
51 virtual void SockError(int iErrno);
52 virtual void Timeout();
53 virtual void ReachedMaxBuffer();
54
55 void PutIRC(const CString& sLine);
56 void ResetChans();
57 void Quit(const CString& sQuitMsg = "");
58
59 /** You can call this from CModule::OnServerCapResult to suspend
60 * sending other CAP requests and CAP END for a while. Each
61 * call to PauseCap should be balanced with a call to ResumeCap.
62 */
63 void PauseCap();
64 /** If you used PauseCap, call this when CAP negotiation and logging in
65 * should be resumed again.
66 */
67 void ResumeCap();
68
69 // Setters
70 void SetPass(const CString& s) { m_sPass = s; }
71 // !Setters
72
73 // Getters
74 unsigned int GetMaxNickLen() const { return m_uMaxNickLen; }
75 EChanModeArgs GetModeType(unsigned char uMode) const;
76 unsigned char GetPermFromMode(unsigned char uMode) const;
77 const map<unsigned char, EChanModeArgs>& GetChanModes() const { return m_mueChanModes; }
78 bool IsPermChar(const char c) const { return (c != '\0' && GetPerms().find(c) != CString::npos); }
79 bool IsPermMode(const char c) const { return (c != '\0' && GetPermModes().find(c) != CString::npos); }
80 const CString& GetPerms() const { return m_sPerms; }
81 const CString& GetPermModes() const { return m_sPermModes; }
82 CString GetNickMask() const { return m_Nick.GetNickMask(); }
83 const CString& GetNick() const { return m_Nick.GetNick(); }
84 const CString& GetPass() const { return m_sPass; }
85 CUser* GetUser() const { return m_pUser; }
86 bool HasNamesx() const { return m_bNamesx; }
87 bool HasUHNames() const { return m_bUHNames; }
88 const set<unsigned char>& GetUserModes() const { return m_scUserModes; }
89 // This is true if we are past raw 001
90 bool IsAuthed() const { return m_bAuthed; }
91 bool IsCapAccepted(const CString& sCap) { return 1 == m_ssAcceptedCaps.count(sCap); }
92 // !Getters
93
94 // This handles NAMESX and UHNAMES in a raw 353 reply
95 void ForwardRaw353(const CString& sLine) const;
96 void ForwardRaw353(const CString& sLine, CClient* pClient) const;
97 private:
98 void SetNick(const CString& sNick);
99 void ParseISupport(const CString& sLine);
100 // This is called when we connect and the nick we want is already taken
101 void SendAltNick(const CString& sBadNick);
102 void SendNextCap();
103 protected:
104 bool m_bAuthed;
105 bool m_bNamesx;
106 bool m_bUHNames;
107 CString m_sPerms;
108 CString m_sPermModes;
109 set<unsigned char> m_scUserModes;
110 map<unsigned char, EChanModeArgs> m_mueChanModes;
111 CUser* m_pUser;
112 CNick m_Nick;
113 CString m_sPass;
114 map<CString, CChan*> m_msChans;
115 unsigned int m_uMaxNickLen;
116 unsigned int m_uCapPaused;
117 SCString m_ssAcceptedCaps;
118 SCString m_ssPendingCaps;
119 time_t m_lastCTCP;
120 unsigned int m_uNumCTCP;
121 static const time_t m_uCTCPFloodTime;
122 static const unsigned int m_uCTCPFloodCount;
123 };
124
125 #endif // !_IRCSOCK_H