2 * ircd-ratbox: A slightly useful ircd.
3 * m_join.c: Joins a channel.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
37 #include "s_newconf.h"
44 static int m_join(struct Client
*, struct Client
*, int, const char **);
45 static int me_svsjoin(struct Client
*, struct Client
*, int, const char **);
46 static int ms_join(struct Client
*, struct Client
*, int, const char **);
47 static int ms_sjoin(struct Client
*, struct Client
*, int, const char **);
49 struct module_modes ModuleModes
;
51 struct Message join_msgtab
= {
52 "JOIN", 0, 0, 0, MFLG_SLOW
,
53 {mg_unreg
, {m_join
, 2}, {ms_join
, 2}, mg_ignore
, mg_ignore
, {m_join
, 2}}
56 struct Message svsjoin_msgtab
= {
57 "SVSJOIN", 0, 0, 0, MFLG_SLOW
,
58 {mg_ignore
, mg_ignore
, mg_ignore
, mg_ignore
, {me_svsjoin
, 3}, mg_ignore
}
61 struct Message sjoin_msgtab
= {
62 "SJOIN", 0, 0, 0, MFLG_SLOW
,
63 {mg_unreg
, mg_ignore
, mg_ignore
, {ms_sjoin
, 4}, mg_ignore
, mg_ignore
}
66 mapi_clist_av1 join_clist
[] = { &join_msgtab
, &svsjoin_msgtab
, &sjoin_msgtab
, NULL
};
68 DECLARE_MODULE_AV1(join
, NULL
, NULL
, join_clist
, NULL
, NULL
, "$Revision: 3494 $");
70 static void set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
);
71 static void remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
);
73 static void remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
74 rb_dlink_list
* list
, char c
, int mems
);
76 static char modebuf
[MODEBUFLEN
];
77 static char omodebuf
[MODEBUFLEN
];
78 static char parabuf
[MODEBUFLEN
];
79 static const char *para
[MAXMODEPARAMS
];
80 static char *mbuf
, *ombuf
;
86 * parv[2] = channel password (key)
89 m_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
91 user_join(client_p
, source_p
, parv
[1], parc
> 2 ? parv
[2] : NULL
); /* channel.c */
97 * me_svsjoin - small function to allow services to forcejoin clients, mainly for ns_ajoin
98 * parv[1] = user to act on (join to a channel)
100 * This does allow opers to "forcejoin" users to channels with operserv/raw or by writing a
101 * custom module (where they can make it not log anything), but the former bitches that it's
102 * being used and the latter...Can probably be done anyway with enough hackyness if this
103 * command didn't exist so it's not all that bad.
106 me_svsjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
108 struct Client
*target_p
;
110 if(!(source_p
->flags
& FLAGS_SERVICE
))
113 if((target_p
= find_person(parv
[1])) == NULL
)
116 if(!MyClient(target_p
))
119 user_join(&me
, target_p
, parv
[2], NULL
);
125 * parv[1] = channel TS
127 * parv[3] = "+", formerly channel modes but now unused
128 * alternatively, a single "0" parameter parts all channels
131 ms_join(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
133 struct Channel
*chptr
;
134 static struct Mode mode
;
138 int keep_our_modes
= YES
;
139 int keep_new_modes
= YES
;
140 rb_dlink_node
*ptr
, *next_ptr
;
142 /* special case for join 0 */
143 if((parv
[1][0] == '0') && (parv
[1][1] == '\0') && parc
== 2)
145 do_join_0(client_p
, source_p
);
152 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
155 /* joins for local channels cant happen. */
156 if(parv
[2][0] == '&')
161 mode
.key
[0] = mode
.forward
[0] = '\0';
162 mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
164 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
167 newts
= atol(parv
[1]);
168 oldts
= chptr
->channelts
;
170 #ifdef IGNORE_BOGUS_TS
171 if(newts
< 800000000)
173 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
174 "*** Bogus TS %ld on %s ignored from %s",
175 (long) newts
, chptr
->chname
, client_p
->name
);
176 newts
= (oldts
== 0) ? oldts
: 800000000;
179 /* making a channel TS0 */
180 if(!isnew
&& !newts
&& oldts
)
182 sendto_channel_local(ALL_MEMBERS
, chptr
,
183 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
184 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
185 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
186 "Server %s changing TS on %s from %ld to 0",
187 source_p
->name
, chptr
->chname
, (long) oldts
);
192 chptr
->channelts
= newts
;
193 else if(newts
== 0 || oldts
== 0)
194 chptr
->channelts
= 0;
195 else if(newts
== oldts
)
197 else if(newts
< oldts
)
200 chptr
->channelts
= newts
;
205 /* Lost the TS, other side wins, so remove modes on this side */
208 set_final_mode(&mode
, &chptr
->mode
);
210 remove_our_modes(chptr
, source_p
);
211 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
213 del_invite(chptr
, ptr
->data
);
215 /* If setting -j, clear join throttle state -- jilles */
216 chptr
->join_count
= chptr
->join_delta
= 0;
217 sendto_channel_local(ALL_MEMBERS
, chptr
,
218 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
219 me
.name
, chptr
->chname
, chptr
->chname
,
220 (long) oldts
, (long) newts
);
221 /* Update capitalization in channel name, this makes the
222 * capitalization timestamped like modes are -- jilles */
223 strcpy(chptr
->chname
, parv
[2]);
225 sendto_channel_local(ALL_MEMBERS
, chptr
,
227 source_p
->servptr
->name
,
228 chptr
->chname
, modebuf
, parabuf
);
229 if(*omodebuf
!= '\0')
230 sendto_channel_local(ONLY_OPERS
, chptr
,
232 source_p
->servptr
->name
,
233 chptr
->chname
, modebuf
, parabuf
);
234 *omodebuf
= *modebuf
= *parabuf
= '\0';
236 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
237 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
240 if(!IsMember(source_p
, chptr
))
242 add_user_to_channel(chptr
, source_p
, CHFL_PEON
);
243 if (chptr
->mode
.join_num
&&
244 rb_current_time() - chptr
->join_delta
>= chptr
->mode
.join_time
)
246 chptr
->join_count
= 0;
247 chptr
->join_delta
= rb_current_time();
250 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
251 source_p
->name
, source_p
->username
,
252 source_p
->host
, chptr
->chname
);
255 sendto_server(client_p
, chptr
, CAP_TS6
, NOCAPS
,
257 source_p
->id
, (long) chptr
->channelts
, chptr
->chname
);
262 ms_sjoin(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
264 static char buf_uid
[BUFSIZE
];
265 static const char empty_modes
[] = "0";
266 struct Channel
*chptr
;
267 struct Client
*target_p
, *fakesource_p
;
270 static struct Mode mode
, *oldmode
;
273 int keep_our_modes
= 1;
274 int keep_new_modes
= 1;
285 int i
, joinc
= 0, timeslice
= 0;
286 static char empty
[] = "";
287 rb_dlink_node
*ptr
, *next_ptr
;
289 if(!IsChannelName(parv
[2]) || !check_channel_name(parv
[2]))
292 /* SJOIN's for local channels can't happen. */
296 omodebuf
[0] = modebuf
[0] = parabuf
[0] = mode
.key
[0] = mode
.forward
[0] = '\0';
297 pargs
= mode
.mode
= mode
.limit
= mode
.join_num
= mode
.join_time
= 0;
299 /* Hide connecting server on netburst -- jilles */
300 if (ConfigServerHide
.flatten_links
&& !HasSentEob(source_p
))
303 fakesource_p
= source_p
;
307 newts
= atol(parv
[1]);
315 rb_strlcpy(mode
.forward
, parv
[4 + args
], sizeof(mode
.forward
));
321 sscanf(parv
[4 + args
], "%d:%d", &joinc
, ×lice
);
323 mode
.join_num
= joinc
;
324 mode
.join_time
= timeslice
;
329 rb_strlcpy(mode
.key
, parv
[4 + args
], sizeof(mode
.key
));
335 mode
.limit
= atoi(parv
[4 + args
]);
341 if(chmode_flags
[(int) *s
] != 0)
343 mode
.mode
|= chmode_flags
[(int) *s
];
352 /* remove any leading spaces */
359 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
360 return 0; /* channel name too long? */
363 oldts
= chptr
->channelts
;
364 oldmode
= &chptr
->mode
;
366 #ifdef IGNORE_BOGUS_TS
367 if(newts
< 800000000)
369 sendto_realops_snomask(SNO_DEBUG
, L_ALL
,
370 "*** Bogus TS %ld on %s ignored from %s",
371 (long) newts
, chptr
->chname
, client_p
->name
);
373 newts
= (oldts
== 0) ? oldts
: 800000000;
376 if(!isnew
&& !newts
&& oldts
)
378 sendto_channel_local(ALL_MEMBERS
, chptr
,
379 ":%s NOTICE %s :*** Notice -- TS for %s "
380 "changed from %ld to 0",
381 me
.name
, chptr
->chname
, chptr
->chname
, (long) oldts
);
382 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
383 "Server %s changing TS on %s from %ld to 0",
384 source_p
->name
, chptr
->chname
, (long) oldts
);
389 chptr
->channelts
= newts
;
391 else if(newts
== 0 || oldts
== 0)
392 chptr
->channelts
= 0;
393 else if(newts
== oldts
)
395 else if(newts
< oldts
)
397 /* If configured, kick people trying to join +i/+k
398 * channels by recreating them on split servers.
399 * Don't kick if the source has sent EOB (services
400 * deopping everyone by TS-1 SJOIN).
402 if (ConfigChannel
.kick_on_split_riding
&&
403 !HasSentEob(source_p
) &&
404 ((mode
.mode
& MODE_INVITEONLY
) ||
405 (mode
.key
[0] != 0 && irccmp(mode
.key
, oldmode
->key
) != 0)))
407 struct membership
*msptr
;
409 int l
= rb_dlink_list_length(&chptr
->members
);
411 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->locmembers
.head
)
414 who
= msptr
->client_p
;
415 sendto_one(who
, ":%s KICK %s %s :Net Rider",
416 me
.name
, chptr
->chname
, who
->name
);
418 sendto_server(NULL
, chptr
, CAP_TS6
, NOCAPS
,
419 ":%s KICK %s %s :Net Rider",
420 me
.id
, chptr
->chname
,
422 remove_user_from_channel(msptr
);
428 /* Channel was emptied, create a new one */
429 if((chptr
= get_or_create_channel(source_p
, parv
[2], &isnew
)) == NULL
)
430 return 0; /* oops! */
432 oldmode
= &chptr
->mode
;
436 chptr
->channelts
= newts
;
443 else if(keep_our_modes
)
445 mode
.mode
|= oldmode
->mode
;
446 if(oldmode
->limit
> mode
.limit
)
447 mode
.limit
= oldmode
->limit
;
448 if(strcmp(mode
.key
, oldmode
->key
) < 0)
449 strcpy(mode
.key
, oldmode
->key
);
450 if(oldmode
->join_num
> mode
.join_num
||
451 (oldmode
->join_num
== mode
.join_num
&&
452 oldmode
->join_time
> mode
.join_time
))
454 mode
.join_num
= oldmode
->join_num
;
455 mode
.join_time
= oldmode
->join_time
;
457 if(irccmp(mode
.forward
, oldmode
->forward
) < 0)
458 strcpy(mode
.forward
, oldmode
->forward
);
462 /* If setting -j, clear join throttle state -- jilles */
464 chptr
->join_count
= chptr
->join_delta
= 0;
467 set_final_mode(&mode
, oldmode
);
470 /* Lost the TS, other side wins, so remove modes on this side */
473 remove_our_modes(chptr
, fakesource_p
);
474 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, chptr
->invites
.head
)
476 del_invite(chptr
, ptr
->data
);
479 if(rb_dlink_list_length(&chptr
->banlist
) > 0)
480 remove_ban_list(chptr
, fakesource_p
, &chptr
->banlist
, 'b', ALL_MEMBERS
);
481 if(rb_dlink_list_length(&chptr
->exceptlist
) > 0)
482 remove_ban_list(chptr
, fakesource_p
, &chptr
->exceptlist
,
484 if(rb_dlink_list_length(&chptr
->invexlist
) > 0)
485 remove_ban_list(chptr
, fakesource_p
, &chptr
->invexlist
,
487 if(rb_dlink_list_length(&chptr
->quietlist
) > 0)
488 remove_ban_list(chptr
, fakesource_p
, &chptr
->quietlist
,
492 sendto_channel_local(ALL_MEMBERS
, chptr
,
493 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
494 me
.name
, chptr
->chname
, chptr
->chname
,
495 (long) oldts
, (long) newts
);
496 /* Update capitalization in channel name, this makes the
497 * capitalization timestamped like modes are -- jilles */
498 strcpy(chptr
->chname
, parv
[2]);
500 /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */
501 set_channel_mlock(client_p
, source_p
, chptr
, NULL
, FALSE
);
505 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s MODE %s %s %s",
506 fakesource_p
->name
, chptr
->chname
, modebuf
, parabuf
);
508 if(*omodebuf
!= '\0')
509 sendto_channel_local(ONLY_OPERS
, chptr
, ":%s MODE %s %s %s",
510 fakesource_p
->name
, chptr
->chname
, omodebuf
, parabuf
);
512 *omodebuf
= *modebuf
= *parabuf
= '\0';
514 if(parv
[3][0] != '0' && keep_new_modes
)
515 modes
= channel_modes(chptr
, source_p
);
519 mlen_uid
= rb_sprintf(buf_uid
, ":%s SJOIN %ld %s %s :",
520 use_id(source_p
), (long) chptr
->channelts
, parv
[2], modes
);
521 ptr_uid
= buf_uid
+ mlen_uid
;
525 para
[0] = para
[1] = para
[2] = para
[3] = empty
;
527 len_nick
= len_uid
= 0;
529 /* if theres a space, theres going to be more than one nick, change the
530 * first space to \0, so s is just the first nick, and point p to the
533 if((p
= strchr(s
, ' ')) != NULL
)
544 for (i
= 0; i
< 4; i
++)
568 /* if the client doesnt exist or is fake direction, skip. */
569 if(!(target_p
= find_client(s
)) ||
570 (target_p
->from
!= client_p
) || !IsPerson(target_p
))
573 /* we assume for these we can fit at least one nick/uid in.. */
575 /* check we can fit another status+nick+space into a buffer */
576 if((mlen_uid
+ len_uid
+ IDLEN
+ 3) > (BUFSIZE
- 3))
578 *(ptr_uid
- 1) = '\0';
579 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
580 ptr_uid
= buf_uid
+ mlen_uid
;
612 /* copy the nick to the two buffers */
613 len
= rb_sprintf(ptr_uid
, "%s ", use_id(target_p
));
620 if(!IsMember(target_p
, chptr
))
622 add_user_to_channel(chptr
, target_p
, fl
);
623 sendto_channel_local(ALL_MEMBERS
, chptr
, ":%s!%s@%s JOIN :%s",
625 target_p
->username
, target_p
->host
, parv
[2]);
629 /* If anyone can think of a way to do this that doesn't make babies cry
630 * I would love to hear it - Taros */
635 para
[pargs
++] = target_p
->name
;
639 /* its possible the +a has filled up MAXMODEPARAMS, if so, start
642 if(pargs
>= MAXMODEPARAMS
)
645 sendto_channel_local(ALL_MEMBERS
, chptr
,
646 ":%s MODE %s %s %s %s %s %s",
647 fakesource_p
->name
, chptr
->chname
,
649 para
[0], para
[1], para
[2], para
[3]);
652 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
657 para
[pargs
++] = target_p
->name
;
661 /* its possible the +a has filled up MAXMODEPARAMS, if so, start
664 if(pargs
>= MAXMODEPARAMS
)
667 sendto_channel_local(ALL_MEMBERS
, chptr
,
668 ":%s MODE %s %s %s %s %s %s",
669 fakesource_p
->name
, chptr
->chname
,
671 para
[0], para
[1], para
[2], para
[3]);
674 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
679 para
[pargs
++] = target_p
->name
;
683 /* its possible the +a has filled up MAXMODEPARAMS, if so, start
686 if(pargs
>= MAXMODEPARAMS
)
689 sendto_channel_local(ALL_MEMBERS
, chptr
,
690 ":%s MODE %s %s %s %s %s %s",
691 fakesource_p
->name
, chptr
->chname
,
693 para
[0], para
[1], para
[2], para
[3]);
696 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
701 para
[pargs
++] = target_p
->name
;
704 else if(fl
& CHFL_CHANOP
)
707 para
[pargs
++] = target_p
->name
;
711 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
714 if(pargs
>= MAXMODEPARAMS
)
717 sendto_channel_local(ALL_MEMBERS
, chptr
,
718 ":%s MODE %s %s %s %s %s %s",
719 fakesource_p
->name
, chptr
->chname
,
721 para
[0], para
[1], para
[2], para
[3]);
724 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
729 para
[pargs
++] = target_p
->name
;
733 /* its possible the +o has filled up MAXMODEPARAMS, if so, start
736 if(pargs
>= MAXMODEPARAMS
)
739 sendto_channel_local(ALL_MEMBERS
, chptr
,
740 ":%s MODE %s %s %s %s %s %s",
741 fakesource_p
->name
, chptr
->chname
,
743 para
[0], para
[1], para
[2], para
[3]);
746 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
751 para
[pargs
++] = target_p
->name
;
754 else if(fl
& CHFL_HALFOP
)
757 para
[pargs
++] = target_p
->name
;
761 /* its possible the +h has filled up MAXMODEPARAMS, if so, start
764 if(pargs
>= MAXMODEPARAMS
)
767 sendto_channel_local(ALL_MEMBERS
, chptr
,
768 ":%s MODE %s %s %s %s %s %s",
769 fakesource_p
->name
, chptr
->chname
,
771 para
[0], para
[1], para
[2], para
[3]);
774 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
779 para
[pargs
++] = target_p
->name
;
782 else if(fl
& CHFL_VOICE
)
785 para
[pargs
++] = target_p
->name
;
788 if(pargs
>= MAXMODEPARAMS
)
791 sendto_channel_local(ALL_MEMBERS
, chptr
,
792 ":%s MODE %s %s %s %s %s %s",
795 modebuf
, para
[0], para
[1], para
[2], para
[3]);
798 para
[0] = para
[1] = para
[2] = para
[3] = NULL
;
803 /* p points to the next nick */
806 /* if there was a trailing space and p was pointing to it, then we
807 * need to exit.. this has the side effect of breaking double spaces
808 * in an sjoin.. but that shouldnt happen anyway
810 if(s
&& (*s
== '\0'))
813 /* if p was NULL due to no spaces, s wont exist due to the above, so
814 * we cant check it for spaces.. if there are no spaces, then when
815 * we next get here, s will be NULL
817 if(s
&& ((p
= strchr(s
, ' ')) != NULL
))
826 sendto_channel_local(ALL_MEMBERS
, chptr
,
827 ":%s MODE %s %s %s %s %s %s",
828 fakesource_p
->name
, chptr
->chname
, modebuf
,
829 para
[0], CheckEmpty(para
[1]),
830 CheckEmpty(para
[2]), CheckEmpty(para
[3]));
833 if(!joins
&& !(chptr
->mode
.mode
& ModuleModes
.MODE_PERMANENT
) && isnew
)
835 destroy_channel(chptr
);
840 /* Keep the colon if we're sending an SJOIN without nicks -- jilles */
843 *(ptr_uid
- 1) = '\0';
846 sendto_server(client_p
->from
, NULL
, CAP_TS6
, NOCAPS
, "%s", buf_uid
);
853 set_final_mode(struct Mode
*mode
, struct Mode
*oldmode
)
855 int dir
= MODE_QUERY
, odir
= MODE_QUERY
;
856 char *pbuf
= parabuf
;
860 /* ok, first get a list of modes we need to add */
861 for (i
= 0; i
< 256; i
++)
863 if((mode
->mode
& chmode_flags
[i
]) && !(oldmode
->mode
& chmode_flags
[i
]))
865 if (chmode_table
[i
].set_func
== chm_hidden
)
887 /* now the ones we need to remove. */
888 for (i
= 0; i
< 256; i
++)
890 if((oldmode
->mode
& chmode_flags
[i
]) && !(mode
->mode
& chmode_flags
[i
]))
892 if(chmode_table
[i
].set_func
== chm_hidden
)
913 if(oldmode
->limit
&& !mode
->limit
)
922 if(oldmode
->key
[0] && !mode
->key
[0])
930 len
= rb_sprintf(pbuf
, "%s ", oldmode
->key
);
933 if(oldmode
->join_num
&& !mode
->join_num
)
942 if(oldmode
->forward
[0] && !mode
->forward
[0])
951 if(mode
->limit
&& oldmode
->limit
!= mode
->limit
)
959 len
= rb_sprintf(pbuf
, "%d ", mode
->limit
);
962 if(mode
->key
[0] && strcmp(oldmode
->key
, mode
->key
))
970 len
= rb_sprintf(pbuf
, "%s ", mode
->key
);
973 if(mode
->join_num
&& (oldmode
->join_num
!= mode
->join_num
|| oldmode
->join_time
!= mode
->join_time
))
981 len
= rb_sprintf(pbuf
, "%d:%d ", mode
->join_num
, mode
->join_time
);
984 if(mode
->forward
[0] && strcmp(oldmode
->forward
, mode
->forward
) && ModuleModes
.MODE_FORWARD
)
992 len
= rb_sprintf(pbuf
, "%s ", mode
->forward
);
1006 remove_our_modes(struct Channel
*chptr
, struct Client
*source_p
)
1008 struct membership
*msptr
;
1010 char lmodebuf
[MODEBUFLEN
];
1011 char *lpara
[MAXMODEPARAMS
];
1018 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1021 RB_DLINK_FOREACH(ptr
, chptr
->members
.head
)
1025 /* If anyone can think of a way to do this that doesn't make babies cry
1026 * I would love to hear it - Taros */
1030 msptr
->flags
&= ~CHFL_ADMIN
;
1031 lpara
[count
++] = msptr
->client_p
->name
;
1034 /* Make sure it fits if +h, +o, or +v are involved */
1035 if(is_chanop(msptr
))
1037 if(count
>= MAXMODEPARAMS
)
1040 sendto_channel_local(ALL_MEMBERS
, chptr
,
1041 ":%s MODE %s %s %s %s %s %s",
1042 source_p
->name
, chptr
->chname
,
1043 lmodebuf
, lpara
[0], lpara
[1],
1044 lpara
[2], lpara
[3]);
1046 /* preserve the initial '-' */
1051 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1055 msptr
->flags
&= ~CHFL_CHANOP
;
1056 lpara
[count
++] = msptr
->client_p
->name
;
1059 if(is_halfop(msptr
))
1061 if(count
>= MAXMODEPARAMS
)
1064 sendto_channel_local(ALL_MEMBERS
, chptr
,
1065 ":%s MODE %s %s %s %s %s %s",
1066 source_p
->name
, chptr
->chname
,
1067 lmodebuf
, lpara
[0], lpara
[1],
1068 lpara
[2], lpara
[3]);
1070 /* preserve the initial '-' */
1075 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1079 msptr
->flags
&= ~CHFL_HALFOP
;
1080 lpara
[count
++] = msptr
->client_p
->name
;
1083 if(is_voiced(msptr
))
1085 if(count
>= MAXMODEPARAMS
)
1088 sendto_channel_local(ALL_MEMBERS
, chptr
,
1089 ":%s MODE %s %s %s %s %s %s",
1090 source_p
->name
, chptr
->chname
,
1091 lmodebuf
, lpara
[0], lpara
[1],
1092 lpara
[2], lpara
[3]);
1094 /* preserve the initial '-' */
1099 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1103 msptr
->flags
&= ~CHFL_VOICE
;
1104 lpara
[count
++] = msptr
->client_p
->name
;
1108 else if(is_chanop(msptr
))
1110 msptr
->flags
&= ~CHFL_CHANOP
;
1111 lpara
[count
++] = msptr
->client_p
->name
;
1114 /* Make sure it fits if +h or +v are involved */
1115 if(is_halfop(msptr
))
1117 if(count
>= MAXMODEPARAMS
)
1120 sendto_channel_local(ALL_MEMBERS
, chptr
,
1121 ":%s MODE %s %s %s %s %s %s",
1122 source_p
->name
, chptr
->chname
,
1123 lmodebuf
, lpara
[0], lpara
[1],
1124 lpara
[2], lpara
[3]);
1126 /* preserve the initial '-' */
1131 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1135 msptr
->flags
&= ~CHFL_HALFOP
;
1136 lpara
[count
++] = msptr
->client_p
->name
;
1139 if(is_voiced(msptr
))
1141 if(count
>= MAXMODEPARAMS
)
1144 sendto_channel_local(ALL_MEMBERS
, chptr
,
1145 ":%s MODE %s %s %s %s %s %s",
1146 source_p
->name
, chptr
->chname
,
1147 lmodebuf
, lpara
[0], lpara
[1],
1148 lpara
[2], lpara
[3]);
1150 /* preserve the initial '-' */
1155 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1159 msptr
->flags
&= ~CHFL_VOICE
;
1160 lpara
[count
++] = msptr
->client_p
->name
;
1164 else if(is_halfop(msptr
))
1166 msptr
->flags
&= ~CHFL_HALFOP
;
1167 lpara
[count
++] = msptr
->client_p
->name
;
1170 /* +hv, might not fit so check. */
1171 if(is_voiced(msptr
))
1173 if(count
>= MAXMODEPARAMS
)
1176 sendto_channel_local(ALL_MEMBERS
, chptr
,
1177 ":%s MODE %s %s %s %s %s %s",
1178 source_p
->name
, chptr
->chname
,
1179 lmodebuf
, lpara
[0], lpara
[1],
1180 lpara
[2], lpara
[3]);
1182 /* preserve the initial '-' */
1187 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1191 msptr
->flags
&= ~CHFL_VOICE
;
1192 lpara
[count
++] = msptr
->client_p
->name
;
1196 else if(is_voiced(msptr
))
1198 msptr
->flags
&= ~CHFL_VOICE
;
1199 lpara
[count
++] = msptr
->client_p
->name
;
1205 if(count
>= MAXMODEPARAMS
)
1208 sendto_channel_local(ALL_MEMBERS
, chptr
,
1209 ":%s MODE %s %s %s %s %s %s",
1210 source_p
->name
, chptr
->chname
, lmodebuf
,
1211 lpara
[0], lpara
[1], lpara
[2], lpara
[3]);
1216 for(i
= 0; i
< MAXMODEPARAMS
; i
++)
1224 sendto_channel_local(ALL_MEMBERS
, chptr
,
1225 ":%s MODE %s %s %s %s %s %s",
1226 source_p
->name
, chptr
->chname
, lmodebuf
,
1227 EmptyString(lpara
[0]) ? "" : lpara
[0],
1228 EmptyString(lpara
[1]) ? "" : lpara
[1],
1229 EmptyString(lpara
[2]) ? "" : lpara
[2],
1230 EmptyString(lpara
[3]) ? "" : lpara
[3]);
1235 /* remove_ban_list()
1237 * inputs - channel, source, list to remove, char of mode, caps needed
1239 * side effects - given list is removed, with modes issued to local clients
1242 remove_ban_list(struct Channel
*chptr
, struct Client
*source_p
,
1243 rb_dlink_list
* list
, char c
, int mems
)
1245 static char lmodebuf
[BUFSIZE
];
1246 static char lparabuf
[BUFSIZE
];
1249 rb_dlink_node
*next_ptr
;
1252 int cur_len
, mlen
, plen
;
1256 cur_len
= mlen
= rb_sprintf(lmodebuf
, ":%s MODE %s -", source_p
->name
, chptr
->chname
);
1257 mbuf
= lmodebuf
+ mlen
;
1259 RB_DLINK_FOREACH_SAFE(ptr
, next_ptr
, list
->head
)
1263 /* trailing space, and the mode letter itself */
1264 plen
= strlen(banptr
->banstr
) + 2;
1266 if(count
>= MAXMODEPARAMS
|| (cur_len
+ plen
) > BUFSIZE
- 4)
1268 /* remove trailing space */
1272 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1275 mbuf
= lmodebuf
+ mlen
;
1282 pbuf
+= rb_sprintf(pbuf
, "%s ", banptr
->banstr
);
1290 sendto_channel_local(mems
, chptr
, "%s %s", lmodebuf
, lparabuf
);
1292 list
->head
= list
->tail
= NULL
;