The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
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 
00017 #include "inspircd_config.h"
00018 #include "base.h"
00019 #include <time.h>
00020 #include <vector>
00021 #include <string>
00022 #include <map>
00023 
00026 enum ChannelModes {
00027         CM_TOPICLOCK = 't'-65,  /* +t: Only operators can change topic */
00028         CM_NOEXTERNAL = 'n'-65, /* +n: Only users in the channel can message it */
00029         CM_INVITEONLY = 'i'-65, /* +i: Invite only */
00030         CM_MODERATED = 'm'-65,  /* +m: Only voices and above can talk */
00031         CM_SECRET = 's'-65,     /* +s: Secret channel */
00032         CM_PRIVATE = 'p'-65,    /* +p: Private channel */
00033         CM_KEY = 'k'-65,        /* +k: Keyed channel */
00034         CM_LIMIT = 'l'-65       /* +l: Maximum user limit */
00035 };
00036 
00037 /* Forward declarations - needed */
00038 class userrec;
00039 class chanrec;
00040 
00044 class HostItem : public classbase
00045 {
00046  public:
00049         time_t set_time;
00052         char set_by[NICKMAX];
00055         char data[MAXBUF];
00056 
00057         HostItem() { /* stub */ }
00058         virtual ~HostItem() { /* stub */ }
00059 };
00060 
00063 class BanItem : public HostItem
00064 {
00065 };
00066 
00069 typedef std::vector<BanItem>    BanList;
00070 
00073 typedef std::map<userrec*,std::string> CUList;
00074 
00077 typedef CUList::iterator CUListIter;
00078 
00081 typedef CUList::const_iterator CUListConstIter;
00082 
00085 typedef std::map<char,char*> CustomModeList;
00086 
00087 
00090 enum UserChannelModes {
00091         UCMODE_OP       = 1,    /* Opped user */
00092         UCMODE_VOICE    = 2,    /* Voiced user */
00093         UCMODE_HOP      = 4     /* Halfopped user */
00094 };
00095 
00096 /* Forward declaration -- required */
00097 class InspIRCd;
00098 
00101 typedef std::pair<char, unsigned int> prefixtype;
00102 
00105 typedef std::vector<prefixtype> pfxcontainer;
00106 
00109 typedef std::map<userrec*, std::vector<prefixtype> > prefixlist;
00110 
00115 class CoreExport chanrec : public Extensible
00116 {
00117  private:
00118 
00121         InspIRCd* ServerInstance;
00122 
00125         static chanrec* ForceChan(InspIRCd* Instance, chanrec* Ptr, userrec* user, const std::string &privs);
00126 
00129         void SetDefaultModes();
00130 
00134         prefixlist prefixes;
00135 
00138         int maxbans;
00139 
00140  public:
00143         char name[CHANMAX];
00144 
00151         char modes[64];
00152 
00158         CUList internal_userlist;
00159 
00165         CUList internal_op_userlist;
00166 
00172         CUList internal_halfop_userlist;
00173 
00179         CUList internal_voice_userlist;
00180 
00184         CustomModeList custom_mode_params;
00185 
00189         char topic[MAXTOPIC];
00190 
00194         time_t created;
00195 
00199         time_t topicset;
00200 
00204         char setby[128];
00205 
00209         short int limit;
00210         
00214         char key[32];
00215 
00218         BanList bans;
00219         
00224         void SetMode(char mode,bool mode_on);
00225 
00231         void SetModeParam(char mode,const char* parameter,bool mode_on);
00232  
00237         bool IsModeSet(char mode);
00238 
00249         std::string GetModeParameter(char mode);
00250 
00258         long GetUserCounter();
00259 
00267         void AddUser(userrec* user);
00268 
00272         void AddOppedUser(userrec* user);
00273 
00277         void AddHalfoppedUser(userrec* user);
00278 
00282         void AddVoicedUser(userrec* user);
00283 
00288         unsigned long DelUser(userrec* user);
00289 
00293         void DelOppedUser(userrec* user);
00294 
00298         void DelHalfoppedUser(userrec* user);
00299 
00303         void DelVoicedUser(userrec* user);
00304 
00314         CUList* GetUsers();
00315 
00319         CUList* GetOppedUsers();
00320 
00324         CUList* GetHalfoppedUsers();
00325 
00329         CUList* GetVoicedUsers();
00330 
00335         bool HasUser(userrec* user);
00336 
00340         chanrec(InspIRCd* Instance);
00341 
00349         long KickUser(userrec *src, userrec *user, const char* reason);
00350 
00358         long ServerKickUser(userrec* user, const char* reason, bool triggerevents);
00359 
00367         long PartUser(userrec *user, const char* reason = NULL);
00368 
00369         /* Join a user to a channel. May be a channel that doesnt exist yet.
00370          * @param user The user to join to the channel.
00371          * @param cn The channel name to join to. Does not have to exist.
00372          * @param key The key of the channel, if given
00373          * @param override If true, override all join restrictions such as +bkil
00374          * @return A pointer to the chanrec the user was joined to. A new chanrec may have
00375          * been created if the channel did not exist before the user was joined to it.
00376          * If the user could not be joined to a channel, the return value may be NULL.
00377          */
00378         static chanrec* JoinUser(InspIRCd* ServerInstance, userrec *user, const char* cn, bool override, const char* key, time_t TS = 0);
00379 
00385         void WriteChannel(userrec* user, char* text, ...);
00386 
00391         void WriteChannel(userrec* user, const std::string &text);
00392 
00398         void WriteChannelWithServ(const char* ServName, const char* text, ...);
00399 
00404         void WriteChannelWithServ(const char* ServName, const std::string &text);
00405 
00415         void WriteAllExceptSender(userrec* user, bool serversource, char status, char* text, ...);
00416 
00426         void WriteAllExcept(userrec* user, bool serversource, char status, CUList &except_list, char* text, ...);
00427 
00436         void WriteAllExceptSender(userrec* user, bool serversource, char status, const std::string& text);
00437 
00446         void WriteAllExcept(userrec* user, bool serversource, char status, CUList &except_list, const std::string& text);
00447 
00451         long GetMaxBans();
00452 
00458         char* ChanModes(bool showkey);
00459 
00465         void UserList(userrec *user, CUList* ulist = NULL);
00466 
00470         int CountInvisible();
00471 
00476         int GetStatus(userrec *user);
00477 
00482         int GetStatusFlags(userrec *user);
00483 
00495         const char* GetPrefixChar(userrec *user);
00496 
00503         const char* GetAllPrefixChars(userrec* user);
00504 
00516         unsigned int GetPrefixValue(userrec* user);
00517 
00523         void RemoveAllPrefixes(userrec* user);
00524 
00534         void SetPrefix(userrec* user, char prefix, unsigned int prefix_rank, bool adding);
00535 
00540         bool IsBanned(userrec* user);
00541 
00544         void ResetMaxBans();
00545 
00548         virtual ~chanrec() { /* stub */ }
00549 };
00550 
00551 #endif