1 #ifndef INSPIRCD_LISTMODE_PROVIDER
2 #define INSPIRCD_LISTMODE_PROVIDER
11 #include "helperfuncs.h"
13 /* $ModDesc: Provides support for easily creating listmodes, stores the time set, the user, and a parameter. */
15 /* Updated to use the <banlist> config tag if it exists */
16 /* Written by Om <omster@gmail.com>, December 2005. */
17 /* Based on code previously written by Om - April 2005 */
18 /* Updated to new API July 8th 2006 by Brain */
19 /* Originally based on m_chanprotect and m_silence */
21 inline std::string stringtime()
23 std::ostringstream TIME;
43 // Just defining the type we use for the exception list here...
44 typedef std::vector<ListItem> modelist;
45 typedef std::vector<ListLimit> limitlist;
47 class ListModeBase : public ModeHandler
51 std::string listnumeric;
52 std::string endoflistnumeric;
53 std::string endofliststring;
59 ListModeBase(Server* serv, char modechar, const std::string &eolstr, const std::string &lnum, const std::string &eolnum) : ModeHandler(modechar, 1, 1, true, MODETYPE_CHANNEL, false)
62 Conf = new ConfigReader;
65 endoflistnumeric = eolnum;
66 endofliststring = eolstr;
68 infokey = "exceptionbase_mode_" + std::string(1, mode) + "_list";
71 virtual void DisplayList(userrec* user, chanrec* channel)
73 modelist* el = (modelist*)channel->GetExt(infokey);
76 for(modelist::iterator it = el->begin(); it != el->end(); it++)
78 WriteServ(user->fd, "%s %s %s %s %s %s", listnumeric.c_str(), user->nick, channel->name, it->mask.c_str(), it->nick.c_str(), it->time.c_str());
81 WriteServ(user->fd, "%s %s %s %s", endoflistnumeric.c_str(), user->nick, channel->name, endofliststring.c_str());
84 virtual void DoRehash()
87 Conf = new ConfigReader;
91 for(int i = 0; i < Conf->Enumerate("banlist"); i++)
93 // For each <banlist> tag
95 limit.mask = Conf->ReadValue("banlist", "chan", i);
96 limit.limit = Conf->ReadInteger("banlist", "limit", i, true);
98 if(limit.mask.size() && limit.limit > 0)
100 chanlimits.push_back(limit);
101 log(DEBUG, "m_exceptionbase.so: Read channel listmode limit of %u for mask '%s'", limit.limit, limit.mask.c_str());
105 log(DEBUG, "m_exceptionbase.so: Invalid tag");
108 if(chanlimits.size() == 0)
113 chanlimits.push_back(limit);
117 virtual void DoImplements(char* List)
119 List[I_OnChannelDelete] = List[I_OnSyncChannel] = List[I_OnCleanup] = List[I_OnRehash] = 1;
122 virtual ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
124 // Try and grab the list
125 modelist* el = (modelist*)channel->GetExt(infokey);
129 // If there was no list
134 channel->Extend(infokey, (char*)el);
138 ModeParser::CleanMask(parameter);
140 // Check if the item already exists in the list
141 for (modelist::iterator it = el->begin(); it != el->end(); it++)
143 if(parameter == it->mask)
145 // it does, deny the change
147 return MODEACTION_DENY;
151 unsigned int maxsize = 0;
153 for (limitlist::iterator it = chanlimits.begin(); it != chanlimits.end(); it++)
155 if (Srv->MatchText(channel->name, it->mask))
157 // We have a pattern matching the channel...
158 maxsize = el->size();
159 if (maxsize < it->limit)
161 // And now add the mask onto the list...
164 e.nick = source->nick;
165 e.time = stringtime();
168 return MODEACTION_ALLOW;
174 WriteServ(source->fd, "478 %s %s %s :Channel ban/ignore list is full", source->nick, channel->name, parameter.c_str());
176 return MODEACTION_DENY;
180 // We're taking the mode off
183 for (modelist::iterator it = el->begin(); it != el->end(); it++)
185 if(parameter == it->mask)
190 channel->Shrink(infokey);
193 return MODEACTION_ALLOW;
197 return MODEACTION_DENY;
201 // Hmm, taking an exception off a non-existant list, DIE
203 return MODEACTION_DENY;
206 return MODEACTION_DENY;
209 virtual std::string& GetInfoKey()
214 virtual void DoChannelDelete(chanrec* chan)
216 modelist* list = (modelist*)chan->GetExt(infokey);
220 chan->Shrink(infokey);
225 virtual void DoSyncChannel(chanrec* chan, Module* proto, void* opaque)
227 modelist* list = (modelist*)chan->GetExt(infokey);
230 for (modelist::iterator it = list->begin(); it != list->end(); it++)
232 proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, "+" + std::string(1, mode) + " " + it->mask);
237 virtual void DoCleanup(int target_type, void* item)
239 if (target_type == TYPE_CHANNEL)
241 chanrec* chan = (chanrec*)item;
243 modelist* list = (modelist*)chan->GetExt(infokey);
247 chan->Shrink(infokey);