X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_services.cpp;h=bc6c68864533e698244258df253a03f7f1718011;hb=d185decae97752368d5cf62311cbc0d1a52aa22c;hp=d1b63c3b497e78157bd173a7c3adf09dd344187a;hpb=8ad1d8ecdfd182a74837099c749be33a5c006157;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_services.cpp b/src/modules/m_services.cpp index d1b63c3b4..bc6c68864 100644 --- a/src/modules/m_services.cpp +++ b/src/modules/m_services.cpp @@ -2,193 +2,211 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * Inspire is copyright (C) 2002-2004 ChatSpike-Dev. - * E-mail: - * - * - * - * Written by Craig Edwards, Craig McLure, and others. + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * * This program is free but copyrighted software; see * the file COPYING for details. * * --------------------------------------------------- */ -#include -#include "users.h" -#include "channels.h" -#include "modules.h" -#include +#include "inspircd.h" +static bool kludgeme = false; /* $ModDesc: Povides support for services +r user/chan modes and more */ -class ModuleServices : public Module +/** Channel mode +r - mark a channel as identified + */ +class Channel_r : public ModeHandler { - Server *Srv; + public: - ModuleServices() - { - Srv = new Server; + Channel_r(InspIRCd* Instance) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_CHANNEL, false) { } - Srv->AddExtendedMode('r',MT_CHANNEL,false,0,0); - Srv->AddExtendedMode('r',MT_CLIENT,false,0,0); - Srv->AddExtendedMode('R',MT_CHANNEL,false,0,0); - Srv->AddExtendedMode('R',MT_CLIENT,false,0,0); - Srv->AddExtendedMode('M',MT_CHANNEL,false,0,0); + ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool) + { + // only a u-lined server may add or remove the +r mode. + if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server || (source->nick.find('.') != std::string::npos))) + { + channel->SetMode('r',adding); + return MODEACTION_ALLOW; + } + else + { + source->WriteNumeric(500, "%s :Only a server may modify the +r channel mode", source->nick.c_str()); + return MODEACTION_DENY; + } } +}; + +/** User mode +r - mark a user as identified + */ +class User_r : public ModeHandler +{ - virtual void On005Numeric(std::string &output) - { - std::stringstream line(output); - std::string temp1, temp2; - while (!line.eof()) - { - line >> temp1; - if (temp1.substr(0,10) == "CHANMODES=") - { - // append the chanmode to the end - temp1 = temp1.substr(10,temp1.length()); - temp1 = "CHANMODES=" + temp1 + "rRM"; - } - temp2 = temp2 + temp1 + " "; - } - if (temp2.length()) - output = temp2.substr(0,temp2.length()-1); - } - - virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) + public: + User_r(InspIRCd* Instance) : ModeHandler(Instance, 'r', 0, 0, false, MODETYPE_USER, false) { } + + ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool) { - - if (modechar == 'r') - { - if (type == MT_CHANNEL) + if ((kludgeme) || (ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server || (source->nick.find('.') != std::string::npos))) + { + if ((adding && !dest->IsModeSet('r')) || (!adding && dest->IsModeSet('r'))) { - // only a u-lined server may add or remove the +r mode. - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server))) - { - return 1; - } - else - { - Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r channel mode"); - } - } - else - { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,""))) - { - return 1; - } - else - { - Srv->SendServ(user->fd,"500 "+std::string(user->nick)+" :Only a U-Lined server may modify the +r user mode"); - } + dest->SetMode('r',adding); + return MODEACTION_ALLOW; } + return MODEACTION_DENY; } - else if (modechar == 'R') + else { - if (type == MT_CHANNEL) - { - return 1; - } + source->WriteNumeric(500, "%s :Only a server may modify the +r user mode", source->nick.c_str()); + return MODEACTION_DENY; } - else if (modechar == 'M') + } +}; + +/** Channel mode +R - registered users only + */ +class Channel_R : public SimpleChannelModeHandler +{ + public: + Channel_R(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'R') { } +}; + +/** User mode +R - only allow PRIVMSG and NOTICE from registered users + */ +class User_R : public SimpleUserModeHandler +{ + public: + User_R(InspIRCd* Instance) : SimpleUserModeHandler(Instance, 'R') { } +}; + +/** Channel mode +M - only allow privmsg and notice to channel from registered users + */ +class Channel_M : public SimpleChannelModeHandler +{ + public: + Channel_M(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'M') { } +}; + +/** Dreamnforge-like services support + */ +class ModuleServices : public Module +{ + + Channel_r* m1; + Channel_R* m2; + Channel_M* m3; + User_r* m4; + User_R* m5; + public: + ModuleServices(InspIRCd* Me) + : Module(Me) + { + + m1 = new Channel_r(ServerInstance); + m2 = new Channel_R(ServerInstance); + m3 = new Channel_M(ServerInstance); + m4 = new User_r(ServerInstance); + m5 = new User_R(ServerInstance); + + if (!ServerInstance->Modes->AddMode(m1) || !ServerInstance->Modes->AddMode(m2) || !ServerInstance->Modes->AddMode(m3) + || !ServerInstance->Modes->AddMode(m4) || !ServerInstance->Modes->AddMode(m5)) { - if (type == MT_CHANNEL) - { - return 1; - } + throw ModuleException("Could not add user and channel modes!"); } - return 0; + kludgeme = false; + Implementation eventlist[] = { I_OnWhois, I_OnUserPostNick, I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserPreJoin }; + ServerInstance->Modules->Attach(eventlist, this, 5); } - virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text) + /* <- :stitch.chatspike.net 307 w00t w00t :is a registered nick */ + virtual void OnWhois(User* source, User* dest) { - if (target_type == TYPE_CHANNEL) + if (dest->IsModeSet('r')) { - chanrec* c = (chanrec*)dest; - if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r'))) - { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server)) || (!strcmp(user->server,""))) - { - // user is ulined, can speak regardless - return 0; - } - // user messaging a +M channel and is not registered - Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel"); - return 1; - } + /* user is registered */ + ServerInstance->SendWhoisLine(source, dest, 307, "%s %s :is a registered nick", source->nick.c_str(), dest->nick.c_str()); } - if (target_type == TYPE_USER) + } + + + virtual void OnUserPostNick(User* user, const std::string &oldnick) + { + /* On nickchange, if they have +r, remove it */ + if (user->IsModeSet('r') && assign(user->nick) != oldnick) { - userrec* u = (userrec*)dest; - if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r'))) - { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server))) - { - // user is ulined, can speak regardless - return 0; - } - // user messaging a +R user and is not registered - Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user"); - return 1; - } + std::vector modechange; + modechange.push_back(user->nick); + modechange.push_back("-r"); + kludgeme = true; + ServerInstance->SendMode(modechange,user); + kludgeme = false; } - return 0; } - - virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text) + + virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list) { + if (!IS_LOCAL(user)) + return 0; + if (target_type == TYPE_CHANNEL) { - chanrec* c = (chanrec*)dest; - if ((c->IsCustomModeSet('M')) && (!strchr(user->modes,'r'))) + Channel* c = (Channel*)dest; + if ((c->IsModeSet('M')) && (!user->IsModeSet('r'))) { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server))) + if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server))) { // user is ulined, can speak regardless return 0; } - // user noticing a +M channel and is not registered - Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(c->name)+" :You need a registered nickname to speak on this channel"); + // user messaging a +M channel and is not registered + user->WriteNumeric(477, "%s %s :You need a registered nickname to speak on this channel", user->nick.c_str(), c->name.c_str()); return 1; } } if (target_type == TYPE_USER) { - userrec* u = (userrec*)dest; - if ((strchr(u->modes,'R')) && (!strchr(user->modes,'r'))) + User* u = (User*)dest; + if ((u->IsModeSet('R')) && (!user->IsModeSet('r'))) { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server))) + if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server))) { // user is ulined, can speak regardless return 0; } - // user noticing a +R user and is not registered - Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(u->nick)+" :You need a registered nickname to message this user"); + // user messaging a +R user and is not registered + user->WriteNumeric(477, "%s %s :You need a registered nickname to message this user", user->nick.c_str(), u->nick.c_str()); return 1; } } return 0; } - - virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname) + + virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list) + { + return OnUserPreMessage(user,dest,target_type,text,status, exempt_list); + } + + virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) { if (chan) { - if (chan->IsCustomModeSet('R')) + if (chan->IsModeSet('R')) { - if (!strchr(user->modes,'r')) + if (!user->IsModeSet('r')) { - if ((Srv->IsUlined(user->nick)) || (Srv->IsUlined(user->server))) + if ((ServerInstance->ULine(user->nick.c_str())) || (ServerInstance->ULine(user->server))) { // user is ulined, won't be stopped from joining return 0; } // joining a +R channel and not identified - Srv->SendServ(user->fd,"477 "+std::string(user->nick)+" "+std::string(chan->name)+" :You need a registered nickname to join this channel"); + user->WriteNumeric(477, "%s %s :You need a registered nickname to join this channel", user->nick.c_str(), chan->name.c_str()); return 1; } } @@ -198,42 +216,24 @@ class ModuleServices : public Module virtual ~ModuleServices() { - delete Srv; + kludgeme = true; + ServerInstance->Modes->DelMode(m1); + ServerInstance->Modes->DelMode(m2); + ServerInstance->Modes->DelMode(m3); + ServerInstance->Modes->DelMode(m4); + ServerInstance->Modes->DelMode(m5); + delete m1; + delete m2; + delete m3; + delete m4; + delete m5; } - - virtual Version GetVersion() - { - return Version(1,0,0,0,VF_STATIC|VF_VENDOR); - } - - virtual void OnUserConnect(userrec* user) - { - } - -}; - -class ModuleServicesFactory : public ModuleFactory -{ - public: - ModuleServicesFactory() - { - } - - ~ModuleServicesFactory() - { - } - - virtual Module * CreateModule() + virtual Version GetVersion() { - return new ModuleServices; + return Version(1,2,0,0,VF_COMMON|VF_VENDOR,API_VERSION); } - }; -extern "C" void * init_module( void ) -{ - return new ModuleServicesFactory; -} - +MODULE_INIT(ModuleServices)