-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChannel.hpp
More file actions
158 lines (131 loc) · 3.63 KB
/
Channel.hpp
File metadata and controls
158 lines (131 loc) · 3.63 KB
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
#ifndef _CHANNEL_
#define _CHANNEL_
#include <iostream>
#include <vector>
#include <map>
#include "UserIRC.hpp"
#include "MsgIRC.hpp"
#include "ServerClass.hpp"
namespace MODES {
namespace CHANNEL {
static const char ANONYMOUS = 'a';
static const char INVITE_ONLY = 'i';
static const char MODERATED = 'm';
static const char NO_OUTSIDE_MESSAGES = 'n';
static const char QUIET = 'q';
static const char PRIVATE = 'p';
static const char SECRET = 's';
static const char REOP = 'r';
static const char SETTABLE_TOPIC = 't';
static const char USER_LIMIT_SET = 'l';
static const char CREATOR = 'O';
static const char OPERATOR = 'o';
static const char VOICE = 'v';
static const string ALL = "aimnqpsrtl";
static const string USER_RELATED = "Oov";
static const string NEED_PARAMS = "lOov";
static const string TOGGLEABLE = "aimnqpsrtl";
}
}
class Server;
class ChannelModes {
public:
ChannelModes() : anonymous(false)
, inviteOnly(false)
, moderated(false)
, noOutsideMessages(false)
, quiet(false)
, privateChannel(false)
, secret(false)
, reop(false)
, topicSettable(false)
, keySet(false)
, limitSet(false)
, banMaskSet(false)
, exceptionMaskSet(false)
, invitationMaskSet(false) {}
bool anonymous;
bool inviteOnly;
bool moderated;
bool noOutsideMessages;
bool quiet;
bool privateChannel;
bool secret;
bool reop;
bool topicSettable;
bool keySet;
bool limitSet;
bool banMaskSet;
bool exceptionMaskSet;
bool invitationMaskSet;
static bool is(char mode, const string& modes) {
for (string::const_iterator it = modes.begin(); it != modes.end(); it++) {
if (*it == mode) { return true; }
}
return false;
};
static bool exist(char mode) {
for (string::const_iterator it = MODES::CHANNEL::ALL.begin(); it != MODES::CHANNEL::ALL.end(); it++) {
if (*it == mode) { return true; }
}
for (string::const_iterator it = MODES::CHANNEL::USER_RELATED.begin(); it != MODES::CHANNEL::USER_RELATED.end(); it++) {
if (*it == mode) { return true; }
}
return false;
};
class UnknownMode : public exception {
const char* what(void) const throw();
};
};
class UserChannelModes {
public:
UserChannelModes() : creator(false)
, channelOperator(false)
, voice(false) {}
bool creator;
bool channelOperator;
bool voice;
class UnknownMode : public exception {
const char* what(void) const throw();
};
class UnknownUser : public exception {
const char* what(void) const throw();
};
};
class Channel
{
public:
int _maximum_users;
std::string _topic;
std::string _name;
map<UserIRC*, UserChannelModes> user_modes;
vector<UserIRC*> current_users;
vector<UserIRC*> banned_users;
vector<UserIRC*> invited_users;
ChannelModes modes;
Channel();
Channel(string name);
Channel(const Channel &chan);
Channel& operator=(const Channel &rhs);
~Channel();
string getModes(void) const;
bool getMode(char mode) const;
void setMode(char mode, bool value);
string getUserModes(UserIRC* user) const;
bool getUserMode(UserIRC* user, char mode) const;
void setUserMode(UserIRC* user, char mode, bool value);
bool isAuthorizedUser(UserIRC *user);
void acceptUser(UserIRC *user);
void getInfo(void);
void sendToAll(PayloadIRC& payload, Server& server, UserIRC* exception = 0);
bool isInChannel(UserIRC *user);
bool isInvited(UserIRC *user);
//return a string of all users in the chan separated by space
string userList();
//is protected against user that dosen't are in the chan
void removeUsersFromChan(UserIRC *user);
private:
//return current_users.end() if not found
vector<UserIRC*>::iterator UserIterator(UserIRC *user);
};
#endif