ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/core/m_join.c
Revision: 855
Committed: Mon Feb 26 22:06:45 2007 UTC (17 years, 1 month ago) by db
Content type: text/x-csrc
File size: 18498 byte(s)
Log Message:
- fix core in temp channel resv
- remove unused variable in m_join
- update RELNOTES


File Contents

# User Rev Content
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 keep_our_modes = 1;
321     int keep_new_modes = 1;
322     int isnew = 0;
323     const char *servername = NULL;
324     struct Channel *chptr = NULL;
325     struct Mode mode, *oldmode;
326 adx 30
327 michael 632 if (parc == 2 && !irccmp(parv[1], "0"))
328 adx 30 {
329     do_join_0(client_p, source_p);
330     return;
331     }
332    
333 michael 632 if (parc < 4 || *parv[2] == '&')
334 adx 30 return;
335    
336 michael 632 if (!check_channel_name(parv[2], 0))
337     {
338     sendto_realops_flags(UMODE_DEBUG, L_ALL,
339     "*** Too long or invalid channel name from %s: %s",
340     client_p->name, parv[2]);
341 adx 30 return;
342 michael 632 }
343 adx 30
344     mbuf = modebuf;
345     mode.mode = mode.limit = 0;
346     mode.key[0] = '\0';
347    
348 michael 632 if ((chptr = hash_find_channel(parv[2])) == NULL)
349     {
350     isnew = 1;
351     chptr = make_channel(parv[2]);
352     }
353    
354     newts = atol(parv[1]);
355 adx 30 oldts = chptr->channelts;
356     oldmode = &chptr->mode;
357    
358     if (ConfigFileEntry.ignore_bogus_ts)
359     {
360     if (newts < 800000000)
361     {
362     sendto_realops_flags(UMODE_DEBUG, L_ALL,
363     "*** Bogus TS %lu on %s ignored from %s",
364     (unsigned long)newts, chptr->chname,
365     client_p->name);
366    
367     newts = (oldts == 0) ? 0 : 800000000;
368     }
369     }
370     else
371     {
372     if (!newts && !isnew && oldts)
373     {
374     sendto_channel_local(ALL_MEMBERS, NO, chptr,
375     ":%s NOTICE %s :*** Notice -- TS for %s changed from %lu to 0",
376     me.name, chptr->chname, chptr->chname, (unsigned long)oldts);
377     sendto_realops_flags(UMODE_ALL, L_ALL,
378     "Server %s changing TS on %s from %lu to 0",
379     source_p->name, chptr->chname, (unsigned long)oldts);
380     }
381     }
382    
383     if (isnew)
384     chptr->channelts = newts;
385     else if (newts == 0 || oldts == 0)
386     chptr->channelts = 0;
387     else if (newts == oldts)
388     ;
389     else if (newts < oldts)
390     {
391     keep_our_modes = NO;
392     chptr->channelts = newts;
393     }
394     else
395     keep_new_modes = NO;
396    
397     if (!keep_new_modes)
398     mode = *oldmode;
399     else if (keep_our_modes)
400     {
401     mode.mode |= oldmode->mode;
402     if (oldmode->limit > mode.limit)
403     mode.limit = oldmode->limit;
404     if (strcmp(mode.key, oldmode->key) < 0)
405     strcpy(mode.key, oldmode->key);
406     }
407    
408     set_final_mode(&mode, oldmode);
409     chptr->mode = mode;
410    
411     /* Lost the TS, other side wins, so remove modes on this side */
412     if (!keep_our_modes)
413     {
414     remove_our_modes(chptr, source_p);
415     sendto_channel_local(ALL_MEMBERS, NO, chptr,
416     ":%s NOTICE %s :*** Notice -- TS for %s changed from %lu to %lu",
417     me.name, chptr->chname, chptr->chname,
418     (unsigned long)oldts, (unsigned long)newts);
419     }
420    
421     if (*modebuf != '\0')
422     {
423     servername = (ConfigServerHide.hide_servers || IsHidden(source_p)) ?
424     me.name : source_p->name;
425    
426     /* This _SHOULD_ be to ALL_MEMBERS
427     * It contains only +imnpstlk, etc */
428     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s MODE %s %s %s",
429     servername, chptr->chname, modebuf, parabuf);
430     }
431    
432     if (!IsMember(source_p, chptr))
433     {
434     add_user_to_channel(chptr, source_p, 0, YES);
435     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s JOIN :%s",
436     source_p->name, source_p->username,
437     source_p->host, chptr->chname);
438     }
439    
440     sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, NOFLAGS,
441     ":%s JOIN %lu %s +",
442     ID(source_p), (unsigned long)chptr->channelts, chptr->chname);
443     sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, NOFLAGS,
444     ":%s SJOIN %lu %s + :%s",
445     source_p->servptr->name, (unsigned long)chptr->channelts,
446     chptr->chname, source_p->name);
447     }
448    
449     /* do_join_0()
450     *
451     * inputs - pointer to client doing join 0
452     * output - NONE
453     * side effects - Use has decided to join 0. This is legacy
454     * from the days when channels were numbers not names. *sigh*
455     * There is a bunch of evilness necessary here due to
456     * anti spambot code.
457     */
458     static void
459     do_join_0(struct Client *client_p, struct Client *source_p)
460     {
461     struct Channel *chptr = NULL;
462 michael 488 dlink_node *ptr = NULL, *ptr_next = NULL;
463 adx 30
464 michael 488 if (source_p->channel.head && MyConnect(source_p) && !IsOper(source_p))
465 adx 30 check_spambot_warning(source_p, NULL);
466    
467     DLINK_FOREACH_SAFE(ptr, ptr_next, source_p->channel.head)
468     {
469     chptr = ((struct Membership *)ptr->data)->chptr;
470    
471 michael 488 sendto_server(client_p, NULL, chptr, CAP_TS6, NOCAPS, NOFLAGS,
472     ":%s PART %s", ID(source_p), chptr->chname);
473     sendto_server(client_p, NULL, chptr, NOCAPS, CAP_TS6, NOFLAGS,
474     ":%s PART %s", source_p->name, chptr->chname);
475     sendto_channel_local(ALL_MEMBERS, NO, chptr, ":%s!%s@%s PART %s",
476     source_p->name, source_p->username,
477     source_p->host, chptr->chname);
478 adx 30
479 michael 488 remove_user_from_channel(ptr->data);
480 adx 30 }
481     }
482    
483     /* set_final_mode()
484     *
485     * inputs - pointer to mode to setup
486     * - pointer to old mode
487     * output - NONE
488     * side effects -
489     */
490     static const struct mode_letter
491     {
492     unsigned int mode;
493     unsigned char letter;
494     } flags[] = {
495     { MODE_NOPRIVMSGS, 'n' },
496     { MODE_TOPICLIMIT, 't' },
497     { MODE_SECRET, 's' },
498     { MODE_MODERATED, 'm' },
499     { MODE_INVITEONLY, 'i' },
500     { MODE_PRIVATE, 'p' },
501     { 0, '\0' }
502     };
503    
504     static void
505     set_final_mode(struct Mode *mode, struct Mode *oldmode)
506     {
507     char *pbuf = parabuf;
508     int what = 0;
509     int len;
510     int i;
511    
512     for (i = 0; flags[i].letter; i++)
513     {
514     if ((flags[i].mode & mode->mode) &&
515     !(flags[i].mode & oldmode->mode))
516     {
517     if (what != 1)
518     {
519     *mbuf++ = '+';
520     what = 1;
521     }
522     *mbuf++ = flags[i].letter;
523     }
524     }
525    
526     for (i = 0; flags[i].letter; i++)
527     {
528     if ((flags[i].mode & oldmode->mode) &&
529     !(flags[i].mode & mode->mode))
530     {
531     if (what != -1)
532     {
533     *mbuf++ = '-';
534     what = -1;
535     }
536     *mbuf++ = flags[i].letter;
537     }
538     }
539    
540     if (oldmode->limit != 0 && mode->limit == 0)
541     {
542     if (what != -1)
543     {
544     *mbuf++ = '-';
545     what = -1;
546     }
547     *mbuf++ = 'l';
548     }
549    
550     if (oldmode->key[0] && !mode->key[0])
551     {
552     if (what != -1)
553     {
554     *mbuf++ = '-';
555     what = -1;
556     }
557     *mbuf++ = 'k';
558     len = ircsprintf(pbuf, "%s ", oldmode->key);
559     pbuf += len;
560     }
561    
562     if (mode->limit != 0 && oldmode->limit != mode->limit)
563     {
564     if (what != 1)
565     {
566     *mbuf++ = '+';
567     what = 1;
568     }
569     *mbuf++ = 'l';
570     len = ircsprintf(pbuf, "%d ", mode->limit);
571     pbuf += len;
572     }
573    
574     if (mode->key[0] && strcmp(oldmode->key, mode->key))
575     {
576     if (what != 1)
577     {
578     *mbuf++ = '+';
579     what = 1;
580     }
581     *mbuf++ = 'k';
582     len = ircsprintf(pbuf, "%s ", mode->key);
583     pbuf += len;
584     }
585     *mbuf = '\0';
586     }
587    
588     /* remove_our_modes()
589     *
590     * inputs - pointer to channel to remove modes from
591     * - client pointer
592     * output - NONE
593     * side effects - Go through the local members, remove all their
594     * chanop modes etc., this side lost the TS.
595     */
596     static void
597     remove_our_modes(struct Channel *chptr, struct Client *source_p)
598     {
599     remove_a_mode(chptr, source_p, CHFL_CHANOP, 'o');
600     #ifdef HALFOPS
601     remove_a_mode(chptr, source_p, CHFL_HALFOP, 'h');
602     #endif
603     remove_a_mode(chptr, source_p, CHFL_VOICE, 'v');
604     }
605    
606     /* remove_a_mode()
607     *
608     * inputs -
609     * output - NONE
610     * side effects - remove ONE mode from a channel
611     */
612     static void
613     remove_a_mode(struct Channel *chptr, struct Client *source_p,
614     int mask, char flag)
615     {
616     dlink_node *ptr;
617     struct Membership *ms;
618     char lmodebuf[MODEBUFLEN];
619     const char *lpara[MAXMODEPARAMS];
620     int count = 0;
621     int lcount;
622    
623     mbuf = lmodebuf;
624     *mbuf++ = '-';
625    
626     for (lcount = 0; lcount < MAXMODEPARAMS; lcount++)
627     lpara[lcount] = "";
628     sendbuf[0] = '\0';
629    
630     DLINK_FOREACH(ptr, chptr->members.head)
631     {
632     ms = ptr->data;
633    
634     if ((ms->flags & mask) == 0)
635     continue;
636    
637     ms->flags &= ~mask;
638    
639     lpara[count++] = ms->client_p->name;
640    
641     *mbuf++ = flag;
642    
643     if (count >= MAXMODEPARAMS)
644     {
645     for (lcount = 0; lcount < MAXMODEPARAMS; lcount++)
646     {
647     if (*lpara[lcount] == '\0')
648     break;
649    
650     strlcat(sendbuf, " ", sizeof(sendbuf));
651     strlcat(sendbuf, lpara[lcount], sizeof(sendbuf));
652     lpara[lcount] = "";
653     }
654    
655     *mbuf = '\0';
656     sendto_channel_local(ALL_MEMBERS, NO, chptr,
657     ":%s MODE %s %s%s",
658     (IsHidden(source_p) ||
659     ConfigServerHide.hide_servers) ?
660     me.name : source_p->name,
661     chptr->chname, lmodebuf, sendbuf);
662     mbuf = lmodebuf;
663     *mbuf++ = '-';
664     count = 0;
665     sendbuf[0] = '\0';
666     }
667     }
668    
669     if (count != 0)
670     {
671     *mbuf = '\0';
672     for (lcount = 0; lcount < MAXMODEPARAMS; lcount++)
673     {
674     if (*lpara[lcount] == '\0')
675     break;
676    
677     strlcat(sendbuf, " ", sizeof(sendbuf));
678     strlcat(sendbuf, lpara[lcount], sizeof(sendbuf));
679     }
680     sendto_channel_local(ALL_MEMBERS, NO, chptr,
681     ":%s MODE %s %s%s",
682     (IsHidden(source_p) || ConfigServerHide.hide_servers) ?
683     me.name : source_p->name,
684     chptr->chname, lmodebuf, sendbuf);
685     }
686     }
687    

Properties

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