cmdsnote.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * cmdsnote.c -- part of notes.mod
  3. * handles all notes interaction over the party line
  4. *
  5. */
  6. static void cmd_pls_noteign(struct userrec *u, int idx, char *par)
  7. {
  8. struct userrec *u2;
  9. char *handle, *mask, *buf, *p;
  10. if (!par[0]) {
  11. dprintf(idx, "%s: +noteign [handle] <ignoremask>\n", NOTES_USAGE);
  12. return;
  13. }
  14. putlog(LOG_CMDS, "*", "#%s# +noteign %s", dcc[idx].nick, par);
  15. p = buf = nmalloc(strlen(par)+1);
  16. strcpy(p, par);
  17. handle = newsplit(&p);
  18. mask = newsplit(&p);
  19. if (mask[0]) {
  20. u2 = get_user_by_handle(userlist, handle);
  21. if (u != u2) {
  22. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  23. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  24. if (!(glob_master(fr) || glob_owner(fr))) {
  25. dprintf(idx, NOTES_IGN_OTHERS, handle);
  26. nfree(buf);
  27. return;
  28. }
  29. }
  30. if (!u2) {
  31. dprintf(idx, NOTES_UNKNOWN_USER, handle);
  32. nfree(buf);
  33. return;
  34. }
  35. } else {
  36. u2 = u;
  37. mask = handle;
  38. }
  39. if (add_note_ignore(u2, mask))
  40. dprintf(idx, NOTES_IGN_NEW, mask);
  41. else
  42. dprintf(idx, NOTES_IGN_ALREADY, mask);
  43. nfree(buf);
  44. return;
  45. }
  46. static void cmd_mns_noteign(struct userrec *u, int idx, char *par)
  47. {
  48. struct userrec *u2;
  49. char *handle, *mask, *buf, *p;
  50. if (!par[0]) {
  51. dprintf(idx, "%s: -noteign [handle] <ignoremask>\n", NOTES_USAGE);
  52. return;
  53. }
  54. putlog(LOG_CMDS, "*", "#%s# -noteign %s", dcc[idx].nick, par);
  55. p = buf = nmalloc(strlen(par)+1);
  56. strcpy(p, par);
  57. handle = newsplit(&p);
  58. mask = newsplit(&p);
  59. if (mask[0]) {
  60. u2 = get_user_by_handle(userlist, handle);
  61. if (u != u2) {
  62. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  63. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  64. if (!(glob_master(fr) || glob_owner(fr))) {
  65. dprintf(idx, NOTES_IGN_OTHERS, handle);
  66. nfree(buf);
  67. return;
  68. }
  69. }
  70. if (!u2) {
  71. dprintf(idx, NOTES_UNKNOWN_USER, handle);
  72. nfree(buf);
  73. return;
  74. }
  75. } else {
  76. u2 = u;
  77. mask = handle;
  78. }
  79. if (del_note_ignore(u2, mask))
  80. dprintf(idx, NOTES_IGN_REM, mask);
  81. else
  82. dprintf(idx, NOTES_IGN_NOTFOUND, mask);
  83. nfree(buf);
  84. return;
  85. }
  86. static void cmd_noteigns(struct userrec *u, int idx, char *par)
  87. {
  88. struct userrec *u2;
  89. char **ignores;
  90. int ignoresn, i;
  91. if (par[0]) {
  92. u2 = get_user_by_handle(userlist, par);
  93. if (u != u2) {
  94. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  95. get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
  96. if (!(glob_master(fr) || glob_owner(fr))) {
  97. dprintf(idx, NOTES_IGN_OTHERS, par);
  98. return;
  99. }
  100. }
  101. if (!u2) {
  102. dprintf(idx, NOTES_UNKNOWN_USER, par);
  103. return;
  104. }
  105. } else
  106. u2 = u;
  107. ignoresn = get_note_ignores(u2, &ignores);
  108. if (!ignoresn) {
  109. dprintf(idx, "%s", NOTES_IGN_NONE);
  110. return;
  111. }
  112. putlog(LOG_CMDS, "*", "#%s# noteigns %s", dcc[idx].nick, par);
  113. dprintf(idx, NOTES_IGN_FOR, u2->handle);
  114. for (i = 0; i < ignoresn; i++)
  115. dprintf(idx, " %s", ignores[i]);
  116. dprintf(idx, "\n");
  117. nfree(ignores[0]); /* Free the string buffer */
  118. nfree(ignores); /* Free the ptr array */
  119. }
  120. static void cmd_fwd(struct userrec *u, int idx, char *par)
  121. {
  122. char *handle;
  123. struct userrec *u1;
  124. if (!par[0]) {
  125. dprintf(idx, "%s: fwd <handle> [user@bot]\n", NOTES_USAGE);
  126. return;
  127. }
  128. handle = newsplit(&par);
  129. u1 = get_user_by_handle(userlist, handle);
  130. if (!u1) {
  131. dprintf(idx, "%s\n", NOTES_NO_SUCH_USER);
  132. return;
  133. }
  134. if ((u1->flags & USER_OWNER) && egg_strcasecmp(handle, dcc[idx].nick)) {
  135. dprintf(idx, "%s\n", NOTES_FWD_OWNER);
  136. return;
  137. }
  138. if (!par[0]) {
  139. putlog(LOG_CMDS, "*", "#%s# fwd %s", dcc[idx].nick, handle);
  140. dprintf(idx, NOTES_FWD_FOR, handle);
  141. set_user(&USERENTRY_FWD, u1, NULL);
  142. return;
  143. }
  144. /* Thanks to vertex & dw */
  145. if (strchr(par, '@') == NULL) {
  146. dprintf(idx, "%s\n", NOTES_FWD_BOTNAME);
  147. return;
  148. }
  149. putlog(LOG_CMDS, "*", "#%s# fwd %s %s", dcc[idx].nick, handle, par);
  150. dprintf(idx, NOTES_FWD_CHANGED, handle, par);
  151. set_user(&USERENTRY_FWD, u1, par);
  152. }
  153. static void cmd_notes(struct userrec *u, int idx, char *par)
  154. {
  155. char *fcn;
  156. if (!par[0]) {
  157. dprintf(idx, "%s: notes index\n", NOTES_USAGE);
  158. dprintf(idx, " notes read <# or ALL>\n");
  159. dprintf(idx, " notes erase <# or ALL>\n");
  160. dprintf(idx, " %s\n", NOTES_MAYBE);
  161. dprintf(idx, " ex: notes erase 2-4;8;16-\n");
  162. return;
  163. }
  164. fcn = newsplit(&par);
  165. if (!egg_strcasecmp(fcn, "index"))
  166. notes_read(dcc[idx].nick, "", "+", idx);
  167. else if (!egg_strcasecmp(fcn, "read")) {
  168. if (!egg_strcasecmp(par, "all"))
  169. notes_read(dcc[idx].nick, "", "-", idx);
  170. else
  171. notes_read(dcc[idx].nick, "", par, idx);
  172. } else if (!egg_strcasecmp(fcn, "erase")) {
  173. if (!egg_strcasecmp(par, "all"))
  174. notes_del(dcc[idx].nick, "", "-", idx);
  175. else
  176. notes_del(dcc[idx].nick, "", par, idx);
  177. } else {
  178. dprintf(idx, "%s\n", NOTES_MUSTBE);
  179. return;
  180. }
  181. putlog(LOG_CMDS, "*", "#%s# notes %s %s", dcc[idx].nick, fcn, par);
  182. }
  183. static void cmd_note(struct userrec *u, int idx, char *par)
  184. {
  185. char handle[512], *p;
  186. int echo;
  187. p = newsplit(&par);
  188. if (!par[0]) {
  189. dprintf(idx, "%s: note <to-whom> <message>\n", NOTES_USAGE);
  190. return;
  191. }
  192. while ((*par == ' ') || (*par == '<') || (*par == '>'))
  193. par++; /* These are now illegal *starting* notes
  194. * characters */
  195. echo = (dcc[idx].status & STAT_ECHO);
  196. splitc(handle, p, ',');
  197. while (handle[0]) {
  198. rmspace(handle);
  199. add_note(handle, dcc[idx].nick, par, idx, echo);
  200. splitc(handle, p, ',');
  201. }
  202. rmspace(p);
  203. add_note(p, dcc[idx].nick, par, idx, echo);
  204. }
  205. static cmd_t notes_cmds[] =
  206. {
  207. {"fwd", "m", (Function) cmd_fwd, NULL},
  208. {"notes", "", (Function) cmd_notes, NULL},
  209. {"+noteign", "", (Function) cmd_pls_noteign, NULL},
  210. {"-noteign", "", (Function) cmd_mns_noteign, NULL},
  211. {"noteigns", "", (Function) cmd_noteigns, NULL},
  212. {"note", "", (Function) cmd_note, NULL},
  213. {NULL, NULL, NULL, NULL}
  214. };