/
Chan.h
137 lines (124 loc) · 4.05 KB
/
Chan.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
#ifndef _CHAN_H
#define _CHAN_H
#include "Nick.h"
#include <vector>
#include <map>
using std::vector;
using std::map;
// Forward Declarations
class CUser;
// !Forward Declarations
class CChan {
public:
typedef enum {
Private = 1 << 0,
Secret = 1 << 1,
NoMessages = 1 << 2,
Moderated = 1 << 3,
OpTopic = 1 << 4,
InviteOnly = 1 << 5,
Key = 1 << 6
} EMode;
CChan(const string& sName, CUser* pUser, unsigned int uBufferCount = 0) {
m_sName = sName;
m_pUser = pUser;
m_bKeepBuffer = false;
m_bAutoCycle = true;
m_bDetached = false;
m_uBufferCount = uBufferCount;
Reset();
}
virtual ~CChan() {
ClearNicks();
}
void Reset();
void Joined();
void Cycle() const;
void IncClientRequests();
bool DecClientRequests();
bool Who();
void OnWho(const string& sNick, const string& sIdent, const string& sHost);
// Modes
void SetModes(const string& s);
void ModeChange(const string& sModes, const string& sNick = "");
void OnOp(const string& sOpNick, const string& sNick, bool bOpped);
void OnVoice(const string& sOpNick, const string& sNick, bool bVoiced);
string GetModeString() const;
string GetModeArg(string& sArgs) const;
// !Modes
// Nicks
void ClearNicks();
CNick* FindNick(const string& sNick) const;
int AddNicks(const string& sNicks);
bool AddNick(const string& sNick);
bool RemNick(const string& sNick);
bool ChangeNick(const string& sOldNick, const string& sNewNick);
// !Nicks
// Buffer
int AddBuffer(const string& sLine);
void ClearBuffer();
// !Buffer
// Setters
void SetIsOn(bool b) { m_bIsOn = b; if (!b) { Reset(); } else { Joined(); } }
void SetOpped(bool b) { m_bIsOp = b; }
void SetVoiced(bool b) { m_bIsVoice = b; }
void SetKey(const string& s) { m_sKey = s; }
void SetTopic(const string& s) { m_sTopic = s; }
void SetDefaultModes(const string& s) { m_sDefaultModes = s; }
void IncOpCount() { m_uOpCount++; }
void DecOpCount() { m_uOpCount -= (m_uOpCount > 0); }
void IncVoiceCount() { m_uVoiceCount++; }
void DecVoiceCount() { m_uVoiceCount -= (m_uVoiceCount > 0); }
void SetBufferCount(unsigned int u) { m_uBufferCount = u; }
void SetKeepBuffer(bool b) { m_bKeepBuffer = b; }
void SetAutoCycle(bool b) { m_bAutoCycle = b; }
void SetWhoDone(bool b = true) { m_bWhoDone = b; }
void SetDetached(bool b = true) { m_bDetached = b; }
// !Setters
// Getters
const bool IsOn() const { return m_bIsOn; }
const bool IsOp() const { return m_bIsOp; }
const bool IsVoice() const { return m_bIsVoice; }
const string& GetName() const { return m_sName; }
unsigned int GetModes() const { return m_uModes; }
const string& GetKey() const { return m_sKey; }
unsigned int GetLimit() const { return m_uLimit; }
const string& GetTopic() const { return m_sTopic; }
const string& GetDefaultModes() const { return m_sDefaultModes; }
const vector<string>& GetBans() const { return m_vsBans; }
const vector<string>& GetBuffer() const { return m_vsBuffer; }
const map<string,CNick*>& GetNicks() const { return m_msNicks; }
unsigned int GetNickCount() const { return m_msNicks.size(); }
unsigned int GetOpCount() const { return m_uOpCount; }
unsigned int GetVoiceCount() const { return m_uVoiceCount; }
unsigned int GetBufferCount() const { return m_uBufferCount; }
bool HasMode(EMode eMode) const { return (m_uModes & eMode); }
bool KeepBuffer() const { return m_bKeepBuffer; }
bool AutoCycle() const { return m_bAutoCycle; }
bool IsDetached() const { return m_bDetached; }
// !Getters
private:
protected:
bool m_bDetached;
bool m_bIsOn;
bool m_bIsOp;
bool m_bIsVoice;
bool m_bWhoDone;
bool m_bKeepBuffer;
bool m_bAutoCycle;
string m_sName;
string m_sKey;
string m_sTopic;
CUser* m_pUser;
unsigned int m_uLimit;
unsigned int m_uModes;
string m_sDefaultModes;
vector<string> m_vsBans;
map<string,CNick*> m_msNicks; // Todo: make this caseless (irc style)
unsigned int m_uBufferCount;
unsigned int m_uOpCount;
unsigned int m_uVoiceCount;
unsigned int m_uClientRequests; // Used to tell how many times a client tried to join this chan
vector<string> m_vsBuffer;
};
#endif // !_CHAN_H