1 /*
2 * cmdsnote.c -- part of notes.mod
3 * handles all notes interaction over the party line
4 */
5 /*
6 * Copyright (C) 1997 Robey Pointer
7 * Copyright (C) 1999 - 2021 Eggheads Development Team
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
cmd_pls_noteign(struct userrec * u,int idx,char * par)24 static void cmd_pls_noteign(struct userrec *u, int idx, char *par)
25 {
26 struct userrec *u2;
27 char *handle, *mask, *buf, *p;
28
29 if (!par[0]) {
30 dprintf(idx, "%s: +noteign [handle] <ignoremask>\n", NOTES_USAGE);
31 return;
32 }
33 putlog(LOG_CMDS, "*", "#%s# +noteign %s", dcc[idx].nick, par);
34
35 p = buf = nmalloc(strlen(par) + 1);
36 strcpy(p, par);
37 handle = newsplit(&p);
38 mask = newsplit(&p);
39 if (mask[0]) {
40 u2 = get_user_by_handle(userlist, handle);
41 if (u != u2) {
42 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
43
44 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
45 if (!(glob_master(fr) || glob_owner(fr))) {
46 dprintf(idx, NOTES_IGN_OTHERS, handle);
47 nfree(buf);
48 return;
49 }
50 }
51 if (!u2) {
52 dprintf(idx, NOTES_UNKNOWN_USER, handle);
53 nfree(buf);
54 return;
55 }
56 } else {
57 u2 = u;
58 mask = handle;
59 }
60 if (add_note_ignore(u2, mask))
61 dprintf(idx, NOTES_IGN_NEW, mask);
62 else
63 dprintf(idx, NOTES_IGN_ALREADY, mask);
64 nfree(buf);
65 return;
66 }
67
cmd_mns_noteign(struct userrec * u,int idx,char * par)68 static void cmd_mns_noteign(struct userrec *u, int idx, char *par)
69 {
70 struct userrec *u2;
71 char *handle, *mask, *buf, *p;
72
73 if (!par[0]) {
74 dprintf(idx, "%s: -noteign [handle] <ignoremask>\n", NOTES_USAGE);
75 return;
76 }
77 putlog(LOG_CMDS, "*", "#%s# -noteign %s", dcc[idx].nick, par);
78 p = buf = nmalloc(strlen(par) + 1);
79 strcpy(p, par);
80 handle = newsplit(&p);
81 mask = newsplit(&p);
82 if (mask[0]) {
83 u2 = get_user_by_handle(userlist, handle);
84 if (u != u2) {
85 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
86
87 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
88 if (!(glob_master(fr) || glob_owner(fr))) {
89 dprintf(idx, NOTES_IGN_OTHERS, handle);
90 nfree(buf);
91 return;
92 }
93 }
94 if (!u2) {
95 dprintf(idx, NOTES_UNKNOWN_USER, handle);
96 nfree(buf);
97 return;
98 }
99 } else {
100 u2 = u;
101 mask = handle;
102 }
103
104 if (del_note_ignore(u2, mask))
105 dprintf(idx, NOTES_IGN_REM, mask);
106 else
107 dprintf(idx, NOTES_IGN_NOTFOUND, mask);
108 nfree(buf);
109 return;
110 }
111
cmd_noteigns(struct userrec * u,int idx,char * par)112 static void cmd_noteigns(struct userrec *u, int idx, char *par)
113 {
114 struct userrec *u2;
115 char **ignores;
116 int ignoresn, i;
117
118 if (par[0]) {
119 u2 = get_user_by_handle(userlist, par);
120 if (u != u2) {
121 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
122
123 get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
124 if (!(glob_master(fr) || glob_owner(fr))) {
125 dprintf(idx, NOTES_IGN_OTHERS, par);
126 return;
127 }
128 }
129 if (!u2) {
130 dprintf(idx, NOTES_UNKNOWN_USER, par);
131 return;
132 }
133 } else
134 u2 = u;
135
136 ignoresn = get_note_ignores(u2, &ignores);
137 if (!ignoresn) {
138 dprintf(idx, "%s", NOTES_IGN_NONE);
139 return;
140 }
141 putlog(LOG_CMDS, "*", "#%s# noteigns %s", dcc[idx].nick, par);
142 dprintf(idx, NOTES_IGN_FOR, u2->handle);
143 for (i = 0; i < ignoresn; i++)
144 dprintf(idx, " %s", ignores[i]);
145 dprintf(idx, "\n");
146 nfree(ignores[0]); /* Free the string buffer */
147 nfree(ignores); /* Free the ptr array */
148 }
149
cmd_fwd(struct userrec * u,int idx,char * par)150 static void cmd_fwd(struct userrec *u, int idx, char *par)
151 {
152 char *handle;
153 struct userrec *u1;
154
155 if (!par[0]) {
156 dprintf(idx, "%s: fwd <handle> [user@bot]\n", NOTES_USAGE);
157 return;
158 }
159 handle = newsplit(&par);
160 u1 = get_user_by_handle(userlist, handle);
161 if (!u1) {
162 dprintf(idx, "%s\n", NOTES_NO_SUCH_USER);
163 return;
164 }
165 if ((u1->flags & USER_OWNER) && strcasecmp(handle, dcc[idx].nick)) {
166 dprintf(idx, "%s\n", NOTES_FWD_OWNER);
167 return;
168 }
169 if (!par[0]) {
170 putlog(LOG_CMDS, "*", "#%s# fwd %s", dcc[idx].nick, handle);
171 dprintf(idx, NOTES_FWD_FOR, handle);
172 set_user(&USERENTRY_FWD, u1, NULL);
173 return;
174 }
175 /* Thanks to vertex & dw */
176 if (strchr(par, '@') == NULL) {
177 dprintf(idx, "%s\n", NOTES_FWD_BOTNAME);
178 return;
179 }
180 putlog(LOG_CMDS, "*", "#%s# fwd %s %s", dcc[idx].nick, handle, par);
181 dprintf(idx, NOTES_FWD_CHANGED, handle, par);
182 set_user(&USERENTRY_FWD, u1, par);
183 }
184
cmd_notes(struct userrec * u,int idx,char * par)185 static void cmd_notes(struct userrec *u, int idx, char *par)
186 {
187 char *fcn;
188
189 if (!par[0]) {
190 dprintf(idx, "%s: notes index\n", NOTES_USAGE);
191 dprintf(idx, " notes read <# or ALL>\n");
192 dprintf(idx, " notes erase <# or ALL>\n");
193 dprintf(idx, " %s\n", NOTES_MAYBE);
194 dprintf(idx, " ex: notes erase 2-4;8;16-\n");
195 return;
196 }
197 fcn = newsplit(&par);
198 if (!strcasecmp(fcn, "index"))
199 notes_read(dcc[idx].nick, "", "+", idx);
200 else if (!strcasecmp(fcn, "read")) {
201 if (!strcasecmp(par, "all"))
202 notes_read(dcc[idx].nick, "", "-", idx);
203 else
204 notes_read(dcc[idx].nick, "", par, idx);
205 } else if (!strcasecmp(fcn, "erase")) {
206 if (!strcasecmp(par, "all"))
207 notes_del(dcc[idx].nick, "", "-", idx);
208 else
209 notes_del(dcc[idx].nick, "", par, idx);
210 } else {
211 dprintf(idx, "%s\n", NOTES_MUSTBE);
212 return;
213 }
214 putlog(LOG_CMDS, "*", "#%s# notes %s %s", dcc[idx].nick, fcn, par);
215 }
216
cmd_note(struct userrec * u,int idx,char * par)217 static void cmd_note(struct userrec *u, int idx, char *par)
218 {
219 char handle[512], *p;
220 int echo;
221
222 p = newsplit(&par);
223 if (!par[0]) {
224 dprintf(idx, "%s: note <to-whom> <message>\n", NOTES_USAGE);
225 return;
226 }
227 while ((*par == ' ') || (*par == '<') || (*par == '>'))
228 par++; /* These are now illegal *starting* notes characters */
229 echo = (dcc[idx].status & STAT_ECHO);
230 splitc(handle, p, ',');
231 while (handle[0]) {
232 rmspace(handle);
233 add_note(handle, dcc[idx].nick, par, idx, echo);
234 splitc(handle, p, ',');
235 }
236 rmspace(p);
237 add_note(p, dcc[idx].nick, par, idx, echo);
238 }
239
240 static cmd_t notes_cmds[] = {
241 {"fwd", "m", (IntFunc) cmd_fwd, NULL},
242 {"notes", "", (IntFunc) cmd_notes, NULL},
243 {"+noteign", "", (IntFunc) cmd_pls_noteign, NULL},
244 {"-noteign", "", (IntFunc) cmd_mns_noteign, NULL},
245 {"noteigns", "", (IntFunc) cmd_noteigns, NULL},
246 {"note", "", (IntFunc) cmd_note, NULL},
247 {NULL, NULL, NULL, NULL}
248 };
249