Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/VibeDevelopers/Comet.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550/* * Comet: a slightly advanced ircd * chmode.c: channel mode management * * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center * Copyright (C) 1996-2002 Hybrid Development Team * Copyright (C) 2002-2005 ircd-ratbox development team * Copyright (C) 2005-2006 charybdis development team * * 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 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */
#include "stdinc.h"#include "channel.h"#include "client.h"#include "hash.h"#include "hook.h"#include "match.h"#include "ircd.h"#include "numeric.h"#include "s_serv.h" /* captab */#include "s_user.h"#include "send.h"#include "whowas.h"#include "s_conf.h" /* ConfigFileEntry, ConfigChannel */#include "s_newconf.h"#include "logger.h"#include "chmode.h"#include "s_assert.h"#include "parse.h"#include "msgbuf.h"#include "packet.h"
/* bitmasks for error returns, so we send once per call */#define SM_ERR_NOTS 0x00000001 /* No TS on channel */#define SM_ERR_NOOPS 0x00000002 /* No chan ops */#define SM_ERR_UNKNOWN 0x00000004#define SM_ERR_RPL_C 0x00000008#define SM_ERR_RPL_B 0x00000010#define SM_ERR_RPL_E 0x00000020#define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */#define SM_ERR_RPL_I 0x00000100#define SM_ERR_RPL_D 0x00000200#define SM_ERR_NOPRIVS 0x00000400#define SM_ERR_RPL_Q 0x00000800#define SM_ERR_RPL_F 0x00001000#define SM_ERR_MLOCK 0x00002000
#define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */
static struct ChModeChange mode_changes[BUFSIZE];static int mode_count;static int mask_pos;static int removed_mask_pos;
char cflagsbuf[256];char cflagsmyinfo[256];
int chmode_flags[256];
extern int h_get_channel_access;
/* OPTIMIZE ME! -- dwr */voidconstruct_cflags_strings(void){ int i; char *ptr = cflagsbuf; char *ptr2 = cflagsmyinfo;
*ptr = '\0'; *ptr2 = '\0';
for(i = 0; i < 256; i++) { if (chmode_table[i].set_func != chm_ban && chmode_table[i].set_func != chm_forward && chmode_table[i].set_func != chm_throttle && chmode_table[i].set_func != chm_key && chmode_table[i].set_func != chm_limit && chmode_table[i].set_func != chm_op && chmode_table[i].set_func != chm_halfop && chmode_table[i].set_func != chm_voice) { chmode_flags[i] = chmode_table[i].mode_type; } else { chmode_flags[i] = 0; }
switch (chmode_flags[i]) { case MODE_FREETARGET: case MODE_DISFORWARD: if(ConfigChannel.use_forward) *ptr++ = (char) i; break; default: if(chmode_flags[i] != 0) { *ptr++ = (char) i; } }
/* Should we leave orphaned check here? -- dwr */ if (chmode_table[i].set_func != NULL && chmode_table[i].set_func != chm_orphaned) { *ptr2++ = (char) i; } }
*ptr++ = '\0'; *ptr2++ = '\0';}
/* * find_umode_slot * * inputs - NONE * outputs - an available cflag bitmask or * 0 if no cflags are available * side effects - NONE */static unsigned intfind_cflag_slot(void){ unsigned int all_cflags = 0, my_cflag = 0, i;
for (i = 0; i < 256; i++) all_cflags |= chmode_flags[i];
for (my_cflag = 1; my_cflag && (all_cflags & my_cflag); my_cflag <<= 1);
return my_cflag;}
unsigned intcflag_add(char c_, ChannelModeFunc function){ int c = (unsigned char)c_;
if (chmode_table[c].set_func != NULL && chmode_table[c].set_func != chm_orphaned) return 0;
if (chmode_table[c].set_func == NULL) chmode_table[c].mode_type = find_cflag_slot(); if (chmode_table[c].mode_type == 0) return 0; chmode_table[c].set_func = function; construct_cflags_strings(); return chmode_table[c].mode_type;}
voidcflag_orphan(char c_){ int c = (unsigned char)c_;
s_assert(chmode_flags[c] != 0); chmode_table[c].set_func = chm_orphaned; construct_cflags_strings();}
intget_channel_access(struct Client *source_p, struct Channel *chptr, struct membership *msptr, int dir, const char *modestr){ hook_data_channel_approval moduledata;
if(!MyClient(source_p)) return CHFL_CHANOP;
moduledata.client = source_p; moduledata.chptr = chptr; moduledata.msptr = msptr; moduledata.target = NULL; if (msptr != NULL && is_chanop(msptr)) moduledata.approved = CHFL_CHANOP; else if (msptr != NULL && is_halfop(msptr)) moduledata.approved = CHFL_HALFOP; else moduledata.approved = CHFL_PEON; moduledata.dir = dir; moduledata.modestr = modestr;
call_hook(h_get_channel_access, &moduledata);
return moduledata.approved;}
/* allow_mode_change() * * Checks if mlock and chanops permit a mode change. * * inputs - client, channel, access level, errors pointer, mode char * outputs - false on failure, true on success * side effects - error message sent on failure */static boolallow_mode_change(struct Client *source_p, struct Channel *chptr, int alevel, int *errors, char c){ /* If this mode char is locked, don't allow local users to change it. */ if (MyClient(source_p) && chptr->mode_lock && strchr(chptr->mode_lock, c)) { if (!(*errors & SM_ERR_MLOCK)) sendto_one_numeric(source_p, ERR_MLOCKRESTRICTED, form_str(ERR_MLOCKRESTRICTED), chptr->chname, c, chptr->mode_lock); *errors |= SM_ERR_MLOCK; return false; } if(alevel < CHFL_HALFOP) { if(!(*errors & SM_ERR_NOOPS)) sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), me.name, source_p->name, chptr->chname); *errors |= SM_ERR_NOOPS; return false; } return true;}
/* add_id() * * inputs - client, channel, id to add, type, forward * outputs - NULL on failure, allocated Ban on success * side effects - given id is added to the appropriate list */struct Ban *add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward, rb_dlink_list * list, long mode_type){ struct Ban *actualBan; static char who[USERHOST_REPLYLEN]; char *realban = LOCAL_COPY(banid); rb_dlink_node *ptr;
/* dont let local clients overflow the banlist */ if(MyClient(source_p)) { if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (unsigned long)((chptr->mode.mode & MODE_EXLIMIT) ? ConfigChannel.max_bans_large : ConfigChannel.max_bans)) { sendto_one(source_p, form_str(ERR_BANLISTFULL), me.name, source_p->name, chptr->chname, realban); return NULL; } }
/* don't let anyone set duplicate bans */ RB_DLINK_FOREACH(ptr, list->head) { actualBan = ptr->data; if(!irccmp(actualBan->banstr, realban)) return NULL; }
if(IsPerson(source_p)) sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host); else rb_strlcpy(who, source_p->name, sizeof(who));
actualBan = allocate_ban(realban, who, forward); actualBan->when = rb_current_time();
rb_dlinkAdd(actualBan, &actualBan->node, list);
/* invalidate the can_send() cache */ if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) chptr->bants++;
return actualBan;}
/* del_id() * * inputs - channel, id to remove, type * outputs - pointer to ban that was removed, if any * side effects - given id is removed from the appropriate list and returned */struct Ban *del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type){ rb_dlink_node *ptr; struct Ban *banptr;
if(EmptyString(banid)) return NULL;
RB_DLINK_FOREACH(ptr, list->head) { banptr = ptr->data;
if(irccmp(banid, banptr->banstr) == 0) { rb_dlinkDelete(&banptr->node, list);
/* invalidate the can_send() cache */ if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) chptr->bants++;
return banptr; } }
return NULL;}
/* check_string() * * input - string to check * output - pointer to 'fixed' string, or "*" if empty * side effects - any white space found becomes \0 */static char *check_string(char *s){ char *str = s; static char splat[] = "*"; if(!(s && *s)) return splat;
for(; *s; ++s) { if(IsSpace(*s)) { *s = '\0'; break; } } return str;}
/* pretty_mask() * * inputs - mask to pretty * outputs - better version of the mask * side effects - mask is chopped to limits, and transformed: * x!y@z => x!y@z * y@z => *!y@z * x!y => x!y@* * x => x!*@* * z.d => *!*@z.d */static char *pretty_mask(const char *idmask){ static char mask_buf[BUFSIZE]; int old_mask_pos; const char *nick, *user, *host, *forward = NULL; char *t, *at, *ex; int nl, ul, hl, fl; char *mask; size_t masklen;
mask = LOCAL_COPY(idmask); mask = check_string(mask); collapse(mask); masklen = strlen(mask);
nick = user = host = "*"; nl = ul = hl = 1; fl = 0;
if((size_t) BUFSIZE - mask_pos < masklen + 5) return NULL;
old_mask_pos = mask_pos;
if (*mask == '$') { memcpy(mask_buf + mask_pos, mask, masklen + 1); mask_pos += masklen + 1; t = mask_buf + old_mask_pos + 1; if (*t == '!') *t = '~'; if (*t == '~') t++; *t = irctolower(*t); return mask_buf + old_mask_pos; }
at = ex = NULL; if((t = memchr(mask, '@', masklen)) != NULL) { at = t; t++; if(*t != '\0') host = t, hl = strlen(t);
if((t = memchr(mask, '!', at - mask)) != NULL) { ex = t; t++; if(at != t) user = t, ul = at - t; if(ex != mask) nick = mask, nl = ex - mask; } else { if(at != mask) user = mask, ul = at - mask; }
if((t = memchr(host, '!', hl)) != NULL || (t = memchr(host, '$', hl)) != NULL) { t++; if (host + hl != t) forward = t, fl = host + hl - t; hl = t - 1 - host; } } else if((t = memchr(mask, '!', masklen)) != NULL) { ex = t; t++; if(ex != mask) nick = mask, nl = ex - mask; if(*t != '\0') user = t, ul = strlen(t); } else if(memchr(mask, '.', masklen) != NULL || memchr(mask, ':', masklen) != NULL) { host = mask, hl = masklen; } else { if(masklen > 0) nick = mask, nl = masklen; }
/* truncate values to max lengths */ if(nl > NICKLEN - 1) nl = NICKLEN - 1; if(ul > USERLEN) ul = USERLEN; if(hl > HOSTLEN) hl = HOSTLEN; if(fl > CHANNELLEN) fl = CHANNELLEN;
memcpy(mask_buf + mask_pos, nick, nl), mask_pos += nl; mask_buf[mask_pos++] = '!'; memcpy(mask_buf + mask_pos, user, ul), mask_pos += ul; mask_buf[mask_pos++] = '@'; memcpy(mask_buf + mask_pos, host, hl), mask_pos += hl; if (forward) { mask_buf[mask_pos++] = '$'; memcpy(mask_buf + mask_pos, forward, fl), mask_pos += fl; } mask_buf[mask_pos++] = '\0';
return mask_buf + old_mask_pos;}
/* check_forward() * * input - client, channel to set mode on, target channel name * output - true if forwarding should be allowed * side effects - numeric sent if not allowed */static boolcheck_forward(struct Client *source_p, struct Channel *chptr, const char *forward){ struct Channel *targptr = NULL; struct membership *msptr;
if(!check_channel_name(forward) || (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward)))) { sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward); return false; } /* don't forward to inconsistent target -- jilles */ if(chptr->chname[0] == '#' && forward[0] == '&') { sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward); return false; } if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL) { sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, form_str(ERR_NOSUCHCHANNEL), forward); return false; } if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET)) { if((msptr = find_channel_membership(targptr, source_p)) == NULL || get_channel_access(source_p, targptr, msptr, MODE_QUERY, NULL) < CHFL_CHANOP) { sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), me.name, source_p->name, targptr->chname); return false; } } return true;}
/* fix_key() * * input - key to fix * output - the same key, fixed * side effects - anything below ascii 13 is discarded, ':' discarded, * high ascii is dropped to lower half of ascii table */static char *fix_key(char *arg){ unsigned char *s, *t, c;
for(s = t = (unsigned char *) arg; (c = *s); s++) { c &= 0x7f; if(c != ':' && c != ',' && c > ' ') *t++ = c; }
*t = '\0'; return arg;}
/* fix_key_remote() * * input - key to fix * ouput - the same key, fixed * side effects - high ascii dropped to lower half of table, * CR/LF/':' are dropped */static char *fix_key_remote(char *arg){ unsigned char *s, *t, c;
for(s = t = (unsigned char *) arg; (c = *s); s++) { c &= 0x7f; if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' ')) *t++ = c; }
*t = '\0'; return arg;}
voidchm_simple(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ if(!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
/* setting + */ if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { /* if +f is disabled, ignore an attempt to set +QF locally */ if(!ConfigChannel.use_forward && MyClient(source_p) && (c == 'Q' || c == 'F')) return;
chptr->mode.mode |= mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].id = NULL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count++].arg = NULL; } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { chptr->mode.mode &= ~mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = NULL; }}
voidchm_orphaned(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ if(MyClient(source_p)) return;
if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { chptr->mode.mode |= mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].id = NULL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count++].arg = NULL; } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { chptr->mode.mode &= ~mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = NULL; }}
voidchm_hidden(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ if(MyClient(source_p) && !IsOperGeneral(source_p)) { if(!(*errors & SM_ERR_NOPRIVS)) sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); *errors |= SM_ERR_NOPRIVS; return; } if(MyClient(source_p) && !IsOperAdmin(source_p)) { if(!(*errors & SM_ERR_NOPRIVS)) sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); *errors |= SM_ERR_NOPRIVS; return; }
/* setting + */ if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { chptr->mode.mode |= mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].id = NULL; mode_changes[mode_count].mems = ONLY_OPERS; mode_changes[mode_count++].arg = NULL; } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { chptr->mode.mode &= ~mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ONLY_OPERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = NULL; }}
voidchm_staff(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ if(MyClient(source_p) && !IsOper(source_p)) { if(!(*errors & SM_ERR_NOPRIVS)) sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); *errors |= SM_ERR_NOPRIVS; return; } if(MyClient(source_p) && !HasPrivilege(source_p, "oper:cmodes")) { if(!(*errors & SM_ERR_NOPRIVS)) sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "cmodes"); *errors |= SM_ERR_NOPRIVS; return; }
/* setting + */ if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) { chptr->mode.mode |= mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].id = NULL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count++].arg = NULL; } else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) { chptr->mode.mode &= ~mode_type;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = NULL; }}
voidchm_ban(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ const char *mask; char *forward; rb_dlink_list *list; rb_dlink_node *ptr; struct Ban *banptr; int errorval; const char *rpl_list_p; const char *rpl_endlist_p; int mems;
switch (mode_type) { case CHFL_BAN: list = &chptr->banlist; errorval = SM_ERR_RPL_B; rpl_list_p = form_str(RPL_BANLIST); rpl_endlist_p = form_str(RPL_ENDOFBANLIST); mems = ALL_MEMBERS; break;
case CHFL_EXCEPTION: /* if +e is disabled, allow all but +e locally */ if (!ConfigChannel.use_except && MyClient(source_p) && dir == MODE_ADD) return;
list = &chptr->exceptlist; errorval = SM_ERR_RPL_E; rpl_list_p = form_str(RPL_EXCEPTLIST); rpl_endlist_p = form_str(RPL_ENDOFEXCEPTLIST);
if(ConfigChannel.use_except || (dir == MODE_DEL)) mems = ONLY_CHANOPS; else mems = ONLY_SERVERS; break;
case CHFL_INVEX: /* if +I is disabled, allow all but +I locally */ if (!ConfigChannel.use_invex && MyClient(source_p) && dir == MODE_ADD) return;
list = &chptr->invexlist; errorval = SM_ERR_RPL_I; rpl_list_p = form_str(RPL_INVITELIST); rpl_endlist_p = form_str(RPL_ENDOFINVITELIST);
if(ConfigChannel.use_invex || (dir == MODE_DEL)) mems = ONLY_CHANOPS; else mems = ONLY_SERVERS; break;
case CHFL_QUIET: list = &chptr->quietlist; errorval = SM_ERR_RPL_Q; rpl_list_p = form_str(RPL_QUIETLIST); rpl_endlist_p = form_str(RPL_ENDOFQUIETLIST); mems = ALL_MEMBERS; break;
default: sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "chm_ban() called with unknown type!"); return; }
if (dir == MODE_QUERY) { if((*errors & errorval) != 0) return; *errors |= errorval;
/* non-ops cant see +eI lists.. */ /* note that this is still permitted if +e/+I are mlocked. */ if(alevel < CHFL_HALFOP && mode_type != CHFL_BAN && mode_type != CHFL_QUIET) { if(!(*errors & SM_ERR_NOOPS)) sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), me.name, source_p->name, chptr->chname); *errors |= SM_ERR_NOOPS; return; }
RB_DLINK_FOREACH(ptr, list->head) { char buf[BANLEN]; banptr = ptr->data; if(banptr->forward) snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward); else rb_strlcpy(buf, banptr->banstr, sizeof(buf));
sendto_one(source_p, rpl_list_p, me.name, source_p->name, chptr->chname, buf, banptr->who, banptr->when); } sendto_one(source_p, rpl_endlist_p, me.name, source_p->name, chptr->chname); return; }
if (!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
/* empty ban, or starts with ':' which messes up s2s, ignore it */ if (EmptyString(arg) || *arg == ':') return;
if (!MyClient(source_p)) { if (strchr(arg, ' ')) return;
mask = arg; } else mask = pretty_mask(arg);
/* we'd have problems parsing this, hyb6 does it too * also make sure it will always fit on a line with channel * name etc. */ if(strlen(mask) > MIN(BANLEN, MODEBUFLEN - 5)) { sendto_one_numeric(source_p, ERR_INVALIDBAN, form_str(ERR_INVALIDBAN), chptr->chname, c, arg); return; }
/* Look for a $ after the first character. * As the first character, it marks an extban; afterwards * it delimits a forward channel. */ if ((forward = strchr(mask+1, '$')) != NULL) { *forward++ = '\0'; if (*forward == '\0') forward = NULL; }
/* if we're adding a NEW id */ if (dir == MODE_ADD) { if (*mask == '$' && MyClient(source_p)) { if (!valid_extban(mask, source_p, chptr, mode_type)) { sendto_one_numeric(source_p, ERR_INVALIDBAN, form_str(ERR_INVALIDBAN), chptr->chname, c, arg); return; } }
/* For compatibility, only check the forward channel from * local clients. Accept any forward channel from servers. */ if (forward != NULL && MyClient(source_p)) { /* For simplicity and future flexibility, do not * allow '$' in forwarding targets. */ if (!ConfigChannel.use_forward || strchr(forward, '$') != NULL) { sendto_one_numeric(source_p, ERR_INVALIDBAN, form_str(ERR_INVALIDBAN), chptr->chname, c, arg); return; } /* check_forward() sends its own error message */ if (!check_forward(source_p, chptr, forward)) return; /* Forwards only make sense for bans. */ if (mode_type != CHFL_BAN) { sendto_one_numeric(source_p, ERR_INVALIDBAN, form_str(ERR_INVALIDBAN), chptr->chname, c, arg); return; } }
/* dont allow local clients to overflow the banlist, dont * let remote servers set duplicate bans */ if (!add_id(source_p, chptr, mask, forward, list, mode_type)) return;
if (forward) forward[-1]= '$';
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = mems; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = mask; } else if (dir == MODE_DEL) { struct Ban *removed; static char buf[BANLEN * MAXMODEPARAMS]; int old_removed_mask_pos = removed_mask_pos; if ((removed = del_id(chptr, mask, list, mode_type)) == NULL) { /* mask isn't a valid ban, check arg */ if ((removed = del_id(chptr, arg, list, mode_type)) != NULL) mask = arg; }
if (removed && removed->forward) removed_mask_pos += snprintf(buf + old_removed_mask_pos, sizeof(buf) - old_removed_mask_pos, "%s$%s", removed->banstr, removed->forward) + 1; else removed_mask_pos += rb_strlcpy(buf + old_removed_mask_pos, removed ? removed->banstr : mask, sizeof(buf)) + 1; if (removed) { free_ban(removed); removed = NULL; }
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = mems; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = buf + old_removed_mask_pos; }}
voidchm_op(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ struct membership *mstptr; struct Client *targ_p;
if(!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
/* Halfops cannot grant or remove ops */ if (alevel == CHFL_HALFOP) { if (!(*errors & SM_ERR_NOOPS)) sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), me.name, source_p->name, chptr->chname); *errors |= SM_ERR_NOOPS; return; }
/* empty nick */ if(EmptyString(arg)) { sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); return; }
if((targ_p = find_chasing(source_p, arg, NULL)) == NULL) { return; }
mstptr = find_channel_membership(chptr, targ_p);
if(mstptr == NULL) { if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, form_str(ERR_USERNOTINCHANNEL), arg, chptr->chname); *errors |= SM_ERR_NOTONCHANNEL; return; }
if(dir == MODE_ADD) { if(targ_p == source_p && mstptr->flags & CHFL_CHANOP) return;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = targ_p->id; mode_changes[mode_count++].arg = targ_p->name;
mstptr->flags |= CHFL_CHANOP; } else { if(MyClient(source_p) && IsService(targ_p)) { sendto_one(source_p, form_str(ERR_ISCHANSERVICE), me.name, source_p->name, targ_p->name, chptr->chname); return; }
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = targ_p->id; mode_changes[mode_count++].arg = targ_p->name;
mstptr->flags &= ~CHFL_CHANOP; }}
voidchm_halfop(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ struct membership *mstptr; struct Client *targ_p;
if(!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
/* empty nick */ if(EmptyString(arg)) { sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); return; }
if((targ_p = find_chasing(source_p, arg, NULL)) == NULL) { return; }
mstptr = find_channel_membership(chptr, targ_p);
if(mstptr == NULL) { if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, form_str(ERR_USERNOTINCHANNEL), arg, chptr->chname); *errors |= SM_ERR_NOTONCHANNEL; return; }
if(dir == MODE_ADD) { if(targ_p == source_p && mstptr->flags & CHFL_HALFOP) return;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = targ_p->id; mode_changes[mode_count++].arg = targ_p->name;
mstptr->flags |= CHFL_HALFOP; } else { if(MyClient(source_p) && IsService(targ_p)) { sendto_one(source_p, form_str(ERR_ISCHANSERVICE), me.name, source_p->name, targ_p->name, chptr->chname); return; }
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = targ_p->id; mode_changes[mode_count++].arg = targ_p->name;
mstptr->flags &= ~CHFL_HALFOP; }}
voidchm_voice(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ struct membership *mstptr; struct Client *targ_p;
if(!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
/* empty nick */ if(EmptyString(arg)) { sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); return; }
if((targ_p = find_chasing(source_p, arg, NULL)) == NULL) { return; }
mstptr = find_channel_membership(chptr, targ_p);
if(mstptr == NULL) { if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, form_str(ERR_USERNOTINCHANNEL), arg, chptr->chname); *errors |= SM_ERR_NOTONCHANNEL; return; }
if(dir == MODE_ADD) { mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = targ_p->id; mode_changes[mode_count++].arg = targ_p->name;
mstptr->flags |= CHFL_VOICE; } else { mode_changes[mode_count].letter = 'v'; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = targ_p->id; mode_changes[mode_count++].arg = targ_p->name;
mstptr->flags &= ~CHFL_VOICE; }}
voidchm_limit(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ static char limitstr[30]; int limit;
if (!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
if (dir == MODE_ADD) { if (EmptyString(arg) || (limit = atoi(arg)) <= 0) return;
sprintf(limitstr, "%d", limit);
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = limitstr;
chptr->mode.limit = limit; } else if (dir == MODE_DEL) { if(!chptr->mode.limit) return;
chptr->mode.limit = 0;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = NULL; }}
voidchm_throttle(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ int joins = 0, timeslice = 0;
if (!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
if (dir == MODE_ADD) { if (sscanf(arg, "%d:%d", &joins, ×lice) < 2) return;
if(joins <= 0 || timeslice <= 0) return;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = arg;
chptr->mode.join_num = joins; chptr->mode.join_time = timeslice; } else if(dir == MODE_DEL) { if(!chptr->mode.join_num) return;
chptr->mode.join_num = 0; chptr->mode.join_time = 0; chptr->join_count = 0; chptr->join_delta = 0;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = NULL; }}
voidchm_forward(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ /* if +f is disabled, ignore local attempts to set it */ if (!ConfigChannel.use_forward && MyClient(source_p) && dir == MODE_ADD) return;
if (dir == MODE_QUERY) { if (!(*errors & SM_ERR_RPL_F)) { if (*chptr->mode.forward == '\0') sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname); else sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward); *errors |= SM_ERR_RPL_F; } return; }
#ifndef FORWARD_OPERONLY if (!allow_mode_change(source_p, chptr, alevel, errors, c)) return;#else if (!IsOperGeneral(source_p) && !IsServer(source_p)) { if(!(*errors & SM_ERR_NOPRIVS)) sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); *errors |= SM_ERR_NOPRIVS; return; }#endif
if (dir == MODE_ADD) { if(EmptyString(arg)) return;
if(!check_forward(source_p, chptr, arg)) return;
rb_strlcpy(chptr->mode.forward, arg, sizeof(chptr->mode.forward));
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = arg; } else if(dir == MODE_DEL) { if(!(*chptr->mode.forward)) return;
*chptr->mode.forward = '\0';
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = NULL; }}
voidchm_key(struct Client *source_p, struct Channel *chptr, int alevel, const char *arg, int *errors, int dir, char c, long mode_type){ char *key;
if (!allow_mode_change(source_p, chptr, alevel, errors, c)) return;
if (dir == MODE_ADD) { key = LOCAL_COPY(arg);
if(MyClient(source_p)) fix_key(key); else fix_key_remote(key);
if(EmptyString(key)) return;
s_assert(key[0] != ' '); rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_ADD; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = chptr->mode.key; } else if(dir == MODE_DEL) { static char splat[] = "*"; int i;
if(!(*chptr->mode.key)) return;
/* hack time. when we get a +k-k mode, the +k arg is * chptr->mode.key, which the -k sets to \0, so hunt for a * +k when we get a -k, and set the arg to splat. --anfl */ for(i = 0; i < mode_count; i++) { if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD) mode_changes[i].arg = splat; }
*chptr->mode.key = 0;
mode_changes[mode_count].letter = c; mode_changes[mode_count].dir = MODE_DEL; mode_changes[mode_count].mems = ALL_MEMBERS; mode_changes[mode_count].id = NULL; mode_changes[mode_count++].arg = "*"; }}
/* *INDENT-OFF* */struct ChannelMode chmode_table[256] ={ ['F'] = {chm_simple, MODE_FREETARGET, 0 }, ['I'] = {chm_ban, CHFL_INVEX, CHM_QUERYABLE | CHM_OPS_QUERY }, ['L'] = {chm_staff, MODE_EXLIMIT, 0 }, ['P'] = {chm_staff, MODE_PERMANENT, 0 }, ['Q'] = {chm_simple, MODE_DISFORWARD, 0 }, ['b'] = {chm_ban, CHFL_BAN, CHM_QUERYABLE }, ['e'] = {chm_ban, CHFL_EXCEPTION, CHM_QUERYABLE | CHM_OPS_QUERY }, ['f'] = {chm_forward, 0, CHM_ARG_SET | CHM_CAN_QUERY }, /* weird because it's nonstandard and violates isupport */ ['g'] = {chm_simple, MODE_FREEINVITE, 0 }, ['i'] = {chm_simple, MODE_INVITEONLY, 0 }, ['j'] = {chm_throttle, 0, CHM_ARG_SET }, ['k'] = {chm_key, 0, CHM_QUERYABLE }, ['l'] = {chm_limit, 0, CHM_ARG_SET }, ['m'] = {chm_simple, MODE_MODERATED, 0 }, ['n'] = {chm_simple, MODE_NOPRIVMSGS, 0 }, ['h'] = {chm_halfop, 0, CHM_ARGS }, ['o'] = {chm_op, 0, CHM_ARGS }, ['p'] = {chm_simple, MODE_PRIVATE, 0 }, ['q'] = {chm_ban, CHFL_QUIET, CHM_QUERYABLE }, ['r'] = {chm_simple, MODE_REGONLY, 0 }, ['s'] = {chm_simple, MODE_SECRET, 0 }, ['t'] = {chm_simple, MODE_TOPICLIMIT, 0 }, ['v'] = {chm_voice, 0, CHM_ARGS }, ['z'] = {chm_simple, MODE_OPMODERATE, 0 }, ['U'] = {chm_simple, MODE_HIDEBANS, 0 },};
/* *INDENT-ON* */
/* set_channel_mode() * * inputs - client, source, channel, membership pointer, params * output - * side effects - channel modes/memberships are changed, MODE is issued * * Extensively modified to be hotpluggable, 03/09/06 -- nenolod */voidset_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]){ static char modebuf[BUFSIZE * 2]; /* paranoid case: 2 canonical chars per input char */ static char parabuf[BUFSIZE]; char *mbuf; char *pbuf; int cur_len, mlen, paralen, paracount, arglen, len; int i, j, flags; int dir = MODE_ADD; bool changes = false; bool privileged_query = false; int parn = 1; int errors = 0; int alevel; const char *ml = parv[0]; char c; struct Client *fakesource_p; int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; int mode_limit = 0; int mode_limit_simple = 0;
mask_pos = 0; removed_mask_pos = 0; mode_count = 0;
/* Hide connecting server on netburst -- jilles */ if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p)) fakesource_p = &me; else fakesource_p = source_p;
struct modeset { const struct ChannelMode *cm; const char *arg; int dir; char mode; };
static struct modeset modesets[MAXMODEPARAMS + MAXMODES_SIMPLE]; struct modeset *ms = modesets, *mend; char canon_op = '\0';
mbuf = modebuf;
for (ml = parv[0]; *ml != 0 && ms - modesets < ARRAY_SIZE(modesets); ml++) { c = *ml; switch (c) { case '+': dir = MODE_ADD; break; case '-': dir = MODE_DEL; break; case '=': dir = MODE_QUERY; break; default: { int effective_dir = dir; const struct ChannelMode *cm = &chmode_table[(unsigned char) c]; bool use_arg = dir == MODE_ADD ? cm->flags & CHM_ARG_SET : dir == MODE_DEL ? cm->flags & CHM_ARG_DEL : false; if (cm->set_func == NULL) { sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); return; } if (use_arg && parn >= parc) { if (!(cm->flags & CHM_CAN_QUERY)) { sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MODE"); return; } effective_dir = MODE_QUERY; use_arg = false; }
if (effective_dir == MODE_QUERY && !(cm->flags & CHM_CAN_QUERY)) { /* XXX this currently replicates traditional behaviour and just * does nothing for a query on a mode with no query. would it be * good to send an error here? */ continue; }
if (MyClient(source_p)) { if (use_arg && ++mode_limit > MAXMODEPARAMS) continue; if (!use_arg && ++mode_limit_simple > MAXMODES_SIMPLE) continue; }
char op = effective_dir == MODE_ADD ? '+' : effective_dir == MODE_DEL ? '-' : '=';
if (op != canon_op) *mbuf++ = canon_op = op;
*mbuf++ = c;
if (effective_dir != MODE_QUERY) changes = true; if (effective_dir == MODE_QUERY && cm->flags & CHM_OPS_QUERY) privileged_query = true;
ms->cm = cm; ms->dir = effective_dir; if (use_arg) ms->arg = parv[parn++]; else ms->arg = NULL; ms->mode = c; ms++; } } }
/* this will happen on something like MODE +-=++-. * we'd have caught that with the if !mode_count * later on, but this saves an override notice */ if (ms == modesets) return;
if (parn < parc) { /* XXX we could reject excess params here */ }
/* Finish the flood grace period if we were asked to do anything */ if (changes && MyClient(source_p) && !IsFloodDone(source_p)) { flood_endgrace(source_p); }
mend = ms;
if (parn > 1) { strcpy(mbuf, " "); rb_strlcat(modebuf, reconstruct_parv(parn - 1, parv + 1), sizeof modebuf); } else { *mbuf = '\0'; } int access_dir = privileged_query ? MODE_OP_QUERY : changes ? MODE_ADD : MODE_QUERY; alevel = get_channel_access(source_p, chptr, msptr, access_dir, modebuf);
for (ms = modesets; ms < mend; ms++) { ChannelModeFunc *set_func = ms->cm->set_func; set_func(fakesource_p, chptr, alevel, ms->arg, &errors, ms->dir, ms->mode, ms->cm->mode_type); }
/* bail out if we have nothing to do... */ if (!mode_count) return;
if (IsServer(source_p)) mlen = sprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname); else mlen = sprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name, source_p->username, source_p->host, chptr->chname);
for(j = 0; j < 3; j++) { int send_flags = flags = flags_list[j]; const char *priv = NULL; if (flags == ONLY_OPERS) { send_flags = ALL_MEMBERS; priv = "auspex:cmodes"; } cur_len = mlen; mbuf = modebuf + mlen; pbuf = parabuf; parabuf[0] = '\0'; paracount = paralen = 0; dir = MODE_QUERY;
for(i = 0; i < mode_count; i++) { if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags) continue;
if(mode_changes[i].arg != NULL) { arglen = strlen(mode_changes[i].arg);
if(arglen > MODEBUFLEN - 5) continue; } else arglen = 0;
/* if we're creeping over MAXMODEPARAMSSERV, or over * bufsize (4 == +/-,modechar,two spaces) send now. */ if(mode_changes[i].arg != NULL && ((paracount == MAXMODEPARAMSSERV) || ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) { *mbuf = '\0';
if(cur_len > mlen) sendto_channel_local_priv(IsServer(source_p) ? fakesource_p : source_p, send_flags, priv, chptr, "%s %s", modebuf, parabuf); else continue;
paracount = paralen = 0; cur_len = mlen; mbuf = modebuf + mlen; pbuf = parabuf; parabuf[0] = '\0'; dir = MODE_QUERY; }
if(dir != mode_changes[i].dir) { *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; cur_len++; dir = mode_changes[i].dir; }
*mbuf++ = mode_changes[i].letter; cur_len++;
if(mode_changes[i].arg != NULL) { paracount++; len = sprintf(pbuf, "%s ", mode_changes[i].arg); pbuf += len; paralen += len; } }
if(paralen && parabuf[paralen - 1] == ' ') parabuf[paralen - 1] = '\0';
*mbuf = '\0'; if(cur_len > mlen) sendto_channel_local_priv(IsServer(source_p) ? fakesource_p : source_p, send_flags, priv, chptr, "%s %s", modebuf, parabuf); }
/* only propagate modes originating locally, or if we're hubbing */ if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1) send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count);}
/* set_channel_mlock() * * inputs - client, source, channel, params * output - * side effects - channel mlock is changed / MLOCK is propagated */voidset_channel_mlock(struct Client *client_p, struct Client *source_p, struct Channel *chptr, const char *newmlock, bool propagate){ rb_free(chptr->mode_lock); chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL;
if (propagate) { sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s", source_p->id, (long) chptr->channelts, chptr->chname, chptr->mode_lock ? chptr->mode_lock : ""); }}