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
00026 static void cmd_pls_noteign(struct userrec *u, int idx, char *par)
00027 {
00028 struct userrec *u2;
00029 char *handle, *mask, *buf, *p;
00030
00031 if (!par[0]) {
00032 dprintf(idx, "%s: +noteign [handle] <ignoremask>\n", NOTES_USAGE);
00033 return;
00034 }
00035 putlog(LOG_CMDS, "*", "#%s# +noteign %s", dcc[idx].nick, par);
00036
00037 p = buf = nmalloc(strlen(par) + 1);
00038 strcpy(p, par);
00039 handle = newsplit(&p);
00040 mask = newsplit(&p);
00041 if (mask[0]) {
00042 u2 = get_user_by_handle(userlist, handle);
00043 if (u != u2) {
00044 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
00045
00046 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
00047 if (!(glob_master(fr) || glob_owner(fr))) {
00048 dprintf(idx, NOTES_IGN_OTHERS, handle);
00049 nfree(buf);
00050 return;
00051 }
00052 }
00053 if (!u2) {
00054 dprintf(idx, NOTES_UNKNOWN_USER, handle);
00055 nfree(buf);
00056 return;
00057 }
00058 } else {
00059 u2 = u;
00060 mask = handle;
00061 }
00062 if (add_note_ignore(u2, mask))
00063 dprintf(idx, NOTES_IGN_NEW, mask);
00064 else
00065 dprintf(idx, NOTES_IGN_ALREADY, mask);
00066 nfree(buf);
00067 return;
00068 }
00069
00070 static void cmd_mns_noteign(struct userrec *u, int idx, char *par)
00071 {
00072 struct userrec *u2;
00073 char *handle, *mask, *buf, *p;
00074
00075 if (!par[0]) {
00076 dprintf(idx, "%s: -noteign [handle] <ignoremask>\n", NOTES_USAGE);
00077 return;
00078 }
00079 putlog(LOG_CMDS, "*", "#%s# -noteign %s", dcc[idx].nick, par);
00080 p = buf = nmalloc(strlen(par) + 1);
00081 strcpy(p, par);
00082 handle = newsplit(&p);
00083 mask = newsplit(&p);
00084 if (mask[0]) {
00085 u2 = get_user_by_handle(userlist, handle);
00086 if (u != u2) {
00087 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
00088
00089 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
00090 if (!(glob_master(fr) || glob_owner(fr))) {
00091 dprintf(idx, NOTES_IGN_OTHERS, handle);
00092 nfree(buf);
00093 return;
00094 }
00095 }
00096 if (!u2) {
00097 dprintf(idx, NOTES_UNKNOWN_USER, handle);
00098 nfree(buf);
00099 return;
00100 }
00101 } else {
00102 u2 = u;
00103 mask = handle;
00104 }
00105
00106 if (del_note_ignore(u2, mask))
00107 dprintf(idx, NOTES_IGN_REM, mask);
00108 else
00109 dprintf(idx, NOTES_IGN_NOTFOUND, mask);
00110 nfree(buf);
00111 return;
00112 }
00113
00114 static void cmd_noteigns(struct userrec *u, int idx, char *par)
00115 {
00116 struct userrec *u2;
00117 char **ignores;
00118 int ignoresn, i;
00119
00120 if (par[0]) {
00121 u2 = get_user_by_handle(userlist, par);
00122 if (u != u2) {
00123 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
00124
00125 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
00126 if (!(glob_master(fr) || glob_owner(fr))) {
00127 dprintf(idx, NOTES_IGN_OTHERS, par);
00128 return;
00129 }
00130 }
00131 if (!u2) {
00132 dprintf(idx, NOTES_UNKNOWN_USER, par);
00133 return;
00134 }
00135 } else
00136 u2 = u;
00137
00138 ignoresn = get_note_ignores(u2, &ignores);
00139 if (!ignoresn) {
00140 dprintf(idx, "%s", NOTES_IGN_NONE);
00141 return;
00142 }
00143 putlog(LOG_CMDS, "*", "#%s# noteigns %s", dcc[idx].nick, par);
00144 dprintf(idx, NOTES_IGN_FOR, u2->handle);
00145 for (i = 0; i < ignoresn; i++)
00146 dprintf(idx, " %s", ignores[i]);
00147 dprintf(idx, "\n");
00148 nfree(ignores[0]);
00149 nfree(ignores);
00150 }
00151
00152 static void cmd_fwd(struct userrec *u, int idx, char *par)
00153 {
00154 char *handle;
00155 struct userrec *u1;
00156
00157 if (!par[0]) {
00158 dprintf(idx, "%s: fwd <handle> [user@bot]\n", NOTES_USAGE);
00159 return;
00160 }
00161 handle = newsplit(&par);
00162 u1 = get_user_by_handle(userlist, handle);
00163 if (!u1) {
00164 dprintf(idx, "%s\n", NOTES_NO_SUCH_USER);
00165 return;
00166 }
00167 if ((u1->flags & USER_OWNER) && egg_strcasecmp(handle, dcc[idx].nick)) {
00168 dprintf(idx, "%s\n", NOTES_FWD_OWNER);
00169 return;
00170 }
00171 if (!par[0]) {
00172 putlog(LOG_CMDS, "*", "#%s# fwd %s", dcc[idx].nick, handle);
00173 dprintf(idx, NOTES_FWD_FOR, handle);
00174 set_user(&USERENTRY_FWD, u1, NULL);
00175 return;
00176 }
00177
00178 if (strchr(par, '@') == NULL) {
00179 dprintf(idx, "%s\n", NOTES_FWD_BOTNAME);
00180 return;
00181 }
00182 putlog(LOG_CMDS, "*", "#%s# fwd %s %s", dcc[idx].nick, handle, par);
00183 dprintf(idx, NOTES_FWD_CHANGED, handle, par);
00184 set_user(&USERENTRY_FWD, u1, par);
00185 }
00186
00187 static void cmd_notes(struct userrec *u, int idx, char *par)
00188 {
00189 char *fcn;
00190
00191 if (!par[0]) {
00192 dprintf(idx, "%s: notes index\n", NOTES_USAGE);
00193 dprintf(idx, " notes read <# or ALL>\n");
00194 dprintf(idx, " notes erase <# or ALL>\n");
00195 dprintf(idx, " %s\n", NOTES_MAYBE);
00196 dprintf(idx, " ex: notes erase 2-4;8;16-\n");
00197 return;
00198 }
00199 fcn = newsplit(&par);
00200 if (!egg_strcasecmp(fcn, "index"))
00201 notes_read(dcc[idx].nick, "", "+", idx);
00202 else if (!egg_strcasecmp(fcn, "read")) {
00203 if (!egg_strcasecmp(par, "all"))
00204 notes_read(dcc[idx].nick, "", "-", idx);
00205 else
00206 notes_read(dcc[idx].nick, "", par, idx);
00207 } else if (!egg_strcasecmp(fcn, "erase")) {
00208 if (!egg_strcasecmp(par, "all"))
00209 notes_del(dcc[idx].nick, "", "-", idx);
00210 else
00211 notes_del(dcc[idx].nick, "", par, idx);
00212 } else {
00213 dprintf(idx, "%s\n", NOTES_MUSTBE);
00214 return;
00215 }
00216 putlog(LOG_CMDS, "*", "#%s# notes %s %s", dcc[idx].nick, fcn, par);
00217 }
00218
00219 static void cmd_note(struct userrec *u, int idx, char *par)
00220 {
00221 char handle[512], *p;
00222 int echo;
00223
00224 p = newsplit(&par);
00225 if (!par[0]) {
00226 dprintf(idx, "%s: note <to-whom> <message>\n", NOTES_USAGE);
00227 return;
00228 }
00229 while ((*par == ' ') || (*par == '<') || (*par == '>'))
00230 par++;
00231 echo = (dcc[idx].status & STAT_ECHO);
00232 splitc(handle, p, ',');
00233 while (handle[0]) {
00234 rmspace(handle);
00235 add_note(handle, dcc[idx].nick, par, idx, echo);
00236 splitc(handle, p, ',');
00237 }
00238 rmspace(p);
00239 add_note(p, dcc[idx].nick, par, idx, echo);
00240 }
00241
00242 static cmd_t notes_cmds[] = {
00243 {"fwd", "m", (IntFunc) cmd_fwd, NULL},
00244 {"notes", "", (IntFunc) cmd_notes, NULL},
00245 {"+noteign", "", (IntFunc) cmd_pls_noteign, NULL},
00246 {"-noteign", "", (IntFunc) cmd_mns_noteign, NULL},
00247 {"noteigns", "", (IntFunc) cmd_noteigns, NULL},
00248 {"note", "", (IntFunc) cmd_note, NULL},
00249 {NULL, NULL, NULL, NULL}
00250 };