Added OnChannelDelete() method (called on KICK, PART or QUIT where a channel is deleted for cleanup of metadata)

Added m_messageflood.so (not yet finished, do not use yet)


git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2826 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2006-01-22 15:51:06 +00:00
parent 9295960ea1
commit 02280596a0
5 changed files with 205 additions and 1 deletions

View File

@ -285,7 +285,7 @@ enum Implementation { I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUse
I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnStats, I_OnChangeLocalUserHost, I_OnChangeLocalUserGecos, I_OnLocalTopicChange,
I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnGlobalConnect, I_OnAddBan, I_OnDelBan,
I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
I_OnOperCompare };
I_OnOperCompare, I_OnChannelDelete };
/** Base class for all InspIRCd modules
* This class is the base class for InspIRCd modules. All modules must inherit from this class,
@ -340,6 +340,11 @@ class Module : public classbase
*/
virtual void OnUserDisconnect(userrec* user);
/** Called whenever a channel is deleted, either by QUIT, KICK or PART.
* @param chan The channel being deleted
*/
virtual void OnChannelDelete(chanrec* chan);
/** Called when a user joins a channel.
* The details of the joining user are available to you in the parameter userrec *user,
* and the details of the channel they have joined is available in the variable chanrec *channel

View File

@ -442,6 +442,7 @@ chanrec* del_channel(userrec *user, const char* cname, const char* reason, bool
if (iter != chanlist.end())
{
log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
delete Ptr;
chanlist.erase(iter);
}
@ -531,6 +532,7 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
if (iter != chanlist.end())
{
log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
delete Ptr;
chanlist.erase(iter);
}

View File

@ -979,7 +979,10 @@ void purge_empty_chans(userrec* u)
{
log(DEBUG,"del_channel: destroyed: %s",i2->second->name);
if (i2->second)
{
FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second));
delete i2->second;
}
chanlist.erase(i2);
purge++;
u->chans[i].channel = NULL;

View File

@ -298,6 +298,7 @@ void Module::OnDelQLine(userrec* source, std::string nickmask) { };
void Module::OnDelELine(userrec* source, std::string hostmask) { };
void Module::OnCleanup(int target_type, void* item) { };
void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; };
void Module::OnChannelDelete(chanrec* chan) { };
Priority Module::Prioritize() { return PRIORITY_DONTCARE; }
/* server is a wrapper class that provides methods to all of the C-style

View File

@ -0,0 +1,193 @@
/* +------------------------------------+
* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
* E-mail:
* <brain@chatspike.net>
* <Craig@chatspike.net>
*
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
* the file COPYING for details.
*
* ---------------------------------------------------
*/
using namespace std;
#include <stdio.h>
#include "users.h"
#include "channels.h"
#include "modules.h"
#include "helperfuncs.h"
/* $ModDesc: Provides channel mode +f (message flood protection) */
class floodsettings
{
bool ban;
int secs;
int lines;
floodsettings() : ban(0), secs(0), lines(0) {};
floodsettings(bool a, int b, int c) : ban(a), secs(b), lines(c) {};
}
class ModuleMsgFlood : public Module
{
Server *Srv;
public:
ModuleMsgFlood(Server* Me)
: Module::Module(Me)
{
Srv = Me;
Srv->AddExtendedMode('f',MT_CHANNEL,false,1,0);
}
virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
{
if ((modechar == 'f') && (type == MT_CHANNEL))
{
if (mode_on)
{
std::string FloodParams = params[0];
chanrec* c = (chanrec*)target;
char data[MAXBUF];
strlcpy(data,FloodParams.c_str(),MAXBUF);
char* lines = data;
char* secs = NULL;
bool ban = false;
if (*data == '*')
{
ban = true;
data++;
}
else
{
ban = false;
}
while (*data)
{
if (*data == ':')
{
*data = 0;
data++;
secs = data;
break;
}
else data++;
}
if (secs)
{
/* Set up the flood parameters for this channel */
int nlines = atoi(lines);
int nsecs = atoi(secs);
if ((nlines<1) || (nsecs<1))
{
WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
return 0;
}
else
{
if (!c->GetExt("flood"))
{
floodsettings *f = new floodsettings(ban,nlines,nsecs);
c->Extend("flood",(char*)f);
}
}
return 1;
}
else
{
WriteServ(user->fd,"608 %s %s :Invalid flood parameter",user->nick,c->name);
return 0;
}
}
else
{
if (c->GetExt("flood"))
{
floodsettings *f = (floodsettings*)c->GetExt("flood");
delete f;
c->Shrink("flood");
}
}
return 1;
}
return 0;
}
void OnChannelDelete(chanrec* chan)
{
if (c->GetExt("flood"))
{
floodsettings *f = (floodsettings*)c->GetExt("flood");
delete f;
c->Shrink("flood");
}
}
void Implements(char* List)
{
List[I_On005Numeric] = List[I_OnExtendedMode] = List[I_OnChannelDelete] = 1;
}
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=")
{
// By doing this we're *assuming* no other module has fucked up the CHANMODES=
// section of the 005 numeric. If they have, we're going DOWN in a blaze of glory,
// with a honking great EXCEPTION :)
temp1.insert(temp1.find(",")+1,"L");
}
temp2 = temp2 + temp1 + " ";
}
if (temp2.length())
output = temp2.substr(0,temp2.length()-1);
}
virtual ~ModuleMsgFlood()
{
}
virtual Version GetVersion()
{
return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
}
};
class ModuleMsgFloodFactory : public ModuleFactory
{
public:
ModuleMsgFloodFactory()
{
}
~ModuleMsgFloodFactory()
{
}
virtual Module * CreateModule(Server* Me)
{
return new ModuleMsgFlood(Me);
}
};
extern "C" void * init_module( void )
{
return new ModuleMsgFloodFactory;
}