ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/channel_mode.c (file contents):
Revision 3235 by michael, Sat Mar 29 19:34:16 2014 UTC vs.
Revision 4962 by michael, Mon Dec 1 13:08:31 2014 UTC

# Line 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 34 | Line 34
34   #include "irc_string.h"
35   #include "ircd.h"
36   #include "numeric.h"
37 < #include "s_serv.h"
37 > #include "server.h"
38   #include "send.h"
39   #include "memory.h"
40   #include "mempool.h"
# Line 83 | Line 83 | const struct mode_letter chan_modes[] =
83   static char *
84   check_string(char *s)
85   {
86 <  char *str = s;
86 >  char *const str = s;
87    static char star[] = "*";
88  
89    if (EmptyString(str))
# Line 112 | Line 112 | int
112   add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type)
113   {
114    dlink_list *list = NULL;
115 <  dlink_node *ban = NULL;
115 >  dlink_node *node = NULL;
116 >  struct Ban *ban = NULL;
117    size_t len = 0;
117 –  struct Ban *ban_p = NULL;
118 –  unsigned int num_mask;
118    char name[NICKLEN + 1] = "";
119    char user[USERLEN + 1] = "";
120    char host[HOSTLEN + 1] = "";
121    struct split_nuh_item nuh;
122  
123 <  /* dont let local clients overflow the b/e/I lists */
123 >  /* Don't let local clients overflow the b/e/I lists */
124    if (MyClient(client_p))
125    {
126 <    num_mask = dlink_list_length(&chptr->banlist) +
127 <               dlink_list_length(&chptr->exceptlist) +
128 <               dlink_list_length(&chptr->invexlist);
126 >    unsigned int num_mask = dlink_list_length(&chptr->banlist) +
127 >                            dlink_list_length(&chptr->exceptlist) +
128 >                            dlink_list_length(&chptr->invexlist);
129  
130      if (num_mask >= ConfigChannel.max_bans)
131      {
132 <      sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->chname, banid);
132 >      sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->name, banid);
133        return 0;
134      }
135  
# Line 152 | Line 151 | add_id(struct Client *client_p, struct C
151     * Re-assemble a new n!u@h and print it back to banid for sending
152     * the mode to the channel.
153     */
154 <  len = sprintf(banid, "%s!%s@%s", name, user, host);
154 >  len = snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host);
155  
156    switch (type)
157    {
158      case CHFL_BAN:
159        list = &chptr->banlist;
160 <      clear_ban_cache(chptr);
160 >      clear_ban_cache_channel(chptr);
161        break;
162      case CHFL_EXCEPTION:
163        list = &chptr->exceptlist;
164 <      clear_ban_cache(chptr);
164 >      clear_ban_cache_channel(chptr);
165        break;
166      case CHFL_INVEX:
167        list = &chptr->invexlist;
# Line 172 | Line 171 | add_id(struct Client *client_p, struct C
171        return 0;
172    }
173  
174 <  DLINK_FOREACH(ban, list->head)
174 >  DLINK_FOREACH(node, list->head)
175    {
176 <    ban_p = ban->data;
176 >    ban = node->data;
177  
178 <    if (!irccmp(ban_p->name, name) &&
179 <        !irccmp(ban_p->user, user) &&
180 <        !irccmp(ban_p->host, host))
178 >    if (!irccmp(ban->name, name) &&
179 >        !irccmp(ban->user, user) &&
180 >        !irccmp(ban->host, host))
181        return 0;
182    }
183  
184 <  ban_p = mp_pool_get(ban_pool);
185 <  memset(ban_p, 0, sizeof(*ban_p));
186 <  ban_p->name = xstrdup(name);
187 <  ban_p->user = xstrdup(user);
188 <  ban_p->host = xstrdup(host);
189 <  ban_p->when = CurrentTime;
190 <  ban_p->len = len - 2;  /* -2 for @ and ! */
192 <  ban_p->type = parse_netmask(host, &ban_p->addr, &ban_p->bits);
184 >  ban = mp_pool_get(ban_pool);
185 >  ban->name = xstrdup(name);
186 >  ban->user = xstrdup(user);
187 >  ban->host = xstrdup(host);
188 >  ban->when = CurrentTime;
189 >  ban->len = len - 2;  /* -2 for ! + @ */
190 >  ban->type = parse_netmask(host, &ban->addr, &ban->bits);
191  
192    if (IsClient(client_p))
193    {
194 <    ban_p->who = MyMalloc(strlen(client_p->name) +
195 <                          strlen(client_p->username) +
196 <                          strlen(client_p->host) + 3);
197 <    sprintf(ban_p->who, "%s!%s@%s", client_p->name,
194 >    ban->who = MyCalloc(strlen(client_p->name) +
195 >                        strlen(client_p->username) +
196 >                        strlen(client_p->host) + 3);
197 >    sprintf(ban->who, "%s!%s@%s", client_p->name,
198              client_p->username, client_p->host);
199    }
200    else if (IsHidden(client_p) || (IsServer(client_p) && ConfigServerHide.hide_servers))
201 <    ban_p->who = xstrdup(me.name);
201 >    ban->who = xstrdup(me.name);
202    else
203 <    ban_p->who = xstrdup(client_p->name);
203 >    ban->who = xstrdup(client_p->name);
204  
205 <  dlinkAdd(ban_p, &ban_p->node, list);
205 >  dlinkAdd(ban, &ban->node, list);
206  
207    return 1;
208   }
# Line 219 | Line 217 | add_id(struct Client *client_p, struct C
217   static int
218   del_id(struct Channel *chptr, char *banid, unsigned int type)
219   {
220 <  dlink_list *list;
221 <  dlink_node *ban;
220 >  dlink_list *list = NULL;
221 >  dlink_node *node = NULL;
222    char name[NICKLEN + 1] = "";
223    char user[USERLEN + 1] = "";
224    char host[HOSTLEN + 1] = "";
# Line 243 | Line 241 | del_id(struct Channel *chptr, char *bani
241     * Re-assemble a new n!u@h and print it back to banid for sending
242     * the mode to the channel.
243     */
244 <  sprintf(banid, "%s!%s@%s", name, user, host);
244 >  snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host);
245  
246    switch (type)
247    {
248      case CHFL_BAN:
249        list = &chptr->banlist;
250 <      clear_ban_cache(chptr);
250 >      clear_ban_cache_channel(chptr);
251        break;
252      case CHFL_EXCEPTION:
253        list = &chptr->exceptlist;
254 <      clear_ban_cache(chptr);
254 >      clear_ban_cache_channel(chptr);
255        break;
256      case CHFL_INVEX:
257        list = &chptr->invexlist;
# Line 263 | Line 261 | del_id(struct Channel *chptr, char *bani
261        return 0;
262    }
263  
264 <  DLINK_FOREACH(ban, list->head)
264 >  DLINK_FOREACH(node, list->head)
265    {
266 <    struct Ban *banptr = ban->data;
266 >    struct Ban *ban = node->data;
267  
268 <    if (!irccmp(name, banptr->name) &&
269 <        !irccmp(user, banptr->user) &&
270 <        !irccmp(host, banptr->host))
268 >    if (!irccmp(name, ban->name) &&
269 >        !irccmp(user, ban->user) &&
270 >        !irccmp(host, ban->host))
271      {
272 <      remove_ban(banptr, list);
272 >      remove_ban(ban, list);
273        return 1;
274      }
275    }
# Line 290 | Line 288 | del_id(struct Channel *chptr, char *bani
288   * chptr onto buffer mbuf with the parameters in pbuf.
289   */
290   void
291 < channel_modes(struct Channel *chptr, struct Client *client_p,
294 <              char *mbuf, char *pbuf)
291 > channel_modes(struct Channel *chptr, struct Client *client_p, char *mbuf, char *pbuf)
292   {
296 –  const struct mode_letter *tab = chan_modes;
297 –
293    *mbuf++ = '+';
294    *pbuf = '\0';
295  
296 <  for (; tab->mode; ++tab)
296 >  for (const struct mode_letter *tab = chan_modes; tab->mode; ++tab)
297      if (chptr->mode.mode & tab->mode)
298        *mbuf++ = tab->letter;
299  
# Line 346 | Line 341 | fix_key(char *arg)
341    return arg;
342   }
343  
349 – /* fix_key_old()
350 – *
351 – * inputs       - pointer to key to clean up
352 – * output       - pointer to cleaned up key
353 – * side effects - input string is modifed
354 – *
355 – * Here we attempt to be compatible with older non-hybrid servers.
356 – * We can't back down from the ':' issue however.  --Rodder
357 – */
358 – static char *
359 – fix_key_old(char *arg)
360 – {
361 –  unsigned char *s, *t, c;
362 –
363 –  for (s = t = (unsigned char *)arg; (c = *s); ++s)
364 –  {
365 –    c &= 0x7f;
366 –
367 –    if ((c != 0x0a) && (c != ':') &&
368 –        (c != 0x0d) && (c != ','))
369 –      *t++ = c;
370 –  }
371 –
372 –  *t = '\0';
373 –  return arg;
374 – }
375 –
344   /*
345   * inputs       - pointer to channel
346   * output       - none
347   * side effects - clear ban cache
348   */
349   void
350 < clear_ban_cache(struct Channel *chptr)
350 > clear_ban_cache_channel(struct Channel *chptr)
351   {
352 <  dlink_node *ptr = NULL;
352 >  dlink_node *node = NULL;
353  
354 <  DLINK_FOREACH(ptr, chptr->members.head)
354 >  DLINK_FOREACH(node, chptr->locmembers.head)
355    {
356 <    struct Membership *ms = ptr->data;
357 <
390 <    if (MyConnect(ms->client_p))
391 <      ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
356 >    struct Membership *member = node->data;
357 >    member->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
358    }
359   }
360  
361   void
362   clear_ban_cache_client(struct Client *client_p)
363   {
364 <  dlink_node *ptr = NULL;
364 >  dlink_node *node = NULL;
365  
366 <  DLINK_FOREACH(ptr, client_p->channel.head)
366 >  DLINK_FOREACH(node, client_p->channel.head)
367    {
368 <    struct Membership *ms = ptr->data;
369 <    ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
368 >    struct Membership *member = node->data;
369 >    member->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED);
370    }
371   }
372  
373 < /* bitmasks for various error returns that set_channel_mode should only return
373 > /*
374 > * Bitmasks for various error returns that set_channel_mode should only return
375   * once per call  -orabidoo
376   */
377 <
378 < #define SM_ERR_NOTS         0x00000001 /* No TS on channel  */
379 < #define SM_ERR_NOOPS        0x00000002 /* No chan ops       */
380 < #define SM_ERR_UNKNOWN      0x00000004
381 < #define SM_ERR_RPL_B        0x00000008
382 < #define SM_ERR_RPL_E        0x00000010
383 < #define SM_ERR_NOTONCHANNEL 0x00000020 /* Not on channel    */
384 < #define SM_ERR_RPL_I        0x00000040
385 < #define SM_ERR_NOTOPER      0x00000080
386 < #define SM_ERR_ONLYSERVER   0x00000100
377 > enum
378 > {
379 >  SM_ERR_NOOPS        = 1 << 0,  /* No chan ops */
380 >  SM_ERR_UNKNOWN      = 1 << 1,
381 >  SM_ERR_RPL_B        = 1 << 2,
382 >  SM_ERR_RPL_E        = 1 << 3,
383 >  SM_ERR_RPL_I        = 1 << 4,
384 >  SM_ERR_NOTONCHANNEL = 1 << 5,  /* Client is not on channel */
385 >  SM_ERR_NOTOPER      = 1 << 6,
386 >  SM_ERR_ONLYSERVER   = 1 << 7
387 > };
388  
389   /* Mode functions handle mode changes for a particular mode... */
390   static void
391 < chm_nosuch(struct Client *source_p,
424 <           struct Channel *chptr, int parc, int *parn,
391 > chm_nosuch(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
392             char **parv, int *errors, int alev, int dir, char c, unsigned int d)
393   {
394    if (*errors & SM_ERR_UNKNOWN)
# Line 432 | Line 399 | chm_nosuch(struct Client *source_p,
399   }
400  
401   static void
402 < chm_simple(struct Client *source_p, struct Channel *chptr,
403 <           int parc, int *parn, char **parv, int *errors, int alev, int dir,
437 <           char c, unsigned int d)
402 > chm_simple(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
403 >           char **parv, int *errors, int alev, int dir, char c, unsigned int d)
404   {
405 <  if ((alev < CHACCESS_HALFOP) ||
440 <      ((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
405 >  if (alev < CHACCESS_HALFOP)
406    {
407      if (!(*errors & SM_ERR_NOOPS))
408        sendto_one_numeric(source_p, &me,
409                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
410 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
410 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
411 >
412      *errors |= SM_ERR_NOOPS;
413      return;
414    }
# Line 466 | Line 432 | chm_simple(struct Client *source_p, stru
432      chptr->mode.mode |= d;
433  
434      mode_changes[mode_count].letter = c;
435 <    mode_changes[mode_count].dir = MODE_ADD;
435 >    mode_changes[mode_count].arg = NULL;
436      mode_changes[mode_count].id = NULL;
437 <    mode_changes[mode_count].mems = ALL_MEMBERS;
472 <    mode_changes[mode_count++].arg = NULL;
437 >    mode_changes[mode_count++].dir = dir;
438    }
439    else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
440    {
# Line 478 | Line 443 | chm_simple(struct Client *source_p, stru
443      chptr->mode.mode &= ~d;
444  
445      mode_changes[mode_count].letter = c;
446 <    mode_changes[mode_count].dir = MODE_DEL;
482 <    mode_changes[mode_count].mems = ALL_MEMBERS;
446 >    mode_changes[mode_count].arg = NULL;
447      mode_changes[mode_count].id = NULL;
448 <    mode_changes[mode_count++].arg = NULL;
448 >    mode_changes[mode_count++].dir = dir;
449    }
450   }
451  
452   static void
453 < chm_registered(struct Client *source_p, struct Channel *chptr,
454 <               int parc, int *parn, char **parv, int *errors, int alev, int dir,
491 <               char c, unsigned int d)
453 > chm_registered(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
454 >               char **parv, int *errors, int alev, int dir, char c, unsigned int d)
455   {
456    if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE))
457    {
458      if (!(*errors & SM_ERR_ONLYSERVER))
459        sendto_one_numeric(source_p, &me,
460                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
461 <                         ERR_ONLYSERVERSCANCHANGE, chptr->chname);
461 >                         ERR_ONLYSERVERSCANCHANGE, chptr->name);
462 >
463      *errors |= SM_ERR_ONLYSERVER;
464      return;
465    }
# Line 519 | Line 483 | chm_registered(struct Client *source_p,
483      chptr->mode.mode |= d;
484  
485      mode_changes[mode_count].letter = c;
486 <    mode_changes[mode_count].dir = MODE_ADD;
486 >    mode_changes[mode_count].arg = NULL;
487      mode_changes[mode_count].id = NULL;
488 <    mode_changes[mode_count].mems = ALL_MEMBERS;
525 <    mode_changes[mode_count++].arg = NULL;
488 >    mode_changes[mode_count++].dir = dir;
489    }
490    else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
491    {
# Line 531 | Line 494 | chm_registered(struct Client *source_p,
494      chptr->mode.mode &= ~d;
495  
496      mode_changes[mode_count].letter = c;
497 <    mode_changes[mode_count].dir = MODE_DEL;
535 <    mode_changes[mode_count].mems = ALL_MEMBERS;
497 >    mode_changes[mode_count].arg = NULL;
498      mode_changes[mode_count].id = NULL;
499 <    mode_changes[mode_count++].arg = NULL;
499 >    mode_changes[mode_count++].dir = dir;
500    }
501   }
502  
503   static void
504 < chm_operonly(struct Client *source_p, struct Channel *chptr,
505 <             int parc, int *parn, char **parv, int *errors, int alev, int dir,
544 <             char c, unsigned int d)
504 > chm_operonly(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
505 >             char **parv, int *errors, int alev, int dir, char c, unsigned int d)
506   {
507 <  if ((alev < CHACCESS_HALFOP) ||
547 <      ((d == MODE_PRIVATE) && (alev < CHACCESS_CHANOP)))
507 >  if (alev < CHACCESS_CHANOP)
508    {
509      if (!(*errors & SM_ERR_NOOPS))
510        sendto_one_numeric(source_p, &me,
511                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
512 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
512 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
513 >
514      *errors |= SM_ERR_NOOPS;
515      return;
516    }
517 <  else if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER))
517 >
518 >  if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER))
519    {
520      if (!(*errors & SM_ERR_NOTOPER))
521 <    {
560 <      if (alev == CHACCESS_NOTONCHAN)
561 <        sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
562 <      else
563 <        sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
564 <    }
521 >      sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
522  
523      *errors |= SM_ERR_NOTOPER;
524      return;
# Line 578 | Line 535 | chm_operonly(struct Client *source_p, st
535      chptr->mode.mode |= d;
536  
537      mode_changes[mode_count].letter = c;
538 <    mode_changes[mode_count].dir = MODE_ADD;
538 >    mode_changes[mode_count].arg = NULL;
539      mode_changes[mode_count].id = NULL;
540 <    mode_changes[mode_count].mems = ALL_MEMBERS;
584 <    mode_changes[mode_count].mems = ALL_MEMBERS;
585 <    mode_changes[mode_count++].arg = NULL;
540 >    mode_changes[mode_count++].dir = dir;
541    }
542    else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
543    {
# Line 591 | Line 546 | chm_operonly(struct Client *source_p, st
546      chptr->mode.mode &= ~d;
547  
548      mode_changes[mode_count].letter = c;
549 <    mode_changes[mode_count].dir = MODE_DEL;
595 <    mode_changes[mode_count].mems = ALL_MEMBERS;
549 >    mode_changes[mode_count].arg = NULL;
550      mode_changes[mode_count].id = NULL;
551 <    mode_changes[mode_count++].arg = NULL;
551 >    mode_changes[mode_count++].dir = dir;
552    }
553   }
554  
555   static void
556 < chm_ban(struct Client *source_p,
603 <        struct Channel *chptr, int parc, int *parn,
556 > chm_ban(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
557          char **parv, int *errors, int alev, int dir, char c, unsigned int d)
558   {
559    char *mask = NULL;
560  
561    if (dir == MODE_QUERY || parc <= *parn)
562    {
563 <    dlink_node *ptr = NULL;
563 >    dlink_node *node = NULL;
564  
565      if (*errors & SM_ERR_RPL_B)
566        return;
567  
568      *errors |= SM_ERR_RPL_B;
569  
570 <    DLINK_FOREACH(ptr, chptr->banlist.head)
570 >    DLINK_FOREACH(node, chptr->banlist.head)
571      {
572 <      const struct Ban *banptr = ptr->data;
573 <      sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->chname,
574 <                         banptr->name, banptr->user, banptr->host,
575 <                         banptr->who, banptr->when);
572 >      const struct Ban *ban = node->data;
573 >      sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->name,
574 >                         ban->name, ban->user, ban->host,
575 >                         ban->who, ban->when);
576      }
577  
578 <    sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->chname);
578 >    sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->name);
579      return;
580    }
581  
# Line 631 | Line 584 | chm_ban(struct Client *source_p,
584      if (!(*errors & SM_ERR_NOOPS))
585        sendto_one_numeric(source_p, &me,
586                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
587 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
587 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
588 >
589      *errors |= SM_ERR_NOOPS;
590      return;
591    }
# Line 641 | Line 595 | chm_ban(struct Client *source_p,
595  
596    mask = nuh_mask[*parn];
597    memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
598 <  ++*parn;
598 >  ++(*parn);
599  
600    if (!MyConnect(source_p))
601      if (strchr(mask, ' '))
# Line 662 | Line 616 | chm_ban(struct Client *source_p,
616    }
617  
618    mode_changes[mode_count].letter = c;
619 <  mode_changes[mode_count].dir = dir;
666 <  mode_changes[mode_count].mems = ALL_MEMBERS;
619 >  mode_changes[mode_count].arg = mask;
620    mode_changes[mode_count].id = NULL;
621 <  mode_changes[mode_count++].arg = mask;
621 >  mode_changes[mode_count++].dir = dir;
622   }
623  
624   static void
625 < chm_except(struct Client *source_p,
673 <           struct Channel *chptr, int parc, int *parn,
625 > chm_except(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
626             char **parv, int *errors, int alev, int dir, char c, unsigned int d)
627   {
628    char *mask = NULL;
629  
678 –  if (alev < CHACCESS_HALFOP)
679 –  {
680 –    if (!(*errors & SM_ERR_NOOPS))
681 –      sendto_one_numeric(source_p, &me,
682 –                         alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
683 –                         ERR_CHANOPRIVSNEEDED, chptr->chname);
684 –    *errors |= SM_ERR_NOOPS;
685 –    return;
686 –  }
687 –
630    if (dir == MODE_QUERY || parc <= *parn)
631    {
632 <    dlink_node *ptr = NULL;
632 >    dlink_node *node = NULL;
633  
634      if (*errors & SM_ERR_RPL_E)
635        return;
636  
637      *errors |= SM_ERR_RPL_E;
638  
639 <    DLINK_FOREACH(ptr, chptr->exceptlist.head)
639 >    DLINK_FOREACH(node, chptr->exceptlist.head)
640      {
641 <      const struct Ban *banptr = ptr->data;
641 >      const struct Ban *ban = node->data;
642  
643 <      sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->chname,
644 <                         banptr->name, banptr->user, banptr->host,
645 <                         banptr->who, banptr->when);
643 >      sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->name,
644 >                         ban->name, ban->user, ban->host,
645 >                         ban->who, ban->when);
646      }
647  
648 <    sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->chname);
648 >    sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->name);
649 >    return;
650 >  }
651 >
652 >  if (alev < CHACCESS_HALFOP)
653 >  {
654 >    if (!(*errors & SM_ERR_NOOPS))
655 >      sendto_one_numeric(source_p, &me,
656 >                         alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
657 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
658 >
659 >    *errors |= SM_ERR_NOOPS;
660      return;
661    }
662  
# Line 712 | Line 665 | chm_except(struct Client *source_p,
665  
666    mask = nuh_mask[*parn];
667    memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
668 <  ++*parn;
668 >  ++(*parn);
669  
670    if (!MyConnect(source_p))
671      if (strchr(mask, ' '))
# Line 733 | Line 686 | chm_except(struct Client *source_p,
686    }
687  
688    mode_changes[mode_count].letter = c;
689 <  mode_changes[mode_count].dir = dir;
737 <  mode_changes[mode_count].mems = ONLY_CHANOPS;
689 >  mode_changes[mode_count].arg = mask;
690    mode_changes[mode_count].id = NULL;
691 <  mode_changes[mode_count++].arg = mask;
691 >  mode_changes[mode_count++].dir = dir;
692   }
693  
694   static void
695 < chm_invex(struct Client *source_p,
744 <          struct Channel *chptr, int parc, int *parn,
695 > chm_invex(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
696            char **parv, int *errors, int alev, int dir, char c, unsigned int d)
697   {
698    char *mask = NULL;
699  
749 –  if (alev < CHACCESS_HALFOP)
750 –  {
751 –    if (!(*errors & SM_ERR_NOOPS))
752 –      sendto_one_numeric(source_p, &me,
753 –                         alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
754 –                         ERR_CHANOPRIVSNEEDED, chptr->chname);
755 –    *errors |= SM_ERR_NOOPS;
756 –    return;
757 –  }
758 –
700    if (dir == MODE_QUERY || parc <= *parn)
701    {
702 <    dlink_node *ptr = NULL;
702 >    dlink_node *node = NULL;
703  
704      if (*errors & SM_ERR_RPL_I)
705        return;
706  
707      *errors |= SM_ERR_RPL_I;
708  
709 <    DLINK_FOREACH(ptr, chptr->invexlist.head)
709 >    DLINK_FOREACH(node, chptr->invexlist.head)
710      {
711 <      const struct Ban *banptr = ptr->data;
711 >      const struct Ban *ban = node->data;
712  
713 <      sendto_one_numeric(source_p, &me, RPL_INVITELIST, chptr->chname,
714 <                         banptr->name, banptr->user, banptr->host,
715 <                         banptr->who, banptr->when);
713 >      sendto_one_numeric(source_p, &me, RPL_INVEXLIST, chptr->name,
714 >                         ban->name, ban->user, ban->host,
715 >                         ban->who, ban->when);
716      }
717  
718 <    sendto_one_numeric(source_p, &me, RPL_ENDOFINVITELIST, chptr->chname);
718 >    sendto_one_numeric(source_p, &me, RPL_ENDOFINVEXLIST, chptr->name);
719 >    return;
720 >  }
721 >
722 >  if (alev < CHACCESS_HALFOP)
723 >  {
724 >    if (!(*errors & SM_ERR_NOOPS))
725 >      sendto_one_numeric(source_p, &me,
726 >                         alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
727 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
728 >
729 >    *errors |= SM_ERR_NOOPS;
730      return;
731    }
732  
# Line 783 | Line 735 | chm_invex(struct Client *source_p,
735  
736    mask = nuh_mask[*parn];
737    memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
738 <  ++*parn;
738 >  ++(*parn);
739  
740    if (!MyConnect(source_p))
741      if (strchr(mask, ' '))
# Line 804 | Line 756 | chm_invex(struct Client *source_p,
756    }
757  
758    mode_changes[mode_count].letter = c;
759 <  mode_changes[mode_count].dir = dir;
808 <  mode_changes[mode_count].mems = ONLY_CHANOPS;
759 >  mode_changes[mode_count].arg = mask;
760    mode_changes[mode_count].id = NULL;
761 <  mode_changes[mode_count++].arg = mask;
761 >  mode_changes[mode_count++].dir = dir;
762   }
763  
764   static void
765 < chm_voice(struct Client *source_p,
815 <          struct Channel *chptr, int parc, int *parn,
765 > chm_voice(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
766            char **parv, int *errors, int alev, int dir, char c, unsigned int d)
767   {
818 –  const char *opnick = NULL;
768    struct Client *target_p;
769    struct Membership *member;
770  
# Line 824 | Line 773 | chm_voice(struct Client *source_p,
773      if (!(*errors & SM_ERR_NOOPS))
774        sendto_one_numeric(source_p, &me,
775                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
776 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
776 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
777 >
778      *errors |= SM_ERR_NOOPS;
779      return;
780    }
781  
782 <  if ((dir == MODE_QUERY) || parc <= *parn)
782 >  if (dir == MODE_QUERY || parc <= *parn)
783      return;
784  
785 <  opnick = parv[(*parn)++];
786 <
837 <  if ((target_p = find_chasing(source_p, opnick)) == NULL)
838 <    return;
785 >  if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
786 >    return;  /* find_chasing sends ERR_NOSUCHNICK */
787  
788    if ((member = find_channel_link(target_p, chptr)) == NULL)
789    {
790      if (!(*errors & SM_ERR_NOTONCHANNEL))
791 <      sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
791 >      sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
792 >
793      *errors |= SM_ERR_NOTONCHANNEL;
794      return;
795    }
# Line 851 | Line 800 | chm_voice(struct Client *source_p,
800    /* no redundant mode changes */
801    if (dir == MODE_ADD &&  has_member_flags(member, CHFL_VOICE))
802      return;
803 +
804    if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE))
805      return;
806  
807 <  mode_changes[mode_count].letter = 'v';
858 <  mode_changes[mode_count].dir = dir;
859 <  mode_changes[mode_count].mems = ALL_MEMBERS;
860 <  mode_changes[mode_count].id = target_p->id;
807 >  mode_changes[mode_count].letter = c;
808    mode_changes[mode_count].arg = target_p->name;
809 <  mode_changes[mode_count++].client = target_p;
809 >  mode_changes[mode_count].id = target_p->id;
810 >  mode_changes[mode_count++].dir = dir;
811  
812    if (dir == MODE_ADD)
813      AddMemberFlag(member, CHFL_VOICE);
# Line 867 | Line 815 | chm_voice(struct Client *source_p,
815      DelMemberFlag(member, CHFL_VOICE);
816   }
817  
870 – #ifdef HALFOPS
818   static void
819 < chm_hop(struct Client *source_p,
873 <        struct Channel *chptr, int parc, int *parn,
819 > chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
820          char **parv, int *errors, int alev, int dir, char c, unsigned int d)
821   {
876 –  const char *opnick = NULL;
822    struct Client *target_p;
823    struct Membership *member;
824  
825 <  /* *sigh* - dont allow halfops to set +/-h, they could fully control a
881 <   * channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE
882 <   * when used with MODE_SECRET is paranoid - cant use +p
883 <   *
884 <   * it needs to be optional per channel - but not via +p, that or remove
885 <   * paranoid.. -- fl_
886 <   *
887 <   * +p means paranoid, it is useless for anything else on modern IRC, as
888 <   * list isn't really usable. If you want to have a private channel these
889 <   * days, you set it +s. Halfops can no longer remove simple modes when
890 <   * +p is set (although they can set +p) so it is safe to use this to
891 <   * control whether they can (de)halfop...
892 <   */
893 <  if (alev <
894 <      ((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP))
825 >  if (alev < CHACCESS_CHANOP)
826    {
827      if (!(*errors & SM_ERR_NOOPS))
828        sendto_one_numeric(source_p, &me,
829                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
830 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
830 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
831 >
832      *errors |= SM_ERR_NOOPS;
833      return;
834    }
835  
836 <  if ((dir == MODE_QUERY) || (parc <= *parn))
836 >  if (dir == MODE_QUERY || parc <= *parn)
837      return;
838  
839 <  opnick = parv[(*parn)++];
840 <
909 <  if ((target_p = find_chasing(source_p, opnick)) == NULL)
910 <    return;
839 >  if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
840 >    return;  /* find_chasing sends ERR_NOSUCHNICK */
841  
842    if ((member = find_channel_link(target_p, chptr)) == NULL)
843    {
844      if (!(*errors & SM_ERR_NOTONCHANNEL))
845 <      sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
845 >      sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
846 >
847      *errors |= SM_ERR_NOTONCHANNEL;
848      return;
849    }
# Line 923 | Line 854 | chm_hop(struct Client *source_p,
854    /* no redundant mode changes */
855    if (dir == MODE_ADD &&  has_member_flags(member, CHFL_HALFOP))
856      return;
857 +
858    if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP))
859      return;
860  
861 <  mode_changes[mode_count].letter = 'h';
930 <  mode_changes[mode_count].dir = dir;
931 <  mode_changes[mode_count].mems = ALL_MEMBERS;
932 <  mode_changes[mode_count].id = target_p->id;
861 >  mode_changes[mode_count].letter = c;
862    mode_changes[mode_count].arg = target_p->name;
863 <  mode_changes[mode_count++].client = target_p;
863 >  mode_changes[mode_count].id = target_p->id;
864 >  mode_changes[mode_count++].dir = dir;
865  
866    if (dir == MODE_ADD)
937 –  {
867      AddMemberFlag(member, CHFL_HALFOP);
939 –    DelMemberFlag(member, CHFL_DEOPPED);
940 –  }
868    else
869      DelMemberFlag(member, CHFL_HALFOP);
870   }
944 – #endif
871  
872   static void
873 < chm_op(struct Client *source_p,
948 <       struct Channel *chptr, int parc, int *parn,
873 > chm_op(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
874         char **parv, int *errors, int alev, int dir, char c, unsigned int d)
875   {
951 –  const char *opnick = NULL;
876    struct Client *target_p;
877    struct Membership *member;
878  
# Line 957 | Line 881 | chm_op(struct Client *source_p,
881      if (!(*errors & SM_ERR_NOOPS))
882        sendto_one_numeric(source_p, &me,
883                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
884 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
884 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
885 >
886      *errors |= SM_ERR_NOOPS;
887      return;
888    }
889  
890 <  if ((dir == MODE_QUERY) || (parc <= *parn))
890 >  if (dir == MODE_QUERY || parc <= *parn)
891      return;
892  
893 <  opnick = parv[(*parn)++];
894 <
970 <  if ((target_p = find_chasing(source_p, opnick)) == NULL)
971 <    return;
893 >  if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
894 >    return;  /* find_chasing sends ERR_NOSUCHNICK */
895  
896    if ((member = find_channel_link(target_p, chptr)) == NULL)
897    {
898      if (!(*errors & SM_ERR_NOTONCHANNEL))
899 <      sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, opnick, chptr->chname);
899 >      sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
900 >
901      *errors |= SM_ERR_NOTONCHANNEL;
902      return;
903    }
# Line 984 | Line 908 | chm_op(struct Client *source_p,
908    /* no redundant mode changes */
909    if (dir == MODE_ADD &&  has_member_flags(member, CHFL_CHANOP))
910      return;
911 +
912    if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP))
913      return;
914  
915 <  mode_changes[mode_count].letter = 'o';
991 <  mode_changes[mode_count].dir = dir;
992 <  mode_changes[mode_count].mems = ALL_MEMBERS;
993 <  mode_changes[mode_count].id = target_p->id;
915 >  mode_changes[mode_count].letter = c;
916    mode_changes[mode_count].arg = target_p->name;
917 <  mode_changes[mode_count++].client = target_p;
917 >  mode_changes[mode_count].id = target_p->id;
918 >  mode_changes[mode_count++].dir = dir;
919  
920    if (dir == MODE_ADD)
998 –  {
921      AddMemberFlag(member, CHFL_CHANOP);
1000 –    DelMemberFlag(member, CHFL_DEOPPED);
1001 –  }
922    else
923      DelMemberFlag(member, CHFL_CHANOP);
924   }
925  
926   static void
927 < chm_limit(struct Client *source_p,
1008 <          struct Channel *chptr, int parc, int *parn,
927 > chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
928            char **parv, int *errors, int alev, int dir, char c, unsigned int d)
929   {
1011 –  unsigned int i = 0;
930    int limit = 0;
931  
932    if (alev < CHACCESS_HALFOP)
# Line 1016 | Line 934 | chm_limit(struct Client *source_p,
934      if (!(*errors & SM_ERR_NOOPS))
935        sendto_one_numeric(source_p, &me,
936                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
937 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
937 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
938      *errors |= SM_ERR_NOOPS;
939      return;
940    }
# Line 1024 | Line 942 | chm_limit(struct Client *source_p,
942    if (dir == MODE_QUERY)
943      return;
944  
945 <  if ((dir == MODE_ADD) && parc > *parn)
945 >  if (dir == MODE_ADD && parc > *parn)
946    {
947 <    char *lstr = parv[(*parn)++];
947 >    char *const lstr = parv[(*parn)++];
948  
949      if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
950        return;
# Line 1034 | Line 952 | chm_limit(struct Client *source_p,
952      sprintf(lstr, "%d", limit);
953  
954      /* If somebody sets MODE #channel +ll 1 2, accept latter --fl */
955 <    for (i = 0; i < mode_count; ++i)
955 >    for (unsigned int i = 0; i < mode_count; ++i)
956        if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
957          mode_changes[i].letter = 0;
958  
959      mode_changes[mode_count].letter = c;
960 <    mode_changes[mode_count].dir = MODE_ADD;
1043 <    mode_changes[mode_count].mems = ALL_MEMBERS;
960 >    mode_changes[mode_count].arg = lstr;
961      mode_changes[mode_count].id = NULL;
962 <    mode_changes[mode_count++].arg = lstr;
962 >    mode_changes[mode_count++].dir = dir;
963  
964      chptr->mode.limit = limit;
965    }
# Line 1054 | Line 971 | chm_limit(struct Client *source_p,
971      chptr->mode.limit = 0;
972  
973      mode_changes[mode_count].letter = c;
974 <    mode_changes[mode_count].dir = MODE_DEL;
1058 <    mode_changes[mode_count].mems = ALL_MEMBERS;
974 >    mode_changes[mode_count].arg = NULL;
975      mode_changes[mode_count].id = NULL;
976 <    mode_changes[mode_count++].arg = NULL;
976 >    mode_changes[mode_count++].dir = dir;
977    }
978   }
979  
980   static void
981 < chm_key(struct Client *source_p,
1066 <        struct Channel *chptr, int parc, int *parn,
981 > chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
982          char **parv, int *errors, int alev, int dir, char c, unsigned int d)
983   {
1069 –  unsigned int i = 0;
1070 –
984    if (alev < CHACCESS_HALFOP)
985    {
986      if (!(*errors & SM_ERR_NOOPS))
987        sendto_one_numeric(source_p, &me,
988                           alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
989 <                         ERR_CHANOPRIVSNEEDED, chptr->chname);
989 >                         ERR_CHANOPRIVSNEEDED, chptr->name);
990      *errors |= SM_ERR_NOOPS;
991      return;
992    }
# Line 1081 | Line 994 | chm_key(struct Client *source_p,
994    if (dir == MODE_QUERY)
995      return;
996  
997 <  if ((dir == MODE_ADD) && parc > *parn)
997 >  if (dir == MODE_ADD && parc > *parn)
998    {
999 <    char *key = parv[(*parn)++];
1087 <
1088 <    if (MyClient(source_p))
1089 <      fix_key(key);
1090 <    else
1091 <      fix_key_old(key);
999 >    char *const key = fix_key(parv[(*parn)++]);
1000  
1001      if (EmptyString(key))
1002        return;
# Line 1097 | Line 1005 | chm_key(struct Client *source_p,
1005      strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1006  
1007      /* If somebody does MODE #channel +kk a b, accept latter --fl */
1008 <    for (i = 0; i < mode_count; ++i)
1008 >    for (unsigned int i = 0; i < mode_count; ++i)
1009        if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1010          mode_changes[i].letter = 0;
1011  
1012      mode_changes[mode_count].letter = c;
1013 <    mode_changes[mode_count].dir = MODE_ADD;
1106 <    mode_changes[mode_count].mems = ALL_MEMBERS;
1013 >    mode_changes[mode_count].arg = chptr->mode.key;
1014      mode_changes[mode_count].id = NULL;
1015 <    mode_changes[mode_count++].arg = chptr->mode.key;
1015 >    mode_changes[mode_count++].dir = dir;
1016    }
1017    else if (dir == MODE_DEL)
1018    {
1019      if (parc > *parn)
1020 <      (*parn)++;
1020 >      ++(*parn);
1021  
1022      if (chptr->mode.key[0] == '\0')
1023        return;
# Line 1118 | Line 1025 | chm_key(struct Client *source_p,
1025      chptr->mode.key[0] = '\0';
1026  
1027      mode_changes[mode_count].letter = c;
1028 <    mode_changes[mode_count].dir = MODE_DEL;
1122 <    mode_changes[mode_count].mems = ALL_MEMBERS;
1028 >    mode_changes[mode_count].arg = "*";
1029      mode_changes[mode_count].id = NULL;
1030 <    mode_changes[mode_count++].arg = "*";
1030 >    mode_changes[mode_count++].dir = dir;
1031    }
1032   }
1033  
1034 < struct ChannelMode
1129 < {
1130 <  void (*func)(struct Client *,
1131 <               struct Channel *, int, int *, char **,
1132 <               int *, int, int, char, unsigned int);
1133 <  unsigned int d;
1134 < };
1135 <
1136 < static struct ChannelMode ModeTable[256] =
1034 > const struct ChannelMode ModeTable[256] =
1035   {
1036    { chm_nosuch,  0 },                   /* 0x00 */
1037    { chm_nosuch,  0 },                   /* 0x01 */
# Line 1239 | Line 1137 | static struct ChannelMode ModeTable[256]
1137    { chm_except,  0 },                   /* e */
1138    { chm_nosuch,  0 },                   /* f */
1139    { chm_nosuch,  0 },                   /* g */
1242 – #ifdef HALFOPS
1140    { chm_hop,     0 },                   /* h */
1244 – #else
1245 –  { chm_nosuch,  0 },                   /* h */
1246 – #endif
1141    { chm_simple,     MODE_INVITEONLY },  /* i */
1142    { chm_nosuch,     0               },  /* j */
1143    { chm_key,        0               },  /* k */
# Line 1411 | Line 1305 | get_channel_access(const struct Client *
1305   {
1306    /* Let hacked servers in for now... */
1307    if (!MyClient(source_p))
1308 <    return CHACCESS_CHANOP;
1308 >    return CHACCESS_REMOTE;
1309  
1310    if (!member)
1311      return CHACCESS_NOTONCHAN;
1312  
1313 <  /* just to be sure.. */
1313 >  /* Just to be sure.. */
1314    assert(source_p == member->client_p);
1315  
1316    if (has_member_flags(member, CHFL_CHANOP))
1317      return CHACCESS_CHANOP;
1318  
1425 – #ifdef HALFOPS
1319    if (has_member_flags(member, CHFL_HALFOP))
1320      return CHACCESS_HALFOP;
1428 – #endif
1321  
1322    return CHACCESS_PEON;
1323   }
# Line 1440 | Line 1332 | get_channel_access(const struct Client *
1332   static void
1333   send_mode_changes_server(struct Client *source_p, struct Channel *chptr)
1334   {
1443 –  unsigned int i;
1335    int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1336    int len = 0;
1446 –  const char *arg = NULL;
1447 –  char *parptr;
1337    int dir = MODE_QUERY;
1338 +  const char *arg = NULL;
1339 +  char *parptr = NULL;
1340  
1341    parabuf[0] = '\0';
1342    parptr = parabuf;
1343  
1344    mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1345 <                 (unsigned long)chptr->channelts, chptr->chname);
1345 >                 (unsigned long)chptr->creationtime, chptr->name);
1346  
1347 <  /* loop the list of modes we have */
1348 <  for (i = 0; i < mode_count; ++i)
1347 >  /* Loop the list of modes we have */
1348 >  for (unsigned i = 0; i < mode_count; ++i)
1349    {
1350 <    if (mode_changes[i].letter == 0) /* XXX: can it ever happen? */
1350 >    if (mode_changes[i].letter == 0)
1351        continue;
1352  
1353      if (mode_changes[i].id)
# Line 1478 | Line 1369 | send_mode_changes_server(struct Client *
1369          (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1370      {
1371        if (nc)
1372 <        sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1372 >        sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1373  
1374        nc = 0;
1375        mc = 0;
1376  
1377        mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1378 <                     (unsigned long)chptr->channelts, chptr->chname);
1378 >                     (unsigned long)chptr->creationtime, chptr->name);
1379  
1380        pbl = 0;
1381        parabuf[0] = '\0';
# Line 1500 | Line 1391 | send_mode_changes_server(struct Client *
1391  
1392      modebuf[mbl++] = mode_changes[i].letter;
1393      modebuf[mbl] = '\0';
1394 <    nc++;
1394 >    ++nc;
1395  
1396      if (arg)
1397      {
1398        len = sprintf(parptr, "%s ", arg);
1399        pbl += len;
1400        parptr += len;
1401 <      mc++;
1401 >      ++mc;
1402      }
1403    }
1404  
# Line 1515 | Line 1406 | send_mode_changes_server(struct Client *
1406      parabuf[pbl - 1] = '\0';
1407  
1408    if (nc)
1409 <    sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1409 >    sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1410   }
1411  
1412   /* void send_mode_changes(struct Client *client_p,
# Line 1532 | Line 1423 | send_mode_changes_server(struct Client *
1423   static void
1424   send_mode_changes(struct Client *source_p, struct Channel *chptr)
1425   {
1535 –  unsigned int i;
1426    int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1427    int len = 0;
1538 –  const char *arg = NULL;
1539 –  char *parptr;
1428    int dir = MODE_QUERY;
1429 +  const char *arg = NULL;
1430 +  char *parptr = NULL;
1431  
1432    /* Bail out if we have nothing to do... */
1433    if (!mode_count)
# Line 1546 | Line 1436 | send_mode_changes(struct Client *source_
1436    if (IsServer(source_p))
1437      mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1438                     ConfigServerHide.hide_servers) ?
1439 <                   me.name : source_p->name, chptr->chname);
1439 >                   me.name : source_p->name, chptr->name);
1440    else
1441      mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1442 <                   source_p->username, source_p->host, chptr->chname);
1442 >                   source_p->username, source_p->host, chptr->name);
1443  
1444    parabuf[0] = '\0';
1445    parptr = parabuf;
1446  
1447 <  for (i = 0; i < mode_count; ++i)
1447 >  for (unsigned int i = 0; i < mode_count; ++i)
1448    {
1449 <    if (mode_changes[i].letter == 0 ||
1560 <        mode_changes[i].mems == NON_CHANOPS ||
1561 <        mode_changes[i].mems == ONLY_SERVERS)
1449 >    if (mode_changes[i].letter == 0)
1450        continue;
1451  
1452      arg = mode_changes[i].arg;
# Line 1567 | Line 1455 | send_mode_changes(struct Client *source_
1455      else
1456        arglen = 0;
1457  
1458 <    if ((mc == MAXMODEPARAMS)  ||
1458 >    if ((mc == MAXMODEPARAMS) ||
1459          ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1460          ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1461      {
# Line 1575 | Line 1463 | send_mode_changes(struct Client *source_
1463          modebuf[mbl - 1] = '\0';
1464  
1465        if (nc)
1466 <        sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1466 >        sendto_channel_local(0, chptr, "%s %s", modebuf, parabuf);
1467  
1468        nc = 0;
1469        mc = 0;
# Line 1583 | Line 1471 | send_mode_changes(struct Client *source_
1471        if (IsServer(source_p))
1472          mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1473                         ConfigServerHide.hide_servers) ?
1474 <                       me.name : source_p->name, chptr->chname);
1474 >                       me.name : source_p->name, chptr->name);
1475        else
1476          mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1477 <                       source_p->username, source_p->host, chptr->chname);
1477 >                       source_p->username, source_p->host, chptr->name);
1478  
1479        pbl = 0;
1480        parabuf[0] = '\0';
# Line 1602 | Line 1490 | send_mode_changes(struct Client *source_
1490  
1491      modebuf[mbl++] = mode_changes[i].letter;
1492      modebuf[mbl] = '\0';
1493 <    nc++;
1493 >    ++nc;
1494  
1495      if (arg)
1496      {
1497        len = sprintf(parptr, "%s ", arg);
1498        pbl += len;
1499        parptr += len;
1500 <      mc++;
1500 >      ++mc;
1501      }
1502    }
1503  
# Line 1617 | Line 1505 | send_mode_changes(struct Client *source_
1505      parabuf[pbl - 1] = '\0';
1506  
1507    if (nc)
1508 <    sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1508 >    sendto_channel_local(0, chptr, "%s %s", modebuf, parabuf);
1509  
1510    send_mode_changes_server(source_p, chptr);
1511   }
1512  
1513 < /*
1513 > /*
1514   * Input: The the client this originated
1515   *        from, the channel, the parameter count starting at the modes,
1516   *        the parameters, the channel name.
# Line 1637 | Line 1525 | set_channel_mode(struct Client *source_p
1525   {
1526    int dir = MODE_ADD;
1527    int parn = 1;
1528 <  int alevel, errors = 0;
1641 <  char *ml = parv[0], c;
1528 >  int alevel = 0, errors = 0;
1529  
1530    mode_count = 0;
1531    mode_limit = 0;
# Line 1646 | Line 1533 | set_channel_mode(struct Client *source_p
1533  
1534    alevel = get_channel_access(source_p, member);
1535  
1536 <  for (; (c = *ml); ++ml)
1536 >  for (const char *ml = parv[0]; *ml; ++ml)
1537    {
1538 <    switch (c)
1538 >    switch (*ml)
1539      {
1540        case '+':
1541          dir = MODE_ADD;
# Line 1661 | Line 1548 | set_channel_mode(struct Client *source_p
1548          break;
1549        default:
1550        {
1551 <        struct ChannelMode *tptr = &ModeTable[(unsigned char)c];
1551 >        const struct ChannelMode *tptr = &ModeTable[(unsigned char)*ml];
1552  
1553          tptr->func(source_p, chptr, parc, &parn, parv,
1554 <                   &errors, alevel, dir, c, tptr->d);
1554 >                   &errors, alevel, dir, *ml, tptr->d);
1555          break;
1556        }
1557      }

Diff Legend

– Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)