summaryrefslogtreecommitdiff
path: root/src/modules/m_safelist.cpp
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:30:25 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-09-13 20:30:25 +0000
commit6d57bbe05c31c79eaad02fe81cfb9c1ed6b79c58 (patch)
treee0c89ed36b00f4c2925d7f39c32a835657b0fa6e /src/modules/m_safelist.cpp
parent7eea21b8d43b0d5993e88b62d9d4894c2af49303 (diff)
Change Extensible to use strongly typed entries
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11696 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules/m_safelist.cpp')
-rw-r--r--src/modules/m_safelist.cpp87
1 files changed, 25 insertions, 62 deletions
diff --git a/src/modules/m_safelist.cpp b/src/modules/m_safelist.cpp
index bd1a54110..127b5f304 100644
--- a/src/modules/m_safelist.cpp
+++ b/src/modules/m_safelist.cpp
@@ -37,19 +37,23 @@ class ModuleSafeList : public Module
size_t ServerNameSize;
int global_listing;
int LimitList;
+ SimpleExtItem<ListData> listData;
+ LocalIntExt listTime;
public:
- ModuleSafeList(InspIRCd* Me) : Module(Me)
+ ModuleSafeList(InspIRCd* Me) : Module(Me), listData("safelist_data", this), listTime("safelist_last", this)
{
OnRehash(NULL);
- Implementation eventlist[] = { I_OnBufferFlushed, I_OnPreCommand, I_OnCleanup, I_OnUserQuit, I_On005Numeric, I_OnRehash };
- ServerInstance->Modules->Attach(eventlist, this, 6);
+ Extensible::Register(&listData);
+ Extensible::Register(&listTime);
+ Implementation eventlist[] = { I_OnBufferFlushed, I_OnPreCommand, I_On005Numeric, I_OnRehash };
+ ServerInstance->Modules->Attach(eventlist, this, 4);
}
- virtual ~ModuleSafeList()
+ ~ModuleSafeList()
{
}
- virtual void OnRehash(User* user)
+ void OnRehash(User* user)
{
ConfigReader MyConf(ServerInstance);
ThrottleSecs = MyConf.ReadInteger("safelist", "throttle", "60", 0, true);
@@ -58,7 +62,7 @@ class ModuleSafeList : public Module
global_listing = 0;
}
- virtual Version GetVersion()
+ Version GetVersion()
{
return Version("$Id$",VF_VENDOR,API_VERSION);
}
@@ -68,7 +72,7 @@ class ModuleSafeList : public Module
* OnPreCommand()
* Intercept the LIST command.
*/
- virtual ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
+ ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
{
/* If the command doesnt appear to be valid, we dont want to mess with it. */
if (!validated)
@@ -99,8 +103,7 @@ class ModuleSafeList : public Module
}
/* First, let's check if the user is currently /list'ing */
- ListData *ld;
- user->GetExt("safelist_cache", ld);
+ ListData *ld = listData.get(user);
if (ld)
{
@@ -125,32 +128,21 @@ class ModuleSafeList : public Module
}
}
- time_t* last_list_time;
- user->GetExt("safelist_last", last_list_time);
- if (last_list_time)
+ time_t last_list_time = listTime.get(user);
+ if (last_list_time && ServerInstance->Time() < last_list_time + ThrottleSecs)
{
- if (ServerInstance->Time() < (*last_list_time)+ThrottleSecs)
- {
- user->WriteServ("NOTICE %s :*** Woah there, slow down a little, you can't /LIST so often!",user->nick.c_str());
- user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
- user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
- return MOD_RES_DENY;
- }
-
- delete last_list_time;
- user->Shrink("safelist_last");
+ user->WriteServ("NOTICE %s :*** Woah there, slow down a little, you can't /LIST so often!",user->nick.c_str());
+ user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
+ user->WriteNumeric(323, "%s :End of channel list.",user->nick.c_str());
+ return MOD_RES_DENY;
}
-
/*
* start at channel 0! ;)
*/
ld = new ListData(0,ServerInstance->Time(), (pcnt && (parameters[0][0] != '<' && parameters[0][0] != '>')) ? parameters[0] : "*", minusers, maxusers);
- user->Extend("safelist_cache", ld);
-
- time_t* llt = new time_t;
- *llt = ServerInstance->Time();
- user->Extend("safelist_last", llt);
+ listData.set(user, ld);
+ listTime.set(user, ServerInstance->Time());
user->WriteNumeric(321, "%s Channel :Users Name",user->nick.c_str());
@@ -159,11 +151,11 @@ class ModuleSafeList : public Module
return MOD_RES_DENY;
}
- virtual void OnBufferFlushed(User* user)
+ void OnBufferFlushed(User* user)
{
char buffer[MAXBUF];
- ListData* ld;
- if (user->GetExt("safelist_cache", ld))
+ ListData* ld = listData.get(user);
+ if (ld)
{
Channel* chan = NULL;
unsigned long amount_sent = 0;
@@ -228,46 +220,17 @@ class ModuleSafeList : public Module
while ((chan != NULL) && (amount_sent < (user->MyClass->GetSendqMax() / 4)));
if (ld->list_ended)
{
- user->Shrink("safelist_cache");
- delete ld;
- global_listing--;
- }
- }
- }
-
- virtual void OnCleanup(int target_type, void* item)
- {
- if(target_type == TYPE_USER)
- {
- User* u = (User*)item;
- ListData* ld;
- u->GetExt("safelist_cache", ld);
- if (ld)
- {
- u->Shrink("safelist_cache");
- delete ld;
+ listData.unset(user);
global_listing--;
}
- time_t* last_list_time;
- u->GetExt("safelist_last", last_list_time);
- if (last_list_time)
- {
- delete last_list_time;
- u->Shrink("safelist_last");
- }
}
}
- virtual void On005Numeric(std::string &output)
+ void On005Numeric(std::string &output)
{
output.append(" SAFELIST");
}
- virtual void OnUserQuit(User* user, const std::string &message, const std::string &oper_message)
- {
- this->OnCleanup(TYPE_USER,user);
- }
-
};
MODULE_INIT(ModuleSafeList)