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

m_blockcolor.cpp

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 #include "inspircd.h"
00015 
00016 /* $ModDesc: Provides support for unreal-style channel mode +c */
00017 
00020 class BlockColor : public SimpleChannelModeHandler
00021 {
00022  public:
00023         BlockColor(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'c') { }
00024 };
00025 
00026 class ModuleBlockColour : public Module
00027 {
00028         bool AllowChanOps;
00029         BlockColor *bc;
00030  public:
00031 
00032         ModuleBlockColour(InspIRCd* Me) : Module(Me)
00033         {
00034                 bc = new BlockColor(ServerInstance);
00035                 if (!ServerInstance->Modes->AddMode(bc))
00036                         throw ModuleException("Could not add new modes!");
00037                 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_On005Numeric };
00038                 ServerInstance->Modules->Attach(eventlist, this, 3);
00039         }
00040 
00041         virtual void On005Numeric(std::string &output)
00042         {
00043                 ServerInstance->AddExtBanChar('c');
00044         }
00045 
00046         virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00047         {
00048                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
00049                 {
00050                         Channel* c = (Channel*)dest;
00051 
00052                         if (CHANOPS_EXEMPT(ServerInstance, 'c') && c->GetStatus(user) == STATUS_OP)
00053                         {
00054                                 return 0;
00055                         }
00056 
00057                         if(c->IsModeSet('c') || c->IsExtBanned(user, 'c'))
00058                         {
00059                                 for (std::string::iterator i = text.begin(); i != text.end(); i++)
00060                                 {
00061                                         switch (*i)
00062                                         {
00063                                                 case 2:
00064                                                 case 3:
00065                                                 case 15:
00066                                                 case 21:
00067                                                 case 22:
00068                                                 case 31:
00069                                                         user->WriteNumeric(404, "%s %s :Can't send colours to channel (+c set)",user->nick.c_str(), c->name.c_str());
00070                                                         return 1;
00071                                                 break;
00072                                         }
00073                                 }
00074                         }
00075                 }
00076                 return 0;
00077         }
00078 
00079         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
00080         {
00081                 return OnUserPreMessage(user,dest,target_type,text,status,exempt_list);
00082         }
00083 
00084         virtual ~ModuleBlockColour()
00085         {
00086                 ServerInstance->Modes->DelMode(bc);
00087                 delete bc;
00088         }
00089 
00090         virtual Version GetVersion()
00091         {
00092                 return Version("$Id: m_blockcolor.cpp 10291 2008-08-25 20:35:51Z w00t $",VF_COMMON|VF_VENDOR,API_VERSION);
00093         }
00094 };
00095 
00096 MODULE_INIT(ModuleBlockColour)