Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: cs_autolimit and dropped channel  (Read 5673 times)

0 Members and 1 Guest are viewing this topic.

CrazyCat

  • Anope User
  • Offline Offline
  • Posts: 241
    • French Eggdrop community
cs_autolimit and dropped channel
« on: January 10, 2012, 09:18:00 AM »

Hello there,

I've a funny bug with cs_autolimit:
I had a channel #dune, autolimit setted on it. I drop the channel, but the autolimit stay. So, look at this log:
Quote
10:15:02 --> CrazyCat (felinus@g33k-zone.org) a rejoint #dune
10:15:02 -- Mode #dune [+nt] par crazycat.zeolia.net
10:15:02 -- Pseudos #dune: [@CrazyCat]
10:15:02 -- Canal #dune: 1 pseudo (1 op, 0 halfop, 0 voice, 0 normal)
10:15:02 -- Mode #dune [+l 3] par ChanServ
10:15:04 -- Canal créé le mar., 10 janv. 2012 10:15:01
10:15:19 -- Mode #dune [+l 4] par [Guru]
10:15:26 -- Mode #dune [+l 3] par ChanServ
10:15:36 -- Mode #dune [+l 4] par [Guru]
10:15:52 -- Mode #dune [+l 3] par ChanServ
10:16:01 -- Mode #dune [+l 4] par [Guru]
***********
10:17:03  Zeolia -- MSG(chanserv): autolimit #dune del
10:17:03  Zeolia -- ChanServ (services@zeolia.net): Channel #dune isnt registered
10:17:35  Zeolia -- MSG(chanserv): autolimit list
10:17:35  Zeolia -- ChanServ (services@zeolia.net): AutoLimits:
10:17:35  Zeolia -- ChanServ (services@zeolia.net): Channel: #dune [5:2]
Funny, isn't it ?

So, if you use cs_autolimit too, think to del the setting before drop the channel
« Last Edit: January 10, 2012, 09:19:44 AM by CrazyCat »
Logged

katsklaw

  • Supporter
  • Anope User
  • Offline Offline
  • Posts: 537
Re: cs_autolimit and dropped channel
« Reply #1 on: January 10, 2012, 10:38:32 PM »

Looks like a bug in the module, you'll likely have to contact the module author.
Logged

CrazyCat

  • Anope User
  • Offline Offline
  • Posts: 241
    • French Eggdrop community
Re: cs_autolimit and dropped channel
« Reply #2 on: January 11, 2012, 02:39:33 PM »

I'll do. And also try to find the correction to add to the module :)

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: cs_autolimit and dropped channel
« Reply #3 on: January 11, 2012, 02:47:35 PM »

just needs a hook for EVENT_CHAN_EXPIRE and EVENT_CHAN_DROP.. look at any well written module that stores channel that in its own internal db.. they should all have it. (eg: bs_fantasy_karma)  ::)
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)

CrazyCat

  • Anope User
  • Offline Offline
  • Posts: 241
    • French Eggdrop community
Re: cs_autolimit and dropped channel
« Reply #4 on: January 13, 2012, 03:27:43 PM »

Thanks for the example, I'll follow it.

CrazyCat

  • Anope User
  • Offline Offline
  • Posts: 241
    • French Eggdrop community
Re: cs_autolimit and dropped channel
« Reply #5 on: January 15, 2012, 02:16:04 PM »

Hello there,

I don't know how to contact CyberWarrior, I can't spend my time on his irc network waiting for him and I don't know his nick here.
So, here is my small contribution to cs_autolimit.c :
Code: [Select]
#define AutoLimit_DB "cs_autolimit.db"                //you may want to modify it (or not)

//////////////////////////////////////////////////////////////////////////////////////////
/****************************************************************************************/
/*                                                                                      */
/*  What does it do:                                                                    */
/*    basicly it increases the channel limit every X seconds by Y (lookie help for set) */
/*    kinda usefull for flood protection and whatever u want it for                     */
/*                                                                                      */
/*  Tested on:                                                                          */
/*    -anope 1.6.2 with an heavily modified ultimate ircd version                       */
/*    -in use on abjects since feb 3rd 2008                                             */
/*                                                                                      */
/*  TODO:                                                                               */
/*    -no clue                                                                          */
/*                                                                                      */
/*  Changelog:                                                                          */
/*    v1.1.5                                                                            */
/*      -added settings remove on chan dropped by CrazyCat AT c-p-f.org                 */
/*    v1.1.4                                                                            */
/*      -increased limits                                                               */
/*      -added AUTOLIMIT HELP (blame drak)                                              */
/*    v1.1.3                                                                            */
/*      -fixed a bug in the dlink engine (bla)                                          */
/*    v1.1.2                                                                            */
/*      -fixed a bug in the dlink engine                                                */
/*    v1.1.1                                                                            */
/*      -fixed a bug in the dlink engine                                                */
/*      -added some limits                                                              */
/*    v1.1.0                                                                            */
/*      -db support added                                                               */
/*      -list added                                                                     */
/*    v1.0.2                                                                            */
/*      -not using SJOIN msg anymore                                                    */
/*    v1.0.1                                                                            */
/*      -show, set and del added                                                        */
/*      -help added                                                                     */
/*    v1.0.0                                                                            */
/*      -basic engine done                                                              */
/*                                                                                      */
/****************************************************************************************/
//////////////////////////////////////////////////////////////////////////////////////////

#include "module.h"

#define AUTHOR "CyberWarrior @ irc.Abjects.net"
#define VERSION "1.1.5"

void autolimit_help(User *u);
int load_settings();
int save_settings();
int autolimit_help_full(User *u);
int autolimit_doset(int ac, char **av);
int autolimit_drop(int ac, char **av);
void autolimit_dodrop(char *chan);
int cs_autolimit(User * u);

typedef struct autolimit_ AutoLimit;

struct autolimit_ {
AutoLimit *prev, *next;
long int OldTS;
long int wait_time;
unsigned long inc_limit;
char channame[CHANMAX];
};

AutoLimit first_entry;

int AnopeInit(int argc, char **argv) {
Command *c;
EvtHook *hook;
int error1 = 0, error2 = 0;
first_entry.next = 0;
c = createCommand("AutoLimit", cs_autolimit, NULL, -1, -1, -1, -1, -1);
error2 = moduleAddCommand(CHANSERV, c, MOD_HEAD);
alog("cs_autolimit.so: Add Command 'AutoLimit' Status: %d",  error2);
if ((error1 != MOD_ERR_OK) || (error2 != MOD_ERR_OK)) {
alog("cs_autolimit.so: Error appeared!!! MOD_STOP");
return MOD_STOP;
}
load_settings();
moduleAddAuthor(AUTHOR);
moduleAddVersion(VERSION);
moduleAddHelp(c, autolimit_help_full);
moduleSetChanHelp(autolimit_help);
moduleAddCallback("AutoLimit", time(NULL) + 1, autolimit_doset, 0, 0);
hook = createEventHook(EVENT_CHAN_DROP, autolimit_drop);
if (moduleAddEventHook(hook) != MOD_ERR_OK) {
alog("cs_autolimit.so: Can't hook to EVENT_CHAN_DROP event.");
return MOD_STOP;
}
hook = createEventHook(EVENT_CHAN_EXPIRE, autolimit_drop);
if (moduleAddEventHook(hook) != MOD_ERR_OK) {
alog("cs_autolimit.so: Can't hook to EVENT_CHAN_EXPIRE event.");
return MOD_STOP;
}
return MOD_CONT;
}

void AnopeFini(void) {
AutoLimit *p, *p2;
save_settings();
p = first_entry.next;
while (p) {
send_cmd(s_ChanServ, "MODE %s -l", p->channame);
p2 = p;
p = p->next;
free(p2);
}
alog("cs_autolimit.so: Module unloaded");
}

void autolimit_help(User *u) {
notice(s_ChanServ,u->nick,"    AUTOLIMIT   Automaticly increases the Channel limit");
}

int autolimit_help_full(User *u) {
notice(s_ChanServ,u->nick,"Syntax: AUTOLIMIT <channel> <command>");
notice(s_ChanServ,u->nick,"  Commands:");
notice(s_ChanServ,u->nick,"    DEL          Delete AutoLimit");
notice(s_ChanServ,u->nick,"    SHOW         Shows Current Settings");
notice(s_ChanServ,u->nick,"    SET seconds:limit");
notice(s_ChanServ,u->nick,"      seconds == seconds between update changes (1-300)");
notice(s_ChanServ,u->nick,"      limit == limit to set (1-500) (will be increased to channel count)");
if (is_services_admin(u)) {
notice(s_ChanServ,u->nick," ");
notice(s_ChanServ,u->nick,"  Service Admin Commands:");
notice(s_ChanServ,u->nick,"    AUTOLIMIT LIST         Lists all entries");
}
return MOD_CONT;
}

AutoLimit *FindEntry(char *chan) {
AutoLimit *p;
for (p = first_entry.next; p; p = p->next) {
if (stricmp(p->channame, chan) == 0) {
break;
}
}
return p;
}

int cs_autolimit(User * u) {
AutoLimit *p;
char *chan = NULL;
char *cmd = NULL;
char *cmd2 = NULL;
char *p1;
long int wait_time = 0;
unsigned long inc_limit = 0;
Channel *c;
ChannelInfo *ci;
chan = strtok(NULL, " ");
if (!chan) {
notice(s_ChanServ,u->nick,"not enough parameters");
} else if (stricmp(chan, "LIST") == 0) {
if (is_services_admin(u)) {
notice(s_ChanServ,u->nick,"AutoLimits:");
for (p = first_entry.next; p; p = p->next) {
notice(s_ChanServ,u->nick,"Channel: %s [%u:%u]", p->channame, (unsigned int)p->wait_time, (unsigned int)p->inc_limit);
}
}
} else if (stricmp(chan, "HELP") == 0) {
autolimit_help_full(u);
} else if (!(c = findchan(chan))) {
notice(s_ChanServ,u->nick,"Channel %s doesnt exist", chan);
} else if (!(ci = c->ci)) {
notice(s_ChanServ,u->nick,"Channel %s isnt registered", chan);
} else if (!is_services_admin(u) && !check_access(u, ci, CA_AKICK)) {
notice(s_ChanServ,u->nick,"You dont have enough access to do this");
} else {
cmd = strtok(NULL, " ");
if (!cmd) {
notice(s_ChanServ,u->nick,"not enough parameters");
} else if (stricmp(cmd, "SET") == 0) {
cmd2 = strtok(NULL, " ");
if (!cmd2) {
notice(s_ChanServ,u->nick,"not enough parameters");
} else {
p1 = strstr(cmd2, ":");
if (!p1) {
notice(s_ChanServ,u->nick,"not enough parameters");
} else {
*p1 = 0;
p1++;
wait_time = atol(cmd2);
if ((wait_time > 300) || (wait_time < 1)) {
notice(s_ChanServ,u->nick,"Seconds must be between 1 and 300");
return MOD_CONT;
}
if (wait_time > 20)
notice(s_ChanServ,u->nick,"WARNING: Long update times can lock up your channel on splits!");
inc_limit = atol(p1);
if ((inc_limit > 500) || (inc_limit < 1)) {
notice(s_ChanServ,u->nick,"limit must be between 1 and 500");
return MOD_CONT;
}
if (!(p = FindEntry(chan))) {
p = malloc(sizeof(AutoLimit));
if (p) {
p->next = first_entry.next;
first_entry.next = p;
strcpy(p->channame, chan);
p->OldTS = 0;
p->prev = 0;
if (p->next)
p->next->prev = p;
}
}
if (p) {
p->wait_time = wait_time;
p->inc_limit = inc_limit;
notice(s_ChanServ,u->nick,"AutoLimit for %s set to increase limit every %u seconds by %u", chan, (unsigned int)p->wait_time, (unsigned int)p->inc_limit);
save_settings();
} else {
notice(s_ChanServ,u->nick,"Some error that shouldnt happen just appeared!");
}
}
}
} else if (stricmp(cmd, "DEL") == 0) {
if ((p = FindEntry(chan))) {
    autolimit_dodrop(chan);
notice(s_ChanServ,u->nick,"AutoLimit for %s removed", chan);
} else {
notice(s_ChanServ,u->nick,"Cant find an AutoLimit for %s", chan);
}
} else if (stricmp(cmd, "SHOW") == 0) {
if ((p = FindEntry(chan))) {
notice(s_ChanServ,u->nick,"AutoLimit for %s will increase channel limit every %u seconds by %u", chan, (unsigned int)p->wait_time, (unsigned int)p->inc_limit);
} else {
notice(s_ChanServ,u->nick,"No AutoLimit Set");
}
} else {
notice(s_ChanServ,u->nick,"Not Enough Params");
}
}
return MOD_CONT;
}

int autolimit_drop(int ac, char **av) {
   autolimit_dodrop(av[0]);
   return MOD_CONT;
}

void autolimit_dodrop(char *chan) {
   AutoLimit *p;
   if ((p = FindEntry(chan))) {
      send_cmd(s_ChanServ, "MODE %s -l", p->channame);
if (p->next) {
   p->next->prev = p->prev;
} else {
if (p->prev)
   p->prev->next = 0;
}
if (p->prev) {
p->prev->next = p->next;
} else {
first_entry.next = p->next;
if (p->next)
p->next->prev = 0;
}
free(p);
save_settings();
}
}

int autolimit_doset(int ac, char **av) {
AutoLimit *p;
Channel *c;
ChannelInfo *ci = 0;
BotInfo *bi = 0;
moduleAddCallback("AutoLimit", time(NULL) + 1, autolimit_doset, 0, 0);
if (first_entry.next == 0)
return MOD_CONT;
for (p = first_entry.next; p; p = p->next) {
if (p->OldTS < (long int)time(NULL)) {
c = findchan(p->channame);
if (c) {
ci = c->ci;
if (ci)
bi = ci->bi;
p->OldTS = (long int)time(NULL) + p->wait_time;
if (bi)
send_cmd(bi->nick, "MODE %s +l %u", p->channame, (unsigned short)((c->usercount + p->inc_limit + 1) & 0xFFFF));
else
send_cmd(s_ChanServ, "MODE %s +l %u", p->channame, (unsigned short)((c->usercount + p->inc_limit) & 0xFFFF));
}
}
}
return MOD_CONT;
}

int save_settings() {
FILE *fp;
char DB_HEADER[12];
AutoLimit *p;
strcpy(DB_HEADER, "AutoLimit1");
if ((fp = fopen(AutoLimit_DB, "wb")) != NULL) {
fwrite(DB_HEADER, 12, 1, fp);
for (p = first_entry.next; p; p = p->next) {
fwrite(&(p->wait_time), sizeof(long int), 1, fp);
fwrite(&(p->inc_limit), sizeof(unsigned long), 1, fp);
fwrite(p->channame, CHANMAX, 1, fp);
}
fclose(fp);
return 1;
}
alog("cs_autolimit.so: Unable to save DataBase!");
return 0;
}

int load_settings() {
FILE *fp = 0;
char DB_HEADER[12];
AutoLimit *p;
DB_HEADER[12] = 0;
if ((fp = fopen(AutoLimit_DB, "rb")) != NULL) {
fread(DB_HEADER, 12, 1, fp);
if (0 == strcmp(DB_HEADER, "AutoLimit1")) {
while (1) {
p = malloc(sizeof(AutoLimit));
if (p) {
fread(&(p->wait_time), sizeof(long int), 1, fp);
fread(&(p->inc_limit), sizeof(unsigned long), 1, fp);
if (!fread(p->channame, CHANMAX, 1, fp)) {
free(p);
fclose(fp);
alog("cs_autolimit.so: DataBase loaded!");
return 1;
}
p->next = first_entry.next;
first_entry.next = p;
p->OldTS = 0;
p->prev = 0;
if (p->next)
p->next->prev = p;
} else {
break;
}
}
}
}
if (fp)
fclose(fp);
alog("cs_autolimit.so: Unable to load DataBase!");
return 0;
}
I hope it'll be usefull
Pages: [1]   Go Up