/[svn]/ircd-hybrid-7.2/modules/core/m_join.c
ViewVC logotype

Annotation of /ircd-hybrid-7.2/modules/core/m_join.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 853 - (hide annotations)
Thu Feb 22 06:01:30 2007 UTC (14 years, 1 month ago) by db
File MIME type: text/x-chdr
File size: 18514 byte(s)
- fix typo in ircd_parser.y regenerate y.tab.c and lex.yy.c
- fix order shown in CLIEXIT
- remove mode parsing in ms_join
- reflect addiction cconn_full flag


1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_join.c: Joins a channel.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "tools.h"
27     #include "handlers.h"
28     #include "channel.h"
29     #include "channel_mode.h"
30     #include "client.h"
31     #include "common.h" /* bleah */
32     #include "hash.h"
33     #include "irc_string.h"
34     #include "sprintf_irc.h"
35     #include "ircd.h"
36     #include "list.h"
37     #include "numeric.h"
38     #include "send.h"
39     #include "s_serv.h"
40     #include "s_conf.h"
41     #include "msg.h"
42     #include "parse.h"
43     #include "modules.h"
44    
45    
46     static void m_join(struct Client *, struct Client *, int, char **);
47     static void ms_join(struct Client *, struct Client *, int, char **);
48     static void do_join_0(struct Client *client_p, struct Client *source_p);
49    
50     static void set_final_mode(struct Mode *, struct Mode *);
51     static void remove_our_modes(struct Channel *, struct Client *);
52     static void remove_a_mode(struct Channel *, struct Client *, int, char);
53    
54     static char modebuf[MODEBUFLEN];
55     static char parabuf[MODEBUFLEN];
56     static char sendbuf[MODEBUFLEN];
57     static char *mbuf;
58    
59     struct Message join_msgtab = {
60     "JOIN", 0, 0, 2, 0, MFLG_SLOW, 0,
61     {m_unregistered, m_join, ms_join, m_ignore, m_join, m_ignore}
62     };
63    
64     #ifndef STATIC_MODULES
65     void
66     _modinit(void)
67     {
68     mod_add_cmd(&join_msgtab);
69     }
70    
71     void
72     _moddeinit(void)
73     {
74     mod_del_cmd(&join_msgtab);
75     }
76    
77 knight 31 const char *_version = "$Revision$";
78 adx 30 #endif
79    
80 michael 488 /* last0() stolen from ircu */
81     static char *
82     last0(struct Client *client_p, struct Client *source_p, char *chanlist)
83     {
84     char *p;
85     int join0 = 0;
86    
87     for (p = chanlist; *p; ++p) /* find last "JOIN 0" */
88     {
89     if (*p == '0' && (*(p + 1) == ',' || *(p + 1) == '\0'))
90     {
91     if ((*p + 1) == ',')
92     ++p;
93    
94     chanlist = p + 1;
95     join0 = 1;
96     }
97     else
98     {
99     while (*p != ',' && *p != '\0') /* skip past channel name */
100     ++p;
101    
102     if (*p == '\0') /* hit the end */
103     break;
104     }
105     }
106    
107     if (join0)
108     do_join_0(client_p, source_p);
109    
110     return chanlist;
111     }
112    
113 adx 30 /* m_join()
114     * parv[0] = sender prefix
115     * parv[1] = channel
116     * parv[2] = channel password (key)
117     */
118     static void
119     m_join(struct Client *client_p, struct Client *source_p,
120     int parc, char *parv[])
121     {
122 michael 488 char *p = NULL;
123     char *key_list = NULL;
124     char *chan_list = NULL;
125     char *chan = NULL;
126 adx 30 struct Channel *chptr = NULL;
127 michael 488 int i = 0;
128 adx 30 unsigned int flags = 0;
129    
130 michael 632 if (EmptyString(parv[1]))
131 adx 30 {
132     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
133     me.name, source_p->name, "JOIN");
134     return;
135     }
136    
137 michael 487 assert(client_p == source_p);
138 adx 30
139 michael 488 key_list = parv[2];
140     chan_list = last0(client_p, source_p, parv[1]);
141 michael 487
142 michael 488 for (chan = strtoken(&p, chan_list, ","); chan;
143     chan = strtoken(&p, NULL, ","))
144 adx 30 {
145 michael 488 char *key = NULL;
146 adx 30
147 michael 488 /* If we have any more keys, take the first for this channel. */
148     if (!EmptyString(key_list) && (key_list = strchr(key = key_list, ',')))
149     *key_list++ = '\0';
150    
151     /* Empty keys are the same as no keys. */
152     if (key && *key == '\0')
153     key = NULL;
154    
155 michael 632 if (!check_channel_name(chan, 1))
156 michael 488 {
157     sendto_one(source_p, form_str(ERR_BADCHANNAME),
158     me.name, source_p->name, chan);
159 adx 30 continue;
160 michael 488 }
161 adx 30
162 michael 488 if (ConfigChannel.disable_local_channels && (*chan == '&'))
163     {
164     sendto_one(source_p, form_str(ERR_NOSUCHCHANNEL),
165     me.name, source_p->name, chan);
166     continue;
167     }
168    
169     if (!IsExemptResv(source_p) &&
170     !(IsOper(source_p) && ConfigFileEntry.oper_pass_resv) &&
171     (!hash_find_resv(chan) == ConfigChannel.restrict_channels))
172     {
173     sendto_one(source_p, form_str(ERR_BADCHANNAME),
174     me.name, source_p->name, chan);
175     sendto_realops_flags(UMODE_SPY, L_ALL,
176     "User %s (%s@%s) is attempting to join locally juped channel %s",
177     source_p->name, source_p->username, source_p->host, chan);
178     continue;
179     }
180    
181     if ((dlink_list_length(&source_p->channel) >= ConfigChannel.max_chans_per_user) &&
182     (!IsOper(source_p) || (dlink_list_length(&source_p->channel) >=
183     ConfigChannel.max_chans_per_user * 3)))
184     {
185 michael 494 sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS),
186     me.name, source_p->name, chan);
187     break;
188 michael 488 }
189    
190     if ((chptr = hash_find_channel(chan)) != NULL)
191     {
192     if (IsMember(source_p, chptr))
193     continue;
194    
195     if (splitmode && !IsOper(source_p) && (*chan != '&') &&
196     ConfigChannel.no_join_on_split)
197     {
198     sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
199     me.name, source_p->name, chan);
200     continue;
201     }
202    
203     /*
204     * This should never be the case unless there is some sort of
205     * persistant channels.
206     */
207     if (dlink_list_length(&chptr->members) == 0)
208     flags = CHFL_CHANOP;
209     else
210     flags = 0;
211     }
212     else
213     {
214     if (splitmode && !IsOper(source_p) && (*chan != '&') &&
215     (ConfigChannel.no_create_on_split || ConfigChannel.no_join_on_split))
216     {
217     sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE),
218     me.name, source_p->name, chan);
219     continue;
220     }
221    
222     flags = CHFL_CHANOP;
223 michael 632 chptr = make_channel(chan);
224 michael 488 }
225    
226 adx 30 if (!IsOper(source_p))
227     check_spambot_warning(source_p, chptr->chname);
228    
229     /*
230     * can_join checks for +i key, bans.
231     */
232     if ((i = can_join(source_p, chptr, key)))
233     {
234 michael 488 sendto_one(source_p, form_str(i), me.name,
235     source_p->name, chptr->chname);
236 adx 30 continue;
237     }
238    
239     add_user_to_channel(chptr, source_p, flags, YES);
240    
241     /*
242 michael 488 * Set timestamp if appropriate, and propagate
243     */
244 adx 30 if (flags & CHFL_CHANOP)
245     {
246     chptr->channelts = CurrentTime;
247     chptr->mode.mode |= MODE_TOPICLIMIT;
248     chptr->mode.mode |= MODE_NOPRIVMSGS;
249    
250     sendto_server(client_p, source_p, chptr, CAP_TS6, NOCAPS, LL_ICLIENT,
251     ":%s SJOIN %lu %s +nt :@%s",
252     me.id, (unsigned long)chptr->channelts,
253     chptr->chname, source_p->id);
254     sendto_server(client_p, source_p, chptr, NOCAPS, CAP_TS6, LL_ICLIENT,
255     ":%s SJOIN %lu %s +nt :@%s",
256     me.name, (unsigned long)chptr->channelts,
257 michael 632 chptr->chname, source_p->name);
258 adx 30 /*
259     * notify all other users on the new channel
260     */
261     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s JOIN :%s",
262     source_p->name, source_p->username,
263     source_p->host, chptr->chname);
264 michael 488 sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s +nt",
265 adx 30 me.name, chptr->chname);
266     }
267     else
268     {
269     sendto_server(client_p, source_p, chptr, CAP_TS6, NOCAPS, LL_ICLIENT,
270     ":%s JOIN %lu %s +",
271     source_p->id, (unsigned long)chptr->channelts,
272     chptr->chname);
273     sendto_server(client_p, source_p, chptr, NOCAPS, CAP_TS6, LL_ICLIENT,
274     ":%s SJOIN %lu %s + :%s",
275     me.name, (unsigned long)chptr->channelts,
276     chptr->chname, source_p->name);
277    
278     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s JOIN :%s",
279     source_p->name, source_p->username,
280     source_p->host, chptr->chname);
281     }
282    
283     del_invite(chptr, source_p);
284    
285     if (chptr->topic != NULL)
286     {
287     sendto_one(source_p, form_str(RPL_TOPIC), me.name,
288     source_p->name, chptr->chname, chptr->topic);
289    
290     sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
291     me.name, source_p->name, chptr->chname,
292     chptr->topic_info, chptr->topic_time);
293     }
294    
295     channel_member_names(source_p, chptr, 1);
296    
297 michael 487 source_p->localClient->last_join_time = CurrentTime;
298 adx 30 }
299     }
300    
301     /* ms_join()
302     *
303     * inputs - parv[0] = uid
304     * parv[1] = ts
305     * parv[2] = channel name
306 db 853 * parv[3] = modes (Deprecated)
307 adx 30 * output - none
308     * side effects - handles remote JOIN's sent by servers. In TSora
309     * remote clients are joined using SJOIN, hence a
310     * JOIN sent by a server on behalf of a client is an error.
311     * here, the initial code is in to take an extra parameter
312     * and use it for the TimeStamp on a new channel.
313     */
314     static void
315     ms_join(struct Client *client_p, struct Client *source_p,
316     int parc, char *parv[])
317     {
318 michael 632 time_t newts = 0;
319     time_t oldts = 0;
320     int args = 0;
321     int keep_our_modes = 1;
322     int keep_new_modes = 1;
323     int isnew = 0;
324     const char *servername = NULL;
325     struct Channel *chptr = NULL;
326     struct Mode mode, *oldmode;
327 adx 30
328 michael 632 if (parc == 2 && !irccmp(parv[1], "0"))
329 adx 30 {
330     do_join_0(client_p, source_p);
331     return;
332     }
333    
334 michael 632 if (parc < 4 || *parv[2] == '&')
335 adx 30 return;
336    
337 michael 632 if (!check_channel_name(parv[2], 0))
338     {
339     sendto_realops_flags(UMODE_DEBUG, L_ALL,
340     "*** Too long or invalid channel name from %s: %s",
341     client_p->name, parv[2]);
342 adx 30 return;
343 michael 632 }
344 adx 30
345     mbuf = modebuf;
346     mode.mode = mode.limit = 0;
347     mode.key[0] = '\0';
348    
349 michael 632 if ((chptr = hash_find_channel(parv[2])) == NULL)
350     {
351     isnew = 1;
352     chptr = make_channel(parv[2]);
353     }
354    
355     newts = atol(parv[1]);
356 adx 30 oldts = chptr->channelts;
357     oldmode = &chptr->mode;
358    
359     if (ConfigFileEntry.ignore_bogus_ts)
360     {
361     if (newts < 800000000)
362     {
363     sendto_realops_flags(UMODE_DEBUG, L_ALL,
364     "*** Bogus TS %lu on %s ignored from %s",
365     (unsigned long)newts, chptr->chname,
366     client_p->name);
367    
368     newts = (oldts == 0) ? 0 : 800000000;
369     }
370     }
371     else
372     {
373     if (!newts && !isnew && oldts)
374     {
375     sendto_channel_local(ALL_MEMBERS, NO, chptr,
376     ":%s NOTICE %s :*** Notice -- TS for %s changed from %lu to 0",
377     me.name, chptr->chname, chptr->chname, (unsigned long)oldts);
378     sendto_realops_flags(UMODE_ALL, L_ALL,
379     "Server %s changing TS on %s from %lu to 0",
380     source_p->name, chptr->chname, (unsigned long)oldts);
381     }
382     }
383    
384     if (isnew)
385     chptr->channelts = newts;
386     else if (newts == 0 || oldts == 0)
387     chptr->channelts = 0;
388     else if (newts == oldts)
389     ;
390     else if (newts < oldts)
391     {
392     keep_our_modes = NO;
393     chptr->channelts = newts;
394     }
395     else
396     keep_new_modes = NO;
397    
398     if (!keep_new_modes)
399     mode = *oldmode;
400     else if (keep_our_modes)
401     {
402     mode.mode |= oldmode->mode;
403     if (oldmode->limit > mode.limit)
404     mode.limit = oldmode->limit;
405     if (strcmp(mode.key, oldmode->key) < 0)
406     strcpy(mode.key, oldmode->key);
407     }
408    
409     set_final_mode(&mode, oldmode);
410     chptr->mode = mode;
411    
412     /* Lost the TS, other side wins, so remove modes on this side */
413     if (!keep_our_modes)
414     {
415     remove_our_modes(chptr, source_p);
416     sendto_channel_local(ALL_MEMBERS, NO, chptr,
417     ":%s NOTICE %s :*** Notice -- TS for %s changed from %lu to %lu",
418     me.name, chptr->chname, chptr->chname,
419     (unsigned long)oldts, (unsigned long)newts);
420     }
421    
422     if (*modebuf != '\0')
423     {
424     servername = (ConfigServerHide.hide_servers || IsHidden(source_p)) ?
425     me.name : source_p->name;
426    
427     /* This _SHOULD_ be to ALL_MEMBERS
428     * It contains only +imnpstlk, etc */
429     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s %s %s",
430     servername, chptr->chname, modebuf, parabuf);
431     }
432    
433     if (!IsMember(source_p, chptr))
434     {
435     add_user_to_channel(chptr, source_p, 0, YES);
436     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s JOIN :%s",
437     source_p->name, source_p->username,
438     source_p->host, chptr->chname);
439     }
440    
441     sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, NOFLAGS,
442     ":%s JOIN %lu %s +",
443     ID(source_p), (unsigned long)chptr->channelts, chptr->chname);
444     sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, NOFLAGS,
445     ":%s SJOIN %lu %s + :%s",
446     source_p->servptr->name, (unsigned long)chptr->channelts,
447     chptr->chname, source_p->name);
448     }
449    
450     /* do_join_0()
451     *
452     * inputs - pointer to client doing join 0
453     * output - NONE
454     * side effects - Use has decided to join 0. This is legacy
455     * from the days when channels were numbers not names. *sigh*
456     * There is a bunch of evilness necessary here due to
457     * anti spambot code.
458     */
459     static void
460     do_join_0(struct Client *client_p, struct Client *source_p)
461     {
462     struct Channel *chptr = NULL;
463 michael 488 dlink_node *ptr = NULL, *ptr_next = NULL;
464 adx 30
465 michael 488 if (source_p->channel.head && MyConnect(source_p) && !IsOper(source_p))
466 adx 30 check_spambot_warning(source_p, NULL);
467    
468     DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
469     {
470     chptr = ((struct Membership *)ptr->data)->chptr;
471    
472 michael 488 sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, NOFLAGS,
473     ":%s PART %s", ID(source_p), chptr->chname);
474     sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, NOFLAGS,
475     ":%s PART %s", source_p->name, chptr->chname);
476     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s PART %s",
477     source_p->name, source_p->username,
478     source_p->host, chptr->chname);
479 adx 30
480 michael 488 remove_user_from_channel(ptr->data);
481 adx 30 }
482     }
483    
484     /* set_final_mode()
485     *
486     * inputs - pointer to mode to setup
487     * - pointer to old mode
488     * output - NONE
489     * side effects -
490     */
491     static const struct mode_letter
492     {
493     unsigned int mode;
494     unsigned char letter;
495     } flags[] = {
496     { MODE_NOPRIVMSGS, 'n' },
497     { MODE_TOPICLIMIT, 't' },
498     { MODE_SECRET, 's' },
499     { MODE_MODERATED, 'm' },
500     { MODE_INVITEONLY, 'i' },
501     { MODE_PRIVATE, 'p' },
502     { 0, '\0' }
503     };
504    
505     static void
506     set_final_mode(struct Mode *mode, struct Mode *oldmode)
507     {
508     char *pbuf = parabuf;
509     int what = 0;
510     int len;
511     int i;
512    
513     for (i = 0; flags[i].letter; i++)
514     {
515     if ((flags[i].mode & mode->mode) &&
516     !(flags[i].mode & oldmode->mode))
517     {
518     if (what != 1)
519     {
520     *mbuf++ = '+';
521     what = 1;
522     }
523     *mbuf++ = flags[i].letter;
524     }
525     }
526    
527     for (i = 0; flags[i].letter; i++)
528     {
529     if ((flags[i].mode & oldmode->mode) &&
530     !(flags[i].mode & mode->mode))
531     {
532     if (what != -1)
533     {
534     *mbuf++ = '-';
535     what = -1;
536     }
537     *mbuf++ = flags[i].letter;
538     }
539     }
540    
541     if (oldmode->limit != 0 && mode->limit == 0)
542     {
543     if (what != -1)
544     {
545     *mbuf++ = '-';
546     what = -1;
547     }
548     *mbuf++ = 'l';
549     }
550    
551     if (oldmode->key[0] && !mode->key[0])
552     {
553     if (what != -1)
554     {
555     *mbuf++ = '-';
556     what = -1;
557     }
558     *mbuf++ = 'k';
559     len = ircsprintf(pbuf, "%s ", oldmode->key);
560     pbuf += len;
561     }
562    
563     if (mode->limit != 0 && oldmode->limit != mode->limit)
564     {
565     if (what != 1)
566     {
567     *mbuf++ = '+';
568     what = 1;
569     }
570     *mbuf++ = 'l';
571     len = ircsprintf(pbuf, "%d ", mode->limit);
572     pbuf += len;
573     }
574    
575     if (mode->key[0] && strcmp(oldmode->key, mode->key))
576     {
577     if (what != 1)
578     {
579     *mbuf++ = '+';
580     what = 1;
581     }
582     *mbuf++ = 'k';
583     len = ircsprintf(pbuf, "%s ", mode->key);
584     pbuf += len;
585     }
586     *mbuf = '\0';
587     }
588    
589     /* remove_our_modes()
590     *
591     * inputs - pointer to channel to remove modes from
592     * - client pointer
593     * output - NONE
594     * side effects - Go through the local members, remove all their
595     * chanop modes etc., this side lost the TS.
596     */
597     static void
598     remove_our_modes(struct Channel *chptr, struct Client *source_p)
599     {
600     remove_a_mode(chptr, source_p, CHFL_CHANOP, 'o');
601     #ifdef HALFOPS
602     remove_a_mode(chptr, source_p, CHFL_HALFOP, 'h');
603     #endif
604     remove_a_mode(chptr, source_p, CHFL_VOICE, 'v');
605     }
606    
607     /* remove_a_mode()
608     *
609     * inputs -
610     * output - NONE
611     * side effects - remove ONE mode from a channel
612     */
613     static void
614     remove_a_mode(struct Channel *chptr, struct Client *source_p,
615     int mask, char flag)
616     {
617     dlink_node *ptr;
618     struct Membership *ms;
619     char lmodebuf[MODEBUFLEN];
620     const char *lpara[MAXMODEPARAMS];
621     int count = 0;
622     int lcount;
623    
624     mbuf = lmodebuf;
625     *mbuf++ = '-';
626    
627     for (lcount = 0; lcount < MAXMODEPARAMS; lcount++)
628     lpara[lcount] = "";
629     sendbuf[0] = '\0';
630    
631     DLINK_FOREACH(ptr, chptr->members.head)
632     {
633     ms = ptr->data;
634    
635     if ((ms->flags & mask) == 0)
636     continue;
637    
638     ms->flags &= ~mask;
639    
640     lpara[count++] = ms->client_p->name;
641    
642     *mbuf++ = flag;
643    
644     if (count >= MAXMODEPARAMS)
645     {
646     for (lcount = 0; lcount < MAXMODEPARAMS; lcount++)
647     {
648     if (*lpara[lcount] == '\0')
649     break;
650    
651     strlcat(sendbuf, " ", sizeof(sendbuf));
652     strlcat(sendbuf, lpara[lcount], sizeof(sendbuf));
653     lpara[lcount] = "";
654     }
655    
656     *mbuf = '\0';
657     sendto_channel_local(ALL_MEMBERS, NO, chptr,
658     ":%s MODE %s %s%s",
659     (IsHidden(source_p) ||
660     ConfigServerHide.hide_servers) ?
661     me.name : source_p->name,
662     chptr->chname, lmodebuf, sendbuf);
663     mbuf = lmodebuf;
664     *mbuf++ = '-';
665     count = 0;
666     sendbuf[0] = '\0';
667     }
668     }
669    
670     if (count != 0)
671     {
672     *mbuf = '\0';
673     for (lcount = 0; lcount < MAXMODEPARAMS; lcount++)
674     {
675     if (*lpara[lcount] == '\0')
676     break;
677    
678     strlcat(sendbuf, " ", sizeof(sendbuf));
679     strlcat(sendbuf, lpara[lcount], sizeof(sendbuf));
680     }
681     sendto_channel_local(ALL_MEMBERS, NO, chptr,
682     ":%s MODE %s %s%s",
683     (IsHidden(source_p) || ConfigServerHide.hide_servers) ?
684     me.name : source_p->name,
685     chptr->chname, lmodebuf, sendbuf);
686     }
687     }
688    

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28