+++ /dev/null
-@include@ @includel@../build.mk@includel@
-
-.PHONY: all
-all: chansearch.so
-
-chansearch.so: chansearch.o
+++ /dev/null
-#include "chansearch.h"
-#include "../parser/parser.h"
-#include "../nick/nick.h"
-#include "../channel/channel.h"
-#include "../control/control.h"
-#include "../lib/flags.h"
-#include "../lib/irc_string.h"
-#include "../lib/version.h"
-
-#include <stdio.h>
-
-MODULE_VERSION("");
-
-#define MAXTERMS 10
-#define MAXMATCHES 500
-
-CommandTree *searchfilters;
-CommandTree *outputfilters;
-
-typedef struct modeflags {
- flag_t setflags;
- flag_t clearflags;
-} modeflags;
-
-void cs_describe(nick *sender, chanindex *cip);
-void cs_desctopic(nick *sender, chanindex *cip);
-void cs_descservices(nick *sender, chanindex *cip);
-int cs_exists(void *chan, int cargc, char **cargv);
-int cs_services(void *chan, int cargc, char **cargv);
-int cs_nick(void *chan, int cargc, char **cargv);
-int cs_size(void *chan, int cargc, char **cargv);
-int cs_namelen(void *chan, int cargc, char **cargv);
-int cs_modes(void *chan, int cargc, char **cargv);
-int cs_name(void *chan, int cargc, char **cargv);
-int cs_topic(void *source, int cargc, char **cargv);
-int cs_oppct(void *source, int cargc, char **cargv);
-int cs_hostpct(void *source, int cargc, char **cargv);
-int cs_authedpct(void *source, int cargc, char **cargv);
-
-int dochansearch(void *source, int cargc, char **cargv);
-
-void _init() {
- searchfilters=newcommandtree();
- outputfilters=newcommandtree();
-
- regchansearchfunc("name", 1, cs_name);
- regchansearchfunc("exists", 0, cs_exists);
- regchansearchfunc("services", 1, cs_services);
- regchansearchfunc("nick", 1, cs_nick);
- regchansearchfunc("size", 1, cs_size);
- regchansearchfunc("namelen", 1, cs_namelen);
- regchansearchfunc("modes", 1, cs_modes);
- regchansearchfunc("topic", 1, cs_topic);
- regchansearchfunc("oppercent", 1, cs_oppct);
- regchansearchfunc("uniquehostpct", 1, cs_hostpct);
- regchansearchfunc("authedpct", 1, cs_authedpct);
-
- regchansearchdisp("default", cs_describe);
- regchansearchdisp("topic", cs_desctopic);
- regchansearchdisp("services", cs_descservices);
-
- registercontrolhelpcmd("chansearch",NO_OPER,19,&dochansearch,"Usage: chansearch <criteria>\nSearches for channels with specified criteria.\nSend chanstats with no arguments for more information.");
-}
-
-void _fini() {
- unregchansearchfunc("name", cs_name);
- unregchansearchfunc("exists", cs_exists);
- unregchansearchfunc("services", cs_services);
- unregchansearchfunc("nick", cs_nick);
- unregchansearchfunc("size", cs_size);
- unregchansearchfunc("namelen", cs_namelen);
- unregchansearchfunc("modes", cs_modes);
- unregchansearchfunc("topic", cs_topic);
- unregchansearchfunc("oppercent", cs_oppct);
- unregchansearchfunc("uniquehostpct", cs_hostpct);
- unregchansearchfunc("authedpct", cs_authedpct);
-
- unregchansearchdisp("default", cs_describe);
- unregchansearchdisp("topic", cs_desctopic);
- unregchansearchdisp("services", cs_descservices);
-
- deregistercontrolcmd("chansearch",&dochansearch);
- destroycommandtree(searchfilters);
- destroycommandtree(outputfilters);
-}
-
-void regchansearchfunc(const char *name, int args, CommandHandler handler) {
- addcommandtotree(searchfilters, name, 0, args, handler);
-}
-
-void unregchansearchfunc(const char *name, CommandHandler handler) {
- deletecommandfromtree(searchfilters, name, handler);
-}
-
-void regchansearchdisp(const char *name, DisplayFunc handler) {
- addcommandtotree(outputfilters, name, 0, 0, (CommandHandler)handler);
-}
-
-void unregchansearchdisp(const char *name, DisplayFunc handler) {
- deletecommandfromtree(outputfilters, name, (CommandHandler)handler);
-}
-
-int dochansearch(void *source, int cargc, char **cargv) {
- nick *sender=(nick *)source;
- filter terms[MAXTERMS];
- int i,j;
- int numterms=0;
- Command *mc;
- chanindex *cip;
- int matched=0;
- int offset;
- int res;
- char *ch;
- int limit=MAXMATCHES;
- DisplayFunc df=cs_describe;
-
- i=0;
- if (cargc>0 && cargv[0][0]=='-') {
- /* We have options, parse them */
- i++;
- for (ch=cargv[0];*ch;ch++) {
- switch(*ch) {
- case 'l': limit=strtol(cargv[i++],NULL,10);
- break;
-
- case 'd': if ((mc=findcommandintree(outputfilters,cargv[i],1))==NULL) {
- controlreply(sender, "Invalid display format %s",cargv[i]);
- return CMD_ERROR;
- } else {
- df=(DisplayFunc)(mc->handler);
- }
- i++;
- break;
- }
- if (i>=cargc) {
- break;
- }
- }
- }
-
- if (i>=cargc) {
- Command *cmdlist[100];
- int i,n,bufpos,j;
- char buf[200];
-
- controlreply(sender,"Usage: chansearch [options] (search terms)");
- controlreply(sender," Note that all options must be bundled together (-ld 5 default not -l 5 -d default)");
- controlreply(sender," Current valid options:");
- controlreply(sender," -l <number> Set maximum number of results to return");
- controlreply(sender," -d <format> Set output display format");
-
- /* Get list of display formats */
-
- bufpos=0;
-
- n=getcommandlist(outputfilters,cmdlist,100);
- for (i=0;i<n;i++) {
- for (j=0;j<cmdlist[i]->command->length;j++) {
- buf[bufpos++]=ToLower(cmdlist[i]->command->content[j]);
- }
- if (i<(n-1)) {
- bufpos+=sprintf(&buf[bufpos],", ");
- }
- if (bufpos>180) {
- bufpos+=sprintf(&buf[bufpos]," ...");
- break;
- }
- }
-
- buf[bufpos]='\0';
-
- controlreply(sender," Valid display formats: %s",buf);
-
- /* Get list of search terms */
-
- bufpos=0;
-
- n=getcommandlist(searchfilters,cmdlist,100);
- for (i=0;i<n;i++) {
- for (j=0;j<cmdlist[i]->command->length;j++) {
- buf[bufpos++]=ToLower(cmdlist[i]->command->content[j]);
- }
- if (i<(n-1)) {
- bufpos+=sprintf(&buf[bufpos],", ");
- }
- if (bufpos>180) {
- bufpos+=sprintf(&buf[bufpos]," ...");
- break;
- }
- }
- buf[bufpos]='\0';
-
- controlreply(sender," Valid search terms: %s",buf);
- controlreply(sender," Terms can be inverted with !");
- return CMD_OK;
- }
-
- for (;i<cargc;) {
- if (cargv[i][0]=='!') {
- offset=1;
- terms[numterms].invert=1;
- } else {
- offset=0;
- terms[numterms].invert=0;
- }
- terms[numterms].mallocarg=0;
-
- /* Do some sanity checking. Note that the "goto"s allows memory
- * to be freed if successful filters have already allocated some */
- if ((mc=findcommandintree(searchfilters, &cargv[i][offset], 1))==NULL) {
- controlreply(sender,"Unrecognised search term: %s",cargv[i]);
- goto abort;
- }
- if ((cargc-i-1) < mc->maxparams) {
- controlreply(sender,"Not enough arguments supplied for %s",cargv[i]);
- goto abort;
- }
-
- /* Call the setup function. This should fill in the function and argument in the structure */
- if ((mc->handler)((void *)&terms[numterms],mc->maxparams,cargv+i+1)) {
- controlreply(sender,"Error setting up filter: %s",cargv[i]);
- goto abort;
- }
- i+=(mc->maxparams+1);
- numterms++;
-
- if (numterms==MAXTERMS)
- break;
- }
-
- controlreply(sender,"The following channels match your criteria:");
-
- for(i=0;i<CHANNELHASHSIZE;i++) {
- for(cip=chantable[i];cip;cip=cip->next) {
- for(j=0;j<numterms;j++) {
- res=(terms[j].sf)(cip,terms[j].arg);
- if (res==0 && terms[j].invert)
- break;
- if (res==1 && !terms[j].invert)
- break;
- }
- if (j==numterms) {
- if (matched == limit) {
- controlreply(sender,"--- More than %d matches found, truncating list.",limit);
- }
- if (matched < limit) {
- (df)(sender, cip);
- }
- matched++;
- }
- }
- }
-
- if (matched==0) {
- controlreply(sender,"--- No matches found.");
- } else {
- controlreply(sender,"--- End of list: %d match(es).",matched);
- }
-
- /* GOTO target: here we just free the args if any were malloc()d */
-abort:
- for (i=0;i<numterms;i++) {
- if (terms[i].mallocarg) {
- free(terms[i].arg);
- }
- }
-
- return CMD_OK;
-}
-
-
-/* Name search execute function: call match2strings */
-int cs_nameexe(chanindex *cip, void *arg) {
- char *pattern=(char *)arg;
-
- return !match2strings(pattern, cip->name->content);
-}
-
-/* Name search setup function: fill in the struct */
-
-int cs_name(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
-
- thefilter->sf=cs_nameexe;
- thefilter->arg=(char *)cargv[0];
-
- return 0;
-}
-
-int cs_topicexe(chanindex *cip, void *arg) {
- char *pattern=(char *)arg;
-
- return ((cip->channel==NULL) ||
- (cip->channel->topic==NULL) ||
- (!match2strings(pattern, cip->channel->topic->content)));
-}
-
-int cs_topic(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
-
- thefilter->sf=cs_topicexe;
- thefilter->arg=(void *)cargv[0];
-
- return 0;
-}
-
-/* services - matches if the specified number of services are in the channel */
-
-int cs_servicesexe(chanindex *cip, void *arg) {
- nick *np;
- int i;
- long count=(long)arg;
-
- if (cip->channel==NULL)
- return 1;
-
- for(i=0;i<cip->channel->users->hashsize;i++) {
- if (cip->channel->users->content[i]==nouser)
- continue;
-
- if (!(np=getnickbynumeric(cip->channel->users->content[i])))
- continue;
-
- if (IsService(np) && !--count)
- return 0;
- }
-
- return 1;
-}
-
-int cs_services(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
-
- thefilter->sf=cs_servicesexe;
- thefilter->arg=(void *)strtoul(cargv[0],NULL,10);
-
- return 0;
-}
-
-int cs_existsexe(chanindex *cip, void *arg) {
- return (cip->channel==NULL);
-}
-
-int cs_exists(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
-
- thefilter->sf=cs_existsexe;
- thefilter->arg=NULL;
-
- return 0;
-}
-
-int cs_nickexe(chanindex *cip, void *arg) {
- nick *np=(nick *)arg;
-
- return ((cip->channel==NULL) ||
- (getnumerichandlefromchanhash(cip->channel->users, np->numeric)==NULL));
-}
-
-int cs_nick(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
- nick *np;
-
- if ((np=getnickbynick(cargv[0]))==NULL) {
- return 1;
- }
-
- thefilter->sf=cs_nickexe;
- thefilter->arg=(void *)np;
-
- return 0;
-}
-
-int cs_sizeexe(chanindex *cip, void *arg) {
- long lim=(long)arg;
-
- return ((cip->channel==NULL) ||
- (cip->channel->users->totalusers < lim));
-}
-
-int cs_size(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
-
- thefilter->sf=cs_sizeexe;
- thefilter->arg=(void *)strtol(cargv[0],NULL,10);
-
- return 0;
-}
-
-int cs_namelenexe(chanindex *cip, void *arg) {
- long lim=(long)arg;
-
- return (cip->name->length < lim);
-}
-
-int cs_namelen(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
-
- thefilter->sf=cs_namelenexe;
- thefilter->arg=(void *)strtol(cargv[0],NULL,10);
-
- return 0;
-}
-
-int cs_oppctexe(chanindex *cip, void *arg) {
- long percent=(long)arg;
- int nonop;
- int i;
-
- if (cip->channel==NULL) {
- return 1;
- }
-
- nonop=(cip->channel->users->totalusers)-((cip->channel->users->totalusers*percent)/100);
-
- for (i=0;i<cip->channel->users->hashsize;i++) {
- if (cip->channel->users->content[i]!=nouser) {
- if (!(cip->channel->users->content[i] & CUMODE_OP)) {
- if (!nonop--) {
- return 1;
- }
- }
- }
- }
-
- return 0;
-}
-
-int cs_oppct(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
-
- thefilter->sf=cs_oppctexe;
- thefilter->arg=(void *)strtol(cargv[0],NULL,10);
-
- return 0;
-}
-
-int cs_hostpctexe(chanindex *cip, void *arg) {
- long percent=(long)arg;
- int hostreq;
- int i;
- unsigned int marker;
- nick *np;
-
- if (cip->channel==NULL) {
- return 1;
- }
-
- marker=nexthostmarker();
-
- hostreq=(cip->channel->users->totalusers * percent) / 100;
-
- for (i=0;i<cip->channel->users->hashsize;i++) {
- if (cip->channel->users->content[i]==nouser)
- continue;
-
- if (!(np=getnickbynumeric(cip->channel->users->content[i])))
- continue;
-
- if (np->host->marker!=marker) {
- /* new unique host */
- if (--hostreq <= 0) {
- return 0;
- }
- np->host->marker=marker;
- }
- }
-
- return 1;
-}
-
-int cs_hostpct(void *source, int cargc, char **cargv) {
- filter *thefilter=source;
-
- thefilter->sf=cs_hostpctexe;
- thefilter->arg=(void *)strtol(cargv[0],NULL,10);
-
- return 0;
-}
-
-int cs_authedpctexe(chanindex *cip, void *arg) {
- int i;
- int j=0;
- nick *np;
- long pct=(long)arg;
-
- if (!cip->channel)
- return 1;
-
- for (i=0;i<cip->channel->users->hashsize;i++) {
- if (cip->channel->users->content[i]==nouser)
- continue;
-
- if ((np=getnickbynumeric(cip->channel->users->content[i])) && IsAccount(np))
- j++;
- }
-
- if (((j * 100) / cip->channel->users->totalusers) >= pct)
- return 0;
- else
- return 1;
-}
-
-int cs_authedpct(void *source, int cargc, char **cargv) {
- filter *thefilter=source;
-
- thefilter->sf=cs_authedpctexe;
- thefilter->arg=(void *)strtol(cargv[0],NULL,10);
-
- return 0;
-}
-
-int cs_modesexe(chanindex *cip, void *arg) {
- struct modeflags *mf=(struct modeflags *)arg;
-
- return ((cip->channel == NULL) ||
- ((cip->channel->flags & mf->setflags) != mf->setflags) ||
- (cip->channel->flags & mf->clearflags));
-}
-
-int cs_modes(void *source, int cargc, char **cargv) {
- filter *thefilter=(filter *)source;
- struct modeflags *mf;
- flag_t flags=0;
-
- mf=(void *)malloc(sizeof(struct modeflags));
-
- setflags(&flags, CHANMODE_ALL, cargv[0], cmodeflags, REJECT_NONE);
-
- mf->setflags=flags;
-
- flags=CHANMODE_ALL;
- setflags(&flags, CHANMODE_ALL, cargv[0], cmodeflags, REJECT_NONE);
-
- mf->clearflags=~flags;
-
- thefilter->sf=cs_modesexe;
- thefilter->arg=(void *)mf;
- thefilter->mallocarg=1;
-
- return 0;
-}
-
-void cs_describe(nick *sender, chanindex *cip) {
- int i;
- int op,voice,peon;
- int oper,service,hosts;
- nick *np;
- chanuserhash *cuhp;
- unsigned int marker;
-
- op=voice=peon=oper=service=hosts=0;
- marker=nexthostmarker();
-
- if (cip->channel==NULL) {
- controlreply(sender,"[ Channel currently empty ] %s",cip->name->content);
- } else {
- cuhp=cip->channel->users;
- for (i=0;i<cuhp->hashsize;i++) {
- if (cuhp->content[i]!=nouser) {
- if (cuhp->content[i]&CUMODE_OP) {
- op++;
- } else if (cuhp->content[i]&CUMODE_VOICE) {
- voice++;
- } else {
- peon++;
- }
- if ((np=getnickbynumeric(cuhp->content[i]&CU_NUMERICMASK))!=NULL) {
- if (IsOper(np)) {
- oper++;
- }
- if (IsService(np)) {
- service++;
- }
- if (np->host->marker!=marker) {
- np->host->marker=marker;
- hosts++;
- }
- }
- }
- }
- controlreply(sender,"[ %4dU %4d@ %4d+ %4d %4d* %4dk %4dH ] %s (%s)",cuhp->totalusers,op,voice,peon,oper,service,hosts,
- cip->name->content, printflags(cip->channel->flags, cmodeflags));
- }
-}
-
-void cs_desctopic(nick *sender, chanindex *cip) {
- if (cip->channel==NULL) {
- controlreply(sender,"[ empty ] %-30s",cip->name->content);
- } else {
- controlreply(sender,"[%4u users] %s (%s)",cip->channel->users->totalusers,cip->name->content,cip->channel->topic?cip->channel->topic->content:"no topic");
- }
-}
-
-void cs_descservices(nick *sender, chanindex *cip) {
- int i;
- chanuserhash *cuhp;
- char servlist[300];
- int slpos=0,slfull=0;
- nick *np;
- int servs=0;
-
- if (cip->channel==NULL) {
- controlreply(sender,"%-30s empty",cip->name->content);
- } else {
- cuhp=cip->channel->users;
- for (i=0;i<cuhp->hashsize;i++) {
- if (cuhp->content[i]!=nouser) {
- if ((np=getnickbynumeric(cuhp->content[i]&CU_NUMERICMASK))) {
- if (IsService(np)) {
- servs++;
- if (!slfull) {
- if (slpos) {
- slpos+=sprintf(&servlist[slpos],", ");
- }
- slpos+=sprintf(&servlist[slpos],"%s",np->nick);
- if (slpos>280) {
- sprintf(&servlist[slpos],", ...");
- slfull=1;
- }
- }
- }
- }
- }
- }
-
- controlreply(sender,"%-30s %5d user%c %2d service%c %s%s%s",cip->name->content,cuhp->totalusers,
- cuhp->totalusers>1?'s':' ',servs,(servs==1)?' ':'s',servs?"(":"",slpos?servlist:"",servs?")":"");
- }
-}
-
+++ /dev/null
-#ifndef __CHANSEARCH_H
-#define __CHANSEARCH_H
-
-#include "../parser/parser.h"
-#include "../channel/channel.h"
-#include "../nick/nick.h"
-
-typedef int (*SearchFunc)(chanindex *cip, void *arg);
-typedef void (*DisplayFunc)(nick *sender, chanindex *cip);
-
-typedef struct filter {
- SearchFunc sf; /* Actual search execute function to be filled in by setup func */
- void *arg; /* Argument for above to be filled in by setup func */
- int mallocarg; /* This should be set by the setup func if arg was malloc()'d (it will cause arg to be freed at the end) */
- int invert;
-} filter;
-
-/* chansearch.c */
-void regchansearchfunc(const char *name, int args, CommandHandler handler);
-void unregchansearchfunc(const char *name, CommandHandler handler);
-void regchansearchdisp(const char *name, DisplayFunc handler);
-void unregchansearchdisp(const char *name, DisplayFunc handler);
-
-#endif
+++ /dev/null
-@include@ @includel@../build.mk@includel@
-
-.PHONY: all
-all: countusers.so
-
-countusers.so: countusers.o
+++ /dev/null
-#include "../control/control.h"
-#include "../nick/nick.h"
-#include "../channel/channel.h"
-#include "../lib/irc_string.h"
-#include <string.h>
-
-int do_countusers(void *source, int cargc, char **cargv) {
- nick *sender=(nick *)source, *np;
- host *hp;
- unsigned int count=0;
- char *chp,*host,*ident;
-
- if (cargc<1)
- return CMD_USAGE;
-
- for (chp=cargv[0]; ;chp++) {
- if (*chp=='@') {
- /* found @, so it's user@host */
- ident=cargv[0];
- *chp='\0';
- host=chp+1;
- break;
- } else if (*chp=='\0') {
- /* found NULL, so just host */
- host=cargv[0];
- ident=NULL;
- break;
- }
- }
-
- if ((hp=findhost(host))==NULL) {
- controlreply(sender,"0 users match %s%s%s",ident?ident:"",ident?"@":"",host);
- return CMD_OK;
- }
-
- if (!ident) {
- /* We want *@host, so it's just the clonecount we have for free */
- controlreply(sender,"%d users match %s",hp->clonecount,host);
- } else {
- /* Do it the slow way */
- for (np=hp->nicks;np;np=np->nextbyhost) {
- if (!ircd_strcmp(np->ident,ident))
- count++;
- }
- controlreply(sender,"%d users match %s@%s",count,ident,host);
- }
-
- return CMD_OK;
-}
-
-void _init() {
- registercontrolhelpcmd("countusers", NO_OPER, 1, do_countusers, "Usage: countusers <hostmask>\nReturns users on specified hostmask.");
-}
-
-void _fini() {
- deregistercontrolcmd("countusers", do_countusers);
-}
+++ /dev/null
-@include@ @includel@../build.mk@includel@
-
-.PHONY: all
-all: fishjoin.so
-
-fishjoin.so: fishjoin.o
+++ /dev/null
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <strings.h>
-#include "../core/hooks.h"
-#include "../irc/irc.h"
-#include "../localuser/localuser.h"
-#include "../localuser/localuserchannel.h"
-#include "../nick/nick.h"
-
-nick *fishbot_nickname, *spamscan_nickname, *fishjoin_nickname;
-
-void fishjoin_handlemessages(nick *target, int messagetype, void **args)
-{
- switch ( messagetype )
- {
- case LU_KILLED:
- fishjoin_nickname = NULL;
- default:
- break;
- }
-}
-
-int fishjoin_isreportable(channel *nc)
-{
-unsigned long *userhand;
-
- if ( !nc || !spamscan_nickname )
- return 0;
-
- userhand = getnumerichandlefromchanhash(nc->users, spamscan_nickname->numeric);
-
- if ( userhand == NULL )
- return 0;
- else
- return 1;
-}
-
-void fishjoin_handlejoin(int hooknum, void* arg)
-{
-void** args = (void**)arg;
-channel *spamchannel;
-
- if ( fishjoin_nickname && fishbot_nickname && spamscan_nickname && fishbot_nickname == (nick *)args[1] && fishjoin_isreportable((channel *)args[0]) )
- {
- spamchannel = findchannel("#qnet.fishbot");
-
- if ( spamchannel )
- sendmessagetochannel(fishjoin_nickname, spamchannel, "fishbot joined %s", ((channel *)args[0])->index->name->content);
- }
-}
-
-void fishjoin_handlekick(int hooknum, void* arg)
-{
-void** args = (void**)arg;
-channel *spamchannel;
-
- if ( fishjoin_nickname && fishbot_nickname && spamscan_nickname && fishbot_nickname == (nick *)args[1] && fishjoin_isreportable((channel *)args[0]) )
- {
- spamchannel = findchannel("#qnet.fishbot");
-
- if ( spamchannel )
- sendmessagetochannel(fishjoin_nickname, spamchannel, "fishbot kicked from %s by %s, Reason: %s", ((channel *)args[0])->index->name->content, args[2] ? ((nick *)args[2])->nick : "???", args[3] ? (char *)args[3] : "???");
- }
-}
-
-void fishjoin_handlenewnick(int hooknum, void* arg)
-{
-channel *spamchannel;
-
- if ( !fishbot_nickname && !strcasecmp(((nick *)arg)->nick, "fishbot") )
- {
- if ( fishjoin_nickname )
- {
- spamchannel = findchannel("#qnet.fishbot");
-
- if ( spamchannel )
- sendmessagetochannel(fishjoin_nickname, spamchannel, "fishbot has returned");
- }
-
- fishbot_nickname = (nick *)arg;
- }
-
- if ( !spamscan_nickname && !strcasecmp(((nick *)arg)->nick, "S") )
- {
- if ( fishjoin_nickname )
- {
- spamchannel = findchannel("#qnet.fishbot");
-
- if ( spamchannel )
- sendmessagetochannel(fishjoin_nickname, spamchannel, "S has returned");
- }
-
- spamscan_nickname = (nick *)arg;
- }
-}
-
-void fishjoin_handlelostnick(int hooknum, void* arg)
-{
-channel *spamchannel;
-
- if ( fishbot_nickname && fishbot_nickname == (nick *)arg )
- {
- if ( fishjoin_nickname )
- {
- spamchannel = findchannel("#qnet.fishbot");
-
- if ( spamchannel )
- sendmessagetochannel(fishjoin_nickname, spamchannel, "fishbot has quit");
- }
-
- fishbot_nickname = NULL;
- }
-
- if ( spamscan_nickname && spamscan_nickname == (nick *)arg )
- {
- if ( fishjoin_nickname )
- {
- spamchannel = findchannel("#qnet.fishbot");
-
- if ( spamchannel )
- sendmessagetochannel(fishjoin_nickname, spamchannel, "S has quit");
- }
-
- spamscan_nickname = NULL;
- }
-}
-
-void _init()
-{
- fishjoin_nickname = registerlocaluser("F", "TheFBot","fishbotsfriend.quakenet.org", "fishbot's friend", NULL, UMODE_SERVICE, &fishjoin_handlemessages);
- registerhook(HOOK_CHANNEL_JOIN, &fishjoin_handlejoin);
- registerhook(HOOK_CHANNEL_KICK, &fishjoin_handlekick);
- registerhook(HOOK_NICK_NEWNICK, &fishjoin_handlenewnick);
- registerhook(HOOK_NICK_LOSTNICK, &fishjoin_handlelostnick);
- fishbot_nickname = getnickbynick("fishbot");
- spamscan_nickname = getnickbynick("S");
-}
-
-void _fini()
-{
- if ( fishjoin_nickname )
- {
- deregisterlocaluser(fishjoin_nickname, NULL);
- fishjoin_nickname = NULL;
- }
-
- deregisterhook(HOOK_CHANNEL_JOIN, &fishjoin_handlejoin);
- deregisterhook(HOOK_CHANNEL_KICK, &fishjoin_handlekick);
- deregisterhook(HOOK_NICK_NEWNICK, &fishjoin_handlenewnick);
- deregisterhook(HOOK_NICK_LOSTNICK, &fishjoin_handlelostnick);
-}
+++ /dev/null
-@include@ @includel@../build.mk@includel@
-
-.PHONY: all
-all: helpmod.so
-
-helpmod.so: helpmod.o helpmod_user.o helpmod_entries.o helpmod_alias.o
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <ctype.h>
-
-#include "helpmod_entries.h"
-#include "helpmod_user.h"
-#include "helpmod_alias.h"
-
-#include "../localuser/localuser.h"
-#include "../localuser/localuserchannel.h"
-#include "../control/control.h"
-#include "../channel/channel.h"
-#include "../nick/nick.h"
-#include "../core/config.h"
-#include "../core/schedule.h"
-
-#define HELPMOD_VERSION "1.05"
-
-helpmod_entry helpmod_base;
-helpmod_user helpmod_users;
-alias_tree aliases;
-nick *helpmodnick;
-char helpmod_db[128] = "helpmod/default";
-long helpmod_usage;
-
-void helpreply(nick *target, char *message, ... ) {
- char buf[512];
- va_list va;
-
- if (helpmodnick==NULL) {
- return;
- }
-
- va_start(va,message);
- vsnprintf(buf,512,message,va);
- va_end(va);
-
- sendmessagetouser(helpmodnick,target,"%s",buf);
-}
-
-void helpmod_send_help(nick* target, helpmod_user hlp_user)
-{
- int i;
- helpmod_usage++;
- for (i=0;i<hlp_user->state->text_lines;i++)
- helpreply(target, "%s", hlp_user->state->text[i]->content);
- for (i=0;i<hlp_user->state->option_count;i++)
- helpreply(target, "%d) %s", i+1, hlp_user->state->options[i]->description->content);
- if (!hlp_user->state->option_count)
- {
- helpreply(target, "This concludes the help for this topic, if you want to, you can restart the service with the 'help' command, or return to the previous entry by selecting 0");
- }
-}
-
-void helpmod_cmd_help (nick* sender, char* arg)
-{
- helpmod_user hlp_user = helpmod_get_user(sender->numeric);
- int hlp_target;
- int i;
-
- if (!helpmod_base)
- {
- helpreply(sender, "The help service is not available at this time, please try again later");
- return;
- }
-
- if (!arg)
- {
- hlp_user->state = helpmod_base;
- helpmod_send_help(sender, hlp_user);
- return;
- }
- else
- if (!sscanf(arg, "%d", &hlp_target))
- {
- helpmod_entry tmp;
- for(i=0;i<strlen(arg);i++)
- if (isspace(arg[i]))
- {
- arg[i] = 0x00;
- break;
- }
- tmp = helpmod_get_alias(arg);
- if (!tmp)
- helpreply(sender, "Invalid value. Either use 'help' to restart or give an integer as a valid selection");
- else
- {
- hlp_user->state = tmp;
- helpmod_send_help(sender, hlp_user);
- }
- return;
- }
-
- hlp_target--;
- if (!helpmod_valid_selection(hlp_user->state, hlp_target))
- {
- if (!hlp_user->state->option_count)
- helpreply(sender, "There are no more options to choose from, you can restart the service by giving the 'help' command or select 0 to return to previous entry");
- else if (!hlp_user->state->parent)
- helpreply(sender, "Bad selection, please enter your selection as an integer from %d to %d", 1, hlp_user->state->option_count);
- else
- helpreply(sender, "Bad selection, please enter your selection as an integer from %d to %d, selecting 0 will take you to the previous entry", 1, hlp_user->state->option_count);
- return;
- }
-
- hlp_user->state = helpmod_make_selection(hlp_user->state, hlp_target);
- helpmod_send_help(sender, hlp_user);
-
- return;
-}
-
-void helpmod_cmd_stats (nick *sender)
-{
- helpreply(sender, "Amount of users: %9ld", helpmod_user_count());
- helpreply(sender, " entries: %9ld", helpmod_entry_count(helpmod_base));
- helpreply(sender, " aliases: %9ld", helpmod_alias_count(aliases));
- helpreply(sender, " service use: %9ld", helpmod_usage);
- helpreply(sender, "Using database: %s", helpmod_db);
- return;
-}
-
-void helpmod_cmd_load (void *sender, char* arg)
-{
- FILE *tmp_file;
- char buf[128] = "helpmod/default";
-
- if (!arg)
- helpreply(sender, "Warning: No config specified, using default");
- else
- {
- if (strlen(arg) >= 100)
- return;
- else
- sprintf(buf, "helpmod/%s", arg);
- }
-
- if (!(tmp_file = fopen(buf, "rt")))
- {
- helpreply(sender, "File %s not found", buf);
- return;
- }
- else
- fclose(tmp_file);
-
- helpmod_clear_aliases(&aliases);
- helpmod_clear_all_entries();
- helpmod_init_entry(&helpmod_base);
- helpmod_clear_users();
- helpmod_load_entries(buf);
- strcpy(helpmod_db, buf);
- helpreply(sender, "New config loaded and system reset");
-}
-
-void helpmod_cmd_showcommands (nick *sender)
-{
- helpreply(sender,"HelpMod %s Commands", HELPMOD_VERSION);
- helpreply(sender,"help Primary command, gives automated help to lusers");
- helpreply(sender,"stats Shows some service statistics");
- helpreply(sender,"aliases Gives a simple list of aliases currently in use");
- helpreply(sender,"load Loads a new help config");
- return;
-}
-
-void helpmod_cmd_aliases (nick *sender)
-{
- char buf[512];
- int i = 0;
- void helpmod_list_aliases(alias_tree node)
- {
- if (i > 256)
- {
- helpreply(sender, buf);
- i = 0;
- }
- if (!node)
- return;
- sprintf(buf+i,"%.200s ",node->name->content);
- i+=(1+strlen(node->name->content));
- helpmod_list_aliases(node->left);
- helpmod_list_aliases(node->right);
- }
- helpmod_list_aliases(aliases);
- if (i)
- helpreply(sender, buf);
-}
-
-void helpmodmessagehandler(nick *sender, int messagetype, void **args)
-{
- char* first_arg;
- char* second_arg = NULL;
- nick *target;
- int i, useless_var;
-
- if (messagetype != LU_PRIVMSG)
- return;
-
- target = getnickbynick((char*)args[0]);
- first_arg = args[1];
-
- for (i=0;i<strlen(args[1]);i++)
- if (((char*)args[1])[i] == ' ')
- {
- second_arg = args[1] + i + 1;
- ((char*)args[1])[i] = 0x00;
- break;
- }
- if (!strcmp(first_arg, "help"))
- {
- helpmod_cmd_help(target, second_arg);
- return;
- }
- if (sscanf(first_arg, "%d", &useless_var))
- {
- helpmod_cmd_help(target, first_arg);
- return;
- }
- if (!IsOper(target))
- {
- helpreply(target, "To access the help service, just type 'help'");
- return;
- }
- if (!strcmp(first_arg, "stats"))
- helpmod_cmd_stats(target);
- else if (!strcmp(first_arg, "load"))
- helpmod_cmd_load(target, second_arg);
- else if (!strcmp(first_arg,"aliases"))
- helpmod_cmd_aliases(target);
- else if (!strcmp(first_arg, "showcommands"))
- helpmod_cmd_showcommands(target);
- else if (!strcmp(first_arg, "help"))
- helpmod_cmd_help(target, first_arg);
- else
- helpreply(target, "Unknown command, see 'showcommands'");
-}
-
-void helpconnect(void) {
- channel *cp;
- /* helpmod offers no channel features, it's merely a decoration */
- char *helpmod_chans[] = {"#twilightzone", "#help", "#feds", "#qnet.help"};
- int i,helpmod_chan_count = 4;
-
- helpmodnick=registerlocaluser("H",
- "help",
- "quakenet.org",
- "NewServ HelpMod, /msg H help",
- "H",
- UMODE_DEAF|UMODE_OPER|UMODE_ACCOUNT,&helpmodmessagehandler);
-
- helpmod_init_entry(&helpmod_base);
- helpmod_init_users();
- helpmod_load_entries(NULL);
- /* join channels */
- for (i=0;i < helpmod_chan_count;i++)
- {
- cp = findchannel(helpmod_chans[i]);
- if (!cp)
- localcreatechannel(helpmodnick, helpmod_chans[i]);
- else
- {
- localjoinchannel(helpmodnick, cp);
- localgetops(helpmodnick, cp);
- }
- }
-}
-
-
-void _init()
-{
- helpmod_usage = 0;
- helpmod_base = NULL;
- aliases = NULL;
- scheduleoneshot(time(NULL)+1,(ScheduleCallback)&helpconnect,NULL);
- schedulerecurring(time(NULL)+1,0,300,(ScheduleCallback)&helpmod_clear_inactives,NULL);
-}
-
-void _fini()
-{
- deregisterlocaluser(helpmodnick, "Module unloaded");
- deleteallschedules((ScheduleCallback)&helpconnect);
- helpmod_clear_aliases(&aliases);
- helpmod_clear_all_entries();
- helpmod_clear_users();
-}
+++ /dev/null
-#include "helpmod_alias.h"
-
-int helpmod_alias_count(alias_tree node)
-{
- if (node == NULL)
- return 0;
- else
- return 1 + helpmod_alias_count(node->left) + helpmod_alias_count(node->right);
-}
-
-void helpmod_init_alias(alias_tree* node)
-{
- *node = (alias_tree)malloc(sizeof(struct alias_tree_struct));
- (*node)->left = NULL;
- (*node)->right = NULL;
- (*node)->name = NULL;
- (*node)->state = NULL;
-}
-void helpmod_clear_aliases(alias_tree* node)
-{
- if (!*node)
- return;
- helpmod_clear_aliases(&(*node)->left);
- helpmod_clear_aliases(&(*node)->right);
- freesstring((*node)->name);
- free(*node);
- *node = NULL;
-}
-helpmod_entry helpmod_get_alias(char* search)
-{
- int val;
- alias_tree tmp = aliases;
- while (tmp)
- {
- val = strcmp(tmp->name->content, search);
- if (!val)
- return tmp->state;
- if (val < 0)
- tmp = tmp->left;
- else
- tmp = tmp->right;
- }
- return NULL;
-}
-
-void helpmod_add_alias(char* name, helpmod_entry state)
-{
- int val;
- alias_tree* tmp = &aliases;
- while (*tmp)
- {
- val = strcmp((*tmp)->name->content, name);
- if (!val)
- return; /* duplicate, let's not do anything, silly person to create duplicates in the file.. */
- if (val < 0)
- tmp = &(*tmp)->left;
- else
- tmp = &(*tmp)->right;
- }
- helpmod_init_alias(tmp);
- (*tmp)->state = state;
- (*tmp)->name = getsstring(name,strlen(name));
- for (val=0;val < strlen(name);val++)
- if (isspace((*tmp)->name->content[val]))
- {
- (*tmp)->name->content[val] = 0x00;
- break;
- }
-}
+++ /dev/null
-#ifndef HELPMOD_ALIAS_C
-#define HELPMOD_ALIAS_C
-
-#include "../lib/sstring.h"
-#include "helpmod_entries.h"
-#include <string.h>
-#include <ctype.h>
-
-typedef struct alias_tree_struct
-{
- sstring* name;
- helpmod_entry state;
- struct alias_tree_struct* left;
- struct alias_tree_struct* right;
-}* alias_tree;
-
-extern alias_tree aliases;
-
-int helpmod_alias_count(alias_tree);
-void helpmod_init_alias(alias_tree*);
-void helpmod_clear_aliases(alias_tree*);
-helpmod_entry helpmod_get_alias(char*);
-void helpmod_add_alias(char*, helpmod_entry);
-
-#endif
-
+++ /dev/null
-#include "helpmod_entries.h"
-#include "helpmod_alias.h"
-#include "../core/error.h"
-
-struct helpmod_parsed_line_struct helpmod_parsed_line;
-
-int helpmod_valid_selection(helpmod_entry state, int selection)
-{
- if (selection == -1)
- return ((int)state->parent);
- return (selection >= 0 && selection < state->option_count);
-}
-
-helpmod_entry helpmod_make_selection(helpmod_entry state, int selection)
-{
- if (selection == -1)
- return state->parent;
- return state->options[selection];
-}
-
-void helpmod_init_entry(helpmod_entry * entry)
-{
- *entry = (helpmod_entry)malloc(sizeof(**entry));
- (*entry)->option_count = (*entry)->text_lines = 0;
- (*entry)->text = NULL;
- (*entry)->options = NULL;
- (*entry)->parent = NULL;
- (*entry)->description = NULL;
-}
-
-void helpmod_clear_entries(helpmod_entry state)
-{
- int i;
- if (state == NULL)
- return;
- if (state->description != NULL)
- freesstring(state->description);
- for (i=0;i<state->text_lines;i++)
- freesstring(state->text[i]);
- if (state->text_lines)
- free(state->text);
- for (i=0;i<state->option_count;i++)
- {
- helpmod_clear_entries(state->options[i]);
- free(state->options[i]);
- }
- if (state->option_count)
- free(state->options);
-}
-
-void helpmod_parse_line(FILE* input)
-{
- int i, slen;
- char str[512] = "";
- /**str = '\0'; */
- fgets(str,511,input);
- helpmod_parsed_line.line_type = HM_LINE_NORMAL;
- if (*str >= '0' && *str <= '0')
- {
- sscanf(str, "%2d", &helpmod_parsed_line.depth);
- if (str[2] == '*')
- {
- helpmod_parsed_line.line_type = HM_LINE_TEXT;
- strcpy(helpmod_parsed_line.text, str + 3);
- }
- else if (str[2] == '$')
- {
- helpmod_parsed_line.line_type = HM_LINE_ALIAS;
- strcpy(helpmod_parsed_line.text, str + 3);
- }
- else
- strcpy(helpmod_parsed_line.text, str + 2);
- return;
- }
- for(i=0,slen=strlen(str);i<slen;i++)
- if (str[i] == '*')
- {
- helpmod_parsed_line.line_type = HM_LINE_TEXT;
- i++;
- break;
- }
- else if (str[i] == '$')
- {
- helpmod_parsed_line.line_type = HM_LINE_ALIAS;
- i++;
- break;
- }
- else if (str[i] != ' ')
- break;
-
- helpmod_parsed_line.depth = i;
- strcpy(helpmod_parsed_line.text, str + i);
-}
-
-void helpmod_clear_all_entries(void)
-{
- helpmod_clear_entries(helpmod_base);
- free(helpmod_base);
- helpmod_base = NULL;
-}
-
-void helpmod_load_entries(char* setting_file)
-{
- FILE *main_input;
- FILE *tmp_input;
- char buffer[512];
- int i;
- if (NULL == setting_file)
- setting_file = "helpmod/default";
- if (NULL == (main_input = fopen(setting_file, "rt")))
- {
- Error("helpmod", ERR_WARNING, "Default database not found, service will be unavailable until a valid database is loaded\n");
- return;
- }
- while (!feof(main_input))
- {
- fgets(buffer,511,main_input);
- if (feof(main_input))
- return;
- if (*buffer == '$')
- {
- helpmod_base->options = (helpmod_entry*)realloc(helpmod_base->options, sizeof(helpmod_entry) * ++helpmod_base->option_count);
- helpmod_base->options[helpmod_base->option_count-1] = NULL;
- /* remove the \n, it's not wanted */
- for (i=0;i<strlen(buffer+1);i++)
- if ((buffer+1)[i] == '\n')
- {
- (buffer+1)[i] = 0x00;
- break;
- }
- tmp_input = fopen(buffer+1, "r");
- if (tmp_input == NULL)
- {
- Error("helpmod", ERR_ERROR, "File %s specified in %s not found\n",buffer+1, setting_file);
- return;
- }
- helpmod_parse_line(tmp_input);
- helpmod_load_entry(&helpmod_base->options[helpmod_base->option_count-1], tmp_input, 0, helpmod_base);
- fclose(tmp_input);
- }
- else
- {
- helpmod_base->text = (sstring**)realloc(helpmod_base->text, sizeof(sstring*) * ++helpmod_base->text_lines);
- helpmod_base->text[helpmod_base->text_lines-1] = getsstring(buffer, strlen(buffer));
- }
- }
- fclose(main_input);
-}
-
-void helpmod_load_entry(helpmod_entry* base, FILE* input, int depth, helpmod_entry parent)
-{
- if (feof(input))
- {
- *base = NULL;
- helpmod_parsed_line.depth = 0;
- return;
- }
-
- if (helpmod_parsed_line.depth < depth)
- {
- *base = NULL;
- return;
- }
-
- helpmod_init_entry(base);
- (*base)->parent = parent;
- (*base)->description = getsstring(helpmod_parsed_line.text, strlen(helpmod_parsed_line.text));
- depth++;
-
- helpmod_parse_line(input);
- while (helpmod_parsed_line.line_type == HM_LINE_ALIAS)
- {
- helpmod_add_alias(helpmod_parsed_line.text, *base); /* create an alias */
- helpmod_parse_line(input);
- }
- while (helpmod_parsed_line.line_type == HM_LINE_TEXT)
- {
- if (feof(input))
- return;
- (*base)->text = (sstring**)realloc((*base)->text, sizeof(sstring*) * ++(*base)->text_lines);
- (*base)->text[(*base)->text_lines - 1] = getsstring(helpmod_parsed_line.text, strlen(helpmod_parsed_line.text));
- helpmod_parse_line(input);
- }
- while (helpmod_parsed_line.depth == depth)
- {
-
- (*base)->options = (helpmod_entry*)realloc((*base)->options, sizeof(helpmod_entry) * ++(*base)->option_count);
- helpmod_load_entry(&(*base)->options[(*base)->option_count-1],input,depth, *base);
- }
- return;
-}
-
-long helpmod_entry_count(helpmod_entry base)
-{
- int i;
- long counter = 0;
- if (base == NULL)
- return 0;
- if (base->options == NULL)
- return 0;
- for (i=0;i<base->option_count;i++)
- counter+=helpmod_entry_count(base->options[i]);
- return i+counter;
-}
+++ /dev/null
-#ifndef HELPMOD_ENTRIES_H
-#define HELPMOD_ENTRIES_H
-
-#include "../lib/sstring.h"
-#include <stdio.h>
-#include <stdlib.h>
-
-typedef enum
-{
- HM_LINE_NORMAL,
- HM_LINE_ALIAS,
- HM_LINE_TEXT
-} HM_line_type;
-
-typedef struct helpmod_entry_struct
-{
- struct helpmod_entry_struct* parent;
- unsigned short int option_count;
- unsigned short int text_lines;
-
- sstring* description;
- sstring** text;
- struct helpmod_entry_struct** options;
-} *helpmod_entry;
-
-extern struct helpmod_parsed_line_struct
-{
- char text[512];
- int depth;
- HM_line_type line_type;
-} helpmod_parsed_line;
-
-extern helpmod_entry helpmod_base;
-
-int helpmod_valid_selection(helpmod_entry, int);
-helpmod_entry helpmod_make_selection(helpmod_entry, int);
-void helpmod_init_entries(void);
-void helpmod_init_entry(helpmod_entry*);
-void helpmod_clear_all_entries(void);
-void helpmod_load_entries(char*);
-void helpmod_load_entry(helpmod_entry*, FILE*, int, helpmod_entry);
-void helpmod_parse_line(FILE*);
-void helpmod_clear_entries(helpmod_entry);
-long helpmod_entry_count(helpmod_entry);
-
-#endif
-
+++ /dev/null
-#include "helpmod_user.h"
-#include "helpmod_entries.h"
-
-helpmod_user helpmod_get_user(long numeric)
-{
-
- helpmod_user *tmp,tmp2;
- for(tmp=&helpmod_users;*tmp;tmp=&(*tmp)->next)
- if ((*tmp)->numeric == numeric)
- {
- (*tmp)->last_active = time(NULL);
- return *tmp;
- }
- tmp2 = *tmp;
- *tmp = (helpmod_user)malloc(sizeof(struct helpmod_user_struct));
- (*tmp)->next = tmp2;
- (*tmp)->last_active = time(NULL);
- (*tmp)->numeric = numeric;
- (*tmp)->state = helpmod_base;
- return *tmp;
-}
-
-void helpmod_clear_users(void)
-{
- helpmod_user tmp;
- while (helpmod_users)
- {
- tmp = helpmod_users->next;
- free(helpmod_users);
- helpmod_users = tmp;
- }
- helpmod_users = NULL;
-}
-
-void helpmod_init_users(void)
-{
- helpmod_users = NULL;
-}
-
-void helpmod_clear_inactives(void)
-{
- helpmod_user *tmp, tmp2;
- for (tmp = &helpmod_users;*tmp;tmp = &(*tmp)->next)
- while (time(NULL) - (*tmp)->last_active > HELPMOD_USER_TIMEOUT)
- {
- tmp2 = (*tmp)->next;
- free(*tmp);
- *tmp = tmp2;
- if (!*tmp)
- return;
- }
-}
-
-long helpmod_user_count(void)
-{
- helpmod_user *tmp;
- long counter;
- for (counter=0, tmp = &helpmod_users;*tmp;counter++, tmp = &(*tmp)->next);
- return counter;
-}
+++ /dev/null
-#ifndef HELPMOD_USER_H
-#define HELPMOD_USER_H
-
-#include <time.h>
-#include "helpmod_entries.h"
-#define HELPMOD_USER_TIMEOUT 300
-typedef struct helpmod_user_struct
-{
- long numeric;
- time_t last_active;
- helpmod_entry state;
- struct helpmod_user_struct* next;
-} *helpmod_user;
-
-extern helpmod_user helpmod_users;
-extern helpmod_entry helpmod_base;
-
-helpmod_user helpmod_get_user(long numeric);
-void helpmod_clear_users(void);
-void helpmod_clear_inactives(void);
-void helpmod_init_users(void);
-long helpmod_user_count(void);
-
-#endif
+++ /dev/null
-@include@ @includel@../build.mk@includel@
-
-.PHONY: all
-all: lpart.so
-
-lpart.so: lpart.o
+++ /dev/null
-/*
- * lpart: simple newserv module to instruct L to leave a channel
- * after it has had no other users for a certain time.
- */
-
-#include "../lib/sstring.h"
-#include "../channel/channel.h"
-#include "../core/config.h"
-#include "../core/hooks.h"
-#include "../nick/nick.h"
-#include "../core/schedule.h"
-#include "../control/control.h"
-#include "../core/error.h"
-
-sstring *targetnick; /* Name of the service to talk to */
-int lpartext; /* Our chanext index */
-int timeout; /* How long to wait for */
-int shorttimeout; /* How long to wait if there are no interesting modes */
-
-void lp_handlepart(int hooknum, void *arg);
-void lp_dopart(void *arg);
-void lp_schedpart(channel *cp);
-
-void _init() {
- sstring *tss;
- int i;
- chanindex *cip;
- nick *np;
-
- lpartext=registerchanext("lpart");
-
- /* Set up the targetnick */
- targetnick=getcopyconfigitem("lpart","servicenick","L",NICKLEN);
-
- /* Set up the timeout */
- tss=getcopyconfigitem("lpart","timeout","86400",6);
- timeout=strtol(tss->content,NULL,10);
- freesstring(tss);
-
- tss=getcopyconfigitem("lpart","shorttimeout","300",6);
- shorttimeout=strtol(tss->content,NULL,10);
- freesstring(tss);
-
- if ((np=getnickbynick(targetnick->content))) {
- for(i=0;i<CHANNELHASHSIZE;i++) {
- for (cip=chantable[i];cip;cip=cip->next) {
- if (cip->channel && cip->channel->users->totalusers==1 &&
- getnumerichandlefromchanhash(cip->channel->users,np->numeric)) {
- lp_schedpart(cip->channel);
- }
- }
- }
- }
-
- registerhook(HOOK_CHANNEL_LOSTNICK,&lp_handlepart);
-}
-
-void _fini() {
- /* We need to clean up any outstanding callbacks we have */
- deleteallschedules(&lp_dopart);
- releasechanext(lpartext);
- deregisterhook(HOOK_CHANNEL_LOSTNICK,&lp_handlepart);
-}
-
-void lp_handlepart(int hooknum, void *arg) {
- void **args=(void **)arg;
- channel *cp;
- nick *np;
-
- /* For a part, first arg is channel and second is nick */
- cp=(channel *)args[0];
-
- /* We're only interested if there is now one user on the channel.
- Note that the parting user is STILL ON THE CHANNEL at this point,
- so we're interested if there are two or fewer users left. */
-
- if (cp->users->totalusers!=2)
- return;
-
- /* Let's see if our user is even on the network */
- if ((np=getnickbynick(targetnick->content))==NULL)
- return;
-
- /* And if it's on the channel in question */
- if (getnumerichandlefromchanhash(cp->users,np->numeric)==NULL)
- return;
-
- /* OK, now let's see if we already had something scheduled for this channel */
- if (cp->index->exts[lpartext]!=NULL) {
- /* We delete the old schedule at this point */
- deleteschedule(cp->index->exts[lpartext],&lp_dopart, (void *)cp->index);
- }
-
-/* Error("lpart",ERR_DEBUG,"Scheduling part of channel %s",cp->index->name->content); */
- lp_schedpart(cp);
-}
-
-void lp_schedpart(channel *cp) {
- int thetimeout;
-
- /* If the channel has anything that might be worth preserving, use the full timeout.
- * Otherwise, use the shorter one
- */
-
- if ((cp->flags & ~(CHANMODE_NOEXTMSG | CHANMODE_TOPICLIMIT | CHANMODE_NOCTCP | CHANMODE_NONOTICE)) || cp->topic || cp->bans) {
- thetimeout=timeout;
- } else {
- thetimeout=shorttimeout;
- }
-
- cp->index->exts[lpartext]=scheduleoneshot(time(NULL)+thetimeout,&lp_dopart,(void *)cp->index);
-}
-
-void lp_dopart(void *arg) {
- chanindex *cip;
- nick *np;
-
- cip=(chanindex *)arg;
- cip->exts[lpartext]=NULL;
-
- /* Check the chan still exists */
- if (cip->channel==NULL) {
- releasechanindex(cip);
- return;
- }
-
- /* Check the usercount is 1 */
- if (cip->channel->users->totalusers>1)
- return;
-
- /* Let's see if our user is even on the network */
- if ((np=getnickbynick(targetnick->content))==NULL)
- return;
-
- /* And if it's on the channel in question */
- if (getnumerichandlefromchanhash(cip->channel->users,np->numeric)==NULL)
- return;
-
- /* OK, we've established that the channel is of size 1 and has our nick on it. Send the part command.
- Use controlreply() for this */
-
-/* Error("lpart",ERR_DEBUG,"Telling L to part %s",cip->name->content); */
- controlmessage(np,"part %s",cip->name->content);
-}
--- /dev/null
+Note: this module is extremely crufty and requires a rewrite.
+++ /dev/null
-@include@ @includel@../build.mk@includel@
-
-.PHONY: all
-all: rannounce.so
-
-rannounce.so: rannounce.o
+++ /dev/null
-
-#include "../nick/nick.h"
-#include "../localuser/localuserchannel.h"
-#include "../lib/irc_string.h"
-
-nick *rannouncenick;
-
-void rannouncehandler(nick *me, int type, void **args);
-
-void _init() {
- channel *cp;
- rannouncenick=registerlocaluser("R","relay","quakenet.org","Relay announcer",NULL,0,rannouncehandler);
-
- if ((cp=findchannel("#twilightzone"))) {
- localjoinchannel(rannouncenick, cp);
- } else {
- localcreatechannel(rannouncenick, "#twilightzone");
- }
-
- if ((cp=findchannel("#qnet.queue"))) {
- localjoinchannel(rannouncenick, cp);
- } else {
- localcreatechannel(rannouncenick, "#qnet.queue");
- }
-
- if ((cp=findchannel("#qrequest"))) {
- localjoinchannel(rannouncenick, cp);
- } else {
- localcreatechannel(rannouncenick, "#qrequest");
- }
-}
-
-void _fini() {
- deregisterlocaluser(rannouncenick,NULL);
-}
-
-void rannouncehandler(nick *me, int type, void **args) {
- nick *np;
- char *text;
- channel *cp;
- int items;
-
- if (type==LU_PRIVMSG) {
- np=args[0];
- text=args[1];
-
- if (IsOper(np) && !ircd_strncmp(text,"announce ",9)) {
- text+=9;
- items=strtoul(text,NULL,10);
-
- if (items) {
- if ((cp=findchannel("#twilightzone"))) {
- sendmessagetochannel(me, cp, "%d item%s in queue - https://www.quakenet.org/secure/queue/",items,items==1?"":"s");
- }
- if ((cp=findchannel("#qnet.queue"))) {
- sendmessagetochannel(me, cp, "%d item%s in queue - https://www.quakenet.org/secure/queue/",items,items==1?"":"s");
- }
- if ((cp=findchannel("#qrequest"))) {
- sendmessagetochannel(me, cp, "%d item%s in queue",items,items==1?"":"s");
- }
- }
- }
- } else if (type==LU_KILLED) {
- rannouncenick=NULL;
- }
-}
-
--- /dev/null
+Crufty module!
+Needs a rewrite!
+++ /dev/null
-@include@ @includel@../build.mk@includel@
-
-.PHONY: all
-all: spawnuser.so
-
-spawnuser.so: spawnuser.o
+++ /dev/null
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <stdarg.h>\r
-#include <string.h>\r
-#include "../channel/channel.h"\r
-#include "../control/control.h"\r
-#include "../core/config.h"\r
-#include "../localuser/localuser.h"\r
-#include "../localuser/localuserchannel.h"\r
-#include "../nick/nick.h"\r
-#include "../irc/irc.h"\r
-\r
-typedef struct spawnuser_user\r
-{\r
- nick *user;\r
- struct spawnuser_user *next;\r
-} spawnuser_user;\r
-\r
-spawnuser_user *spawnuser_users;\r
-\r
-void spawnuser_handlemessages(nick *target, int messagetype, void **args)\r
-{\r
-spawnuser_user *spawnuser;\r
-\r
- switch ( messagetype )\r
- {\r
- case LU_KILLED:\r
- for ( spawnuser = spawnuser_users; spawnuser; spawnuser = spawnuser->next )\r
- {\r
- if ( target == spawnuser->user )\r
- {\r
- Error("spawnuser", ERR_WARNING, "A SpawnUser got killed");\r
- spawnuser->user = NULL;\r
- break;\r
- }\r
- }\r
- default:\r
- break;\r
- }\r
-}\r
-\r
-void _init()\r
-{\r
-char nickbuf[NICKLEN + 1], hostbuf[HOSTLEN + 1];\r
-int i;\r
-spawnuser_user *spawnuser;\r
-channel *spawnchannel;\r
-\r
- spawnuser_users = NULL;\r
- \r
- for ( i = 0; i < 3000; i++ )\r
- {\r
- snprintf(nickbuf, NICKLEN, "SU-%s-%d", mynick->nick, i);\r
- nickbuf[NICKLEN] = '\0';\r
- snprintf(hostbuf, HOSTLEN, "SpawnUser-%s.netsplit.net", mynick->nick);\r
- hostbuf[HOSTLEN] = '\0';\r
- spawnuser = malloc(sizeof(spawnuser_user));\r
- spawnuser->user = registerlocaluser(nickbuf, "SpawnUser", hostbuf, "SpawnUser", NULL, UMODE_INV, &spawnuser_handlemessages);\r
- \r
- spawnchannel = findchannel("#twilightzone");\r
- \r
- if ( !spawnchannel )\r
- localcreatechannel(spawnuser->user, "#twilightzone");\r
- else\r
- localjoinchannel(spawnuser->user, spawnchannel);\r
- \r
- spawnuser->next = spawnuser_users;\r
- spawnuser_users = spawnuser;\r
- }\r
-}\r
-\r
-void _fini()\r
-{\r
-spawnuser_user *temp_spawnuser;\r
-\r
- while ( spawnuser_users )\r
- {\r
- temp_spawnuser = spawnuser_users;\r
- spawnuser_users = temp_spawnuser->next;\r
- \r
- if ( temp_spawnuser->user )\r
- deregisterlocaluser(temp_spawnuser->user, "SpawnUser Unloaded");\r
- \r
- free(temp_spawnuser);\r
- }\r
-}\r
--- /dev/null
+Crufty module!
+Needs a rewrite.