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

Comparing ircd-hybrid/trunk/src/channel.c (file contents):
Revision 3183 by michael, Thu Mar 20 16:49:21 2014 UTC vs.
Revision 3831 by michael, Wed Jun 4 21:47:26 2014 UTC

# Line 35 | Line 35
35   #include "irc_string.h"
36   #include "ircd.h"
37   #include "numeric.h"
38 < #include "s_serv.h"
38 > #include "server.h"
39   #include "send.h"
40   #include "event.h"
41   #include "memory.h"
42   #include "mempool.h"
43 < #include "s_misc.h"
43 > #include "misc.h"
44   #include "resv.h"
45  
46 dlink_list global_channel_list = { NULL, NULL, 0 };
47 mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
46  
47 < static mp_pool_t *member_pool = NULL;
48 < static mp_pool_t *channel_pool = NULL;
47 > dlink_list global_channel_list;
48 > mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
49  
50 + static mp_pool_t *member_pool, *channel_pool;
51   static char buf[IRCD_BUFSIZE];
52  
53  
# Line 65 | Line 64 | channel_init(void)
64    member_pool = mp_pool_new(sizeof(struct Membership), MP_CHUNK_SIZE_MEMBER);
65   }
66  
67 < /*! \brief adds a user to a channel by adding another link to the
67 > /*! \brief Adds a user to a channel by adding another link to the
68   *         channels member chain.
69 < * \param chptr      pointer to channel to add client to
70 < * \param who        pointer to client (who) to add
71 < * \param flags      flags for chanops etc
72 < * \param flood_ctrl whether to count this join in flood calculations
69 > * \param chptr      Pointer to channel to add client to
70 > * \param who        Pointer to client (who) to add
71 > * \param flags      Flags for chanops etc
72 > * \param flood_ctrl Whether to count this join in flood calculations
73   */
74   void
75   add_user_to_channel(struct Channel *chptr, struct Client *who,
# Line 81 | Line 80 | add_user_to_channel(struct Channel *chpt
80    if (GlobalSetOptions.joinfloodtime > 0)
81    {
82      if (flood_ctrl)
83 <      chptr->number_joined++;
83 >      ++chptr->number_joined;
84  
85      chptr->number_joined -= (CurrentTime - chptr->last_join_time) *
86        (((float)GlobalSetOptions.joinfloodcount) /
# Line 120 | Line 119 | add_user_to_channel(struct Channel *chpt
119    dlinkAdd(ms, &ms->usernode, &who->channel);
120   }
121  
122 < /*! \brief deletes an user from a channel by removing a link in the
122 > /*! \brief Deletes an user from a channel by removing a link in the
123   *         channels member chain.
124 < * \param member pointer to Membership struct
124 > * \param member Pointer to Membership struct
125   */
126   void
127   remove_user_from_channel(struct Membership *member)
# Line 161 | Line 160 | send_members(struct Client *client_p, st
160    {
161      const struct Membership *ms = ptr->data;
162  
163 <    tlen = strlen(ID(ms->client_p)) + 1;  /* nick + space */
163 >    tlen = strlen(ms->client_p->id) + 1;  /* nick + space */
164  
165      if (ms->flags & CHFL_CHANOP)
166 <      tlen++;
168 < #ifdef HALFOPS
166 >      ++tlen;
167      if (ms->flags & CHFL_HALFOP)
168 <      tlen++;
169 < #endif
170 <    if (ms->flags & CHFL_VOICE)
173 <      tlen++;
168 >      ++tlen;
169 >    ifs (ms->flags & CHFL_VOICE)
170 >      ++tlen;
171  
172 <    /* space will be converted into CR, but we also need space for LF..
173 <     * That's why we use '- 1' here
174 <     * -adx */
172 >    /*
173 >     * Space will be converted into CR, but we also need space for LF..
174 >     * That's why we use '- 1' here -adx
175 >     */
176      if (t + tlen - buf > IRCD_BUFSIZE - 1)
177      {
178 <      *(t - 1) = '\0';  /* kill the space and terminate the string */
178 >      *(t - 1) = '\0';  /* Kill the space and terminate the string */
179        sendto_one(client_p, "%s", buf);
180        t = start;
181      }
# Line 189 | Line 187 | send_members(struct Client *client_p, st
187      if (ms->flags & CHFL_VOICE)
188        *t++ = '+';
189  
190 <    strcpy(t, ID(ms->client_p));
190 >    strcpy(t, ms->client_p->id);
191  
192      t += strlen(t);
193      *t++ = ' ';
194    }
195  
196 <  /* should always be non-NULL unless we have a kind of persistent channels */
197 <  if (chptr->members.head != NULL)
198 <    t--;  /* take the space out */
196 >  /* Should always be non-NULL unless we have a kind of persistent channels */
197 >  if (chptr->members.head)
198 >    t--;  /* Take the space out */
199    *t = '\0';
200    sendto_one(client_p, "%s", buf);
201   }
202  
203 < /*! \brief sends +b/+e/+I
204 < * \param client_p client pointer to server
205 < * \param chptr    pointer to channel
206 < * \param top      pointer to top of mode link list to send
207 < * \param flag     char flag flagging type of mode. Currently this can be 'b', e' or 'I'
203 > /*! \brief Sends +b/+e/+I
204 > * \param client_p Client pointer to server
205 > * \param chptr    Pointer to channel
206 > * \param top      Pointer to top of mode link list to send
207 > * \param flag     Char flag flagging type of mode. Currently this can be 'b', e' or 'I'
208   */
209   static void
210   send_mode_list(struct Client *client_p, struct Channel *chptr,
211                 const dlink_list *top, char flag)
212   {
213 <  const dlink_node *lp = NULL;
214 <  char pbuf[IRCD_BUFSIZE];
215 <  int tlen, mlen, cur_len, count = 0;
213 >  const dlink_node *ptr = NULL;
214 >  char pbuf[IRCD_BUFSIZE] = "";
215 >  int tlen, mlen, cur_len;
216    char *pp = pbuf;
217  
218 <  if (top == NULL || top->length == 0)
218 >  if (top->length == 0)
219      return;
220  
221    mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id,
222                    (unsigned long)chptr->channelts, chptr->chname, flag);
223    cur_len = mlen;
224  
225 <  DLINK_FOREACH(lp, top->head)
225 >  DLINK_FOREACH(ptr, top->head)
226    {
227 <    const struct Ban *banptr = lp->data;
227 >    const struct Ban *banptr = ptr->data;
228  
229      tlen = banptr->len + 3;
230  
231      /*
232 <     * send buffer and start over if we cannot fit another ban,
232 >     * Send buffer and start over if we cannot fit another ban,
233       * or if the target is non-ts6 and we have too many modes in
234       * in this line.
235       */
236      if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
237      {
238 <      *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
238 >      *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
239        sendto_one(client_p, "%s%s", buf, pbuf);
240  
241        cur_len = mlen;
242        pp = pbuf;
245      count = 0;
243      }
244  
248    count++;
245      pp += sprintf(pp, "%s!%s@%s ", banptr->name, banptr->user,
246                    banptr->host);
247      cur_len += tlen;
248    }
249  
250 <  *(pp - 1) = '\0';  /* get rid of trailing space on buffer */
250 >  *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
251    sendto_one(client_p, "%s%s", buf, pbuf);
252   }
253  
254 < /*! \brief send "client_p" a full list of the modes for channel chptr
255 < * \param client_p pointer to client client_p
256 < * \param chptr    pointer to channel pointer
254 > /*! \brief Send "client_p" a full list of the modes for channel chptr
255 > * \param client_p Pointer to client client_p
256 > * \param chptr    Pointer to channel pointer
257   */
258   void
259   send_channel_modes(struct Client *client_p, struct Channel *chptr)
# Line 273 | Line 269 | send_channel_modes(struct Client *client
269    send_mode_list(client_p, chptr, &chptr->invexlist, 'I');
270   }
271  
272 < /*! \brief check channel name for invalid characters
273 < * \param name pointer to channel name string
274 < * \param local indicates whether it's a local or remote creation
272 > /*! \brief Check channel name for invalid characters
273 > * \param name Pointer to channel name string
274 > * \param local Indicates whether it's a local or remote creation
275   * \return 0 if invalid, 1 otherwise
276   */
277   int
278   check_channel_name(const char *name, const int local)
279   {
280    const char *p = name;
281 <  const int max_length = local ? LOCAL_CHANNELLEN : CHANNELLEN;
281 >
282    assert(name != NULL);
283  
284    if (!IsChanPrefix(*p))
# Line 301 | Line 297 | check_channel_name(const char *name, con
297          return 0;
298    }
299  
300 <  return p - name <= max_length;
300 >  return p - name <= CHANNELLEN;
301   }
302  
303   void
# Line 326 | Line 322 | remove_ban(struct Ban *bptr, dlink_list
322   void
323   free_channel_list(dlink_list *list)
324   {
325 <  dlink_node *ptr = NULL, *next_ptr = NULL;
325 >  dlink_node *ptr = NULL, *ptr_next = NULL;
326  
327 <  DLINK_FOREACH_SAFE(ptr, next_ptr, list->head)
327 >  DLINK_FOREACH_SAFE(ptr, ptr_next, list->head)
328      remove_ban(ptr->data, list);
329  
330    assert(list->tail == NULL && list->head == NULL);
# Line 336 | Line 332 | free_channel_list(dlink_list *list)
332  
333   /*! \brief Get Channel block for chname (and allocate a new channel
334   *         block, if it didn't exist before)
335 < * \param chname channel name
336 < * \return channel block
335 > * \param chname Channel name
336 > * \return Channel block
337   */
338   struct Channel *
339   make_channel(const char *chname)
# Line 350 | Line 346 | make_channel(const char *chname)
346  
347    memset(chptr, 0, sizeof(*chptr));
348  
349 <  /* doesn't hurt to set it here */
349 >  /* Doesn't hurt to set it here */
350    chptr->channelts = CurrentTime;
351    chptr->last_join_time = CurrentTime;
352  
# Line 362 | Line 358 | make_channel(const char *chname)
358    return chptr;
359   }
360  
361 < /*! \brief walk through this channel, and destroy it.
362 < * \param chptr channel pointer
361 > /*! \brief Walk through this channel, and destroy it.
362 > * \param chptr Channel pointer
363   */
364   void
365   destroy_channel(struct Channel *chptr)
# Line 373 | Line 369 | destroy_channel(struct Channel *chptr)
369    DLINK_FOREACH_SAFE(ptr, ptr_next, chptr->invites.head)
370      del_invite(chptr, ptr->data);
371  
372 <  /* free ban/exception/invex lists */
372 >  /* Free ban/exception/invex lists */
373    free_channel_list(&chptr->banlist);
374    free_channel_list(&chptr->exceptlist);
375    free_channel_list(&chptr->invexlist);
# Line 385 | Line 381 | destroy_channel(struct Channel *chptr)
381   }
382  
383   /*!
384 < * \param chptr pointer to channel
385 < * \return string pointer "=" if public, "@" if secret else "*"
384 > * \param chptr Pointer to channel
385 > * \return String pointer "=" if public, "@" if secret else "*"
386   */
387   static const char *
388   channel_pub_or_secret(const struct Channel *chptr)
# Line 399 | Line 395 | channel_pub_or_secret(const struct Chann
395   }
396  
397   /*! \brief lists all names on given channel
398 < * \param source_p pointer to client struct requesting names
399 < * \param chptr    pointer to channel block
400 < * \param show_eon show ENDOFNAMES numeric or not
398 > * \param source_p Pointer to client struct requesting names
399 > * \param chptr    Pointer to channel block
400 > * \param show_eon Show RPL_ENDOFNAMES numeric or not
401   *                 (don't want it with /names with no params)
402   */
403   void
# Line 409 | Line 405 | channel_member_names(struct Client *sour
405                       int show_eon)
406   {
407    const dlink_node *ptr = NULL;
408 <  char lbuf[IRCD_BUFSIZE + 1];
408 >  char lbuf[IRCD_BUFSIZE + 1] = "";
409    char *t = NULL, *start = NULL;
410    int tlen = 0;
411    int is_member = IsMember(source_p, chptr);
# Line 467 | Line 463 | channel_member_names(struct Client *sour
463                       ms->client_p->host);
464      }
465  
466 <    if (tlen != 0)
466 >    if (tlen)
467      {
468        *(t - 1) = '\0';
469        sendto_one(source_p, "%s", lbuf);
# Line 478 | Line 474 | channel_member_names(struct Client *sour
474      sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
475   }
476  
477 < /*! \brief adds client to invite list
478 < * \param chptr pointer to channel block
479 < * \param who   pointer to client to add invite to
477 > /*! \brief Adds client to invite list
478 > * \param chptr Pointer to channel block
479 > * \param who   Pointer to client to add invite to
480   */
481   void
482   add_invite(struct Channel *chptr, struct Client *who)
# Line 488 | Line 484 | add_invite(struct Channel *chptr, struct
484    del_invite(chptr, who);
485  
486    /*
487 <   * delete last link in chain if the list is max length
487 >   * Delete last link in chain if the list is max length
488     */
489    if (dlink_list_length(&who->localClient->invited) >=
490        ConfigChannel.max_chans_per_user)
491      del_invite(who->localClient->invited.tail->data, who);
492  
493 <  /* add client to channel invite list */
493 >  /* Add client to channel invite list */
494    dlinkAdd(who, make_dlink_node(), &chptr->invites);
495  
496 <  /* add channel to the end of the client invite list */
496 >  /* Add channel to the end of the client invite list */
497    dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
498   }
499  
500   /*! \brief Delete Invite block from channel invite list
501   *         and client invite list
502 < * \param chptr pointer to Channel struct
503 < * \param who   pointer to client to remove invites from
502 > * \param chptr Pointer to Channel struct
503 > * \param who   Pointer to client to remove invites from
504   */
505   void
506   del_invite(struct Channel *chptr, struct Client *who)
# Line 542 | Line 538 | get_member_status(const struct Membershi
538      *p++ = '@';
539    }
540  
545 #ifdef HALFOPS
541    if (ms->flags & CHFL_HALFOP)
542    {
543      if (!combine)
544        return "%";
545      *p++ = '%';
546    }
552 #endif
547  
548    if (ms->flags & CHFL_VOICE)
549      *p++ = '+';
# Line 559 | Line 553 | get_member_status(const struct Membershi
553   }
554  
555   /*!
556 < * \param who  pointer to Client to check
557 < * \param list pointer to ban list to search
556 > * \param who  Pointer to Client to check
557 > * \param list Pointer to ban list to search
558   * \return 1 if ban found for given n!u\@h mask, 0 otherwise
559   *
560   */
# Line 603 | Line 597 | find_bmask(const struct Client *who, con
597   }
598  
599   /*!
600 < * \param chptr pointer to channel block
601 < * \param who   pointer to client to check access fo
600 > * \param chptr Pointer to channel block
601 > * \param who   Pointer to client to check access fo
602   * \return 0 if not banned, 1 otherwise
603   */
604   int
# Line 617 | Line 611 | is_banned(const struct Channel *chptr, c
611    return 0;
612   }
613  
614 < /*!
615 < * \param source_p pointer to client attempting to join
616 < * \param chptr    pointer to channel
617 < * \param key      key sent by client attempting to join if present
614 > /*! Tests if a client can join a certain channel
615 > * \param source_p Pointer to client attempting to join
616 > * \param chptr    Pointer to channel
617 > * \param key      Key sent by client attempting to join if present
618   * \return ERR_BANNEDFROMCHAN, ERR_INVITEONLYCHAN, ERR_CHANNELISFULL
619   *         or 0 if allowed to join.
620   */
# Line 657 | Line 651 | can_join(struct Client *source_p, struct
651   int
652   has_member_flags(const struct Membership *ms, const unsigned int flags)
653   {
654 <  if (ms != NULL)
661 <    return ms->flags & flags;
662 <  return 0;
654 >  return ms && (ms->flags & flags);
655   }
656  
657   struct Membership *
# Line 715 | Line 707 | msg_has_ctrls(const char *message)
707    return 0;
708   }
709  
710 < /*!
711 < * \param chptr    pointer to Channel struct
712 < * \param source_p pointer to Client struct
713 < * \param ms       pointer to Membership struct (can be NULL)
710 > /*! Tests if a client can send to a channel
711 > * \param chptr    Pointer to Channel struct
712 > * \param source_p Pointer to Client struct
713 > * \param ms       Pointer to Membership struct (can be NULL)
714 > * \param message  The actual message string the client wants to send
715   * \return CAN_SEND_OPV if op or voiced on channel\n
716   *         CAN_SEND_NONOP if can send to channel but is not an op\n
717   *         ERR_CANNOTSENDTOCHAN or ERR_NEEDREGGEDNICK if they cannot send to channel\n
# Line 749 | Line 742 | can_send(struct Channel *chptr, struct C
742    if ((chptr->mode.mode & MODE_MODREG) && !HasUMode(source_p, UMODE_REGISTERED))
743      return ERR_NEEDREGGEDNICK;
744  
745 <  /* cache can send if banned */
745 >  /* Cache can send if banned */
746    if (MyClient(source_p))
747    {
748      if (ms)
# Line 778 | Line 771 | can_send(struct Channel *chptr, struct C
771   /*! \brief Updates the client's oper_warn_count_down, warns the
772   *         IRC operators if necessary, and updates
773   *         join_leave_countdown as needed.
774 < * \param source_p pointer to struct Client to check
775 < * \param name     channel name or NULL if this is a part.
774 > * \param source_p Pointer to struct Client to check
775 > * \param name     Channel name or NULL if this is a part.
776   */
777   void
778   check_spambot_warning(struct Client *source_p, const char *name)
# Line 798 | Line 791 | check_spambot_warning(struct Client *sou
791  
792      if (source_p->localClient->oper_warn_count_down == 0)
793      {
794 <      /* Its already known as a possible spambot */
795 <      if (name != NULL)
794 >      /* It's already known as a possible spambot */
795 >      if (name)
796          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
797                               "User %s (%s@%s) trying to join %s is a possible spambot",
798                               source_p->name, source_p->username,
# Line 827 | Line 820 | check_spambot_warning(struct Client *sou
820      {
821        if ((CurrentTime - (source_p->localClient->last_join_time)) <
822            GlobalSetOptions.spam_time)
823 <      {
831 <        /* oh, its a possible spambot */
832 <        source_p->localClient->join_leave_count++;
833 <      }
823 >        source_p->localClient->join_leave_count++;  /* It's a possible spambot */
824      }
825  
826 <    if (name != NULL)
826 >    if (name)
827        source_p->localClient->last_join_time = CurrentTime;
828      else
829        source_p->localClient->last_leave_time = CurrentTime;
830    }
831   }
832  
833 < /*! \brief compares usercount and servercount against their split
833 > /*! \brief Compares usercount and servercount against their split
834   *         values and adjusts splitmode accordingly
835   * \param unused Unused address pointer
836   */
# Line 871 | Line 861 | check_splitmode(void *unused)
861    }
862   }
863  
864 < /*! \brief Sets the channel topic for chptr
864 > /*! \brief Sets the channel topic for a certain channel
865   * \param chptr      Pointer to struct Channel
866   * \param topic      The topic string
867   * \param topic_info n!u\@h formatted string of the topic setter
868 < * \param topicts    timestamp on the topic
868 > * \param topicts    Timestamp on the topic
869 > * \param local      Whether the topic is set by a local client
870   */
871   void
872   set_channel_topic(struct Channel *chptr, const char *topic,

Diff Legend

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