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_inviteexception.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 #include "u_listmode.h"
00016 
00017 /* $ModDesc: Provides support for the +I channel mode */
00018 /* $ModDep: ../../include/u_listmode.h */
00019 
00020 /*
00021  * Written by Om <om@inspircd.org>, April 2005.
00022  * Based on m_exception, which was originally based on m_chanprotect and m_silence
00023  *
00024  * The +I channel mode takes a nick!ident@host, glob patterns allowed,
00025  * and if a user matches an entry on the +I list then they can join the channel,
00026  * ignoring if +i is set on the channel
00027  * Now supports CIDR and IP addresses -- Brain
00028  */
00029 
00030 class InspIRCd* ServerInstance;
00031 
00034 class InviteException : public ListModeBase
00035 {
00036  public:
00037         InviteException(InspIRCd* Instance) : ListModeBase(Instance, 'I', "End of Channel Invite Exception List", 346, 347, true) { }
00038 };
00039 
00040 class ModuleInviteException : public Module
00041 {
00042         InviteException* ie;
00043 public:
00044         ModuleInviteException(InspIRCd* Me) : Module(Me)
00045         {
00046                 ie = new InviteException(ServerInstance);
00047                 if (!ServerInstance->Modes->AddMode(ie))
00048                         throw ModuleException("Could not add new modes!");
00049                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
00050 
00051                 ie->DoImplements(this);
00052                 Implementation eventlist[] = { I_OnRequest, I_On005Numeric, I_OnCheckInvite };
00053                 ServerInstance->Modules->Attach(eventlist, this, 3);
00054         }
00055 
00056         virtual void On005Numeric(std::string &output)
00057         {
00058                 output.append(" INVEX=I");
00059         }
00060 
00061         virtual int OnCheckInvite(User* user, Channel* chan)
00062         {
00063                 if(chan != NULL)
00064                 {
00065                         modelist* list;
00066                         chan->GetExt(ie->GetInfoKey(), list);
00067                         if (list)
00068                         {
00069                                 std::string mask = std::string(user->nick) + "!" + user->ident + "@" + user->GetIPString();
00070                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
00071                                 {
00072                                         if(InspIRCd::Match(user->GetFullRealHost(), it->mask) || InspIRCd::Match(user->GetFullHost(), it->mask) || (InspIRCd::MatchCIDR(mask, it->mask)))
00073                                         {
00074                                                 // They match an entry on the list, so let them in.
00075                                                 return 1;
00076                                         }
00077                                 }
00078                         }
00079                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
00080                 }
00081 
00082                 return 0;
00083         }
00084 
00085         virtual const char* OnRequest(Request* request)
00086         {
00087                 ListModeRequest* LM = (ListModeRequest*)request;
00088                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
00089                 {
00090                         modelist* list;
00091                         LM->chan->GetExt(ie->GetInfoKey(), list);
00092                         if (list)
00093                         {
00094                                 std::string mask = std::string(LM->user->nick) + "!" + LM->user->ident + "@" + LM->user->GetIPString();
00095                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
00096                                 {
00097                                         if (InspIRCd::Match(LM->user->GetFullRealHost(), it->mask) || InspIRCd::Match(LM->user->GetFullHost(), it->mask.c_str()) || (InspIRCd::MatchCIDR(mask, it->mask)))
00098                                         {
00099                                                 // They match an entry
00100                                                 return (char*)it->mask.c_str();
00101                                         }
00102                                 }
00103                                 return NULL;
00104                         }
00105                 }
00106                 return NULL;
00107         }
00108 
00109         virtual void OnCleanup(int target_type, void* item)
00110         {
00111                 ie->DoCleanup(target_type, item);
00112         }
00113 
00114         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
00115         {
00116                 ie->DoSyncChannel(chan, proto, opaque);
00117         }
00118 
00119         virtual void OnChannelDelete(Channel* chan)
00120         {
00121                 ie->DoChannelDelete(chan);
00122         }
00123 
00124         virtual void OnRehash(User* user, const std::string &param)
00125         {
00126                 ie->DoRehash();
00127         }
00128 
00129         virtual Version GetVersion()
00130         {
00131                 return Version("$Id: m_inviteexception.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR | VF_COMMON, API_VERSION);
00132         }
00133 
00134         ~ModuleInviteException()
00135         {
00136                 ServerInstance->Modes->DelMode(ie);
00137                 delete ie;
00138                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
00139         }
00140 };
00141 
00142 MODULE_INIT(ModuleInviteException)