summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd_list.cpp29
-rw-r--r--src/modules/m_safelist.cpp42
2 files changed, 59 insertions, 12 deletions
diff --git a/src/cmd_list.cpp b/src/cmd_list.cpp
index 920d77f34..78e586aab 100644
--- a/src/cmd_list.cpp
+++ b/src/cmd_list.cpp
@@ -25,22 +25,43 @@ extern "C" command_t* init_command(InspIRCd* Instance)
CmdResult cmd_list::Handle (const char** parameters, int pcnt, userrec *user)
{
+ int minusers = 0, maxusers = 0;
+
user->WriteServ("321 %s Channel :Users Name",user->nick);
/* Work around mIRC suckyness. YOU SUCK, KHALED! */
- if ((pcnt == 1) && (*parameters[0] == '<'))
- pcnt = 0;
+ if (pcnt == 1)
+ {
+ if (*parameters[0] == '<')
+ {
+ maxusers = atoi(parameters[0]+1);
+ pcnt = 0;
+ }
+ else if (*parameters[0] == '>')
+ {
+ minusers = atoi(parameters[0]+1);
+ pcnt = 0;
+ }
+ }
for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
{
// attempt to match a glob pattern
- if (pcnt && !match(i->second->name, parameters[0]))
+ long users = i->second->GetUserCounter();
+
+ bool too_few = (minusers && (users <= minusers));
+ bool too_many = (maxusers && (users >= maxusers));
+
+ if (too_many || too_few)
continue;
+
+ if (pcnt && (!match(i->second->name, parameters[0]) || (*i->second->topic && !match(i->second->topic, parameters[0]))))
+ continue;
+
// if the channel is not private/secret, OR the user is on the channel anyway
bool n = i->second->HasUser(user);
if ((i->second->modes[CM_PRIVATE]) && (!n))
{
- long users = i->second->GetUserCounter();
if (users)
user->WriteServ("322 %s *",user->nick,i->second->name);
}
diff --git a/src/modules/m_safelist.cpp b/src/modules/m_safelist.cpp
index 53d3e08f6..424d01256 100644
--- a/src/modules/m_safelist.cpp
+++ b/src/modules/m_safelist.cpp
@@ -27,9 +27,11 @@ class ListData : public classbase
long list_position;
bool list_ended;
const std::string glob;
+ int minusers;
+ int maxusers;
ListData() : list_start(0), list_position(0), list_ended(false) {};
- ListData(long pos, time_t t, const std::string &pattern) : list_start(t), list_position(pos), list_ended(false), glob(pattern) {};
+ ListData(long pos, time_t t, const std::string &pattern, int mi, int ma) : list_start(t), list_position(pos), list_ended(false), glob(pattern), minusers(mi), maxusers(ma) {};
};
/* $ModDesc: A module overriding /list, and making it safe - stop those sendq problems. */
@@ -92,6 +94,8 @@ class ModuleSafeList : public Module
*/
int HandleList(const char** parameters, int pcnt, userrec* user)
{
+ int minusers = 0, maxusers = 0;
+
if (global_listing >= LimitList)
{
user->WriteServ("NOTICE %s :*** Server load is currently too heavy. Please try again later.", user->nick);
@@ -111,8 +115,21 @@ class ModuleSafeList : public Module
}
/* Work around mIRC suckyness. YOU SUCK, KHALED! */
- if ((pcnt == 1) && (*parameters[0] == '<'))
- pcnt = 0;
+ if (pcnt == 1)
+ {
+ if (*parameters[0] == '<')
+ {
+ maxusers = atoi(parameters[0]+1);
+ ServerInstance->Log(DEBUG,"Max users: %d", maxusers);
+ pcnt = 0;
+ }
+ else if (*parameters[0] == '>')
+ {
+ minusers = atoi(parameters[0]+1);
+ ServerInstance->Log(DEBUG,"Min users: %d", minusers);
+ pcnt = 0;
+ }
+ }
time_t* last_list_time;
user->GetExt("safelist_last", last_list_time);
@@ -134,7 +151,7 @@ class ModuleSafeList : public Module
/*
* start at channel 0! ;)
*/
- ld = new ListData(0,ServerInstance->Time(), pcnt ? parameters[0] : "*");
+ ld = new ListData(0,ServerInstance->Time(), pcnt ? parameters[0] : "*", minusers, maxusers);
user->Extend("safelist_cache", ld);
time_t* llt = new time_t;
@@ -160,10 +177,20 @@ class ModuleSafeList : public Module
{
chan = ServerInstance->GetChannelIndex(ld->list_position);
bool has_user = (chan && chan->HasUser(user));
+ long users = chan ? chan->GetUserCounter() : 0;
+
+ bool too_few = (ld->minusers && (users <= ld->minusers));
+ bool too_many = (ld->maxusers && (users >= ld->maxusers));
+
+ if (chan && (too_many || too_few))
+ {
+ ld->list_position++;
+ continue;
+ }
+
if ((chan) && (chan->modes[CM_PRIVATE]))
{
- bool display = match(chan->name, ld->glob.c_str());
- long users = chan->GetUserCounter();
+ bool display = (match(chan->name, ld->glob.c_str()) || (*chan->topic && match(chan->topic, ld->glob.c_str())));
if ((users) && (display))
{
int counter = snprintf(buffer, MAXBUF, "322 %s *", user->nick);
@@ -173,8 +200,7 @@ class ModuleSafeList : public Module
}
else if ((chan) && (((!(chan->modes[CM_PRIVATE])) && (!(chan->modes[CM_SECRET]))) || (has_user)))
{
- bool display = match(chan->name, ld->glob.c_str());
- long users = chan->GetUserCounter();
+ bool display = (match(chan->name, ld->glob.c_str()) || (*chan->topic && match(chan->topic, ld->glob.c_str())));
if ((users) && (display))
{
int counter = snprintf(buffer, MAXBUF, "322 %s %s %ld :[+%s] %s",user->nick, chan->name, users, chan->ChanModes(has_user), chan->topic);