~ubuntu-branches/ubuntu/oneiric/eggdrop/oneiric

« back to all changes in this revision

Viewing changes to src/mod/irc.mod/chan.c

  • Committer: Bazaar Package Importer
  • Author(s): Guilherme de S. Pastore
  • Date: 2004-06-17 09:15:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040617091528-64rrw1sa33lkfhmh
Tags: 1.6.16-2
* Fixed typo on README.Debian
* Fixed hyphens in manual page
* Converted debian/rules to CDBS
* Set path to binary on example config file
* Changed LANGDIR on src/eggdrop.h (Closes: #254824)

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 *   user kickban, kick, op, deop
7
7
 *   idle kicking
8
8
 *
9
 
 * $Id: chan.c,v 1.79 2002/01/02 03:46:39 guppy Exp $
 
9
 * $Id: chan.c,v 1.116 2004/05/26 00:20:19 wcc Exp $
10
10
 */
11
11
/*
12
12
 * Copyright (C) 1997 Robey Pointer
13
 
 * Copyright (C) 1999, 2000, 2001, 2002 Eggheads Development Team
 
13
 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Eggheads Development Team
14
14
 *
15
15
 * This program is free software; you can redistribute it and/or
16
16
 * modify it under the terms of the GNU General Public License
28
28
 */
29
29
 
30
30
static time_t last_ctcp = (time_t) 0L;
31
 
static int    count_ctcp = 0;
 
31
static int count_ctcp = 0;
32
32
static time_t last_invtime = (time_t) 0L;
33
 
static char   last_invchan[300] = "";
 
33
static char last_invchan[300] = "";
34
34
 
35
35
/* ID length for !channels.
36
36
 */
43
43
{
44
44
  memberlist *x;
45
45
 
46
 
  for (x = chan->channel.member; x && x->nick[0]; x = x->next); 
 
46
  for (x = chan->channel.member; x && x->nick[0]; x = x->next);
47
47
  x->next = (memberlist *) channel_malloc(sizeof(memberlist));
48
48
  x->next->next = NULL;
49
49
  x->next->nick[0] = 0;
89
89
    s[i++] = 'm';
90
90
  if (atr & CHANNOCLR)
91
91
    s[i++] = 'c';
 
92
  if (atr & CHANNOCTCP)
 
93
    s[i++] = 'C';
92
94
  if (atr & CHANREGON)
93
95
    s[i++] = 'R';
94
96
  if (atr & CHANTOPIC)
95
97
    s[i++] = 't';
96
 
  if (atr & CHANMODR)
 
98
  if (atr & CHANMODREG)
97
99
    s[i++] = 'M';
 
100
  if (atr & CHANLONLY)
 
101
    s[i++] = 'r';
98
102
  if (atr & CHANNOMSG)
99
103
    s[i++] = 'n';
100
104
  if (atr & CHANANON)
133
137
 * Moved all do_ban(), do_exempt() and do_invite() into this single function
134
138
 * as the code bloat is starting to get rediculous <cybah>
135
139
 */
136
 
static void do_mask(struct chanset_t *chan, masklist *m, char *mask, char Mode)
 
140
static void do_mask(struct chanset_t *chan, masklist *m, char *mask, char mode)
137
141
{
138
142
  for (; m && m->mask[0]; m = m->next)
139
143
    if (wild_match(mask, m->mask) && rfc_casecmp(mask, m->mask))
140
 
      add_mode(chan, '-', Mode, m->mask);
141
 
  add_mode(chan, '+', Mode, mask);
 
144
      add_mode(chan, '-', mode, m->mask);
 
145
  add_mode(chan, '+', mode, mask);
142
146
  flush_mode(chan, QUICK);
143
147
}
144
148
 
146
150
 * and handles kick & deop as well.
147
151
 */
148
152
static int detect_chan_flood(char *floodnick, char *floodhost, char *from,
149
 
                             struct chanset_t *chan, int which, char *victim)
 
153
                             struct chanset_t *chan, int which, char *victim)
150
154
{
151
155
  char h[UHOSTLEN], ftype[12], *p;
152
156
  struct userrec *u;
153
157
  memberlist *m;
154
158
  int thr = 0, lapse = 0;
155
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
159
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
156
160
 
157
161
  if (!chan || (which < 0) || (which >= FLOOD_CHAN_MAX))
158
162
    return 0;
164
168
    return 0;
165
169
 
166
170
  get_user_flagrec(get_user_by_host(from), &fr, chan->dname);
167
 
  if (glob_bot(fr) ||
168
 
      ((which == FLOOD_DEOP) && (glob_master(fr) || chan_master(fr))) ||
169
 
      ((which != FLOOD_DEOP) && (glob_friend(fr) || chan_friend(fr))) ||
170
 
      (channel_dontkickops(chan) &&
171
 
       (chan_op(fr) || (glob_op(fr) && !chan_deop(fr)))))       /* arthur2 */
 
171
  if (glob_bot(fr) || ((which == FLOOD_DEOP) && (glob_master(fr) ||
 
172
      chan_master(fr)) && (glob_friend(fr) || chan_friend(fr))) ||
 
173
      ((which == FLOOD_KICK) && (glob_master(fr) || chan_master(fr)) &&
 
174
      (glob_friend(fr) || chan_friend(fr))) || ((which != FLOOD_DEOP) &&
 
175
      (which != FLOOD_KICK) && (glob_friend(fr) || chan_friend(fr))) ||
 
176
      (channel_dontkickops(chan) && (chan_op(fr) || (glob_op(fr) &&
 
177
      !chan_deop(fr)))))
172
178
    return 0;
173
179
 
174
180
  /* Determine how many are necessary to make a flood. */
192
198
  case FLOOD_JOIN:
193
199
    thr = chan->flood_join_thr;
194
200
    lapse = chan->flood_join_time;
195
 
      strcpy(ftype, "join");
 
201
    strcpy(ftype, "join");
196
202
    break;
197
203
  case FLOOD_DEOP:
198
204
    thr = chan->flood_deop_thr;
206
212
    break;
207
213
  }
208
214
  if ((thr == 0) || (lapse == 0))
209
 
    return 0;                   /* no flood protection */
 
215
    return 0;                   /* no flood protection */
210
216
  /* Okay, make sure i'm not flood-checking myself */
211
217
  if (match_my_nick(floodnick))
212
218
    return 0;
223
229
    if (!p)
224
230
      return 0;
225
231
  }
226
 
  if (rfc_casecmp(chan->floodwho[which], p)) {  /* new */
227
 
    strncpy(chan->floodwho[which], p, 81);
228
 
    chan->floodwho[which][81] = 0;
 
232
  if (rfc_casecmp(chan->floodwho[which], p)) {  /* new */
 
233
    strncpy(chan->floodwho[which], p, 80);
 
234
    chan->floodwho[which][80] = 0;
229
235
    chan->floodtime[which] = now;
230
236
    chan->floodnum[which] = 1;
231
237
    return 0;
244
250
      strcpy(chan->deopd, victim);
245
251
  }
246
252
  chan->floodnum[which]++;
247
 
  if (chan->floodnum[which] >= thr) {   /* FLOOD */
 
253
  if (chan->floodnum[which] >= thr) {   /* FLOOD */
248
254
    /* Reset counters */
249
255
    chan->floodnum[which] = 0;
250
256
    chan->floodtime[which] = 0;
259
265
    case FLOOD_NOTICE:
260
266
    case FLOOD_CTCP:
261
267
      /* Flooding chan! either by public or notice */
262
 
      if (me_op(chan) && !chan_sentkick(m)) {
263
 
        putlog(LOG_MODES, chan->dname, IRC_FLOODKICK, floodnick);
264
 
        dprintf(DP_MODE, "KICK %s %s :%s\n", chan->name, floodnick,
265
 
                CHAN_FLOOD);
266
 
        m->flags |= SENTKICK;
 
268
      if (!chan_sentkick(m) &&
 
269
          (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) {
 
270
        putlog(LOG_MODES, chan->dname, IRC_FLOODKICK, floodnick);
 
271
        dprintf(DP_MODE, "KICK %s %s :%s\n", chan->name, floodnick, CHAN_FLOOD);
 
272
        m->flags |= SENTKICK;
267
273
      }
268
274
      return 1;
269
275
    case FLOOD_JOIN:
270
276
    case FLOOD_NICK:
271
 
      if (use_exempts &&
272
 
          (u_match_mask(global_exempts, from) ||
273
 
           u_match_mask(chan->exempts, from)))
274
 
        return 1;
 
277
      if (use_exempts && (u_match_mask(global_exempts, from) ||
 
278
          u_match_mask(chan->exempts, from)))
 
279
        return 1;
275
280
      simple_sprintf(h, "*!*@%s", p);
276
 
      if (!isbanned(chan, h) && me_op(chan)) {
277
 
        check_exemptlist(chan, from);
278
 
        do_mask(chan, chan->channel.ban, h, 'b');
 
281
      if (!isbanned(chan, h) && (me_op(chan) || me_halfop(chan))) {
 
282
        check_exemptlist(chan, from);
 
283
        do_mask(chan, chan->channel.ban, h, 'b');
279
284
      }
280
 
      if ((u_match_mask(global_bans, from))
281
 
          || (u_match_mask(chan->bans, from)))
282
 
        return 1;               /* Already banned */
 
285
      if ((u_match_mask(global_bans, from)) ||
 
286
          (u_match_mask(chan->bans, from)))
 
287
        return 1;               /* Already banned */
283
288
      if (which == FLOOD_JOIN)
284
 
        putlog(LOG_MISC | LOG_JOIN, chan->dname, IRC_FLOODIGNORE3, p);
 
289
        putlog(LOG_MISC | LOG_JOIN, chan->dname, IRC_FLOODIGNORE3, p);
285
290
      else
286
 
        putlog(LOG_MISC | LOG_JOIN, chan->dname, IRC_FLOODIGNORE4, p);
 
291
        putlog(LOG_MISC | LOG_JOIN, chan->dname, IRC_FLOODIGNORE4, p);
287
292
      strcpy(ftype + 4, " flood");
288
 
      u_addban(chan, h, botnetnick, ftype, now + (60 * ban_time), 0);
289
 
      if (!channel_enforcebans(chan) && me_op(chan)) {
290
 
          char s[UHOSTLEN];
291
 
          for (m = chan->channel.member; m && m->nick[0]; m = m->next) {          
292
 
            sprintf(s, "%s!%s", m->nick, m->userhost);
293
 
            if (wild_match(h, s) &&
294
 
                (m->joined >= chan->floodtime[which]) &&
295
 
                   !chan_sentkick(m) && !match_my_nick(m->nick)) {
296
 
              m->flags |= SENTKICK;
297
 
              if (which == FLOOD_JOIN)
298
 
              dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, m->nick,
299
 
                      IRC_JOIN_FLOOD);
300
 
              else
301
 
                dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, m->nick,
302
 
                      IRC_NICK_FLOOD);
303
 
            }
304
 
          }
305
 
        }
 
293
      u_addban(chan, h, botnetnick, ftype, now + (60 * chan->ban_time), 0);
 
294
      if (!channel_enforcebans(chan) && (me_op(chan) || me_halfop(chan))) {
 
295
        char s[UHOSTLEN];
 
296
 
 
297
        for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
 
298
          sprintf(s, "%s!%s", m->nick, m->userhost);
 
299
          if (wild_match(h, s) && (m->joined >= chan->floodtime[which]) &&
 
300
              !chan_sentkick(m) && !match_my_nick(m->nick) && (me_op(chan) ||
 
301
              (me_halfop(chan) && !chan_hasop(m)))) {
 
302
            m->flags |= SENTKICK;
 
303
            if (which == FLOOD_JOIN)
 
304
              dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, m->nick,
 
305
                      IRC_JOIN_FLOOD);
 
306
            else
 
307
              dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, m->nick,
 
308
                      IRC_NICK_FLOOD);
 
309
          }
 
310
        }
 
311
      }
306
312
      return 1;
307
313
    case FLOOD_KICK:
308
 
      if (me_op(chan) && !chan_sentkick(m)) {
309
 
        putlog(LOG_MODES, chan->dname, "Kicking %s, for mass kick.", floodnick);
310
 
        dprintf(DP_MODE, "KICK %s %s :%s\n", chan->name, floodnick,
311
 
                IRC_MASSKICK);
312
 
        m->flags |= SENTKICK;
 
314
      if ((me_op(chan) || (me_halfop(chan) && !chan_hasop(m))) &&
 
315
          !chan_sentkick(m)) {
 
316
        putlog(LOG_MODES, chan->dname, "Kicking %s, for mass kick.", floodnick);
 
317
        dprintf(DP_MODE, "KICK %s %s :%s\n", chan->name, floodnick,
 
318
                IRC_MASSKICK);
 
319
        m->flags |= SENTKICK;
313
320
      }
314
 
    return 1;
 
321
      return 1;
315
322
    case FLOOD_DEOP:
316
 
      if (me_op(chan) && !chan_sentkick(m)) {
317
 
        putlog(LOG_MODES, chan->dname,
318
 
               CHAN_MASSDEOP, chan->dname, from);
319
 
        dprintf(DP_MODE, "KICK %s %s :%s\n",
320
 
                chan->name, floodnick, CHAN_MASSDEOP_KICK);
321
 
        m->flags |= SENTKICK;
 
323
      if ((me_op(chan) || (me_halfop(chan) && !chan_hasop(m))) &&
 
324
          !chan_sentkick(m)) {
 
325
        putlog(LOG_MODES, chan->dname, CHAN_MASSDEOP, chan->dname, from);
 
326
        dprintf(DP_MODE, "KICK %s %s :%s\n",
 
327
                chan->name, floodnick, CHAN_MASSDEOP_KICK);
 
328
        m->flags |= SENTKICK;
322
329
      }
323
330
      return 1;
324
331
    }
332
339
{
333
340
  static char s1[512];
334
341
 
335
 
  maskhost(uhost, s1);
336
 
  if ((strlen(s1) != 1) && (strict_host == 0))
337
 
    s1[2] = '*';                /* arthur2 */
 
342
  maskban(uhost, s1);
338
343
  do_mask(chan, chan->channel.ban, s1, 'b');
339
344
  return s1;
340
345
}
342
347
/* Kick any user (except friends/masters) with certain mask from channel
343
348
 * with a specified comment.  Ernst 18/3/1998
344
349
 */
345
 
static void kick_all(struct chanset_t *chan, char *hostmask, char *comment, int bantype)
 
350
static void kick_all(struct chanset_t *chan, char *hostmask, char *comment,
 
351
                     int bantype)
346
352
{
347
353
  memberlist *m;
348
354
  char kicknick[512], s[UHOSTLEN];
349
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
355
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
350
356
  int k, l, flushed;
351
357
 
352
 
  if (!me_op(chan))
 
358
  if (!me_op(chan) && !me_halfop(chan))
353
359
    return;
 
360
 
354
361
  k = 0;
355
362
  flushed = 0;
356
363
  kicknick[0] = 0;
357
364
  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
358
365
    sprintf(s, "%s!%s", m->nick, m->userhost);
359
366
    get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr, chan->dname);
360
 
    if (wild_match(hostmask, s) && !chan_sentkick(m) &&
361
 
        !match_my_nick(m->nick) && !chan_issplit(m) &&
362
 
        !glob_friend(fr) && !chan_friend(fr) &&
363
 
        !(use_exempts &&
364
 
          ((bantype && isexempted(chan, s)) ||
365
 
           (u_match_mask(global_exempts,s) ||
366
 
            u_match_mask(chan->exempts, s)))) &&
367
 
        !(channel_dontkickops(chan) &&
368
 
          (chan_op(fr) || (glob_op(fr) && !chan_deop(fr))))) {  /* arthur2 */
 
367
    if ((me_op(chan) || (me_halfop(chan) && !chan_hasop(m))) &&
 
368
        wild_match(hostmask, s) && !chan_sentkick(m) &&
 
369
        !match_my_nick(m->nick) && !chan_issplit(m) &&
 
370
        !glob_friend(fr) && !chan_friend(fr) && !(use_exempts && ((bantype &&
 
371
        isexempted(chan, s)) || (u_match_mask(global_exempts, s) ||
 
372
        u_match_mask(chan->exempts, s)))) && !(channel_dontkickops(chan) &&
 
373
        (chan_op(fr) || (glob_op(fr) && !chan_deop(fr))))) {
369
374
      if (!flushed) {
370
 
        /* We need to kick someone, flush eventual bans first */
371
 
        flush_mode(chan, QUICK);
372
 
        flushed += 1;
 
375
        /* We need to kick someone, flush eventual bans first */
 
376
        flush_mode(chan, QUICK);
 
377
        flushed += 1;
373
378
      }
374
 
      m->flags |= SENTKICK;     /* Mark as pending kick */
 
379
      m->flags |= SENTKICK;     /* Mark as pending kick */
375
380
      if (kicknick[0])
376
 
        strcat(kicknick, ",");
 
381
        strcat(kicknick, ",");
377
382
      strcat(kicknick, m->nick);
378
383
      k += 1;
379
384
      l = strlen(chan->name) + strlen(kicknick) + strlen(comment) + 5;
380
385
      if ((kick_method != 0 && k == kick_method) || (l > 480)) {
381
 
        dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, kicknick, comment);
382
 
        k = 0;
383
 
        kicknick[0] = 0;
 
386
        dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, kicknick, comment);
 
387
        k = 0;
 
388
        kicknick[0] = 0;
384
389
      }
385
390
    }
386
391
  }
392
397
 */
393
398
static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick)
394
399
{
395
 
  register maskrec      *b;
396
 
  memberlist            *m;
397
 
  int                    cycle;
 
400
  register maskrec *b;
 
401
  memberlist *m;
 
402
  int cycle;
398
403
 
399
404
  m = ismember(chan, nick);
400
 
  if (!m)
 
405
  if (!m || chan_sentkick(m))
401
406
    return;
402
 
  /* Check global bans in first cycle and channel bans
403
 
     in second cycle. */
 
407
 
 
408
  /* Check global bans in first cycle and channel bans in second cycle. */
404
409
  for (cycle = 0; cycle < 2; cycle++) {
405
410
    for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
406
411
      if (wild_match(b->mask, user)) {
407
 
        struct flag_record      fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
408
 
        char                    c[512];         /* The ban comment.     */
409
 
        char                    s[UHOSTLEN];
 
412
        struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
 
413
        char c[512];            /* The ban comment.     */
 
414
        char s[UHOSTLEN];
410
415
 
411
 
        sprintf(s, "%s!%s", m->nick, m->userhost);
412
 
        get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr,
413
 
                         chan->dname);
414
 
        if (!glob_friend(fr) && !chan_friend(fr))
415
 
          add_mode(chan, '-', 'o', nick);       /* Guess it can't hurt. */
416
 
        check_exemptlist(chan, user);
417
 
        do_mask(chan, chan->channel.ban, b->mask, 'b');
418
 
        b->lastactive = now;
419
 
        if (b->desc && b->desc[0] != '@')
420
 
          egg_snprintf(c, sizeof c, "%s%s", IRC_PREBANNED, b->desc);
421
 
        else
422
 
          c[0] = 0;
423
 
        kick_all(chan, b->mask, c[0] ? c : IRC_YOUREBANNED, 0);
424
 
        return;                                 /* Drop out on 1st ban. */
 
416
        sprintf(s, "%s!%s", m->nick, m->userhost);
 
417
        get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr,
 
418
                         chan->dname);
 
419
        if (!glob_friend(fr) && !chan_friend(fr)) {
 
420
          add_mode(chan, '-', 'o', nick);       /* Guess it can't hurt. */
 
421
          check_exemptlist(chan, user);
 
422
          do_mask(chan, chan->channel.ban, b->mask, 'b');
 
423
          b->lastactive = now;
 
424
          if (b->desc && b->desc[0] != '@')
 
425
            egg_snprintf(c, sizeof c, "%s %s", IRC_PREBANNED, b->desc);
 
426
          else
 
427
            c[0] = 0;
 
428
          kick_all(chan, b->mask, c[0] ? c : IRC_YOUREBANNED, 0);
 
429
          return;               /* Drop out on 1st ban. */
 
430
        }
425
431
      }
426
432
    }
427
433
  }
432
438
 */
433
439
static void refresh_exempt(struct chanset_t *chan, char *user)
434
440
{
435
 
  maskrec       *e;
436
 
  masklist      *b;
437
 
  int            cycle;
 
441
  maskrec *e;
 
442
  masklist *b;
 
443
  int cycle;
438
444
 
439
 
  /* Check global exempts in first cycle and channel exempts
440
 
     in second cycle. */
 
445
  /* Check global exempts in first cycle and channel exempts in second cycle. */
441
446
  for (cycle = 0; cycle < 2; cycle++) {
442
447
    for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
443
 
      if (wild_match(user, e->mask) || wild_match(e->mask,user)) {
 
448
      if (wild_match(user, e->mask) || wild_match(e->mask, user)) {
444
449
        for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
445
450
          if (wild_match(b->mask, user) || wild_match(user, b->mask)) {
446
451
            if (e->lastactive < now - 60 && !isexempted(chan, e->mask)) {
456
461
 
457
462
static void refresh_invite(struct chanset_t *chan, char *user)
458
463
{
459
 
  maskrec       *i;
460
 
  int            cycle;
 
464
  maskrec *i;
 
465
  int cycle;
461
466
 
462
 
  /* Check global invites in first cycle and channel invites
463
 
     in second cycle. */
 
467
  /* Check global invites in first cycle and channel invites in second cycle. */
464
468
  for (cycle = 0; cycle < 2; cycle++) {
465
469
    for (i = cycle ? chan->invites : global_invites; i; i = i->next) {
466
470
      if (wild_match(i->mask, user) &&
467
 
          ((i->flags & MASKREC_STICKY) || (chan->channel.mode & CHANINV))) {
 
471
          ((i->flags & MASKREC_STICKY) || (chan->channel.mode & CHANINV))) {
468
472
        if (i->lastactive < now - 60 && !isinvited(chan, i->mask)) {
469
473
          do_mask(chan, chan->channel.invite, i->mask, 'I');
470
 
          i->lastactive = now;
471
 
          return;
472
 
        }
 
474
          i->lastactive = now;
 
475
          return;
 
476
        }
473
477
      }
474
478
    }
475
479
  }
479
483
 */
480
484
static void enforce_bans(struct chanset_t *chan)
481
485
{
482
 
  char           me[UHOSTLEN];
483
 
  masklist      *b;
484
 
 
485
 
  if (!me_op(chan))
486
 
    return;                     /* Can't do it :( */
 
486
  char me[UHOSTLEN];
 
487
  masklist *b;
 
488
 
 
489
  if (HALFOP_CANTDOMODE('b'))
 
490
    return;
 
491
 
487
492
  simple_sprintf(me, "%s!%s", botname, botuserhost);
488
493
  /* Go through all bans, kicking the users. */
489
494
  for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
490
495
    if (!wild_match(b->mask, me))
491
496
      if (!isexempted(chan, b->mask))
492
 
        kick_all(chan, b->mask, IRC_YOUREBANNED, 1);
 
497
        kick_all(chan, b->mask, IRC_YOUREBANNED, 1);
493
498
  }
494
499
}
495
500
 
500
505
 */
501
506
static void recheck_bans(struct chanset_t *chan)
502
507
{
503
 
  maskrec       *u;
504
 
  int            cycle;
 
508
  maskrec *u;
 
509
  int cycle;
505
510
 
506
 
  /* Check global bans in first cycle and channel bans
507
 
     in second cycle. */
 
511
  /* Check global bans in first cycle and channel bans in second cycle. */
508
512
  for (cycle = 0; cycle < 2; cycle++) {
509
513
    for (u = cycle ? chan->bans : global_bans; u; u = u->next)
510
514
      if (!isbanned(chan, u->mask) && (!channel_dynamicbans(chan) ||
511
 
                                       (u->flags & MASKREC_STICKY)))
512
 
        add_mode(chan, '+', 'b', u->mask);
 
515
          (u->flags & MASKREC_STICKY)))
 
516
        add_mode(chan, '+', 'b', u->mask);
513
517
  }
514
518
}
515
519
 
520
524
 */
521
525
static void recheck_exempts(struct chanset_t *chan)
522
526
{
523
 
  maskrec       *e;
524
 
  masklist      *b;
525
 
  int            cycle;
 
527
  maskrec *e;
 
528
  masklist *b;
 
529
  int cycle;
526
530
 
527
 
  /* Check global exempts in first cycle and channel exempts
528
 
     in second cycle. */
 
531
  /* Check global exempts in first cycle and channel exempts in second cycle. */
529
532
  for (cycle = 0; cycle < 2; cycle++) {
530
533
    for (e = cycle ? chan->exempts : global_exempts; e; e = e->next) {
531
534
      if (!isexempted(chan, e->mask) &&
534
537
      for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
535
538
        if ((wild_match(b->mask, e->mask) || wild_match(e->mask, b->mask)) &&
536
539
            !isexempted(chan, e->mask))
537
 
          add_mode(chan,'+','e',e->mask);
538
 
        /* do_mask(chan, chan->channel.exempt, e->mask, 'e');*/
 
540
          add_mode(chan, '+', 'e', e->mask);
 
541
        /* do_mask(chan, chan->channel.exempt, e->mask, 'e'); */
539
542
      }
540
543
    }
541
544
  }
548
551
 */
549
552
static void recheck_invites(struct chanset_t *chan)
550
553
{
551
 
  maskrec       *ir;
552
 
  int            cycle;
 
554
  maskrec *ir;
 
555
  int cycle;
553
556
 
554
 
  /* Check global invites in first cycle and channel invites
555
 
     in second cycle. */
556
 
  for (cycle = 0; cycle < 2; cycle++)  {
 
557
  /* Check global invites in first cycle and channel invites in second cycle. */
 
558
  for (cycle = 0; cycle < 2; cycle++) {
557
559
    for (ir = cycle ? chan->invites : global_invites; ir; ir = ir->next) {
558
560
      /* If invite isn't set and (channel is not dynamic invites and not invite
559
561
       * only) or invite is sticky.
560
562
       */
561
563
      if (!isinvited(chan, ir->mask) && ((!channel_dynamicinvites(chan) &&
562
564
          !(chan->channel.mode & CHANINV)) || ir->flags & MASKREC_STICKY))
563
 
        add_mode(chan, '+', 'I', ir->mask);
564
 
        /* do_mask(chan, chan->channel.invite, ir->mask, 'I');*/
 
565
        add_mode(chan, '+', 'I', ir->mask);
 
566
      /* do_mask(chan, chan->channel.invite, ir->mask, 'I'); */
565
567
    }
566
568
  }
567
569
}
569
571
/* Resets the masks on the channel.
570
572
 */
571
573
static void resetmasks(struct chanset_t *chan, masklist *m, maskrec *mrec,
572
 
                       maskrec *global_masks, char mode)
 
574
                       maskrec *global_masks, char mode)
573
575
{
574
 
  if (!me_op(chan))
575
 
    return;                     /* Can't do it */
 
576
  if (!me_op(chan) && (!me_halfop(chan) ||
 
577
      (strchr(NOHALFOPS_MODES, 'b') != NULL) ||
 
578
      (strchr(NOHALFOPS_MODES, 'e') != NULL) ||
 
579
      (strchr(NOHALFOPS_MODES, 'I') != NULL)))
 
580
    return;
576
581
 
577
582
  /* Remove masks we didn't put there */
578
583
  for (; m && m->mask[0]; m = m->next) {
582
587
 
583
588
  /* Make sure the intended masks are still there */
584
589
  switch (mode) {
585
 
    case 'b':
586
 
      recheck_bans(chan);
587
 
      break;
588
 
    case 'e':
589
 
      recheck_exempts(chan);
590
 
      break;
591
 
    case 'I':
592
 
      recheck_invites(chan);
593
 
      break;
594
 
    default:
595
 
      putlog(LOG_MISC, "*", "(!) Invalid mode '%c' in resetmasks()", mode);
596
 
      break;
 
590
  case 'b':
 
591
    recheck_bans(chan);
 
592
    break;
 
593
  case 'e':
 
594
    recheck_exempts(chan);
 
595
    break;
 
596
  case 'I':
 
597
    recheck_invites(chan);
 
598
    break;
 
599
  default:
 
600
    putlog(LOG_MISC, "*", "(!) Invalid mode '%c' in resetmasks()", mode);
 
601
    break;
597
602
  }
598
603
}
599
604
static void check_this_ban(struct chanset_t *chan, char *banmask, int sticky)
601
606
  memberlist *m;
602
607
  char user[UHOSTLEN];
603
608
 
604
 
  if (!me_op(chan))
 
609
  if (HALFOP_CANTDOMODE('b'))
605
610
    return;
 
611
 
606
612
  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
607
613
    sprintf(user, "%s!%s", m->nick, m->userhost);
608
614
    if (wild_match(banmask, user) &&
611
617
           u_match_mask(chan->exempts, user))))
612
618
      refresh_ban_kick(chan, user, m->nick);
613
619
  }
614
 
  if (!isbanned(chan, banmask) &&
615
 
      (!channel_dynamicbans(chan) || sticky))
 
620
  if (!isbanned(chan, banmask) && (!channel_dynamicbans(chan) || sticky))
616
621
    add_mode(chan, '+', 'b', banmask);
617
622
}
618
623
 
619
624
static void recheck_channel_modes(struct chanset_t *chan)
620
625
{
621
 
  int cur = chan->channel.mode,
622
 
      mns = chan->mode_mns_prot,
 
626
  int cur = chan->channel.mode, mns = chan->mode_mns_prot,
623
627
      pls = chan->mode_pls_prot;
624
628
 
625
629
  if (!(chan->status & CHAN_ASKEDMODES)) {
643
647
      add_mode(chan, '+', 'c', "");
644
648
    else if (mns & CHANNOCLR && cur & CHANNOCLR)
645
649
      add_mode(chan, '-', 'c', "");
 
650
    if (pls & CHANNOCTCP && !(cur & CHANNOCTCP))
 
651
      add_mode(chan, '+', 'C', "");
 
652
    else if (mns & CHANNOCTCP && cur & CHANNOCTCP)
 
653
      add_mode(chan, '-', 'C', "");
646
654
    if (pls & CHANREGON && !(cur & CHANREGON))
647
655
      add_mode(chan, '+', 'R', "");
648
656
    else if (mns & CHANREGON && cur & CHANREGON)
649
657
      add_mode(chan, '-', 'R', "");
650
 
    if (pls & CHANMODR && !(cur & CHANMODR))
 
658
    if (pls & CHANMODREG && !(cur & CHANMODREG))
651
659
      add_mode(chan, '+', 'M', "");
652
 
    else if (mns & CHANMODR && cur & CHANMODR)
 
660
    else if (mns & CHANMODREG && cur & CHANMODREG)
653
661
      add_mode(chan, '-', 'M', "");
 
662
    if (pls & CHANLONLY && !(cur & CHANLONLY))
 
663
      add_mode(chan, '+', 'r', "");
 
664
    else if (mns & CHANLONLY && cur & CHANLONLY)
 
665
      add_mode(chan, '-', 'r', "");
654
666
    if (pls & CHANTOPIC && !(cur & CHANTOPIC))
655
667
      add_mode(chan, '+', 't', "");
656
668
    else if (mns & CHANTOPIC && cur & CHANTOPIC)
677
689
    if (chan->key_prot[0]) {
678
690
      if (rfc_casecmp(chan->channel.key, chan->key_prot) != 0) {
679
691
        if (chan->channel.key[0])
680
 
          add_mode(chan, '-', 'k', chan->channel.key);
 
692
          add_mode(chan, '-', 'k', chan->channel.key);
681
693
        add_mode(chan, '+', 'k', chan->key_prot);
682
694
      }
683
695
    } else if ((mns & CHANKEY) && (chan->channel.key[0]))
685
697
  }
686
698
}
687
699
 
688
 
static void check_this_member(struct chanset_t *chan, char *nick, struct flag_record *fr)
 
700
static void check_this_member(struct chanset_t *chan, char *nick,
 
701
                              struct flag_record *fr)
689
702
{
690
703
  memberlist *m;
691
704
  char s[UHOSTLEN], *p;
692
705
 
693
706
  m = ismember(chan, nick);
694
 
  if (!m || match_my_nick(nick))
 
707
  if (!m || match_my_nick(nick) || (!me_op(chan) && !me_halfop(chan)))
 
708
    return;
 
709
 
 
710
 
 
711
#ifdef NO_HALFOP_CHANMODES
 
712
  if (me_op(chan)) {
 
713
#else
 
714
  if (me_op(chan) || me_halfop(chan)) {
 
715
#endif
 
716
    if (HALFOP_CANDOMODE('o')) {
 
717
      if (chan_hasop(m) && ((chan_deop(*fr) || (glob_deop(*fr) &&
 
718
          !chan_op(*fr))) || (channel_bitch(chan) && (!chan_op(*fr) &&
 
719
          !(glob_op(*fr) && !chan_deop(*fr)))))) {
 
720
        add_mode(chan, '-', 'o', m->nick);
 
721
      }
 
722
      if (!chan_hasop(m) && (chan_op(*fr) || (glob_op(*fr) &&
 
723
          !chan_deop(*fr))) && (channel_autoop(chan) || glob_autoop(*fr) ||
 
724
          chan_autoop(*fr))) {
 
725
        if (!chan->aop_min)
 
726
          add_mode(chan, '+', 'o', m->nick);
 
727
        else {
 
728
          set_delay(chan, m->nick);
 
729
          m->flags |= SENTOP;
 
730
        }
 
731
      }
 
732
    }
 
733
 
 
734
    if (HALFOP_CANDOMODE('h')) {
 
735
      if (chan_hashalfop(m) && ((chan_dehalfop(*fr) || (glob_dehalfop(*fr) &&
 
736
          !chan_halfop(*fr)) || (channel_bitch(chan) && (!chan_halfop(*fr) &&
 
737
          !(glob_halfop(*fr) && !chan_dehalfop(*fr)))))))
 
738
        add_mode(chan, '-', 'h', m->nick);
 
739
      if (!chan_sentop(m) && !chan_hasop(m) && !chan_hashalfop(m) &&
 
740
          (chan_halfop(*fr) || (glob_halfop(*fr) && !chan_dehalfop(*fr))) &&
 
741
          (channel_autohalfop(chan) || glob_autohalfop(*fr) ||
 
742
          chan_autohalfop(*fr))) {
 
743
        if (!chan->aop_min)
 
744
          add_mode(chan, '+', 'h', m->nick);
 
745
        else {
 
746
          set_delay(chan, m->nick);
 
747
          m->flags |= SENTHALFOP;
 
748
        }
 
749
      }
 
750
    }
 
751
 
 
752
    if (HALFOP_CANDOMODE('v')) {
 
753
      if (chan_hasvoice(m) && (chan_quiet(*fr) || (glob_quiet(*fr) &&
 
754
          !chan_voice(*fr))))
 
755
        add_mode(chan, '-', 'v', m->nick);
 
756
      if (!chan_hasvoice(m) && !chan_hasop(m) && !chan_hashalfop(m) &&
 
757
          (chan_voice(*fr) || (glob_voice(*fr) && !chan_quiet(*fr))) &&
 
758
          (channel_autovoice(chan) || glob_gvoice(*fr) || chan_gvoice(*fr))) {
 
759
        if (!chan->aop_min)
 
760
          add_mode(chan, '+', 'v', m->nick);
 
761
        else {
 
762
          set_delay(chan, m->nick);
 
763
          m->flags |= SENTVOICE;
 
764
        }
 
765
      }
 
766
    }
 
767
  }
 
768
 
 
769
  if (!me_op(chan) && (!me_halfop(chan) ||
 
770
      (strchr(NOHALFOPS_MODES, 'b') != NULL) ||
 
771
      (strchr(NOHALFOPS_MODES, 'e') != NULL) ||
 
772
      (strchr(NOHALFOPS_MODES, 'I') != NULL)))
695
773
    return;
696
774
 
697
775
  sprintf(s, "%s!%s", m->nick, m->userhost);
698
 
  /* if channel user is current a chanop */
699
 
  if (chan_hasop(m)) {
700
 
  /* if user is channel deop */
701
 
    if (chan_deop(*fr) ||
702
 
        /* OR global deop and NOT channel op */
703
 
        (glob_deop(*fr) && !chan_op(*fr))) {
704
 
      /* de-op! */
705
 
      add_mode(chan, '-', 'o', m->nick);
706
 
      /* if channel mode is bitch */
707
 
    } else if (channel_bitch(chan) &&
708
 
               /* AND the user isnt a channel op */
709
 
               (!chan_op(*fr) &&
710
 
                /* AND the user isnt a global op, (or IS a chan deop) */
711
 
                !(glob_op(*fr) && !chan_deop(*fr)))) {
712
 
      /* de-op! mmmbop! */
713
 
      add_mode(chan, '-', 'o', m->nick);
714
 
    }
715
 
  }
716
 
  /* check vs invites */
717
 
  if (use_invites &&
718
 
      (u_match_mask(global_invites,s) ||
719
 
       u_match_mask(chan->invites, s)))
 
776
  if (use_invites && (u_match_mask(global_invites, s) ||
 
777
      u_match_mask(chan->invites, s)))
720
778
    refresh_invite(chan, s);
721
 
  /* don't kickban if permanent exempted */
722
 
  if (!(use_exempts &&
723
 
        (u_match_mask(global_exempts,s) ||
724
 
         u_match_mask(chan->exempts, s)))) {
725
 
    /* if match a ban */
726
 
    if (u_match_mask(global_bans, s) ||
727
 
        u_match_mask(chan->bans, s)) {
728
 
      /* bewm */
 
779
  if (!(use_exempts && (u_match_mask(global_exempts, s) ||
 
780
      u_match_mask(chan->exempts, s)))) {
 
781
    if (u_match_mask(global_bans, s) || u_match_mask(chan->bans, s))
729
782
      refresh_ban_kick(chan, s, m->nick);
730
 
      /* ^ will use the ban comment */
731
 
    }
732
 
    /* are they +k ? */
733
 
    if (!chan_sentkick(m) && (chan_kick(*fr) || glob_kick(*fr))) {
 
783
    if (!chan_sentkick(m) && (chan_kick(*fr) || glob_kick(*fr)) &&
 
784
        (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) {
734
785
      check_exemptlist(chan, s);
735
786
      quickban(chan, m->userhost);
736
787
      p = get_user(&USERENTRY_COMMENT, m->user);
737
788
      dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, m->nick,
738
 
              p ? p : IRC_POLITEKICK);
 
789
              p ? p : IRC_POLITEKICK);
739
790
      m->flags |= SENTKICK;
740
791
    }
741
792
  }
742
 
  /* now lets look at de-op'd ppl */
743
 
  if (!chan_hasop(m) &&
744
 
      /* if they're an op, channel or global (without channel +d) */
745
 
      (chan_op(*fr) || (glob_op(*fr) && !chan_deop(*fr))) &&
746
 
      /* and the channel is op on join, or they are auto-opped */
747
 
      (channel_autoop(chan) || (glob_autoop(*fr) || chan_autoop(*fr)))) {
748
 
    /* op them! */
749
 
    add_mode(chan, '+', 'o', m->nick);
750
 
    /* otherwise, lets check +v stuff if the llamas want it */
751
 
  } else if (!chan_hasvoice(m) && !chan_hasop(m)) {
752
 
    if ((channel_autovoice(chan) && !chan_quiet(*fr) &&
753
 
         (chan_voice(*fr) || glob_voice(*fr))) ||
754
 
          (!chan_quiet(*fr) && (glob_gvoice(*fr) || chan_gvoice(*fr)))) {
755
 
      add_mode(chan, '+', 'v', m->nick);
756
 
    }
757
 
    /* do they have a voice on the channel */
758
 
    if (chan_hasvoice(m) &&
759
 
        /* do they have the +q & no +v */
760
 
        (chan_quiet(*fr) || (glob_quiet(*fr) && !chan_voice(*fr)))) {
761
 
      add_mode(chan, '-', 'v', m->nick);
762
 
    }
763
 
  }
764
793
}
765
794
 
766
795
static void check_this_user(char *hand, int delete, char *host)
769
798
  memberlist *m;
770
799
  struct userrec *u;
771
800
  struct chanset_t *chan;
772
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
801
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
773
802
 
774
803
  for (chan = chanset; chan; chan = chan->next)
775
804
    for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
776
805
      sprintf(s, "%s!%s", m->nick, m->userhost);
777
806
      u = m->user ? m->user : get_user_by_host(s);
778
807
      if ((u && !egg_strcasecmp(u->handle, hand) && delete < 2) ||
779
 
          (!u && delete == 2 && wild_match(host, fixfrom(s)))) {
780
 
        u = delete ? NULL : u;
781
 
        get_user_flagrec(u, &fr, chan->dname);
782
 
        check_this_member(chan, m->nick, &fr);
 
808
          (!u && delete == 2 && wild_match(host, fixfrom(s)))) {
 
809
        u = delete ? NULL : u;
 
810
        get_user_flagrec(u, &fr, chan->dname);
 
811
        check_this_member(chan, m->nick, &fr);
783
812
      }
784
813
    }
785
814
}
790
819
{
791
820
  memberlist *m;
792
821
  char s[UHOSTLEN];
793
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
822
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
794
823
  static int stacking = 0;
795
824
  int stop_reset = 0;
796
825
 
797
 
  if (stacking)
798
 
    return;                     /* wewps */
799
 
  if (!userlist)                /* Bot doesnt know anybody */
800
 
    return;                     /* ... it's better not to deop everybody */
 
826
  if (stacking || !userlist)
 
827
    return;
 
828
 
801
829
  stacking++;
802
830
  /* Okay, sort through who needs to be deopped. */
803
 
  for (m = chan->channel.member; m && m->nick[0]; m = m->next) { 
 
831
  for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
804
832
    sprintf(s, "%s!%s", m->nick, m->userhost);
805
 
    get_user_flagrec(m->user ? m->user : get_user_by_host(s), &fr, chan->dname);
806
 
      if (glob_bot(fr) && chan_hasop(m) && !match_my_nick(m->nick))
807
 
        stop_reset = 1;
808
 
      check_this_member(chan, m->nick, &fr);
 
833
    if (!m->user && !m->tried_getuser) {
 
834
      m->tried_getuser = 1;
 
835
      m->user = get_user_by_host(s);
 
836
    }
 
837
    get_user_flagrec(m->user, &fr, chan->dname);
 
838
    if (glob_bot(fr) && chan_hasop(m) && !match_my_nick(m->nick))
 
839
      stop_reset = 1;
 
840
    /* Perhaps we were halfop and tried to halfop/kick the user earlier but
 
841
     * the server rejected the request, so let's try again. */
 
842
    m->flags &= ~(SENTHALFOP | SENTKICK);
 
843
    check_this_member(chan, m->nick, &fr);
809
844
  }
810
845
  if (dobans) {
811
846
    if (channel_nouserbans(chan) && !stop_reset)
814
849
      recheck_bans(chan);
815
850
    if (use_invites) {
816
851
      if (channel_nouserinvites(chan) && !stop_reset)
817
 
        resetinvites(chan);
 
852
        resetinvites(chan);
818
853
      else
819
 
        recheck_invites(chan);
 
854
        recheck_invites(chan);
820
855
    }
821
856
    if (use_exempts) {
822
857
      if (channel_nouserexempts(chan) && !stop_reset)
823
 
        resetexempts(chan);
 
858
        resetexempts(chan);
824
859
      else
825
 
        recheck_exempts(chan);
 
860
        recheck_exempts(chan);
826
861
    }
827
862
    if (channel_enforcebans(chan))
828
863
      enforce_bans(chan);
829
 
    if ((chan->status & CHAN_ASKEDMODES) &&
830
 
        !channel_inactive(chan)) 
 
864
    if ((chan->status & CHAN_ASKEDMODES) && !channel_inactive(chan))
831
865
      dprintf(DP_MODE, "MODE %s\n", chan->name);
832
866
    recheck_channel_modes(chan);
833
867
  }
839
873
 */
840
874
static int got324(char *from, char *msg)
841
875
{
842
 
  int i = 1, ok =0;
 
876
  int i = 1, ok = 0;
843
877
  char *p, *q, *chname;
844
878
  struct chanset_t *chan;
845
879
 
866
900
      chan->channel.mode |= CHANMODER;
867
901
    if (msg[i] == 'c')
868
902
      chan->channel.mode |= CHANNOCLR;
 
903
    if (msg[i] == 'C')
 
904
      chan->channel.mode |= CHANNOCTCP;
869
905
    if (msg[i] == 'R')
870
906
      chan->channel.mode |= CHANREGON;
871
907
    if (msg[i] == 'M')
872
 
      chan->channel.mode |= CHANMODR;
 
908
      chan->channel.mode |= CHANMODREG;
 
909
    if (msg[i] == 'r')
 
910
      chan->channel.mode |= CHANLONLY;
873
911
    if (msg[i] == 't')
874
912
      chan->channel.mode |= CHANTOPIC;
875
913
    if (msg[i] == 'n')
881
919
    if (msg[i] == 'k') {
882
920
      chan->channel.mode |= CHANKEY;
883
921
      p = strchr(msg, ' ');
884
 
      if (p != NULL) {          /* Test for null key assignment */
885
 
        p++;
886
 
        q = strchr(p, ' ');
887
 
        if (q != NULL) {
888
 
          *q = 0;
889
 
          set_key(chan, p);
890
 
          strcpy(p, q + 1);
891
 
        } else {
892
 
          set_key(chan, p);
893
 
          *p = 0;
894
 
        }
 
922
      if (p != NULL) {          /* Test for null key assignment */
 
923
        p++;
 
924
        q = strchr(p, ' ');
 
925
        if (q != NULL) {
 
926
          *q = 0;
 
927
          set_key(chan, p);
 
928
          strcpy(p, q + 1);
 
929
        } else {
 
930
          set_key(chan, p);
 
931
          *p = 0;
 
932
        }
895
933
      }
896
934
      if ((chan->channel.mode & CHANKEY) && (!chan->channel.key[0] ||
897
 
          !strcmp("*", chan->channel.key)))
898
 
        /* Undernet use to show a blank channel key if one was set when
899
 
         * you first joined a channel; however, this has been replaced by
900
 
         * an asterisk and this has been agreed upon by other major IRC 
901
 
         * networks so we'll check for an asterisk here as well 
902
 
         * (guppy 22Dec2001) */ 
 
935
          !strcmp("*", chan->channel.key)))
 
936
        /* Undernet use to show a blank channel key if one was set when
 
937
         * you first joined a channel; however, this has been replaced by
 
938
         * an asterisk and this has been agreed upon by other major IRC 
 
939
         * networks so we'll check for an asterisk here as well 
 
940
         * (guppy 22Dec2001) */
903
941
        chan->status |= CHAN_ASKEDMODES;
904
942
    }
905
943
    if (msg[i] == 'l') {
906
944
      p = strchr(msg, ' ');
907
 
      if (p != NULL) {          /* test for null limit assignment */
908
 
        p++;
909
 
        q = strchr(p, ' ');
910
 
        if (q != NULL) {
911
 
          *q = 0;
912
 
          chan->channel.maxmembers = atoi(p);
913
 
          strcpy(p, q + 1);
914
 
        } else {
915
 
          chan->channel.maxmembers = atoi(p);
916
 
          *p = 0;
917
 
        }
 
945
      if (p != NULL) {          /* test for null limit assignment */
 
946
        p++;
 
947
        q = strchr(p, ' ');
 
948
        if (q != NULL) {
 
949
          *q = 0;
 
950
          chan->channel.maxmembers = atoi(p);
 
951
          strcpy(p, q + 1);
 
952
        } else {
 
953
          chan->channel.maxmembers = atoi(p);
 
954
          *p = 0;
 
955
        }
918
956
      }
919
957
    }
920
958
    i++;
925
963
}
926
964
 
927
965
static int got352or4(struct chanset_t *chan, char *user, char *host,
928
 
                     char *nick, char *flags)
 
966
                     char *nick, char *flags)
929
967
{
930
968
  char userhost[UHOSTLEN];
931
969
  memberlist *m;
932
970
 
933
 
  m = ismember(chan, nick);     /* In my channel list copy? */
934
 
  if (!m) {                     /* Nope, so update */
935
 
    m = newmember(chan);        /* Get a new channel entry */
936
 
    m->joined = m->split = m->delay = 0L;       /* Don't know when he joined */
937
 
    m->flags = 0;               /* No flags for now */
938
 
    m->last = now;              /* Last time I saw him */
 
971
  m = ismember(chan, nick);     /* In my channel list copy? */
 
972
  if (!m) {                     /* Nope, so update */
 
973
    m = newmember(chan);        /* Get a new channel entry */
 
974
    m->joined = m->split = m->delay = 0L;       /* Don't know when he joined */
 
975
    m->flags = 0;               /* No flags for now */
 
976
    m->last = now;              /* Last time I saw him */
939
977
  }
940
 
  strcpy(m->nick, nick);        /* Store the nick in list */
 
978
  strcpy(m->nick, nick);        /* Store the nick in list */
941
979
  /* Store the userhost */
942
980
  simple_sprintf(m->userhost, "%s@%s", user, host);
943
981
  simple_sprintf(userhost, "%s!%s", nick, m->userhost);
944
982
  /* Combine n!u@h */
945
 
  m->user = NULL;               /* No handle match (yet) */
946
 
  if (match_my_nick(nick)) {    /* Is it me? */
947
 
    strcpy(botuserhost, m->userhost);   /* Yes, save my own userhost */
948
 
    m->joined = now;            /* set this to keep the whining masses happy */
 
983
  m->user = NULL;               /* No handle match (yet) */
 
984
  if (match_my_nick(nick)) {    /* Is it me? */
 
985
    strcpy(botuserhost, m->userhost);   /* Yes, save my own userhost */
 
986
    m->joined = now;            /* set this to keep the whining masses happy */
949
987
  }
950
 
  if (strchr(flags, '@') != NULL)       /* Flags say he's opped? */
951
 
    m->flags |= (CHANOP | WASOP);       /* Yes, so flag in my table */
 
988
  if (strpbrk(flags, opchars) != NULL)
 
989
    m->flags |= (CHANOP | WASOP);
952
990
  else
953
991
    m->flags &= ~(CHANOP | WASOP);
954
 
  if (strchr(flags, '+') != NULL)       /* Flags say he's voiced? */
955
 
    m->flags |= CHANVOICE;      /* Yes */
 
992
  if (strchr(flags, '%') != NULL)
 
993
    m->flags |= (CHANHALFOP | WASHALFOP);
 
994
  else
 
995
    m->flags &= ~(CHANHALFOP | WASHALFOP);
 
996
  if (strchr(flags, '+') != NULL)
 
997
    m->flags |= CHANVOICE;
956
998
  else
957
999
    m->flags &= ~CHANVOICE;
958
 
  if (!(m->flags & (CHANVOICE | CHANOP)))
 
1000
  if (!(m->flags & (CHANVOICE | CHANOP | CHANHALFOP)))
959
1001
    m->flags |= STOPWHO;
960
1002
  if (match_my_nick(nick) && any_ops(chan) && !me_op(chan)) {
961
1003
    check_tcl_need(chan->dname, "op");
973
1015
  char *nick, *user, *host, *chname, *flags;
974
1016
  struct chanset_t *chan;
975
1017
 
976
 
  newsplit(&msg);               /* Skip my nick - effeciently */
977
 
  chname = newsplit(&msg);      /* Grab the channel */
978
 
  chan = findchan(chname);      /* See if I'm on channel */
979
 
  if (chan) {                   /* Am I? */
980
 
    user = newsplit(&msg);      /* Grab the user */
981
 
    host = newsplit(&msg);      /* Grab the host */
982
 
    newsplit(&msg);             /* Skip the server */
983
 
    nick = newsplit(&msg);      /* Grab the nick */
984
 
    flags = newsplit(&msg);     /* Grab the flags */
 
1018
  newsplit(&msg);               /* Skip my nick - effeciently */
 
1019
  chname = newsplit(&msg);      /* Grab the channel */
 
1020
  chan = findchan(chname);      /* See if I'm on channel */
 
1021
  if (chan) {                   /* Am I? */
 
1022
    user = newsplit(&msg);      /* Grab the user */
 
1023
    host = newsplit(&msg);      /* Grab the host */
 
1024
    newsplit(&msg);             /* Skip the server */
 
1025
    nick = newsplit(&msg);      /* Grab the nick */
 
1026
    flags = newsplit(&msg);     /* Grab the flags */
985
1027
    got352or4(chan, user, host, nick, flags);
986
1028
  }
987
1029
  return 0;
995
1037
  struct chanset_t *chan;
996
1038
 
997
1039
  if (use_354) {
998
 
    newsplit(&msg);             /* Skip my nick - effeciently */
 
1040
    newsplit(&msg);             /* Skip my nick - effeciently */
999
1041
    if (msg[0] && (strchr(CHANMETA, msg[0]) != NULL)) {
1000
 
      chname = newsplit(&msg);  /* Grab the channel */
1001
 
      chan = findchan(chname);  /* See if I'm on channel */
1002
 
      if (chan) {               /* Am I? */
1003
 
        user = newsplit(&msg);  /* Grab the user */
1004
 
        host = newsplit(&msg);  /* Grab the host */
1005
 
        nick = newsplit(&msg);  /* Grab the nick */
1006
 
        flags = newsplit(&msg); /* Grab the flags */
1007
 
        got352or4(chan, user, host, nick, flags);
 
1042
      chname = newsplit(&msg);  /* Grab the channel */
 
1043
      chan = findchan(chname);  /* See if I'm on channel */
 
1044
      if (chan) {               /* Am I? */
 
1045
        user = newsplit(&msg);  /* Grab the user */
 
1046
        host = newsplit(&msg);  /* Grab the host */
 
1047
        nick = newsplit(&msg);  /* Grab the nick */
 
1048
        flags = newsplit(&msg); /* Grab the flags */
 
1049
        got352or4(chan, user, host, nick, flags);
1008
1050
      }
1009
1051
    }
1010
1052
  }
1022
1064
  newsplit(&msg);
1023
1065
  chname = newsplit(&msg);
1024
1066
  chan = findchan(chname);
1025
 
  /* May have left the channel before the who info came in */
1026
 
  if (!chan || !channel_pending(chan))
 
1067
  if (!chan || !channel_pending(chan)) /* Left channel before we got a 315? */
1027
1068
    return 0;
1028
 
  /* Finished getting who list, can now be considered officially ON CHANNEL */
 
1069
 
1029
1070
  chan->status |= CHAN_ACTIVE;
1030
1071
  chan->status &= ~CHAN_PEND;
1031
 
  /* Am *I* on the channel now? if not, well d0h. */
1032
 
  if (!ismember(chan, botname)) {
1033
 
    putlog(LOG_MISC | LOG_JOIN, chan->dname, "Oops, I'm not really on %s",
1034
 
           chan->dname);
 
1072
  if (!ismember(chan, botname)) {      /* Am I on the channel now?          */
 
1073
    putlog(LOG_MISC | LOG_JOIN, chan->dname, "Oops, I'm not really on %s.",
 
1074
           chan->dname);
1035
1075
    clear_channel(chan, 1);
1036
1076
    chan->status &= ~CHAN_ACTIVE;
1037
1077
    dprintf(DP_MODE, "JOIN %s %s\n",
1038
 
            (chan->name[0]) ? chan->name : chan->dname,
1039
 
            chan->channel.key[0] ? chan->channel.key : chan->key_prot);
1040
 
  }
1041
 
  else if (me_op(chan))
 
1078
            (chan->name[0]) ? chan->name : chan->dname,
 
1079
            chan->channel.key[0] ? chan->channel.key : chan->key_prot);
 
1080
  } else if (me_op(chan))
1042
1081
    recheck_channel(chan, 1);
1043
1082
  else if (chan->channel.members == 1)
1044
1083
    chan->status |= CHAN_STOP_CYCLE;
1045
 
  /* do not check for i-lines here. */
1046
 
  return 0;
 
1084
  return 0;                            /* Don't check for I-Lines here.     */
1047
1085
}
1048
1086
 
1049
1087
/* got 367: ban info
1210
1248
 
1211
1249
  newsplit(&msg);
1212
1250
  chname = newsplit(&msg);
1213
 
  if (chname && chname[0]=='!') {
 
1251
  if (chname && chname[0] == '!') {
1214
1252
    chan = findchan_by_dname(chname);
1215
1253
    if (!chan) {
1216
1254
      chan = findchan(chname);
1217
1255
      if (!chan)
1218
 
        return 0;       /* Ignore it */
 
1256
        return 0;               /* Ignore it */
1219
1257
      /* We have the channel unique name, so we have attempted to join
1220
1258
       * a specific !channel that doesnt exist. Now attempt to join the
1221
1259
       * channel using it's short name.
1259
1297
  if (chan) {
1260
1298
    putlog(LOG_JOIN, chan->dname, IRC_CHANFULL, chan->dname);
1261
1299
    check_tcl_need(chan->dname, "limit");
 
1300
 
 
1301
    chan = findchan_by_dname(chname);
 
1302
    if (!chan)
 
1303
      return 0;
 
1304
 
1262
1305
    if (chan->need_limit[0])
1263
1306
      do_tcl("need-limit", chan->need_limit);
1264
1307
  } else
1289
1332
  if (chan) {
1290
1333
    putlog(LOG_JOIN, chan->dname, IRC_CHANINVITEONLY, chan->dname);
1291
1334
    check_tcl_need(chan->dname, "invite");
 
1335
 
 
1336
    chan = findchan_by_dname(chname);
 
1337
    if (!chan)
 
1338
      return 0;
 
1339
 
1292
1340
    if (chan->need_invite[0])
1293
1341
      do_tcl("need-invite", chan->need_invite);
1294
1342
  } else
1319
1367
  if (chan) {
1320
1368
    putlog(LOG_JOIN, chan->dname, IRC_BANNEDFROMCHAN, chan->dname);
1321
1369
    check_tcl_need(chan->dname, "unban");
 
1370
 
 
1371
    chan = findchan_by_dname(chname);
 
1372
    if (!chan)
 
1373
      return 0;
 
1374
 
1322
1375
    if (chan->need_unban[0])
1323
1376
      do_tcl("need-unban", chan->need_unban);
1324
1377
  } else
1355
1408
      dprintf(DP_MODE, "JOIN %s %s\n", chan->dname, chan->key_prot);
1356
1409
    } else {
1357
1410
      check_tcl_need(chan->dname, "key");
 
1411
 
 
1412
      chan = findchan_by_dname(chname);
 
1413
      if (!chan)
 
1414
        return 0;
 
1415
 
1358
1416
      if (chan->need_key[0])
1359
 
        do_tcl("need-key", chan->need_key);
 
1417
        do_tcl("need-key", chan->need_key);
1360
1418
    }
1361
1419
  } else
1362
1420
    putlog(LOG_JOIN, chname, IRC_BADCHANKEY, chname);
1375
1433
  nick = splitnick(&from);
1376
1434
  if (!rfc_casecmp(last_invchan, msg))
1377
1435
    if (now - last_invtime < 30)
1378
 
      return 0;         /* Two invites to the same channel in 30 seconds? */
 
1436
      return 0; /* Two invites to the same channel in 30 seconds? */
1379
1437
  putlog(LOG_MISC, "*", "%s!%s invited me to %s", nick, from, msg);
1380
1438
  strncpy(last_invchan, msg, 299);
1381
1439
  last_invchan[299] = 0;
1481
1539
  if (aop_min >= aop_max)
1482
1540
    a_delay = now + aop_min;
1483
1541
  else
1484
 
    a_delay = now + (random() % (aop_max - aop_min)) + aop_min + 1;
 
1542
    a_delay = now + randint(aop_max - aop_min) + aop_min + 1;
1485
1543
  for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
1486
1544
    if (m2->delay && !(m2->flags & FULL_DELAY))
1487
1545
      count++;
1488
1546
  if (count)
1489
1547
    for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
1490
1548
      if (m2->delay && !(m2->flags & FULL_DELAY)) {
1491
 
 m2->delay = a_delay;
1492
 
 if (count + 1 >=  modesperline)
1493
 
   m2->flags |= FULL_DELAY;
 
1549
        m2->delay = a_delay;
 
1550
        if (count + 1 >= modesperline)
 
1551
          m2->flags |= FULL_DELAY;
1494
1552
      }
1495
 
  if (count + 1 >=modesperline)
 
1553
  if (count + 1 >= modesperline)
1496
1554
    m->flags |= FULL_DELAY;
1497
1555
  m->delay = a_delay;
1498
1556
}
1507
1565
  memberlist *m;
1508
1566
  masklist *b;
1509
1567
  struct userrec *u;
1510
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
1568
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
1511
1569
 
1512
1570
  fixcolon(chname);
1513
1571
  chan = findchan(chname);
1516
1574
     * name now. This will happen when we initially join the channel, as we
1517
1575
     * dont know the unique channel name that the server has made up. <cybah>
1518
1576
     */
1519
 
    int l_chname = strlen(chname);
 
1577
    int l_chname = strlen(chname);
1520
1578
 
1521
1579
    if (l_chname > (CHANNEL_ID_LEN + 1)) {
1522
1580
      ch_dname = nmalloc(l_chname + 1);
1523
1581
      if (ch_dname) {
1524
 
        egg_snprintf(ch_dname, l_chname + 2, "!%s",
1525
 
                     chname + (CHANNEL_ID_LEN + 1));
1526
 
        chan = findchan_by_dname(ch_dname);
1527
 
        if (!chan) {
1528
 
          /* Hmm.. okay. Maybe the admin's a genius and doesn't know the
1529
 
           * difference between id and descriptive channel names. Search
1530
 
           * the channel name in the dname list using the id-name.
1531
 
           */
1532
 
           chan = findchan_by_dname(chname);
1533
 
           if (chan) {
1534
 
             /* Duh, I was right. Mark this channel as inactive and log
1535
 
              * the incident.
1536
 
              */
1537
 
             chan->status |= CHAN_INACTIVE;
1538
 
             putlog(LOG_MISC, "*", "Deactivated channel %s, because it uses "
1539
 
                    "an ID channel-name. Use the descriptive name instead.",
1540
 
                    chname);
1541
 
             dprintf(DP_SERVER, "PART %s\n", chname);
1542
 
             goto exit;
1543
 
           }
1544
 
        }
 
1582
        egg_snprintf(ch_dname, l_chname + 2, "!%s",
 
1583
                     chname + (CHANNEL_ID_LEN + 1));
 
1584
        chan = findchan_by_dname(ch_dname);
 
1585
        if (!chan) {
 
1586
          /* Hmm.. okay. Maybe the admin's a genius and doesn't know the
 
1587
           * difference between id and descriptive channel names. Search
 
1588
           * the channel name in the dname list using the id-name.
 
1589
           */
 
1590
          chan = findchan_by_dname(chname);
 
1591
          if (chan) {
 
1592
            /* Duh, I was right. Mark this channel as inactive and log
 
1593
             * the incident.
 
1594
             */
 
1595
            chan->status |= CHAN_INACTIVE;
 
1596
            putlog(LOG_MISC, "*", "Deactivated channel %s, because it uses "
 
1597
                   "an ID channel-name. Use the descriptive name instead.",
 
1598
                   chname);
 
1599
            dprintf(DP_SERVER, "PART %s\n", chname);
 
1600
            goto exit;
 
1601
          }
 
1602
        }
1545
1603
      }
1546
1604
    }
1547
1605
  } else if (!chan) {
1552
1610
  }
1553
1611
 
1554
1612
  if (!chan || channel_inactive(chan)) {
1555
 
    putlog(LOG_MISC, "*", "joined %s but didn't want to!", chname);
1556
 
    dprintf(DP_MODE, "PART %s\n", chname);
 
1613
    strcpy(uhost, from);
 
1614
    nick = splitnick(&uhost);
 
1615
    if (match_my_nick(nick)) {
 
1616
      putlog(LOG_MISC, "*", "joined %s but didn't want to!", chname);
 
1617
      dprintf(DP_MODE, "PART %s\n", chname);
 
1618
    }
1557
1619
  } else if (!channel_pending(chan)) {
1558
1620
    chan->status &= ~CHAN_STOP_CYCLE;
1559
1621
    strcpy(uhost, from);
1560
1622
    nick = splitnick(&uhost);
1561
1623
    detect_chan_flood(nick, uhost, from, chan, FLOOD_JOIN, NULL);
 
1624
 
 
1625
    chan = findchan(chname);
 
1626
    if (!chan) {
 
1627
      if (ch_dname)
 
1628
        chan = findchan_by_dname(ch_dname);
 
1629
      else
 
1630
        chan = findchan_by_dname(chname);
 
1631
    }
 
1632
    if (!chan)
 
1633
      /* The channel doesn't exist anymore, so get out of here. */
 
1634
      goto exit;
 
1635
 
1562
1636
    /* Grab last time joined before we update it */
1563
1637
    u = get_user_by_host(from);
1564
 
    get_user_flagrec(u, &fr, chan->dname); /* Lam: fix to work with !channels */
 
1638
    get_user_flagrec(u, &fr, chan->dname);      /* Lam: fix to work with !channels */
1565
1639
    if (!channel_active(chan) && !match_my_nick(nick)) {
1566
1640
      /* uh, what?!  i'm on the channel?! */
1567
1641
      putlog(LOG_MISC, chan->dname,
1568
 
             "confused bot: guess I'm on %s and didn't realize it",
1569
 
             chan->dname);
 
1642
             "confused bot: guess I'm on %s and didn't realize it",
 
1643
             chan->dname);
1570
1644
      chan->status |= CHAN_ACTIVE;
1571
1645
      chan->status &= ~CHAN_PEND;
1572
1646
      reset_chan_info(chan);
1573
1647
    } else {
1574
1648
      m = ismember(chan, nick);
1575
1649
      if (m && m->split && !egg_strcasecmp(m->userhost, uhost)) {
1576
 
        check_tcl_rejn(nick, uhost, u, chan->dname);
1577
 
        /* The tcl binding might have deleted the current user. Recheck. */
1578
 
        u = get_user_by_host(from);
1579
 
        m->split = 0;
1580
 
        m->last = now;
1581
 
        m->delay = 0L;
1582
 
        m->flags = (chan_hasop(m) ? WASOP : 0);
1583
 
        m->user = u;
1584
 
        set_handle_laston(chan->dname, u, now);
1585
 
        m->flags |= STOPWHO;
1586
 
        putlog(LOG_JOIN, chan->dname, "%s (%s) returned to %s.", nick, uhost,
1587
 
               chan->dname);
 
1650
        check_tcl_rejn(nick, uhost, u, chan->dname);
 
1651
 
 
1652
        chan = findchan(chname);
 
1653
        if (!chan) {
 
1654
          if (ch_dname)
 
1655
            chan = findchan_by_dname(ch_dname);
 
1656
          else
 
1657
            chan = findchan_by_dname(chname);
 
1658
        }
 
1659
        if (!chan)
 
1660
          /* The channel doesn't exist anymore, so get out of here. */
 
1661
          goto exit;
 
1662
 
 
1663
        /* The tcl binding might have deleted the current user. Recheck. */
 
1664
        u = get_user_by_host(from);
 
1665
        m->split = 0;
 
1666
        m->last = now;
 
1667
        m->delay = 0L;
 
1668
        m->flags = (chan_hasop(m) ? WASOP : 0) | (chan_hashalfop(m) ? WASHALFOP : 0);
 
1669
        m->user = u;
 
1670
        set_handle_laston(chan->dname, u, now);
 
1671
        m->flags |= STOPWHO;
 
1672
        putlog(LOG_JOIN, chan->dname, "%s (%s) returned to %s.", nick, uhost,
 
1673
               chan->dname);
1588
1674
      } else {
1589
 
        if (m)
1590
 
          killmember(chan, nick);
1591
 
        m = newmember(chan);
1592
 
        m->joined = now;
1593
 
        m->split = 0L;
1594
 
        m->flags = 0;
1595
 
        m->last = now;
1596
 
        m->delay = 0L;
 
1675
        if (m)
 
1676
          killmember(chan, nick);
 
1677
        m = newmember(chan);
 
1678
        m->joined = now;
 
1679
        m->split = 0L;
 
1680
        m->flags = 0;
 
1681
        m->last = now;
 
1682
        m->delay = 0L;
1597
1683
        strcpy(m->nick, nick);
1598
 
        strcpy(m->userhost, uhost);
1599
 
        m->user = u;
1600
 
        m->flags |= STOPWHO;
1601
 
 
1602
 
        check_tcl_join(nick, uhost, u, chan->dname);
1603
 
 
1604
 
        /* The tcl binding might have deleted the current user and the
1605
 
         * current channel, so we'll now have to re-check whether they
1606
 
         * both still exist.
1607
 
         */
1608
 
        chan = findchan(chname);
1609
 
        if (!chan) {
1610
 
          if (ch_dname)
1611
 
            chan = findchan_by_dname(ch_dname);
1612
 
          else
1613
 
            chan = findchan_by_dname(chname);
1614
 
        }
1615
 
        if (!chan)
1616
 
          /* The channel doesn't exist anymore, so get out of here. */
1617
 
          goto exit;
1618
 
 
1619
 
        /* The record saved in the channel record always gets updated,
1620
 
           so we can use that. */
1621
 
        u = m->user;
1622
 
 
1623
 
        if (match_my_nick(nick)) {
1624
 
          /* It was me joining! Need to update the channel record with the
1625
 
           * unique name for the channel (as the server see's it). <cybah>
1626
 
           */
1627
 
          strncpy(chan->name, chname, 81);
1628
 
          chan->name[80] = 0;
1629
 
          chan->status &= ~CHAN_JUPED;
 
1684
        strcpy(m->userhost, uhost);
 
1685
        m->user = u;
 
1686
        m->flags |= STOPWHO;
 
1687
 
 
1688
        check_tcl_join(nick, uhost, u, chan->dname);
 
1689
 
 
1690
        /* The tcl binding might have deleted the current user and the
 
1691
         * current channel, so we'll now have to re-check whether they
 
1692
         * both still exist.
 
1693
         */
 
1694
        chan = findchan(chname);
 
1695
        if (!chan) {
 
1696
          if (ch_dname)
 
1697
            chan = findchan_by_dname(ch_dname);
 
1698
          else
 
1699
            chan = findchan_by_dname(chname);
 
1700
        }
 
1701
        if (!chan)
 
1702
          /* The channel doesn't exist anymore, so get out of here. */
 
1703
          goto exit;
 
1704
 
 
1705
        /* The record saved in the channel record always gets updated,
 
1706
         * so we can use that. */
 
1707
        u = m->user;
 
1708
 
 
1709
        if (match_my_nick(nick)) {
 
1710
          /* It was me joining! Need to update the channel record with the
 
1711
           * unique name for the channel (as the server see's it). <cybah>
 
1712
           */
 
1713
          strncpy(chan->name, chname, 81);
 
1714
          chan->name[80] = 0;
 
1715
          chan->status &= ~CHAN_JUPED;
1630
1716
 
1631
1717
          /* ... and log us joining. Using chan->dname for the channel is
1632
 
           * important in this case. As the config file will never contain
1633
 
           * logs with the unique name.
1634
 
           */
1635
 
          if (chname[0] == '!')
1636
 
            putlog(LOG_JOIN | LOG_MISC, chan->dname, "%s joined %s (%s)",
1637
 
                   nick, chan->dname, chname);
1638
 
          else
1639
 
            putlog(LOG_JOIN | LOG_MISC, chan->dname, "%s joined %s.", nick,
1640
 
                   chname);
1641
 
          reset_chan_info(chan);
1642
 
        } else {
1643
 
          struct chanuserrec *cr;
1644
 
 
1645
 
          putlog(LOG_JOIN, chan->dname,
1646
 
                 "%s (%s) joined %s.", nick, uhost, chan->dname);
1647
 
          /* Don't re-display greeting if they've been on the channel
1648
 
           * recently.
1649
 
           */
1650
 
          if (u) {
1651
 
            struct laston_info *li = 0;
1652
 
 
1653
 
            cr = get_chanrec(m->user, chan->dname);
1654
 
            if (!cr && no_chanrec_info)
1655
 
              li = get_user(&USERENTRY_LASTON, m->user);
1656
 
            if (channel_greet(chan) && use_info &&
1657
 
                ((cr && now - cr->laston > wait_info) ||
1658
 
                 (no_chanrec_info &&
1659
 
                  (!li || now - li->laston > wait_info)))) {
1660
 
              char s1[512], *s;
1661
 
 
1662
 
              if (!(u->flags & USER_BOT)) {
1663
 
                s = get_user(&USERENTRY_INFO, u);
1664
 
                get_handle_chaninfo(u->handle, chan->dname, s1);
1665
 
                /* Locked info line overides non-locked channel specific
1666
 
                 * info line.
1667
 
                 */
1668
 
                if (!s || (s1[0] && (s[0] != '@' || s1[0] == '@')))
1669
 
                  s = s1;
1670
 
                if (s[0] == '@')
1671
 
                  s++;
1672
 
                if (s && s[0])
1673
 
                  dprintf(DP_HELP, "PRIVMSG %s :[%s] %s\n",
1674
 
                          chan->name, nick, s);
1675
 
              }
1676
 
            }
1677
 
          }
1678
 
          set_handle_laston(chan->dname, u, now);
1679
 
        }
 
1718
           * important in this case. As the config file will never contain
 
1719
           * logs with the unique name.
 
1720
           */
 
1721
          if (chname[0] == '!')
 
1722
            putlog(LOG_JOIN | LOG_MISC, chan->dname, "%s joined %s (%s)",
 
1723
                   nick, chan->dname, chname);
 
1724
          else
 
1725
            putlog(LOG_JOIN | LOG_MISC, chan->dname, "%s joined %s.", nick,
 
1726
                   chname);
 
1727
          reset_chan_info(chan);
 
1728
        } else {
 
1729
          struct chanuserrec *cr;
 
1730
 
 
1731
          putlog(LOG_JOIN, chan->dname,
 
1732
                 "%s (%s) joined %s.", nick, uhost, chan->dname);
 
1733
          /* Don't re-display greeting if they've been on the channel
 
1734
           * recently.
 
1735
           */
 
1736
          if (u) {
 
1737
            struct laston_info *li = 0;
 
1738
 
 
1739
            cr = get_chanrec(m->user, chan->dname);
 
1740
            if (!cr && no_chanrec_info)
 
1741
              li = get_user(&USERENTRY_LASTON, m->user);
 
1742
            if (channel_greet(chan) && use_info &&
 
1743
                ((cr && now - cr->laston > wait_info) ||
 
1744
                (no_chanrec_info && (!li || now - li->laston > wait_info)))) {
 
1745
              char s1[512], *s;
 
1746
 
 
1747
              if (!(u->flags & USER_BOT)) {
 
1748
                s = get_user(&USERENTRY_INFO, u);
 
1749
                get_handle_chaninfo(u->handle, chan->dname, s1);
 
1750
                /* Locked info line overides non-locked channel specific
 
1751
                 * info line.
 
1752
                 */
 
1753
                if (!s || (s1[0] && (s[0] != '@' || s1[0] == '@')))
 
1754
                  s = s1;
 
1755
                if (s[0] == '@')
 
1756
                  s++;
 
1757
                if (s && s[0])
 
1758
                  dprintf(DP_HELP, "PRIVMSG %s :[%s] %s\n", chan->name, nick,
 
1759
                          s);
 
1760
              }
 
1761
            }
 
1762
          }
 
1763
          set_handle_laston(chan->dname, u, now);
 
1764
        }
1680
1765
      }
1681
 
      /* ok, the op-on-join,etc, tests...first only both if Im opped */
1682
 
      if (me_op(chan)) {
1683
 
        /* Check for and reset exempts and invites.
1684
 
         *
1685
 
         * This will require further checking to account for when to use the
1686
 
         * various modes.
1687
 
         */
1688
 
        if (u_match_mask(global_invites,from) ||
1689
 
            u_match_mask(chan->invites, from))
1690
 
          refresh_invite(chan, from);
1691
 
        if (!(use_exempts &&
1692
 
              (u_match_mask(global_exempts,from) ||
1693
 
               u_match_mask(chan->exempts, from)))) {
 
1766
      if (me_op(chan) || me_halfop(chan)) {
 
1767
        /* Check for and reset exempts and invites.
 
1768
         *
 
1769
         * This will require further checking to account for when to use the
 
1770
         * various modes.
 
1771
         */
 
1772
        if ((me_op(chan) || (strchr(NOHALFOPS_MODES, 'I') == NULL)) &&
 
1773
            (u_match_mask(global_invites, from) ||
 
1774
            u_match_mask(chan->invites, from)))
 
1775
          refresh_invite(chan, from);
 
1776
        if ((me_op(chan) || (strchr(NOHALFOPS_MODES, 'b') == NULL)) &&
 
1777
            (!use_exempts || (!u_match_mask(global_exempts, from) &&
 
1778
            !u_match_mask(chan->exempts, from)))) {
1694
1779
          if (channel_enforcebans(chan) && !chan_op(fr) && !glob_op(fr) &&
1695
1780
              !glob_friend(fr) && !chan_friend(fr) && !chan_sentkick(m) &&
1696
 
              !(use_exempts && isexempted(chan, from))) {
 
1781
              (!use_exempts || !isexempted(chan, from)) && (me_op(chan) ||
 
1782
              (me_halfop(chan) && !chan_hasop(m)))) {
1697
1783
            for (b = chan->channel.ban; b->mask[0]; b = b->next) {
1698
1784
              if (wild_match(b->mask, from)) {
1699
1785
                dprintf(DP_SERVER, "KICK %s %s :%s\n", chname, m->nick,
1703
1789
              }
1704
1790
            }
1705
1791
          }
1706
 
          /* If it matches a ban, dispose of them. */
1707
 
          if (u_match_mask(global_bans, from) ||
1708
 
              u_match_mask(chan->bans, from)) {
1709
 
            refresh_ban_kick(chan, from, nick);
1710
 
          /* Likewise for kick'ees */
1711
 
          } else if (!chan_sentkick(m) && (glob_kick(fr) || chan_kick(fr))) {
1712
 
            check_exemptlist(chan, from);
1713
 
            quickban(chan, from);
1714
 
            p = get_user(&USERENTRY_COMMENT, m->user);
1715
 
            dprintf(DP_MODE, "KICK %s %s :%s\n", chname, nick,
1716
 
                    (p && (p[0] != '@')) ? p : IRC_COMMENTKICK);
1717
 
            m->flags |= SENTKICK;
1718
 
          }
1719
 
        }
1720
 
        /* Are they a chan op, or global op without chan deop? */
1721
 
        if ((chan_op(fr) || (glob_op(fr) && !chan_deop(fr))) &&
1722
 
           /* ... and is it op-on-join or is the use marked auto-op? */
1723
 
            (channel_autoop(chan) || glob_autoop(fr) || chan_autoop(fr))) {
1724
 
          /* Yes! do the honors. */
1725
 
          if (!chan->aop_min)
1726
 
            add_mode(chan, '+', 'o', nick);
1727
 
          else {
 
1792
          /* If it matches a ban, dispose of them. */
 
1793
          if (u_match_mask(global_bans, from) || u_match_mask(chan->bans, from))
 
1794
            refresh_ban_kick(chan, from, nick);
 
1795
          else if (!chan_sentkick(m) && (glob_kick(fr) || chan_kick(fr)) &&
 
1796
                   (me_op(chan) || (me_halfop(chan) && !chan_hasop(m)))) {
 
1797
            check_exemptlist(chan, from);
 
1798
            quickban(chan, from);
 
1799
            p = get_user(&USERENTRY_COMMENT, m->user);
 
1800
            dprintf(DP_MODE, "KICK %s %s :%s\n", chname, nick,
 
1801
                    (p && (p[0] != '@')) ? p : IRC_COMMENTKICK);
 
1802
            m->flags |= SENTKICK;
 
1803
          }
 
1804
        }
 
1805
#ifdef NO_HALFOP_CHANMODES
 
1806
        if (me_op(chan)) {
 
1807
#endif
 
1808
        if ((me_op(chan) || (strchr(NOHALFOPS_MODES, 'o') == NULL)) &&
 
1809
            (chan_op(fr) || (glob_op(fr) && !chan_deop(fr))) &&
 
1810
            (channel_autoop(chan) || glob_autoop(fr) || chan_autoop(fr))) {
 
1811
          if (!chan->aop_min)
 
1812
            add_mode(chan, '+', 'o', nick);
 
1813
          else {
1728
1814
            set_delay(chan, nick);
1729
1815
            m->flags |= SENTOP;
1730
 
          }
1731
 
        } else if ((channel_autovoice(chan) &&
1732
 
                    (chan_voice(fr) || (glob_voice(fr) && !chan_quiet(fr)))) ||
1733
 
                   ((glob_gvoice(fr) || chan_gvoice(fr)) && !chan_quiet(fr))) {
1734
 
           if (!chan->aop_min)
1735
 
             add_mode(chan, '+', 'v', nick);
1736
 
           else {
1737
 
             set_delay(chan, nick);
1738
 
             m->flags |= SENTVOICE;
1739
 
           }
1740
 
         }
 
1816
          }
 
1817
        } else if ((me_op(chan) || (strchr(NOHALFOPS_MODES, 'h') == NULL)) &&
 
1818
                   (chan_halfop(fr) || (glob_halfop(fr) &&
 
1819
                   !chan_dehalfop(fr))) && (channel_autohalfop(chan) ||
 
1820
                   glob_autohalfop(fr) || chan_autohalfop(fr))) {
 
1821
          if (!chan->aop_min)
 
1822
            add_mode(chan, '+', 'h', nick);
 
1823
          else {
 
1824
            set_delay(chan, nick);
 
1825
            m->flags |= SENTHALFOP;
 
1826
          }
 
1827
        } else if ((me_op(chan) || (strchr(NOHALFOPS_MODES, 'v') == NULL)) &&
 
1828
                   ((channel_autovoice(chan) && (chan_voice(fr) ||
 
1829
                   (glob_voice(fr) && !chan_quiet(fr)))) ||
 
1830
                   ((glob_gvoice(fr) || chan_gvoice(fr)) &&
 
1831
                   !chan_quiet(fr)))) {
 
1832
          if (!chan->aop_min)
 
1833
            add_mode(chan, '+', 'v', nick);
 
1834
          else {
 
1835
            set_delay(chan, nick);
 
1836
            m->flags |= SENTVOICE;
 
1837
          }
 
1838
        }
 
1839
#ifdef NO_HALFOP_CHANMODES
 
1840
        }
 
1841
#endif
1741
1842
      }
1742
1843
    }
1743
1844
  }
1757
1858
  struct userrec *u;
1758
1859
 
1759
1860
  chname = newsplit(&msg);
 
1861
  fixcolon(chname);
1760
1862
  fixcolon(msg);
1761
1863
  chan = findchan(chname);
1762
1864
  if (chan && channel_inactive(chan)) {
1770
1872
    if (!channel_active(chan)) {
1771
1873
      /* whoa! */
1772
1874
      putlog(LOG_MISC, chan->dname,
1773
 
          "confused bot: guess I'm on %s and didn't realize it", chan->dname);
 
1875
             "confused bot: guess I'm on %s and didn't realize it",
 
1876
             chan->dname);
1774
1877
      chan->status |= CHAN_ACTIVE;
1775
1878
      chan->status &= ~CHAN_PEND;
1776
1879
      reset_chan_info(chan);
1777
1880
    }
1778
1881
    set_handle_laston(chan->dname, u, now);
1779
 
    check_tcl_part(nick, from, u, chan->dname, msg); /* This must be directly above the killmember, in case
1780
 
                                                        we're doing anything to the record that would affect
1781
 
                                                        the above */
 
1882
    /* This must be directly above the killmember, in case we're doing anything
 
1883
     * to the record that would affect the above */
 
1884
    check_tcl_part(nick, from, u, chan->dname, msg);
 
1885
 
 
1886
    chan = findchan(chname);
 
1887
    if (!chan)
 
1888
      return 0;
 
1889
 
1782
1890
    killmember(chan, nick);
1783
1891
    if (msg[0])
1784
 
      putlog(LOG_JOIN, chan->dname, "%s (%s) left %s (%s).", nick, from, chan->dname, msg);
 
1892
      putlog(LOG_JOIN, chan->dname, "%s (%s) left %s (%s).", nick, from,
 
1893
             chan->dname, msg);
1785
1894
    else
1786
 
      putlog(LOG_JOIN, chan->dname, "%s (%s) left %s.", nick, from, chan->dname);
 
1895
      putlog(LOG_JOIN, chan->dname, "%s (%s) left %s.", nick, from,
 
1896
             chan->dname);
1787
1897
    /* If it was me, all hell breaks loose... */
1788
1898
    if (match_my_nick(nick)) {
1789
1899
      clear_channel(chan, 1);
1790
1900
      chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
1791
1901
      if (!channel_inactive(chan))
1792
 
        dprintf(DP_MODE, "JOIN %s %s\n",
1793
 
                (chan->name[0]) ? chan->name : chan->dname,
1794
 
                chan->channel.key[0] ? chan->channel.key : chan->key_prot);
 
1902
        dprintf(DP_MODE, "JOIN %s %s\n",
 
1903
                (chan->name[0]) ? chan->name : chan->dname,
 
1904
                chan->channel.key[0] ? chan->channel.key : chan->key_prot);
1795
1905
    } else
1796
1906
      check_lonely_channel(chan);
1797
1907
  }
1807
1917
  memberlist *m;
1808
1918
  struct chanset_t *chan;
1809
1919
  struct userrec *u;
1810
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
1920
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
1811
1921
 
1812
1922
  strncpy(buf2, origmsg, 510);
1813
1923
  buf2[510] = 0;
1814
1924
  msg = buf2;
1815
1925
  chname = newsplit(&msg);
1816
1926
  chan = findchan(chname);
1817
 
  if (chan && channel_active(chan)) {
1818
 
    nick = newsplit(&msg);
 
1927
  if (!chan)
 
1928
    return 0;
 
1929
  nick = newsplit(&msg);
 
1930
  if (match_my_nick(nick) && channel_pending(chan) &&
 
1931
      !channel_inactive(chan)) {
 
1932
    chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
 
1933
    dprintf(DP_MODE, "JOIN %s %s\n",
 
1934
            (chan->name[0]) ? chan->name : chan->dname,
 
1935
            chan->channel.key[0] ? chan->channel.key : chan->key_prot);
 
1936
    clear_channel(chan, 1);
 
1937
    return 0;                   /* rejoin if kicked before getting needed info <Wcc[08/08/02]> */
 
1938
  }
 
1939
  if (channel_active(chan)) {
1819
1940
    fixcolon(msg);
1820
1941
    u = get_user_by_host(from);
1821
1942
    strcpy(uhost, from);
1822
1943
    whodid = splitnick(&uhost);
1823
1944
    detect_chan_flood(whodid, uhost, from, chan, FLOOD_KICK, nick);
 
1945
 
 
1946
    chan = findchan(chname);
 
1947
    if (!chan)
 
1948
      return 0;
 
1949
 
1824
1950
    m = ismember(chan, whodid);
1825
1951
    if (m)
1826
1952
      m->last = now;
1828
1954
    get_user_flagrec(u, &fr, chan->dname);
1829
1955
    set_handle_laston(chan->dname, u, now);
1830
1956
    check_tcl_kick(whodid, uhost, u, chan->dname, nick, msg);
 
1957
 
 
1958
    chan = findchan(chname);
 
1959
    if (!chan)
 
1960
      return 0;
 
1961
 
1831
1962
    m = ismember(chan, nick);
1832
1963
    if (m) {
1833
1964
      struct userrec *u2;
1838
1969
      maybe_revenge(chan, from, s1, REVENGE_KICK);
1839
1970
    }
1840
1971
    putlog(LOG_MODES, chan->dname, "%s kicked from %s by %s: %s", s1,
1841
 
           chan->dname, from, msg);
 
1972
           chan->dname, from, msg);
1842
1973
    /* Kicked ME?!? the sods! */
1843
 
    if (match_my_nick(nick)) {
 
1974
    if (match_my_nick(nick) && !channel_inactive(chan)) {
1844
1975
      chan->status &= ~(CHAN_ACTIVE | CHAN_PEND);
1845
1976
      dprintf(DP_MODE, "JOIN %s %s\n",
1846
1977
              (chan->name[0]) ? chan->name : chan->dname,
1858
1989
 */
1859
1990
static int gotnick(char *from, char *msg)
1860
1991
{
1861
 
  char *nick, s1[UHOSTLEN], buf[UHOSTLEN], *uhost = buf;
 
1992
  char *nick, *chname, s1[UHOSTLEN], buf[UHOSTLEN], *uhost = buf;
 
1993
  unsigned char found = 0;
1862
1994
  memberlist *m, *mm;
1863
 
  struct chanset_t *chan;
 
1995
  struct chanset_t *chan, *oldchan = NULL;
1864
1996
  struct userrec *u;
1865
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
1997
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
1866
1998
 
1867
1999
  strcpy(uhost, from);
1868
2000
  nick = splitnick(&uhost);
1869
2001
  fixcolon(msg);
1870
 
  clear_chanlist_member(nick);  /* Cache for nick 'nick' is meaningless now. */
1871
 
  for (chan = chanset; chan; chan = chan->next) { 
 
2002
  clear_chanlist_member(nick);  /* Cache for nick 'nick' is meaningless now. */
 
2003
  for (chan = chanset; chan; chan = chan->next) {
 
2004
    oldchan = chan;
 
2005
    chname = chan->dname;
1872
2006
    m = ismember(chan, nick);
1873
2007
    if (m) {
1874
2008
      putlog(LOG_JOIN, chan->dname, "Nick change: %s -> %s", nick, msg);
1875
2009
      m->last = now;
1876
2010
      if (rfc_casecmp(nick, msg)) {
1877
 
        /* Not just a capitalization change */
1878
 
        mm = ismember(chan, msg);
1879
 
        if (mm) {
1880
 
          /* Someone on channel with old nick?! */
1881
 
          if (mm->split)
1882
 
            putlog(LOG_JOIN, chan->dname,
1883
 
                   "Possible future nick collision: %s", mm->nick);
1884
 
          else
1885
 
            putlog(LOG_MISC, chan->dname,
1886
 
                   "* Bug: nick change to existing nick");
1887
 
          killmember(chan, mm->nick);
1888
 
        }
 
2011
        /* Not just a capitalization change */
 
2012
        mm = ismember(chan, msg);
 
2013
        if (mm) {
 
2014
          /* Someone on channel with old nick?! */
 
2015
          if (mm->split)
 
2016
            putlog(LOG_JOIN, chan->dname,
 
2017
                   "Possible future nick collision: %s", mm->nick);
 
2018
          else
 
2019
            putlog(LOG_MISC, chan->dname,
 
2020
                   "* Bug: nick change to existing nick");
 
2021
          killmember(chan, mm->nick);
 
2022
        }
1889
2023
      }
1890
2024
      /*
1891
2025
       * Banned?
1894
2028
      sprintf(s1, "%s!%s", msg, uhost);
1895
2029
      strcpy(m->nick, msg);
1896
2030
      detect_chan_flood(msg, uhost, from, chan, FLOOD_NICK, NULL);
 
2031
 
 
2032
      if (!findchan_by_dname(chname)) {
 
2033
        chan = oldchan;
 
2034
        continue;
 
2035
      }
1897
2036
      /* don't fill the serverqueue with modes or kicks in a nickflood */
1898
2037
      if (chan_sentkick(m) || chan_sentdeop(m) || chan_sentop(m) ||
1899
 
          chan_sentdevoice(m) || chan_sentvoice(m))
1900
 
        m->flags |= STOPCHECK;
 
2038
          chan_sentdehalfop(m) || chan_senthalfop(m) || chan_sentdevoice(m) ||
 
2039
          chan_sentvoice(m))
 
2040
        m->flags |= STOPCHECK;
1901
2041
      /* Any pending kick or mode to the old nick is lost. */
1902
 
        m->flags &= ~(SENTKICK | SENTDEOP | SENTOP | SENTVOICE | SENTDEVOICE);
 
2042
      m->flags &= ~(SENTKICK | SENTDEOP | SENTOP | SENTDEHALFOP | SENTHALFOP |
 
2043
                    SENTVOICE | SENTDEVOICE);
1903
2044
      /* nick-ban or nick is +k or something? */
1904
2045
      if (!chan_stopcheck(m)) {
1905
 
        get_user_flagrec(m->user ? m->user : get_user_by_host(s1), &fr, chan->dname);
1906
 
        check_this_member(chan, m->nick, &fr);
 
2046
        get_user_flagrec(m->user ? m->user : get_user_by_host(s1), &fr,
 
2047
                         chan->dname);
 
2048
        check_this_member(chan, m->nick, &fr);
1907
2049
      }
1908
 
      u = get_user_by_host(from); /* make sure this is in the loop, someone could have changed the record
1909
 
                                     in an earlier iteration of the loop */
 
2050
      /* Make sure this is in the loop, someone could have changed the record
 
2051
       * in an earlier iteration of the loop. */
 
2052
      u = get_user_by_host(from);
 
2053
      found = 1;
1910
2054
      check_tcl_nick(nick, uhost, u, chan->dname, msg);
 
2055
 
 
2056
      if (!findchan_by_dname(chname)) {
 
2057
        chan = oldchan;
 
2058
        continue;
 
2059
      }
1911
2060
    }
1912
2061
  }
 
2062
  if (!found) {
 
2063
    u = get_user_by_host(from);
 
2064
    s1[0] = '*';
 
2065
    s1[1] = 0;
 
2066
    check_tcl_nick(nick, uhost, u, s1, msg);
 
2067
  }
1913
2068
  return 0;
1914
2069
}
1915
2070
 
1917
2072
 */
1918
2073
static int gotquit(char *from, char *msg)
1919
2074
{
1920
 
  char *nick, *p, *alt;
 
2075
  char *nick, *chname, *p, *alt;
1921
2076
  int split = 0;
1922
2077
  char from2[NICKMAX + UHOSTMAX + 1];
1923
2078
  memberlist *m;
1924
 
  struct chanset_t *chan;
 
2079
  struct chanset_t *chan, *oldchan = NULL;
1925
2080
  struct userrec *u;
1926
2081
 
1927
 
  strcpy(from2,from);
 
2082
  strcpy(from2, from);
1928
2083
  u = get_user_by_host(from2);
1929
2084
  nick = splitnick(&from);
1930
2085
  fixcolon(msg);
1940
2095
    z1 = strchr(p + 1, '.');
1941
2096
    z2 = strchr(msg, '.');
1942
2097
    if (z1 && z2 && (*(z1 + 1) != 0) && (z1 - 1 != p) &&
1943
 
        (z2 + 1 != p) && (z2 != msg)) {
 
2098
        (z2 + 1 != p) && (z2 != msg)) {
1944
2099
      /* Server split, or else it looked like it anyway (no harm in
1945
2100
       * assuming)
1946
2101
       */
1949
2104
      *p = ' ';
1950
2105
  }
1951
2106
  for (chan = chanset; chan; chan = chan->next) {
 
2107
    oldchan = chan;
 
2108
    chname = chan->dname;
1952
2109
    m = ismember(chan, nick);
1953
2110
    if (m) {
1954
2111
      u = get_user_by_host(from2);
1955
 
      if (u) {
1956
 
        set_handle_laston(chan->dname, u, now); /* If you remove this, the bot will crash when the user record in question
1957
 
                                                   is removed/modified during the tcl binds below, and the users was on more
1958
 
                                                   than one monitored channel */
1959
 
      }
 
2112
      if (u)
 
2113
        /* If you remove this, the bot will crash when the user record in
 
2114
         * question is removed/modified during the tcl binds below, and the
 
2115
         * users was on more than one monitored channel */
 
2116
        set_handle_laston(chan->dname, u, now); 
1960
2117
      if (split) {
1961
 
        m->split = now;
1962
 
        check_tcl_splt(nick, from, u, chan->dname);
1963
 
        putlog(LOG_JOIN, chan->dname, "%s (%s) got netsplit.", nick,
1964
 
               from);
 
2118
        m->split = now;
 
2119
        check_tcl_splt(nick, from, u, chan->dname);
 
2120
 
 
2121
        if (!findchan_by_dname(chname)) {
 
2122
          chan = oldchan;
 
2123
          continue;
 
2124
        }
 
2125
        putlog(LOG_JOIN, chan->dname, "%s (%s) got netsplit.", nick, from);
1965
2126
      } else {
1966
 
        check_tcl_sign(nick, from, u, chan->dname, msg);
1967
 
        putlog(LOG_JOIN, chan->dname, "%s (%s) left irc: %s", nick,
1968
 
               from, msg);
1969
 
        killmember(chan, nick);
1970
 
        check_lonely_channel(chan);
 
2127
        check_tcl_sign(nick, from, u, chan->dname, msg);
 
2128
 
 
2129
        if (!findchan_by_dname(chname)) {
 
2130
          chan = oldchan;
 
2131
          continue;
 
2132
        }
 
2133
        putlog(LOG_JOIN, chan->dname, "%s (%s) left irc: %s", nick, from, msg);
 
2134
        killmember(chan, nick);
 
2135
        check_lonely_channel(chan);
1971
2136
      }
1972
2137
    }
1973
2138
  }
1981
2146
      dprintf(DP_SERVER, "NICK %s\n", origbotname);
1982
2147
    } else if (alt[0]) {
1983
2148
      if (!rfc_casecmp(nick, alt) && strcmp(botname, origbotname)) {
1984
 
        putlog(LOG_MISC, "*", IRC_GETALTNICK, alt);
1985
 
        dprintf(DP_SERVER, "NICK %s\n", alt);
 
2149
        putlog(LOG_MISC, "*", IRC_GETALTNICK, alt);
 
2150
        dprintf(DP_SERVER, "NICK %s\n", alt);
1986
2151
      }
1987
2152
    }
1988
2153
  }
2000
2165
  int ignoring;
2001
2166
  struct userrec *u;
2002
2167
  memberlist *m;
2003
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
2168
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
2004
2169
 
2005
2170
  if (!strchr("&#!+@$", msg[0]))
2006
2171
    return 0;
2009
2174
  realto = (to[0] == '@') ? to + 1 : to;
2010
2175
  chan = findchan(realto);
2011
2176
  if (!chan)
2012
 
    return 0;                   /* Private msg to an unknown channel?? */
 
2177
    return 0;                   /* Private msg to an unknown channel?? */
2013
2178
  fixcolon(msg);
2014
2179
  strcpy(uhost, from);
2015
2180
  nick = splitnick(&uhost);
2019
2184
    get_user_flagrec(u, &fr, chan->dname);
2020
2185
    m = ismember(chan, nick);
2021
2186
    /* Discard -- kick user if it was to the channel */
2022
 
    if (me_op(chan) && m && !chan_sentkick(m) &&
2023
 
        !chan_friend(fr) && !glob_friend(fr) &&
2024
 
        !(channel_dontkickops(chan) &&
2025
 
          (chan_op(fr) || (glob_op(fr) && !chan_deop(fr)))) &&  /* arthur2 */
2026
 
        !(use_exempts && ban_fun &&
2027
 
          /* don't kickban if permanent exempted -- Eule */
2028
 
          (u_match_mask(global_exempts, from) ||
2029
 
           u_match_mask(chan->exempts, from)))) {
 
2187
    if (m && (me_op(chan) || (me_halfop(chan) && !chan_hasop(m))) &&
 
2188
        !chan_sentkick(m) && !chan_friend(fr) && !glob_friend(fr) &&
 
2189
        !(channel_dontkickops(chan) && (chan_op(fr) || (glob_op(fr) &&
 
2190
        !chan_deop(fr)))) && !(use_exempts && ban_fun &&
 
2191
        (u_match_mask(global_exempts, from) ||
 
2192
        u_match_mask(chan->exempts, from)))) {
2030
2193
      if (ban_fun) {
2031
 
        check_exemptlist(chan, from);
2032
 
        u_addban(chan, quickban(chan, uhost), botnetnick,
2033
 
                IRC_FUNKICK, now + (60 * ban_time), 0);
 
2194
        check_exemptlist(chan, from);
 
2195
        u_addban(chan, quickban(chan, uhost), botnetnick,
 
2196
                 IRC_FUNKICK, now + (60 * chan->ban_time), 0);
2034
2197
      }
2035
2198
      if (kick_fun) {
2036
 
        /* This can induce kickflood - arthur2 */
2037
 
        dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, nick,
2038
 
                IRC_FUNKICK);
2039
 
        m->flags |= SENTKICK;
 
2199
        /* This can induce kickflood - arthur2 */
 
2200
        dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, nick, IRC_FUNKICK);
 
2201
        m->flags |= SENTKICK;
2040
2202
      }
2041
2203
    }
2042
2204
    if (!ignoring) {
2043
2205
      putlog(LOG_MODES, "*", "Avalanche from %s!%s in %s - ignoring",
2044
 
             nick, uhost, chan->dname);
 
2206
             nick, uhost, chan->dname);
2045
2207
      p = strchr(uhost, '@');
2046
2208
      if (p)
2047
 
        p++;
 
2209
        p++;
2048
2210
      else
2049
 
        p = uhost;
 
2211
        p = uhost;
2050
2212
      simple_sprintf(buf2, "*!*@%s", p);
2051
2213
      addignore(buf2, botnetnick, "ctcp avalanche", now + (60 * ignore_time));
2052
2214
    }
2066
2228
      strcpy(ctcp, p1);
2067
2229
      strcpy(p1 - 1, p + 1);
2068
2230
      detect_chan_flood(nick, uhost, from, chan,
2069
 
                        strncmp(ctcp, "ACTION ", 7) ?
2070
 
                        FLOOD_CTCP : FLOOD_PRIVMSG, NULL);
 
2231
                        strncmp(ctcp, "ACTION ", 7) ?
 
2232
                        FLOOD_CTCP : FLOOD_PRIVMSG, NULL);
 
2233
 
 
2234
      chan = findchan(realto);
 
2235
      if (!chan)
 
2236
        return 0;
 
2237
 
2071
2238
      /* Respond to the first answer_ctcp */
2072
2239
      p = strchr(msg, 1);
2073
2240
      if (ctcp_count < answer_ctcp) {
2074
 
        ctcp_count++;
2075
 
        if (ctcp[0] != ' ') {
2076
 
          code = newsplit(&ctcp);
2077
 
          u = get_user_by_host(from);
2078
 
          if (!ignoring || trigger_on_ignore) {
2079
 
            if (!check_tcl_ctcp(nick, uhost, u, to, code, ctcp))
2080
 
              update_idle(chan->dname, nick);
2081
 
            if (!ignoring) {
2082
 
              /* Log DCC, it's to a channel damnit! */
2083
 
              if (!strcmp(code, "ACTION")) {
2084
 
                putlog(LOG_PUBLIC, chan->dname, "Action: %s %s", nick, ctcp);
2085
 
              } else {
2086
 
                putlog(LOG_PUBLIC, chan->dname,
2087
 
                       "CTCP %s: %s from %s (%s) to %s", code, ctcp, nick,
2088
 
                       from, to);
2089
 
              }
2090
 
            }
2091
 
          }
2092
 
        }
 
2241
        ctcp_count++;
 
2242
        if (ctcp[0] != ' ') {
 
2243
          code = newsplit(&ctcp);
 
2244
          u = get_user_by_host(from);
 
2245
          if (!ignoring || trigger_on_ignore) {
 
2246
            if (!check_tcl_ctcp(nick, uhost, u, to, code, ctcp)) {
 
2247
 
 
2248
              chan = findchan(realto);
 
2249
              if (!chan)
 
2250
                return 0;
 
2251
 
 
2252
              update_idle(chan->dname, nick);
 
2253
            }
 
2254
            if (!ignoring) {
 
2255
              /* Log DCC, it's to a channel damnit! */
 
2256
              if (!strcmp(code, "ACTION")) {
 
2257
                putlog(LOG_PUBLIC, chan->dname, "Action: %s %s", nick, ctcp);
 
2258
              } else {
 
2259
                putlog(LOG_PUBLIC, chan->dname,
 
2260
                       "CTCP %s: %s from %s (%s) to %s", code, ctcp, nick,
 
2261
                       from, to);
 
2262
              }
 
2263
            }
 
2264
          }
 
2265
        }
2093
2266
      }
2094
2267
    }
2095
2268
  }
2099
2272
      dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
2100
2273
    } else {
2101
2274
      if (now - last_ctcp > flud_ctcp_time) {
2102
 
        dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
2103
 
        count_ctcp = 1;
 
2275
        dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
 
2276
        count_ctcp = 1;
2104
2277
      } else if (count_ctcp < flud_ctcp_thr) {
2105
 
        dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
2106
 
        count_ctcp++;
 
2278
        dprintf(DP_HELP, "NOTICE %s :%s\n", nick, ctcp_reply);
 
2279
        count_ctcp++;
2107
2280
      }
2108
2281
      last_ctcp = now;
2109
2282
    }
2111
2284
  if (msg[0]) {
2112
2285
    /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
2113
2286
    detect_chan_flood(nick, uhost, from, chan, FLOOD_PRIVMSG, NULL);
 
2287
 
 
2288
    chan = findchan(realto);
 
2289
    if (!chan)
 
2290
      return 0;
 
2291
 
2114
2292
    if (!ignoring || trigger_on_ignore) {
2115
2293
      if (check_tcl_pub(nick, uhost, chan->dname, msg))
2116
 
        return 0;
 
2294
        return 0;
2117
2295
      check_tcl_pubm(nick, uhost, chan->dname, msg);
 
2296
 
 
2297
      chan = findchan(realto);
 
2298
      if (!chan)
 
2299
        return 0;
 
2300
 
2118
2301
    }
2119
2302
    if (!ignoring) {
2120
2303
      if (to[0] == '@')
2121
 
        putlog(LOG_PUBLIC, chan->dname, "@<%s> %s", nick, msg);
 
2304
        putlog(LOG_PUBLIC, chan->dname, "@<%s> %s", nick, msg);
2122
2305
      else
2123
 
        putlog(LOG_PUBLIC, chan->dname, "<%s> %s", nick, msg);
 
2306
        putlog(LOG_PUBLIC, chan->dname, "<%s> %s", nick, msg);
2124
2307
    }
2125
2308
    update_idle(chan->dname, nick);
2126
2309
  }
2136
2319
  struct userrec *u;
2137
2320
  memberlist *m;
2138
2321
  struct chanset_t *chan;
2139
 
  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
 
2322
  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
2140
2323
  int ignoring;
2141
2324
 
2142
2325
  if (!strchr(CHANMETA "@", *msg))
2146
2329
  realto = (*to == '@') ? to + 1 : to;
2147
2330
  chan = findchan(realto);
2148
2331
  if (!chan)
2149
 
    return 0;                   /* Notice to an unknown channel?? */
 
2332
    return 0;                   /* Notice to an unknown channel?? */
2150
2333
  fixcolon(msg);
2151
2334
  strcpy(uhost, from);
2152
2335
  nick = splitnick(&uhost);
2155
2338
    get_user_flagrec(u, &fr, chan->dname);
2156
2339
    m = ismember(chan, nick);
2157
2340
    /* Discard -- kick user if it was to the channel */
2158
 
    if (me_op(chan) && m && !chan_sentkick(m) &&
2159
 
        !chan_friend(fr) && !glob_friend(fr) &&
2160
 
        !(channel_dontkickops(chan) &&
2161
 
          (chan_op(fr) || (glob_op(fr) && !chan_deop(fr)))) &&  /* arthur2 */
2162
 
        !(use_exempts && ban_fun &&
2163
 
          /* don't kickban if permanent exempted -- Eule */
2164
 
          (u_match_mask(global_exempts,from) ||
2165
 
           u_match_mask(chan->exempts, from)))) {
 
2341
    if (me_op(chan) && m && !chan_sentkick(m) && !chan_friend(fr) &&
 
2342
        !glob_friend(fr) && !(channel_dontkickops(chan) && (chan_op(fr) ||
 
2343
        (glob_op(fr) && !chan_deop(fr)))) && !(use_exempts && ban_fun &&
 
2344
        (u_match_mask(global_exempts, from) ||
 
2345
        u_match_mask(chan->exempts, from)))) {
2166
2346
      if (ban_fun) {
2167
 
        check_exemptlist(chan, from);
2168
 
        u_addban(chan, quickban(chan, uhost), botnetnick,
2169
 
                IRC_FUNKICK, now + (60 * ban_time), 0);
 
2347
        check_exemptlist(chan, from);
 
2348
        u_addban(chan, quickban(chan, uhost), botnetnick,
 
2349
                 IRC_FUNKICK, now + (60 * chan->ban_time), 0);
2170
2350
      }
2171
2351
      if (kick_fun) {
2172
 
        /* This can induce kickflood - arthur2 */
2173
 
        dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, nick,
2174
 
                IRC_FUNKICK);
2175
 
        m->flags |= SENTKICK;
 
2352
        /* This can induce kickflood - arthur2 */
 
2353
        dprintf(DP_SERVER, "KICK %s %s :%s\n", chan->name, nick, IRC_FUNKICK);
 
2354
        m->flags |= SENTKICK;
2176
2355
      }
2177
2356
    }
2178
2357
    if (!ignoring)
2193
2372
      strcpy(p1 - 1, p + 1);
2194
2373
      p = strchr(msg, 1);
2195
2374
      detect_chan_flood(nick, uhost, from, chan,
2196
 
                        strncmp(ctcp, "ACTION ", 7) ?
2197
 
                        FLOOD_CTCP : FLOOD_PRIVMSG, NULL);
 
2375
                        strncmp(ctcp, "ACTION ", 7) ?
 
2376
                        FLOOD_CTCP : FLOOD_PRIVMSG, NULL);
 
2377
 
 
2378
      chan = findchan(realto);
 
2379
      if (!chan)
 
2380
        return 0;
 
2381
 
2198
2382
      if (ctcp[0] != ' ') {
2199
 
        code = newsplit(&ctcp);
2200
 
        if (!ignoring || trigger_on_ignore) {
2201
 
          check_tcl_ctcr(nick, uhost, u, chan->dname, code, msg);
2202
 
          if (!ignoring) {
2203
 
            putlog(LOG_PUBLIC, chan->dname, "CTCP reply %s: %s from %s (%s) to %s",
2204
 
                   code, msg, nick, from, chan->dname);
2205
 
            update_idle(chan->dname, nick);
2206
 
          }
2207
 
        }
 
2383
        code = newsplit(&ctcp);
 
2384
        if (!ignoring || trigger_on_ignore) {
 
2385
          check_tcl_ctcr(nick, uhost, u, chan->dname, code, msg);
 
2386
 
 
2387
          chan = findchan(realto);
 
2388
          if (!chan)
 
2389
            return 0;
 
2390
 
 
2391
          if (!ignoring) {
 
2392
            putlog(LOG_PUBLIC, chan->dname,
 
2393
                   "CTCP reply %s: %s from %s (%s) to %s", code, msg, nick,
 
2394
                   from, chan->dname);
 
2395
            update_idle(chan->dname, nick);
 
2396
          }
 
2397
        }
2208
2398
      }
2209
2399
    }
2210
2400
  }
2211
2401
  if (msg[0]) {
2212
2402
    /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
2213
2403
    detect_chan_flood(nick, uhost, from, chan, FLOOD_NOTICE, NULL);
2214
 
    if (!ignoring || trigger_on_ignore)
 
2404
 
 
2405
    chan = findchan(realto);
 
2406
    if (!chan)
 
2407
      return 0;
 
2408
 
 
2409
    if (!ignoring || trigger_on_ignore) {
2215
2410
      check_tcl_notc(nick, uhost, u, to, msg);
 
2411
 
 
2412
      chan = findchan(realto);
 
2413
      if (!chan)
 
2414
        return 0;
 
2415
    }
 
2416
 
2216
2417
    if (!ignoring)
2217
2418
      putlog(LOG_PUBLIC, chan->dname, "-%s:%s- %s", nick, to, msg);
2218
2419
    update_idle(chan->dname, nick);
2220
2421
  return 0;
2221
2422
}
2222
2423
 
2223
 
static cmd_t irc_raw[] =
2224
 
{
2225
 
  {"324",       "",     (Function) got324,      "irc:324"},
2226
 
  {"352",       "",     (Function) got352,      "irc:352"},
2227
 
  {"354",       "",     (Function) got354,      "irc:354"},
2228
 
  {"315",       "",     (Function) got315,      "irc:315"},
2229
 
  {"367",       "",     (Function) got367,      "irc:367"},
2230
 
  {"368",       "",     (Function) got368,      "irc:368"},
2231
 
  {"403",       "",     (Function) got403,      "irc:403"},
2232
 
  {"405",       "",     (Function) got405,      "irc:405"},
2233
 
  {"471",       "",     (Function) got471,      "irc:471"},
2234
 
  {"473",       "",     (Function) got473,      "irc:473"},
2235
 
  {"474",       "",     (Function) got474,      "irc:474"},
2236
 
  {"475",       "",     (Function) got475,      "irc:475"},
2237
 
  {"INVITE",    "",     (Function) gotinvite,   "irc:invite"},
2238
 
  {"TOPIC",     "",     (Function) gottopic,    "irc:topic"},
2239
 
  {"331",       "",     (Function) got331,      "irc:331"},
2240
 
  {"332",       "",     (Function) got332,      "irc:332"},
2241
 
  {"JOIN",      "",     (Function) gotjoin,     "irc:join"},
2242
 
  {"PART",      "",     (Function) gotpart,     "irc:part"},
2243
 
  {"KICK",      "",     (Function) gotkick,     "irc:kick"},
2244
 
  {"NICK",      "",     (Function) gotnick,     "irc:nick"},
2245
 
  {"QUIT",      "",     (Function) gotquit,     "irc:quit"},
2246
 
  {"PRIVMSG",   "",     (Function) gotmsg,      "irc:msg"},
2247
 
  {"NOTICE",    "",     (Function) gotnotice,   "irc:notice"},
2248
 
  {"MODE",      "",     (Function) gotmode,     "irc:mode"},
2249
 
  {"346",       "",     (Function) got346,      "irc:346"},
2250
 
  {"347",       "",     (Function) got347,      "irc:347"},
2251
 
  {"348",       "",     (Function) got348,      "irc:348"},
2252
 
  {"349",       "",     (Function) got349,      "irc:349"},
2253
 
  {NULL,        NULL,   NULL,                   NULL}
 
2424
static cmd_t irc_raw[] = {
 
2425
  {"324",     "",   (Function) got324,       "irc:324"},
 
2426
  {"352",     "",   (Function) got352,       "irc:352"},
 
2427
  {"354",     "",   (Function) got354,       "irc:354"},
 
2428
  {"315",     "",   (Function) got315,       "irc:315"},
 
2429
  {"367",     "",   (Function) got367,       "irc:367"},
 
2430
  {"368",     "",   (Function) got368,       "irc:368"},
 
2431
  {"403",     "",   (Function) got403,       "irc:403"},
 
2432
  {"405",     "",   (Function) got405,       "irc:405"},
 
2433
  {"471",     "",   (Function) got471,       "irc:471"},
 
2434
  {"473",     "",   (Function) got473,       "irc:473"},
 
2435
  {"474",     "",   (Function) got474,       "irc:474"},
 
2436
  {"475",     "",   (Function) got475,       "irc:475"},
 
2437
  {"INVITE",  "",   (Function) gotinvite, "irc:invite"},
 
2438
  {"TOPIC",   "",   (Function) gottopic,   "irc:topic"},
 
2439
  {"331",     "",   (Function) got331,       "irc:331"},
 
2440
  {"332",     "",   (Function) got332,       "irc:332"},
 
2441
  {"JOIN",    "",   (Function) gotjoin,     "irc:join"},
 
2442
  {"PART",    "",   (Function) gotpart,     "irc:part"},
 
2443
  {"KICK",    "",   (Function) gotkick,     "irc:kick"},
 
2444
  {"NICK",    "",   (Function) gotnick,     "irc:nick"},
 
2445
  {"QUIT",    "",   (Function) gotquit,     "irc:quit"},
 
2446
  {"PRIVMSG", "",   (Function) gotmsg,       "irc:msg"},
 
2447
  {"NOTICE",  "",   (Function) gotnotice, "irc:notice"},
 
2448
  {"MODE",    "",   (Function) gotmode,     "irc:mode"},
 
2449
  {"346",     "",   (Function) got346,       "irc:346"},
 
2450
  {"347",     "",   (Function) got347,       "irc:347"},
 
2451
  {"348",     "",   (Function) got348,       "irc:348"},
 
2452
  {"349",     "",   (Function) got349,       "irc:349"},
 
2453
  {NULL,      NULL, NULL,                         NULL}
2254
2454
};