Implement threadsafe banlist and make maintenance of bans cleaner
[clinton/bobotpp.git] / source / Channel.H
CommitLineData
cb21075d 1// Channel.H -*- C++ -*-
2// Copyright (c) 1997, 1998 Etienne BERNARD
f9723c92 3// Copyright (C) 2002,2008 Clinton Ebadi
cb21075d 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
7b564711 17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18// 02110-1301, USA.
cb21075d 19
20#ifndef CHANNEL_H
21#define CHANNEL_H
22
f9723c92 23#include <algorithm>
24#include <functional>
cb21075d 25#include <map>
26#include <vector>
27
f9723c92 28#include <ctime>
29
30#include "BanList.H"
cfa82921 31#include "String.H"
cb21075d 32
cfa82921 33class BanEntry;
cb21075d 34class Bot;
cb21075d 35class Commands;
f9723c92 36class Mask;
cfa82921 37class Parser;
38class Person;
39class ServerConnection;
40class User;
cb21075d 41class UserCommands;
cfa82921 42class UserList;
43
cb21075d 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
51struct 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
60class 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;
f9723c92 76 BanList channelBanlist;
cb21075d 77 ServerConnection * cnx;
78
79public:
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
f9723c92 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); }
cb21075d 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