40caad99e044477096bf1e312b9cc49802745ac2
[clinton/bobotpp.git] / source / Channel.H
1 // Channel.H -*- C++ -*-
2 // Copyright (c) 1997, 1998 Etienne BERNARD
3 // Copyright (C) 2002,2008 Clinton Ebadi
4
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // any later version.
9
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19
20 #ifndef CHANNEL_H
21 #define CHANNEL_H
22
23 #include <algorithm>
24 #include <functional>
25 #include <map>
26 #include <vector>
27
28 #include <ctime>
29
30 #include "BanList.H"
31 #include "String.H"
32
33 class BanEntry;
34 class Bot;
35 class Commands;
36 class Mask;
37 class Parser;
38 class Person;
39 class ServerConnection;
40 class User;
41 class UserCommands;
42 class UserList;
43
44
45 #define DEFAULT_KEEPMODES "iklmnpst"
46
47 // This struct is used to keep information about
48 // the channel we want to join, the modes we
49 // want to set/keep on these channels, and the
50 // channel keys
51 struct wantedChannel {
52 String mode;
53 String keep;
54 String key;
55
56 wantedChannel(String m, String kp, String ky)
57 : mode(m), keep(kp), key(ky) { }
58 };
59
60 class Channel {
61 String channelName;
62 String channelTopic;
63 bool lockedTopic;
64 int channelMode;
65 int channelLimit;
66 String channelKey;
67 String keepModes;
68 String wantedModes;
69
70 int count;
71 int countOp;
72 bool joined;
73 bool doMode;
74 bool gotWho;
75 std::map<String, User *, std::less<String> > channelMemory;
76 BanList channelBanlist;
77 ServerConnection * cnx;
78
79 public:
80
81 enum {
82 PRIVATE = 1, // +p
83 SECRET = 2, // +s
84 INVITE_ONLY = 4, // +i
85 TOPIC_RESTRICTED = 8, // +t
86 EXTMSG_RESTRICTED = 16, // +n
87 MODERATED = 32, // +m
88 HAS_KEY = 64, // +k <key>
89 IS_LIMITED = 128 // +l <limit>
90 };
91
92 Channel(ServerConnection *, String, String);
93 ~Channel();
94
95 void addNick(String, String, int, UserList *, bool = false);
96 void delNick(String);
97 void changeNick(String, String);
98 bool hasNick(String);
99 User * getUser(String);
100
101 void addBan(const Mask&, std::time_t = -1);
102 void delBan(const Mask&);
103 void purge_expired_bans ();
104 template<typename T> void for_each_ban_entry (const T & fun)
105 { channelBanlist.foreach (fun); }
106
107 void parseMode(Person *, String);
108 void resynchModes();
109
110 friend class Bot;
111 friend class Parser;
112 friend class Commands;
113 friend class UserCommands;
114 };
115
116 #endif