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 6681 by michael, Tue Oct 27 19:52:44 2015 UTC vs.
Revision 6682 by michael, Tue Oct 27 20:29:48 2015 UTC

# Line 745 | Line 745 | can_send(struct Channel *chptr, struct C
745    if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE))
746      return CAN_SEND_OPV;
747  
748 <  if (MyClient(cliente_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
748 >  if (MyClient(client_p) && !HasFlag(client_p, FLAGS_EXEMPTRESV))
749      if (!(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)))
750        if ((conf = match_find_resv(chptr->name)) && !resv_find_exempt(client_p, conf))
751          return ERR_CANNOTSENDTOCHAN;
# Line 799 | Line 799 | can_send(struct Channel *chptr, struct C
799   /*! \brief Updates the client's oper_warn_count_down, warns the
800   *         IRC operators if necessary, and updates
801   *         join_leave_countdown as needed.
802 < * \param source_p Pointer to struct Client to check
802 > * \param client_p Pointer to struct Client to check
803   * \param name     Channel name or NULL if this is a part.
804   */
805   void
806 < check_spambot_warning(struct Client *source_p, const char *name)
806 > check_spambot_warning(struct Client *client_p, const char *name)
807   {
808    int t_delta = 0;
809    int decrement_count = 0;
810  
811    if ((GlobalSetOptions.spam_num &&
812 <       (source_p->connection->join_leave_count >=
812 >       (client_p->connection->join_leave_count >=
813          GlobalSetOptions.spam_num)))
814    {
815 <    if (source_p->connection->oper_warn_count_down > 0)
816 <      source_p->connection->oper_warn_count_down--;
815 >    if (client_p->connection->oper_warn_count_down > 0)
816 >      client_p->connection->oper_warn_count_down--;
817      else
818 <      source_p->connection->oper_warn_count_down = 0;
818 >      client_p->connection->oper_warn_count_down = 0;
819  
820 <    if (source_p->connection->oper_warn_count_down == 0)
820 >    if (client_p->connection->oper_warn_count_down == 0)
821      {
822        /* It's already known as a possible spambot */
823        if (name)
824          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
825                               "User %s (%s@%s) trying to join %s is a possible spambot",
826 <                             source_p->name, source_p->username,
827 <                             source_p->host, name);
826 >                             client_p->name, client_p->username,
827 >                             client_p->host, name);
828        else
829          sendto_realops_flags(UMODE_BOTS, L_ALL, SEND_NOTICE,
830                               "User %s (%s@%s) is a possible spambot",
831 <                             source_p->name, source_p->username,
832 <                             source_p->host);
833 <      source_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
831 >                             client_p->name, client_p->username,
832 >                             client_p->host);
833 >      client_p->connection->oper_warn_count_down = OPER_SPAM_COUNTDOWN;
834      }
835    }
836    else
837    {
838 <    if ((t_delta = (CurrentTime - source_p->connection->last_leave_time)) >
838 >    if ((t_delta = (CurrentTime - client_p->connection->last_leave_time)) >
839           JOIN_LEAVE_COUNT_EXPIRE_TIME)
840      {
841        decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME);
842  
843 <      if (decrement_count > source_p->connection->join_leave_count)
844 <        source_p->connection->join_leave_count = 0;
843 >      if (decrement_count > client_p->connection->join_leave_count)
844 >        client_p->connection->join_leave_count = 0;
845        else
846 <        source_p->connection->join_leave_count -= decrement_count;
846 >        client_p->connection->join_leave_count -= decrement_count;
847      }
848      else
849      {
850 <      if ((CurrentTime - (source_p->connection->last_join_time)) <
850 >      if ((CurrentTime - (client_p->connection->last_join_time)) <
851            GlobalSetOptions.spam_time)
852 <        source_p->connection->join_leave_count++;  /* It's a possible spambot */
852 >        client_p->connection->join_leave_count++;  /* It's a possible spambot */
853      }
854  
855      if (name)
856 <      source_p->connection->last_join_time = CurrentTime;
856 >      client_p->connection->last_join_time = CurrentTime;
857      else
858 <      source_p->connection->last_leave_time = CurrentTime;
858 >      client_p->connection->last_leave_time = CurrentTime;
859    }
860   }
861  
# Line 889 | Line 889 | channel_set_topic(struct Channel *chptr,
889   *                anti spambot code.
890   */
891   void
892 < channel_do_join_0(struct Client *source_p)
892 > channel_do_join_0(struct Client *client_p)
893   {
894    dlink_node *node = NULL, *node_next = NULL;
895  
896 <  if (source_p->channel.head)
897 <    if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
898 <      check_spambot_warning(source_p, NULL);
896 >  if (client_p->channel.head)
897 >    if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
898 >      check_spambot_warning(client_p, NULL);
899  
900 <  DLINK_FOREACH_SAFE(node, node_next, source_p->channel.head)
900 >  DLINK_FOREACH_SAFE(node, node_next, client_p->channel.head)
901    {
902      struct Channel *chptr = ((struct Membership *)node->data)->chptr;
903  
904 <    sendto_server(source_p, 0, 0, ":%s PART %s",
905 <                  source_p->id, chptr->name);
904 >    sendto_server(client_p, 0, 0, ":%s PART %s",
905 >                  client_p->id, chptr->name);
906      sendto_channel_local(0, chptr, ":%s!%s@%s PART %s",
907 <                         source_p->name, source_p->username,
908 <                         source_p->host, chptr->name);
907 >                         client_p->name, client_p->username,
908 >                         client_p->host, chptr->name);
909  
910      remove_user_from_channel(node->data);
911    }
912   }
913  
914   static char *
915 < channel_find_last0(struct Client *source_p, char *chanlist)
915 > channel_find_last0(struct Client *client_p, char *chanlist)
916   {
917    int join0 = 0;
918  
# Line 937 | Line 937 | channel_find_last0(struct Client *source
937    }
938  
939    if (join0)
940 <    channel_do_join_0(source_p);
940 >    channel_do_join_0(client_p);
941  
942    return chanlist;
943   }
944  
945   void
946 < channel_do_join(struct Client *source_p, char *channel, char *key_list)
946 > channel_do_join(struct Client *client_p, char *channel, char *key_list)
947   {
948    char *p = NULL;
949    char *chan = NULL;
950    char *chan_list = NULL;
951    struct Channel *chptr = NULL;
952    struct MaskItem *conf = NULL;
953 <  const struct ClassItem *const class = get_class_ptr(&source_p->connection->confs);
953 >  const struct ClassItem *const class = get_class_ptr(&client_p->connection->confs);
954    int i = 0;
955    unsigned int flags = 0;
956  
957 <  assert(IsClient(source_p));
957 >  assert(IsClient(client_p));
958  
959 <  chan_list = channel_find_last0(source_p, channel);
959 >  chan_list = channel_find_last0(client_p, channel);
960  
961    for (chan = strtok_r(chan_list, ",", &p); chan;
962         chan = strtok_r(NULL,      ",", &p))
# Line 973 | Line 973 | channel_do_join(struct Client *source_p,
973  
974      if (!channel_check_name(chan, 1))
975      {
976 <      sendto_one_numeric(source_p, &me, ERR_BADCHANNAME, chan);
976 >      sendto_one_numeric(client_p, &me, ERR_BADCHANNAME, chan);
977        continue;
978      }
979  
980 <    if (!HasFlag(source_p, FLAGS_EXEMPTRESV) &&
981 <        !(HasUMode(source_p, UMODE_OPER) && HasOFlag(source_p, OPER_FLAG_JOIN_RESV)) &&
982 <        ((conf = match_find_resv(chan)) && !resv_find_exempt(source_p, conf)))
980 >    if (!HasFlag(client_p, FLAGS_EXEMPTRESV) &&
981 >        !(HasUMode(client_p, UMODE_OPER) && HasOFlag(client_p, OPER_FLAG_JOIN_RESV)) &&
982 >        ((conf = match_find_resv(chan)) && !resv_find_exempt(client_p, conf)))
983      {
984        ++conf->count;
985 <      sendto_one_numeric(source_p, &me, ERR_CHANBANREASON, chan, conf->reason);
985 >      sendto_one_numeric(client_p, &me, ERR_CHANBANREASON, chan, conf->reason);
986        sendto_realops_flags(UMODE_REJ, L_ALL, SEND_NOTICE,
987                             "Forbidding reserved channel %s from user %s",
988 <                           chan, get_client_name(source_p, HIDE_IP));
988 >                           chan, get_client_name(client_p, HIDE_IP));
989        continue;
990      }
991  
992 <    if (dlink_list_length(&source_p->channel) >=
992 >    if (dlink_list_length(&client_p->channel) >=
993          ((class->max_channels) ? class->max_channels : ConfigChannel.max_channels))
994      {
995 <      sendto_one_numeric(source_p, &me, ERR_TOOMANYCHANNELS, chan);
995 >      sendto_one_numeric(client_p, &me, ERR_TOOMANYCHANNELS, chan);
996        break;
997      }
998  
999      if ((chptr = hash_find_channel(chan)))
1000      {
1001 <      if (IsMember(source_p, chptr))
1001 >      if (IsMember(client_p, chptr))
1002          continue;
1003  
1004        /*
1005         * can_join checks for +i key, bans.
1006         */
1007 <      if ((i = can_join(source_p, chptr, key)))
1007 >      if ((i = can_join(client_p, chptr, key)))
1008        {
1009 <        sendto_one_numeric(source_p, &me, i, chptr->name);
1009 >        sendto_one_numeric(client_p, &me, i, chptr->name);
1010          continue;
1011        }
1012  
# Line 1025 | Line 1025 | channel_do_join(struct Client *source_p,
1025        chptr = channel_make(chan);
1026      }
1027  
1028 <    if (!HasUMode(source_p, UMODE_OPER))
1029 <      check_spambot_warning(source_p, chptr->name);
1028 >    if (!HasUMode(client_p, UMODE_OPER))
1029 >      check_spambot_warning(client_p, chptr->name);
1030  
1031 <    add_user_to_channel(chptr, source_p, flags, 1);
1031 >    add_user_to_channel(chptr, client_p, flags, 1);
1032  
1033      /*
1034       * Set timestamp if appropriate, and propagate
# Line 1039 | Line 1039 | channel_do_join(struct Client *source_p,
1039        chptr->mode.mode |= MODE_TOPICLIMIT;
1040        chptr->mode.mode |= MODE_NOPRIVMSGS;
1041  
1042 <      sendto_server(source_p, 0, 0, ":%s SJOIN %lu %s +nt :@%s",
1042 >      sendto_server(client_p, 0, 0, ":%s SJOIN %lu %s +nt :@%s",
1043                      me.id, (unsigned long)chptr->creationtime,
1044 <                    chptr->name, source_p->id);
1044 >                    chptr->name, client_p->id);
1045  
1046        /*
1047         * Notify all other users on the new channel
1048         */
1049        sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s",
1050 <                                  source_p->name, source_p->username,
1051 <                                  source_p->host, chptr->name,
1052 <                                  (!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*",
1053 <                                  source_p->info);
1050 >                                  client_p->name, client_p->username,
1051 >                                  client_p->host, chptr->name,
1052 >                                  (!IsDigit(client_p->account[0]) && client_p->account[0] != '*') ? client_p->account : "*",
1053 >                                  client_p->info);
1054        sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s",
1055 <                                  source_p->name, source_p->username,
1056 <                                  source_p->host, chptr->name);
1055 >                                  client_p->name, client_p->username,
1056 >                                  client_p->host, chptr->name);
1057        sendto_channel_local(0, chptr, ":%s MODE %s +nt",
1058                             me.name, chptr->name);
1059  
1060 <      if (source_p->away[0])
1061 <        sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr,
1060 >      if (client_p->away[0])
1061 >        sendto_channel_local_butone(client_p, CAP_AWAY_NOTIFY, 0, chptr,
1062                                      ":%s!%s@%s AWAY :%s",
1063 <                                    source_p->name, source_p->username,
1064 <                                    source_p->host, source_p->away);
1063 >                                    client_p->name, client_p->username,
1064 >                                    client_p->host, client_p->away);
1065      }
1066      else
1067      {
1068 <      sendto_server(source_p, 0, 0, ":%s JOIN %lu %s +",
1069 <                    source_p->id, (unsigned long)chptr->creationtime,
1068 >      sendto_server(client_p, 0, 0, ":%s JOIN %lu %s +",
1069 >                    client_p->id, (unsigned long)chptr->creationtime,
1070                      chptr->name);
1071  
1072        sendto_channel_local_butone(NULL, CAP_EXTENDED_JOIN, 0, chptr, ":%s!%s@%s JOIN %s %s :%s",
1073 <                                  source_p->name, source_p->username,
1074 <                                  source_p->host, chptr->name,
1075 <                                  (!IsDigit(source_p->account[0]) && source_p->account[0] != '*') ? source_p->account : "*",
1076 <                                  source_p->info);
1073 >                                  client_p->name, client_p->username,
1074 >                                  client_p->host, chptr->name,
1075 >                                  (!IsDigit(client_p->account[0]) && client_p->account[0] != '*') ? client_p->account : "*",
1076 >                                  client_p->info);
1077        sendto_channel_local_butone(NULL, 0, CAP_EXTENDED_JOIN, chptr, ":%s!%s@%s JOIN :%s",
1078 <                                  source_p->name, source_p->username,
1079 <                                  source_p->host, chptr->name);
1078 >                                  client_p->name, client_p->username,
1079 >                                  client_p->host, chptr->name);
1080  
1081 <      if (source_p->away[0])
1082 <        sendto_channel_local_butone(source_p, CAP_AWAY_NOTIFY, 0, chptr,
1081 >      if (client_p->away[0])
1082 >        sendto_channel_local_butone(client_p, CAP_AWAY_NOTIFY, 0, chptr,
1083                                      ":%s!%s@%s AWAY :%s",
1084 <                                    source_p->name, source_p->username,
1085 <                                    source_p->host, source_p->away);
1084 >                                    client_p->name, client_p->username,
1085 >                                    client_p->host, client_p->away);
1086      }
1087  
1088 <    del_invite(chptr, source_p);
1088 >    del_invite(chptr, client_p);
1089  
1090      if (chptr->topic[0])
1091      {
1092 <      sendto_one_numeric(source_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1093 <      sendto_one_numeric(source_p, &me, RPL_TOPICWHOTIME, chptr->name,
1092 >      sendto_one_numeric(client_p, &me, RPL_TOPIC, chptr->name, chptr->topic);
1093 >      sendto_one_numeric(client_p, &me, RPL_TOPICWHOTIME, chptr->name,
1094                           chptr->topic_info, chptr->topic_time);
1095      }
1096  
1097 <    channel_member_names(source_p, chptr, 1);
1097 >    channel_member_names(client_p, chptr, 1);
1098  
1099 <    source_p->connection->last_join_time = CurrentTime;
1099 >    client_p->connection->last_join_time = CurrentTime;
1100    }
1101   }
1102  
1103   /*! \brief Removes a client from a specific channel
1104 < * \param source_p Pointer to source client to remove
1104 > * \param client_p Pointer to source client to remove
1105   * \param name     Name of channel to remove from
1106   * \param reason   Part reason to show
1107   */
1108   static void
1109 < channel_part_one_client(struct Client *source_p, const char *name, const char *reason)
1109 > channel_part_one_client(struct Client *client_p, const char *name, const char *reason)
1110   {
1111    struct Channel *chptr = NULL;
1112    struct Membership *member = NULL;
1113  
1114    if ((chptr = hash_find_channel(name)) == NULL)
1115    {
1116 <    sendto_one_numeric(source_p, &me, ERR_NOSUCHCHANNEL, name);
1116 >    sendto_one_numeric(client_p, &me, ERR_NOSUCHCHANNEL, name);
1117      return;
1118    }
1119  
1120 <  if ((member = find_channel_link(source_p, chptr)) == NULL)
1120 >  if ((member = find_channel_link(client_p, chptr)) == NULL)
1121    {
1122 <    sendto_one_numeric(source_p, &me, ERR_NOTONCHANNEL, chptr->name);
1122 >    sendto_one_numeric(client_p, &me, ERR_NOTONCHANNEL, chptr->name);
1123      return;
1124    }
1125  
1126 <  if (MyConnect(source_p) && !HasUMode(source_p, UMODE_OPER))
1127 <    check_spambot_warning(source_p, NULL);
1126 >  if (MyConnect(client_p) && !HasUMode(client_p, UMODE_OPER))
1127 >    check_spambot_warning(client_p, NULL);
1128  
1129    /*
1130     * Remove user from the old channel (if any)
1131     * only allow /part reasons in -m chans
1132     */
1133 <  if (*reason && (!MyConnect(source_p) ||
1134 <      ((can_send(chptr, source_p, member, reason) &&
1135 <       (source_p->connection->firsttime + ConfigGeneral.anti_spam_exit_message_time)
1133 >  if (*reason && (!MyConnect(client_p) ||
1134 >      ((can_send(chptr, client_p, member, reason) &&
1135 >       (client_p->connection->firsttime + ConfigGeneral.anti_spam_exit_message_time)
1136          < CurrentTime))))
1137    {
1138 <    sendto_server(source_p, 0, 0, ":%s PART %s :%s",
1139 <                  source_p->id, chptr->name, reason);
1138 >    sendto_server(client_p, 0, 0, ":%s PART %s :%s",
1139 >                  client_p->id, chptr->name, reason);
1140      sendto_channel_local(0, chptr, ":%s!%s@%s PART %s :%s",
1141 <                         source_p->name, source_p->username,
1142 <                         source_p->host, chptr->name, reason);
1141 >                         client_p->name, client_p->username,
1142 >                         client_p->host, chptr->name, reason);
1143    }
1144    else
1145    {
1146 <    sendto_server(source_p, 0, 0, ":%s PART %s",
1147 <                  source_p->id, chptr->name);
1146 >    sendto_server(client_p, 0, 0, ":%s PART %s",
1147 >                  client_p->id, chptr->name);
1148      sendto_channel_local(0, chptr, ":%s!%s@%s PART %s",
1149 <                         source_p->name, source_p->username,
1150 <                         source_p->host, chptr->name);
1149 >                         client_p->name, client_p->username,
1150 >                         client_p->host, chptr->name);
1151    }
1152  
1153    remove_user_from_channel(member);
1154   }
1155  
1156   void
1157 < channel_do_part(struct Client *source_p, char *channel, const char *reason)
1157 > channel_do_part(struct Client *client_p, char *channel, const char *reason)
1158   {
1159    char *p = NULL, *name = NULL;
1160    char buf[KICKLEN + 1] = "";
1161  
1162 <  assert(IsClient(source_p));
1162 >  assert(IsClient(client_p));
1163  
1164    if (!EmptyString(reason))
1165      strlcpy(buf, reason, sizeof(buf));
1166  
1167    for (name = strtok_r(channel, ",", &p); name;
1168         name = strtok_r(NULL,    ",", &p))
1169 <    channel_part_one_client(source_p, name, buf);
1169 >    channel_part_one_client(client_p, name, buf);
1170   }

Diff Legend

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