00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "stdinc.h"
00026 #include "handlers.h"
00027 #include "client.h"
00028 #include "irc_string.h"
00029 #include "sprintf_irc.h"
00030 #include "hash.h"
00031 #include "ircd.h"
00032 #include "list.h"
00033 #include "numeric.h"
00034 #include "s_conf.h"
00035 #include "s_serv.h"
00036 #include "send.h"
00037 #include "msg.h"
00038 #include "parse.h"
00039 #include "s_user.h"
00040 #include "modules.h"
00041
00042 static void m_accept(struct Client *, struct Client *, int, char *[]);
00043 static void build_nicklist(struct Client *, char *, char *, char *);
00044 static void add_accept(struct Client *, struct Client *);
00045 static void list_accepts(struct Client *);
00046
00047 struct Message accept_msgtab = {
00048 "ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0,
00049 {m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore}
00050 };
00051
00052 #ifndef STATIC_MODULES
00053 void
00054 _modinit(void)
00055 {
00056 mod_add_cmd(&accept_msgtab);
00057 }
00058
00059 void
00060 _moddeinit(void)
00061 {
00062 mod_del_cmd(&accept_msgtab);
00063 }
00064
00065 const char *_version = "$Revision: 33 $";
00066 #endif
00067
00068
00069
00070
00071
00072
00073 static void
00074 m_accept(struct Client *client_p, struct Client *source_p,
00075 int parc, char *parv[])
00076 {
00077 char *nick;
00078 char *p = NULL;
00079 char addbuf[IRCD_BUFSIZE] = { '\0' };
00080 char delbuf[IRCD_BUFSIZE] = { '\0' };
00081 struct Client *target_p = NULL;
00082 int accept_num;
00083
00084 if ((parc < 2) || (*parv[1] == '*'))
00085 {
00086 list_accepts(source_p);
00087 return;
00088 }
00089
00090 build_nicklist(source_p, addbuf, delbuf, parv[1]);
00091
00092
00093 for (nick = strtoken(&p, delbuf, ","); nick != NULL;
00094 nick = strtoken(&p, NULL, ","))
00095 {
00096
00097 if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
00098 {
00099 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
00100 me.name, source_p->name, nick);
00101 continue;
00102 }
00103
00104
00105 if (!accept_message(target_p, source_p))
00106 {
00107 sendto_one(source_p, form_str(ERR_ACCEPTNOT),
00108 me.name, source_p->name, target_p->name);
00109 continue;
00110 }
00111
00112 del_from_accept(target_p, source_p);
00113 }
00114
00115
00116 accept_num = dlink_list_length(&source_p->allow_list);
00117
00118
00119 for (nick = strtoken(&p, addbuf, ","); nick;
00120 nick = strtoken(&p, NULL, ","), accept_num++)
00121 {
00122
00123 if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p))
00124 {
00125 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
00126 me.name, source_p->name, nick);
00127 continue;
00128 }
00129
00130
00131 if (accept_message(target_p, source_p))
00132 {
00133 sendto_one(source_p, form_str(ERR_ACCEPTEXIST),
00134 me.name, source_p->name, target_p->name);
00135 continue;
00136 }
00137
00138 if (accept_num >= ConfigFileEntry.max_accept)
00139 {
00140 sendto_one(source_p, form_str(ERR_ACCEPTFULL),
00141 me.name, source_p->name);
00142 return;
00143 }
00144
00145
00146
00147 add_accept(source_p, target_p);
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 static void
00161 build_nicklist(struct Client *source_p, char *addbuf,
00162 char *delbuf, char *nicks)
00163 {
00164 char *name = NULL;
00165 char *p = NULL;
00166 char *buf_p = NULL;
00167 struct Client *target_p = NULL;
00168
00169
00170 for (name = strtoken(&p, nicks, ","); name;
00171 name = strtoken(&p, NULL, ","))
00172 {
00173 if (*name == '-')
00174 buf_p = delbuf, ++name;
00175 else
00176 buf_p = addbuf;
00177
00178 if (((target_p = find_client(name)) == NULL) || !IsClient(target_p))
00179 {
00180 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
00181 me.name, source_p->name, name);
00182 continue;
00183 }
00184
00185 if (*buf_p)
00186 strlcat(buf_p, ",", IRCD_BUFSIZE);
00187 strlcat(buf_p, name, IRCD_BUFSIZE);
00188 }
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198 static void
00199 add_accept(struct Client *source_p, struct Client *target_p)
00200 {
00201 dlinkAdd(target_p, make_dlink_node(), &source_p->allow_list);
00202 dlinkAdd(source_p, make_dlink_node(), &target_p->on_allow_list);
00203 list_accepts(source_p);
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 static void
00213 list_accepts(struct Client *source_p)
00214 {
00215 int len = 0;
00216 char nicks[IRCD_BUFSIZE] = { '\0' };
00217 char *t = nicks;
00218 const dlink_node *ptr = NULL;
00219
00220 len = strlen(me.name) + strlen(source_p->name) + 12;
00221
00222 DLINK_FOREACH(ptr, source_p->allow_list.head)
00223 {
00224 const struct Client *target_p = ptr->data;
00225
00226 if ((t - nicks) + strlen(target_p->name) + len > IRCD_BUFSIZE)
00227 {
00228 *(t - 1) = '\0';
00229 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
00230 me.name, source_p->name, nicks);
00231 t = nicks;
00232 }
00233
00234 t += ircsprintf(t, "%s ", target_p->name);
00235 }
00236
00237 if (nicks[0] != '\0')
00238 {
00239 *(t - 1) = '\0';
00240 sendto_one(source_p, form_str(RPL_ACCEPTLIST),
00241 me.name, source_p->name, nicks);
00242 }
00243
00244 sendto_one(source_p, form_str(RPL_ENDOFACCEPT),
00245 me.name, source_p->name);
00246 }