/************************************************************************ * IRC - Internet Relay Chat, chanmodes/cm_limit.c * * Copyright (C)2000-2003 TR-IRCD Development * Copyright (C) 1990 Jarkko Oikarinen and * University of Oulu, Co Center * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "struct.h" #include "common.h" #include "sys.h" #include "numeric.h" #include "channel.h" #include "h.h" #include "msg.h" #include "hook.h" #include "s_conf.h" #include "chanmode.h" static int set_limit(int adl, aChannel *chptr, int nmodes, int *argnum, int *pidx, int *mbix, char *mbuf, char *pbuf, aClient *cptr, aClient *sptr, int parc, char **parv) { char *pptr; /* temporary paramater pointer */ char *morig = mbuf; /* beginning of mbuf */ int prelen = strlen(cptr->name) + strlen(chptr->chname) + 16; int fargnum = *argnum; int fmbix = *mbix; int fpidx = *pidx; int i; char tmp[16]; /* temporary buffer */ if (adl == CMODE_DEL) { if ((prelen + (mbuf - morig) + fpidx + 1) > REALMODEBUFLEN) return nmodes; mbuf[fmbix++] = 'l'; chptr->mode.mode &= ~MODE_LIMIT; chptr->mode.limit = 0; nmodes++; *mbix = fmbix; } if (adl == CMODE_ADD) { if (parv[fargnum] == NULL) { send_me_numeric(sptr, ERR_NEEDMOREPARAMS, MSG_MODE); return nmodes; } /* * if we're going to overflow our mode buffer, * * drop the change instead */ if ((prelen + (mbuf - morig) + fpidx + 16) > REALMODEBUFLEN) { fargnum++; return nmodes; } i = atoi(parv[fargnum]); if (i < 1) { fargnum++; *argnum = fargnum; return nmodes; } ircsprintf(tmp, "%d", i); chptr->mode.mode |= MODE_LIMIT; chptr->mode.limit = i; mbuf[fmbix++] = 'l'; pptr = tmp; if (fpidx) pbuf[fpidx++] = ' '; while (*pptr) pbuf[fpidx++] = *pptr++; fargnum++; *mbix = fmbix; *pidx = fpidx; *argnum = fargnum; nmodes++; } return nmodes; } static int sl_service(int adl, aChannel *chptr, int nmodes, int *argnum, int *pidx, int *mbix, char *mbuf, char *pbuf, aClient *cptr, aClient *sptr, int parc, char **parv) { if (MyClient(sptr)) send_me_numeric(sptr, ERR_CHANOPRIVSNEEDED, chptr); else ircstp->is_fake++; return nmodes; } static int sl_server(int adl, aChannel *chptr, int nmodes, int *argnum, int *pidx, int *mbix, char *mbuf, char *pbuf, aClient *cptr, aClient *sptr, int parc, char **parv) { return set_limit(adl, chptr, nmodes, argnum, pidx, mbix, mbuf, pbuf, cptr, sptr, parc, parv); } static int sl_uline(int adl, aChannel *chptr, int nmodes, int *argnum, int *pidx, int *mbix, char *mbuf, char *pbuf, aClient *cptr, aClient *sptr, int parc, char **parv) { return set_limit(adl, chptr, nmodes, argnum, pidx, mbix, mbuf, pbuf, cptr, sptr, parc, parv); } static int sl_oper(int adl, aChannel *chptr, int nmodes, int *argnum, int *pidx, int *mbix, char *mbuf, char *pbuf, aClient *cptr, aClient *sptr, int parc, char **parv) { if (IsChanUser(sptr, chptr, CHFL_CHANOP) || IsOperMode(sptr) || IsServer(cptr)) { return set_limit(adl, chptr, nmodes, argnum, pidx, mbix, mbuf, pbuf, cptr, sptr, parc, parv); } else send_me_numeric(sptr, ERR_CHANOPRIVSNEEDED, chptr); return nmodes; } static int sl_user(int adl, aChannel *chptr, int nmodes, int *argnum, int *pidx, int *mbix, char *mbuf, char *pbuf, aClient *cptr, aClient *sptr, int parc, char **parv) { if (IsChanUser(sptr, chptr, CHFL_CHANOP)) return set_limit(adl, chptr, nmodes, argnum, pidx, mbix, mbuf, pbuf, cptr, sptr, parc, parv); else send_me_numeric(sptr, ERR_CHANOPRIVSNEEDED, chptr); return nmodes; } static struct ChanMode mode_limit[] = { {MODE_LIMIT, 1, MFLG_PARAMNUM, CMTYPE_PARAMETRIC | CMTYPE_REMWOPARA, sl_user, sl_oper, sl_uline, sl_server, sl_service} }; static int do_can_join(struct hook_data *thisdata) { aChannel *chptr = thisdata->channel; if (chptr->mode.limit && chptr->users >= chptr->mode.limit) return ERR_CHANNELISFULL; return 0; } #ifndef STATIC_MODULES int _persistent = 1; void _modinit(void) #else void limit_modinit(void) #endif { modetab[(int) 'l'] = mode_limit[0]; GeneralOpts.lists_created = 0; hook_add_hook("can join", (hookfn *) do_can_join); }