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

Comparing ircd-hybrid/branches/8.2.x/src/channel.c (file contents):
Revision 4087 by michael, Sat Jun 28 16:45:42 2014 UTC vs.
Revision 4617 by michael, Sun Sep 7 13:00:55 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 47 | Line 47
47   dlink_list channel_list;
48   mp_pool_t *ban_pool;    /*! \todo ban_pool shouldn't be a global var */
49  
50 + struct event splitmode_event =
51 + {
52 +  .name = "check_splitmode",
53 +  .handler = check_splitmode,
54 +  .when = 5
55 + };
56 +
57   static mp_pool_t *member_pool, *channel_pool;
51 – static char buf[IRCD_BUFSIZE];
58  
59  
60   /*! \brief Initializes the channel blockheap, adds known channel CAPAB
# Line 101 | Line 107 | add_user_to_channel(struct Channel *chpt
107          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
108                               "Possible Join Flooder %s on %s target: %s",
109                               get_client_name(who, HIDE_IP),
110 <                             who->servptr->name, chptr->chname);
110 >                             who->servptr->name, chptr->name);
111        }
112      }
113  
# Line 114 | Line 120 | add_user_to_channel(struct Channel *chpt
120    ms->flags = flags;
121  
122    dlinkAdd(ms, &ms->channode, &chptr->members);
123 +
124 +  if (MyConnect(who))
125 +    dlinkAdd(ms, &ms->locchannode, &chptr->locmembers);
126 +
127    dlinkAdd(ms, &ms->usernode, &who->channel);
128   }
129  
# Line 128 | Line 138 | remove_user_from_channel(struct Membersh
138    struct Channel *chptr = member->chptr;
139  
140    dlinkDelete(&member->channode, &chptr->members);
141 +
142 +  if (MyConnect(client_p))
143 +    dlinkDelete(&member->locchannode, &chptr->locmembers);
144 +
145    dlinkDelete(&member->usernode, &client_p->channel);
146  
147    mp_pool_release(member);
# Line 146 | Line 160 | static void
160   send_members(struct Client *client_p, struct Channel *chptr,
161               char *modebuf, char *parabuf)
162   {
163 +  char buf[IRCD_BUFSIZE] = "";
164    const dlink_node *ptr = NULL;
165    int tlen;              /* length of text to append */
166    char *t, *start;       /* temp char pointer */
167  
168    start = t = buf + snprintf(buf, sizeof(buf), ":%s SJOIN %lu %s %s %s:",
169                               me.id, (unsigned long)chptr->channelts,
170 <                             chptr->chname, modebuf, parabuf);
170 >                             chptr->name, modebuf, parabuf);
171  
172    DLINK_FOREACH(ptr, chptr->members.head)
173    {
# Line 206 | Line 221 | send_members(struct Client *client_p, st
221   */
222   static void
223   send_mode_list(struct Client *client_p, struct Channel *chptr,
224 <               const dlink_list *list, char flag)
224 >               const dlink_list *list, const char flag)
225   {
226    const dlink_node *ptr = NULL;
227 +  char mbuf[IRCD_BUFSIZE] = "";
228    char pbuf[IRCD_BUFSIZE] = "";
229    int tlen, mlen, cur_len;
230    char *pp = pbuf;
# Line 216 | Line 232 | send_mode_list(struct Client *client_p,
232    if (list->length == 0)
233      return;
234  
235 <  mlen = snprintf(buf, sizeof(buf), ":%s BMASK %lu %s %c :", me.id,
236 <                  (unsigned long)chptr->channelts, chptr->chname, flag);
235 >  mlen = snprintf(mbuf, sizeof(mbuf), ":%s BMASK %lu %s %c :", me.id,
236 >                  (unsigned long)chptr->channelts, chptr->name, flag);
237    cur_len = mlen;
238  
239    DLINK_FOREACH(ptr, list->head)
# Line 232 | Line 248 | send_mode_list(struct Client *client_p,
248      if (cur_len + (tlen - 1) > IRCD_BUFSIZE - 2)
249      {
250        *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
251 <      sendto_one(client_p, "%s%s", buf, pbuf);
251 >      sendto_one(client_p, "%s%s", mbuf, pbuf);
252  
253        cur_len = mlen;
254        pp = pbuf;
# Line 244 | Line 260 | send_mode_list(struct Client *client_p,
260    }
261  
262    *(pp - 1) = '\0';  /* Get rid of trailing space on buffer */
263 <  sendto_one(client_p, "%s%s", buf, pbuf);
263 >  sendto_one(client_p, "%s%s", mbuf, pbuf);
264   }
265  
266   /*! \brief Send "client_p" a full list of the modes for channel chptr
# Line 326 | Line 342 | free_channel_list(dlink_list *list)
342    assert(list->tail == NULL && list->head == NULL);
343   }
344  
345 < /*! \brief Get Channel block for chname (and allocate a new channel
345 > /*! \brief Get Channel block for name (and allocate a new channel
346   *         block, if it didn't exist before)
347 < * \param chname Channel name
347 > * \param name Channel name
348   * \return Channel block
349   */
350   struct Channel *
351 < make_channel(const char *chname)
351 > make_channel(const char *name)
352   {
353    struct Channel *chptr = NULL;
354  
355 <  assert(!EmptyString(chname));
355 >  assert(!EmptyString(name));
356  
357    chptr = mp_pool_get(channel_pool);
358  
# Line 344 | Line 360 | make_channel(const char *chname)
360    chptr->channelts = CurrentTime;
361    chptr->last_join_time = CurrentTime;
362  
363 <  strlcpy(chptr->chname, chname, sizeof(chptr->chname));
363 >  strlcpy(chptr->name, name, sizeof(chptr->name));
364    dlinkAdd(chptr, &chptr->node, &channel_list);
365  
366    hash_add_channel(chptr);
# Line 399 | Line 415 | channel_member_names(struct Client *sour
415                       int show_eon)
416   {
417    const dlink_node *ptr = NULL;
418 <  char lbuf[IRCD_BUFSIZE + 1] = "";
418 >  char buf[IRCD_BUFSIZE + 1] = "";
419    char *t = NULL, *start = NULL;
420    int tlen = 0;
421    int is_member = IsMember(source_p, chptr);
# Line 408 | Line 424 | channel_member_names(struct Client *sour
424  
425    if (PubChannel(chptr) || is_member)
426    {
427 <    t = lbuf + snprintf(lbuf, sizeof(lbuf), numeric_form(RPL_NAMREPLY),
428 <                        me.name, source_p->name,
429 <                        channel_pub_or_secret(chptr), chptr->chname);
427 >    t = buf + snprintf(buf, sizeof(buf), numeric_form(RPL_NAMREPLY),
428 >                       me.name, source_p->name,
429 >                       channel_pub_or_secret(chptr), chptr->name);
430      start = t;
431  
432      DLINK_FOREACH(ptr, chptr->members.head)
# Line 441 | Line 457 | channel_member_names(struct Client *sour
457            ++tlen;
458        }
459  
460 <      if (t + tlen - lbuf > IRCD_BUFSIZE - 2)
460 >      if (t + tlen - buf > IRCD_BUFSIZE - 2)
461        {
462          *(t - 1) = '\0';
463 <        sendto_one(source_p, "%s", lbuf);
463 >        sendto_one(source_p, "%s", buf);
464          t = start;
465        }
466  
# Line 460 | Line 476 | channel_member_names(struct Client *sour
476      if (tlen)
477      {
478        *(t - 1) = '\0';
479 <      sendto_one(source_p, "%s", lbuf);
479 >      sendto_one(source_p, "%s", buf);
480      }
481    }
482  
483    if (show_eon)
484 <    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->chname);
484 >    sendto_one_numeric(source_p, &me, RPL_ENDOFNAMES, chptr->name);
485   }
486  
487   /*! \brief Adds client to invite list
# Line 480 | Line 496 | add_invite(struct Channel *chptr, struct
496    /*
497     * Delete last link in chain if the list is max length
498     */
499 <  if (dlink_list_length(&who->localClient->invited) >=
499 >  if (dlink_list_length(&who->connection->invited) >=
500        ConfigChannel.max_channels)
501 <    del_invite(who->localClient->invited.tail->data, who);
501 >    del_invite(who->connection->invited.tail->data, who);
502  
503    /* Add client to channel invite list */
504    dlinkAdd(who, make_dlink_node(), &chptr->invites);
505  
506    /* Add channel to the end of the client invite list */
507 <  dlinkAdd(chptr, make_dlink_node(), &who->localClient->invited);
507 >  dlinkAdd(chptr, make_dlink_node(), &who->connection->invited);
508   }
509  
510   /*! \brief Delete Invite block from channel invite list
# Line 501 | Line 517 | del_invite(struct Channel *chptr, struct
517   {
518    dlink_node *ptr = NULL;
519  
520 <  if ((ptr = dlinkFindDelete(&who->localClient->invited, chptr)))
520 >  if ((ptr = dlinkFindDelete(&who->connection->invited, chptr)))
521      free_dlink_node(ptr);
522  
523    if ((ptr = dlinkFindDelete(&chptr->invites, who)))
# Line 570 | Line 586 | find_bmask(const struct Client *who, con
586              return 1;
587            break;
588          case HM_IPV4:
589 <          if (who->localClient->aftype == AF_INET)
590 <            if (match_ipv4(&who->localClient->ip, &bp->addr, bp->bits))
589 >          if (who->connection->aftype == AF_INET)
590 >            if (match_ipv4(&who->connection->ip, &bp->addr, bp->bits))
591                return 1;
592            break;
577 – #ifdef IPV6
593          case HM_IPV6:
594 <          if (who->localClient->aftype == AF_INET6)
595 <            if (match_ipv6(&who->localClient->ip, &bp->addr, bp->bits))
594 >          if (who->connection->aftype == AF_INET6)
595 >            if (match_ipv6(&who->connection->ip, &bp->addr, bp->bits))
596                return 1;
597            break;
583 – #endif
598          default:
599            assert(0);
600        }
# Line 625 | Line 639 | can_join(struct Client *source_p, struct
639      return ERR_OPERONLYCHAN;
640  
641    if (chptr->mode.mode & MODE_INVITEONLY)
642 <    if (!dlinkFind(&source_p->localClient->invited, chptr))
642 >    if (!dlinkFind(&source_p->connection->invited, chptr))
643        if (!find_bmask(source_p, &chptr->invexlist))
644          return ERR_INVITEONLYCHAN;
645  
# Line 722 | Line 736 | can_send(struct Channel *chptr, struct C
736      return CAN_SEND_OPV;
737  
738    if (MyClient(source_p) && !IsExemptResv(source_p))
739 <    if (!(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv))
740 <      if ((conf = match_find_resv(chptr->chname)) && !resv_find_exempt(source_p, conf))
739 >    if (!(HasUMode(source_p, UMODE_OPER) && ConfigGeneral.oper_pass_resv))
740 >      if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(source_p, conf))
741          return ERR_CANNOTSENDTOCHAN;
742  
743    if ((chptr->mode.mode & MODE_NOCTRL) && msg_has_ctrls(message))
# Line 777 | Line 791 | check_spambot_warning(struct Client *sou
791    int decrement_count = 0;
792  
793    if ((GlobalSetOptions.spam_num &&
794 <       (source_p->localClient->join_leave_count >=
794 >       (source_p->connection->join_leave_count >=
795          GlobalSetOptions.spam_num)))
796    {
797 <    if (source_p->localClient->oper_warn_count_down > 0)
798 <      source_p->localClient->oper_warn_count_down--;
797 >    if (source_p->connection->oper_warn_count_down > 0)
798 >      source_p->connection->oper_warn_count_down--;
799      else
800 <      source_p->localClient->oper_warn_count_down = 0;
800 >      source_p->connection->oper_warn_count_down = 0;
801  
802 <    if (source_p->localClient->oper_warn_count_down == 0)
802 >    if (source_p->connection->oper_warn_count_down == 0)
803      {
804        /* It's already known as a possible spambot */
805        if (name)
# Line 798 | Line 812 | check_spambot_warning(struct Client *sou
812                               "User %s (%s@%s) is a possible spambot",
813                               source_p->name, source_p->username,
814                               source_p->host);
815 <      source_p->localClient->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
815 >      source_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
816      }
817    }
818    else
819    {
820 <    if ((t_delta = (CurrentTime - source_p->localClient->last_leave_time)) >
820 >    if ((t_delta = (CurrentTime - source_p->connection->last_leave_time)) >
821           JOIN_LEAVE_COUNT_EXPIRE_TIME)
822      {
823        decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
824 <      if (decrement_count > source_p->localClient->join_leave_count)
825 <        source_p->localClient->join_leave_count = 0;
824 >      if (decrement_count > source_p->connection->join_leave_count)
825 >        source_p->connection->join_leave_count = 0;
826        else
827 <        source_p->localClient->join_leave_count -= decrement_count;
827 >        source_p->connection->join_leave_count -= decrement_count;
828      }
829      else
830      {
831 <      if ((CurrentTime - (source_p->localClient->last_join_time)) <
831 >      if ((CurrentTime - (source_p->connection->last_join_time)) <
832            GlobalSetOptions.spam_time)
833 <        source_p->localClient->join_leave_count++;  /* It's a possible spambot */
833 >        source_p->connection->join_leave_count++;  /* It's a possible spambot */
834      }
835  
836      if (name)
837 <      source_p->localClient->last_join_time = CurrentTime;
837 >      source_p->connection->last_join_time = CurrentTime;
838      else
839 <      source_p->localClient->last_leave_time = CurrentTime;
839 >      source_p->connection->last_leave_time = CurrentTime;
840    }
841   }
842  
# Line 836 | Line 850 | check_splitmode(void *unused)
850    if (splitchecking && (ConfigChannel.no_join_on_split ||
851                          ConfigChannel.no_create_on_split))
852    {
853 <    const unsigned int server = dlink_list_length(&global_serv_list);
853 >    const unsigned int server = dlink_list_length(&global_server_list);
854  
855      if (!splitmode && ((server < split_servers) || (Count.total < split_users)))
856      {
# Line 844 | Line 858 | check_splitmode(void *unused)
858  
859        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
860                             "Network split, activating splitmode");
861 <      eventAddIsh("check_splitmode", check_splitmode, NULL, 10);
861 >      event_add(&splitmode_event, NULL);
862      }
863      else if (splitmode && (server >= split_servers) && (Count.total >= split_users))
864      {
# Line 852 | Line 866 | check_splitmode(void *unused)
866  
867        sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
868                             "Network rejoined, deactivating splitmode");
869 <      eventDelete(check_splitmode, NULL);
869 >      event_delete(&splitmode_event);
870      }
871    }
872   }
# Line 869 | Line 883 | channel_set_topic(struct Channel *chptr,
883                    const char *topic_info, time_t topicts, int local)
884   {
885    if (local)
886 <    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ServerInfo.max_topic_length + 1));
886 >    strlcpy(chptr->topic, topic, IRCD_MIN(sizeof(chptr->topic), ConfigServerInfo.max_topic_length + 1));
887    else
888      strlcpy(chptr->topic, topic, sizeof(chptr->topic));
889  
# Line 900 | Line 914 | channel_do_join_0(struct Client *source_
914      struct Channel *chptr = ((struct Membership *)ptr->data)->chptr;
915  
916      sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
917 <                  source_p->id, chptr->chname);
917 >                  source_p->id, chptr->name);
918      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
919                           source_p->name, source_p->username,
920 <                         source_p->host, chptr->chname);
920 >                         source_p->host, chptr->name);
921  
922      remove_user_from_channel(ptr->data);
923    }
# Line 948 | Line 962 | channel_do_join(struct Client *source_p,
962    char *chan_list = NULL;
963    struct Channel *chptr = NULL;
964    struct MaskItem *conf = NULL;
965 <  const struct ClassItem *class = get_class_ptr(&source_p->localClient->confs);
965 >  const struct ClassItem *class = get_class_ptr(&source_p->connection->confs);
966    int i = 0;
967    unsigned int flags = 0;
968  
# Line 974 | Line 988 | channel_do_join(struct Client *source_p,
988      }
989  
990      if (!IsExemptResv(source_p) &&
991 <        !(HasUMode(source_p, UMODE_OPER) && ConfigFileEntry.oper_pass_resv) &&
991 >        !(HasUMode(source_p, UMODE_OPER) && ConfigGeneral.oper_pass_resv) &&
992          ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
993      {
994        ++conf->count;
995        sendto_one_numeric(source_p, &me, ERR_CHANBANREASON,
996                           chan, conf->reason ? conf->reason : "Reserved channel");
997 <      sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
997 >      sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
998                             "Forbidding reserved channel %s from user %s",
999                             chan, get_client_name(source_p, HIDE_IP));
1000        continue;
# Line 1001 | Line 1015 | channel_do_join(struct Client *source_p,
1015        if (splitmode && !HasUMode(source_p, UMODE_OPER) &&
1016            ConfigChannel.no_join_on_split)
1017        {
1018 <        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->chname);
1018 >        sendto_one_numeric(source_p, &me, ERR_UNAVAILRESOURCE, chptr->name);
1019          continue;
1020        }
1021  
# Line 1010 | Line 1024 | channel_do_join(struct Client *source_p,
1024         */
1025        if ((i = can_join(source_p, chptr, key)))
1026        {
1027 <        sendto_one_numeric(source_p, &me, i, chptr->chname);
1027 >        sendto_one_numeric(source_p, &me, i, chptr->name);
1028          continue;
1029        }
1030  
# Line 1037 | Line 1051 | channel_do_join(struct Client *source_p,
1051      }
1052  
1053      if (!HasUMode(source_p, UMODE_OPER))
1054 <      check_spambot_warning(source_p, chptr->chname);
1054 >      check_spambot_warning(source_p, chptr->name);
1055  
1056      add_user_to_channel(chptr, source_p, flags, 1);
1057  
# Line 1052 | Line 1066 | channel_do_join(struct Client *source_p,
1066  
1067        sendto_server(source_p, NOCAPS, NOCAPS, ":%s SJOIN %lu %s +nt :@%s",
1068                      me.id, (unsigned long)chptr->channelts,
1069 <                    chptr->chname, source_p->id);
1069 >                    chptr->name, source_p->id);
1070  
1071        /*
1072         * Notify all other users on the new channel
1073         */
1074        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1075                             source_p->name, source_p->username,
1076 <                           source_p->host, chptr->chname);
1076 >                           source_p->host, chptr->name);
1077        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s MODE %s +nt",
1078 <                           me.name, chptr->chname);
1078 >                           me.name, chptr->name);
1079  
1080        if (source_p->away[0])
1081          sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
# Line 1073 | Line 1087 | channel_do_join(struct Client *source_p,
1087      {
1088        sendto_server(source_p, NOCAPS, NOCAPS, ":%s JOIN %lu %s +",
1089                      source_p->id, (unsigned long)chptr->channelts,
1090 <                    chptr->chname);
1090 >                    chptr->name);
1091        sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s JOIN :%s",
1092                             source_p->name, source_p->username,
1093 <                           source_p->host, chptr->chname);
1093 >                           source_p->host, chptr->name);
1094  
1095        if (source_p->away[0])
1096          sendto_channel_local_butone(source_p, 0, CAP_AWAY_NOTIFY, chptr,
# Line 1089 | Line 1103 | channel_do_join(struct Client *source_p,
1103  
1104      if (chptr->topic[0])
1105      {
1106 <      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->chname, chptr->topic);
1107 <      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->chname,
1106 >      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1107 >      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name,
1108                           chptr->topic_info, chptr->topic_time);
1109      }
1110  
1111      channel_member_names(source_p, chptr, 1);
1112  
1113 <    source_p->localClient->last_join_time = CurrentTime;
1113 >    source_p->connection->last_join_time = CurrentTime;
1114    }
1115   }
1116  
# Line 1119 | Line 1133 | channel_part_one_client(struct Client *s
1133  
1134    if ((ms = find_channel_link(source_p, chptr)) == NULL)
1135    {
1136 <    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->chname);
1136 >    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
1137      return;
1138    }
1139  
# Line 1132 | Line 1146 | channel_part_one_client(struct Client *s
1146     */
1147    if (*reason && (!MyConnect(source_p) ||
1148        ((can_send(chptr, source_p, ms, reason) &&
1149 <       (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time)
1149 >       (source_p->connection->firsttime + ConfigGeneral.anti_spam_exit_message_time)
1150          < CurrentTime))))
1151    {
1152      sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s :%s",
1153 <                  source_p->id, chptr->chname, reason);
1153 >                  source_p->id, chptr->name, reason);
1154      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s :%s",
1155                           source_p->name, source_p->username,
1156 <                         source_p->host, chptr->chname, reason);
1156 >                         source_p->host, chptr->name, reason);
1157    }
1158    else
1159    {
1160      sendto_server(source_p, NOCAPS, NOCAPS, ":%s PART %s",
1161 <                  source_p->id, chptr->chname);
1161 >                  source_p->id, chptr->name);
1162      sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s!%s@%s PART %s",
1163                           source_p->name, source_p->username,
1164 <                         source_p->host, chptr->chname);
1164 >                         source_p->host, chptr->name);
1165    }
1166  
1167    remove_user_from_channel(ms);

Diff Legend

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