m_nonicks.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00018 class NoNicks : public ModeHandler
00019 {
00020 public:
00021 NoNicks(InspIRCd* Instance) : ModeHandler(Instance, 'N', 0, 0, false, MODETYPE_CHANNEL, false) { }
00022
00023 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
00024 {
00025 if (adding)
00026 {
00027 if (!channel->IsModeSet('N'))
00028 {
00029 channel->SetMode('N',true);
00030 return MODEACTION_ALLOW;
00031 }
00032 }
00033 else
00034 {
00035 if (channel->IsModeSet('N'))
00036 {
00037 channel->SetMode('N',false);
00038 return MODEACTION_ALLOW;
00039 }
00040 }
00041
00042 return MODEACTION_DENY;
00043 }
00044 };
00045
00046 class ModuleNoNickChange : public Module
00047 {
00048 NoNicks* nn;
00049 public:
00050 ModuleNoNickChange(InspIRCd* Me) : Module(Me)
00051 {
00052
00053 nn = new NoNicks(ServerInstance);
00054 ServerInstance->Modes->AddMode(nn);
00055 Implementation eventlist[] = { I_OnUserPreNick, I_On005Numeric };
00056 ServerInstance->Modules->Attach(eventlist, this, 2);
00057 }
00058
00059 virtual ~ModuleNoNickChange()
00060 {
00061 ServerInstance->Modes->DelMode(nn);
00062 delete nn;
00063 }
00064
00065 virtual Version GetVersion()
00066 {
00067 return Version("$Id: m_nonicks.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_COMMON | VF_VENDOR, API_VERSION);
00068 }
00069
00070
00071 virtual void On005Numeric(std::string &output)
00072 {
00073 ServerInstance->AddExtBanChar('N');
00074 }
00075
00076 virtual int OnUserPreNick(User* user, const std::string &newnick)
00077 {
00078 if (!IS_LOCAL(user))
00079 return 0;
00080
00081 if (isdigit(newnick[0]))
00082 return 0;
00083
00084 for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
00085 {
00086 Channel* curr = i->first;
00087
00088 if (CHANOPS_EXEMPT(ServerInstance, 'N') && curr->GetStatus(user) == STATUS_OP)
00089 continue;
00090
00091 if (curr->IsModeSet('N') || curr->IsExtBanned(user, 'N'))
00092 {
00093 user->WriteNumeric(ERR_CANTCHANGENICK, "%s :Can't change nickname while on %s (+N is set)", user->nick.c_str(), curr->name.c_str());
00094 return 1;
00095 }
00096 }
00097
00098 return 0;
00099 }
00100 };
00101
00102 MODULE_INIT(ModuleNoNickChange)