-
Notifications
You must be signed in to change notification settings - Fork 1
/
Client.h
160 lines (134 loc) · 4.22 KB
/
Client.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
/*
* 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 _CLIENT_H
#define _CLIENT_H
#include "zncconfig.h"
#include "Socket.h"
#include "Utils.h"
#include "main.h"
// Forward Declarations
class CZNC;
class CUser;
class CIRCNetwork;
class CIRCSock;
class CClient;
// !Forward Declarations
class CAuthBase {
public:
CAuthBase(const CString& sUsername, const CString& sPassword, Csock *pSock) {
SetLoginInfo(sUsername, sPassword, pSock);
}
virtual ~CAuthBase() {}
virtual void SetLoginInfo(const CString& sUsername, const CString& sPassword,
Csock *pSock) {
m_sUsername = sUsername;
m_sPassword = sPassword;
m_pSock = pSock;
}
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
const CString& GetUsername() const { return m_sUsername; }
const CString& GetPassword() const { return m_sPassword; }
Csock *GetSocket() const { return m_pSock; }
CString GetRemoteIP() const;
// Invalidate this CAuthBase instance which means it will no longer use
// m_pSock and AcceptLogin() or RefusedLogin() will have no effect.
virtual void Invalidate();
protected:
virtual void AcceptedLogin(CUser& User) = 0;
virtual void RefusedLogin(const CString& sReason) = 0;
private:
CString m_sUsername;
CString m_sPassword;
Csock* m_pSock;
};
class CClientAuth : public CAuthBase {
public:
CClientAuth(CClient* pClient, const CString& sUsername, const CString& sPassword);
virtual ~CClientAuth() {}
void Invalidate() { m_pClient = NULL; CAuthBase::Invalidate(); }
void AcceptedLogin(CUser& User);
void RefusedLogin(const CString& sReason);
private:
protected:
CClient* m_pClient;
};
class CClient : public CZNCSock {
public:
CClient() : CZNCSock() {
m_pUser = NULL;
m_pNetwork = NULL;
m_bGotPass = false;
m_bGotNick = false;
m_bGotUser = false;
m_bInCap = false;
m_bNamesx = false;
m_bUHNames = false;
EnableReadLine();
// RFC says a line can have 512 chars max, but we are
// a little more gentle ;)
SetMaxBufferThreshold(1024);
SetNick("unknown-nick");
}
virtual ~CClient();
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
CString GetNick(bool bAllowIRCNick = true) const;
CString GetNickMask() const;
bool HasNamesx() const { return m_bNamesx; }
bool HasUHNames() const { return m_bUHNames; }
void UserCommand(CString& sLine);
void UserPortCommand(CString& sLine);
void StatusCTCP(const CString& sCommand);
void BouncedOff();
bool IsAttached() const { return m_pUser != NULL; }
void PutIRC(const CString& sLine);
void PutClient(const CString& sLine);
unsigned int PutStatus(const CTable& table);
void PutStatus(const CString& sLine);
void PutStatusNotice(const CString& sLine);
void PutModule(const CString& sModule, const CString& sLine);
void PutModNotice(const CString& sModule, const CString& sLine);
bool IsCapEnabled(const CString& sCap) { return 1 == m_ssAcceptedCaps.count(sCap); }
virtual void ReadLine(const CString& sData);
bool SendMotd();
void HelpUser();
void AuthUser();
virtual void Connected();
virtual void Timeout();
virtual void Disconnected();
virtual void ConnectionRefused();
virtual void ReachedMaxBuffer();
void SetNick(const CString& s);
CUser* GetUser() const { return m_pUser; }
void SetNetwork(CIRCNetwork* pNetwork, bool bDisconnect=true, bool bReconnect=true);
CIRCNetwork* GetNetwork() const { return m_pNetwork; }
vector<CClient*>& GetClients();
const CIRCSock* GetIRCSock() const;
CIRCSock* GetIRCSock();
CString GetFullName();
private:
void HandleCap(const CString& sLine);
void RespondCap(const CString& sResponse);
protected:
bool m_bGotPass;
bool m_bGotNick;
bool m_bGotUser;
bool m_bInCap;
bool m_bNamesx;
bool m_bUHNames;
CUser* m_pUser;
CIRCNetwork* m_pNetwork;
CString m_sNick;
CString m_sPass;
CString m_sUser;
CString m_sNetwork;
CSmartPtr<CAuthBase> m_spAuth;
SCString m_ssAcceptedCaps;
};
#endif // !_CLIENT_H