The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

channels.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #ifndef __CHANNELS_H__
00015 #define __CHANNELS_H__
00016 
00019 enum ChannelModes {
00020         CM_TOPICLOCK = 't'-65,  /* +t: Only operators can change topic */
00021         CM_NOEXTERNAL = 'n'-65, /* +n: Only users in the channel can message it */
00022         CM_INVITEONLY = 'i'-65, /* +i: Invite only */
00023         CM_MODERATED = 'm'-65,  /* +m: Only voices and above can talk */
00024         CM_SECRET = 's'-65,     /* +s: Secret channel */
00025         CM_PRIVATE = 'p'-65,    /* +p: Private channel */
00026         CM_KEY = 'k'-65,        /* +k: Keyed channel */
00027         CM_LIMIT = 'l'-65       /* +l: Maximum user limit */
00028 };
00029 
00030 /* Forward declarations - needed */
00031 class User;
00032 
00036 class HostItem : public classbase
00037 {
00038  public:
00041         time_t set_time;
00044         std::string set_by;
00047         std::string data;
00048 
00049         HostItem() { /* stub */ }
00050         virtual ~HostItem() { /* stub */ }
00051 };
00052 
00055 class BanItem : public HostItem
00056 {
00057 };
00058 
00061 typedef std::vector<BanItem>    BanList;
00062 
00065 typedef std::map<User*,std::string> CUList;
00066 
00069 typedef CUList::iterator CUListIter;
00070 
00073 typedef CUList::const_iterator CUListConstIter;
00074 
00077 typedef std::map<char,char*> CustomModeList;
00078 
00079 
00082 enum UserChannelModes {
00083         UCMODE_OP       = 1,    /* Opped user */
00084         UCMODE_VOICE    = 2,    /* Voiced user */
00085         UCMODE_HOP      = 4     /* Halfopped user */
00086 };
00087 
00090 typedef std::pair<char, unsigned int> prefixtype;
00091 
00094 typedef std::vector<prefixtype> pfxcontainer;
00095 
00098 typedef std::map<User*, std::vector<prefixtype> > prefixlist;
00099 
00104 class CoreExport Channel : public Extensible
00105 {
00106  private:
00107 
00110         InspIRCd* ServerInstance;
00111 
00114         static Channel* ForceChan(InspIRCd* Instance, Channel* Ptr, User* user, const std::string &privs, bool bursting);
00115 
00118         void SetDefaultModes();
00119 
00123         prefixlist prefixes;
00124 
00127         int maxbans;
00128 
00129  public:
00133         Channel(InspIRCd* Instance, const std::string &name, time_t ts);
00134 
00137         std::string name; /* CHANMAX */
00138 
00145         std::bitset<64> modes;
00146 
00152         CUList internal_userlist;
00153 
00159         CUList internal_op_userlist;
00160 
00166         CUList internal_halfop_userlist;
00167 
00173         CUList internal_voice_userlist;
00174 
00178         CustomModeList custom_mode_params;
00179 
00183         std::string topic; /* MAXTOPIC */
00184 
00188         time_t created;
00189 
00193         time_t topicset;
00194 
00198         std::string setby; /* 128 */
00199 
00202         BanList bans;
00203         
00208         void SetMode(char mode,bool mode_on);
00209 
00215         void SetModeParam(char mode,const char* parameter,bool mode_on);
00216  
00221         bool IsModeSet(char mode);
00222 
00233         std::string GetModeParameter(char mode);
00234 
00240         int SetTopic(User *u, std::string &t, bool forceset = false);
00241 
00249         long GetUserCounter();
00250 
00258         void AddUser(User* user);
00259 
00263         void AddOppedUser(User* user);
00264 
00268         void AddHalfoppedUser(User* user);
00269 
00273         void AddVoicedUser(User* user);
00274 
00279         unsigned long DelUser(User* user);
00280 
00284         void DelOppedUser(User* user);
00285 
00289         void DelHalfoppedUser(User* user);
00290 
00294         void DelVoicedUser(User* user);
00295 
00305         CUList* GetUsers();
00306 
00310         CUList* GetOppedUsers();
00311 
00315         CUList* GetHalfoppedUsers();
00316 
00320         CUList* GetVoicedUsers();
00321 
00326         bool HasUser(User* user);
00327 
00335         long KickUser(User *src, User *user, const char* reason);
00336 
00344         long ServerKickUser(User* user, const char* reason, bool triggerevents, const char* servername = NULL);
00345 
00353         long PartUser(User *user, std::string &reason);
00354 
00355         /* Join a user to a channel. May be a channel that doesnt exist yet.
00356          * @param user The user to join to the channel.
00357          * @param cn The channel name to join to. Does not have to exist.
00358          * @param key The key of the channel, if given
00359          * @param override If true, override all join restrictions such as +bkil
00360          * @return A pointer to the Channel the user was joined to. A new Channel may have
00361          * been created if the channel did not exist before the user was joined to it.
00362          * If the user could not be joined to a channel, the return value may be NULL.
00363          */
00364         static Channel* JoinUser(InspIRCd* ServerInstance, User *user, const char* cn, bool override, const char* key, bool bursting, time_t TS = 0);
00365 
00371         void WriteChannel(User* user, const char* text, ...) CUSTOM_PRINTF(3, 4);
00372 
00377         void WriteChannel(User* user, const std::string &text);
00378 
00384         void WriteChannelWithServ(const char* ServName, const char* text, ...) CUSTOM_PRINTF(3, 4);
00385 
00390         void WriteChannelWithServ(const char* ServName, const std::string &text);
00391 
00401         void WriteAllExceptSender(User* user, bool serversource, char status, const char* text, ...) CUSTOM_PRINTF(5, 6);
00402 
00412         void WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const char* text, ...) CUSTOM_PRINTF(6, 7);
00413 
00422         void WriteAllExceptSender(User* user, bool serversource, char status, const std::string& text);
00423 
00432         void WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
00433 
00437         long GetMaxBans();
00438 
00444         char* ChanModes(bool showkey);
00445 
00451         void UserList(User *user, CUList* ulist = NULL);
00452 
00456         int CountInvisible();
00457 
00462         int GetStatus(User *user);
00463 
00468         int GetStatusFlags(User *user);
00469 
00481         const char* GetPrefixChar(User *user);
00482 
00489         const char* GetAllPrefixChars(User* user);
00490 
00502         unsigned int GetPrefixValue(User* user);
00503 
00509         void RemoveAllPrefixes(User* user);
00510 
00520         void SetPrefix(User* user, char prefix, unsigned int prefix_rank, bool adding);
00521 
00526         bool IsBanned(User* user);
00527 
00533         bool IsExtBanned(User *u, char type);
00534 
00537         bool IsExtBanned(const std::string &str, char type);
00538 
00541         void ResetMaxBans();
00542 
00545         virtual ~Channel() { /* stub */ }
00546 };
00547 
00548 #endif