| 1 | // Channel.H -*- C++ -*- |
| 2 | // Copyright (c) 1997, 1998 Etienne BERNARD |
| 3 | // Copyright (C) 2002,2008,2009 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 <list> |
| 26 | #include <string> |
| 27 | #include <vector> |
| 28 | |
| 29 | #include <ctime> |
| 30 | |
| 31 | #include "BanList.H" |
| 32 | #include "ChannelUserList.H" |
| 33 | #include "Utils.H" |
| 34 | |
| 35 | class BanEntry; |
| 36 | class Bot; |
| 37 | class Commands; |
| 38 | class Mask; |
| 39 | class Parser; |
| 40 | class Person; |
| 41 | class ServerConnection; |
| 42 | class User; |
| 43 | class UserCommands; |
| 44 | class UserList; |
| 45 | |
| 46 | |
| 47 | #define DEFAULT_KEEPMODES "iklmnpst" |
| 48 | |
| 49 | // This struct is used to keep information about |
| 50 | // the channel we want to join, the modes we |
| 51 | // want to set/keep on these channels, and the |
| 52 | // channel keys |
| 53 | struct wantedChannel { |
| 54 | std::string mode; |
| 55 | std::string keep; |
| 56 | std::string key; |
| 57 | |
| 58 | wantedChannel(std::string m, std::string kp, std::string ky) |
| 59 | : mode(m), keep(kp), key(ky) { } |
| 60 | }; |
| 61 | |
| 62 | class Channel { |
| 63 | std::string channelName; |
| 64 | std::string channelTopic; |
| 65 | bool lockedTopic; |
| 66 | int channelMode; |
| 67 | int channelLimit; |
| 68 | std::string channelKey; |
| 69 | std::string keepModes; |
| 70 | std::string wantedModes; |
| 71 | |
| 72 | bool joined; |
| 73 | bool doMode; |
| 74 | bool gotWho; |
| 75 | ChannelUserList channelUserlist; |
| 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 *, std::string, std::string); |
| 93 | ~Channel(); |
| 94 | |
| 95 | void addNick(std::string, std::string, int, UserList *, bool = false); |
| 96 | void delNick(std::string); |
| 97 | void changeNick(std::string, std::string); |
| 98 | void change_user_key (std::string, std::string); |
| 99 | bool hasNick(const std::string &) const; |
| 100 | const User getUser(const std::string &) const; |
| 101 | unsigned int user_count () const throw (); |
| 102 | unsigned int operator_count () const throw (); |
| 103 | template<typename T> void for_each_channel_users (const T & fun) |
| 104 | { channelUserlist.foreach (fun); } |
| 105 | |
| 106 | void addBan(const Mask&, std::time_t = -1); |
| 107 | void delBan(const Mask&); |
| 108 | void purge_expired_bans (); |
| 109 | template<typename T> void for_each_ban_entry (const T & fun) |
| 110 | { channelBanlist.foreach (fun); } |
| 111 | |
| 112 | void parseMode(Person *, std::string); |
| 113 | void resynchModes(); |
| 114 | |
| 115 | friend class Bot; |
| 116 | friend class Parser; |
| 117 | friend class Commands; |
| 118 | friend class UserCommands; |
| 119 | }; |
| 120 | |
| 121 | #endif |