cmdsnote.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * cmdsnote.c -- part of notes.mod
  3. * handles all notes interaction over the party line
  4. *
  5. */
  6. static void cmd_fwd(struct userrec *u, int idx, char *par)
  7. {
  8. char *handle = NULL;
  9. struct userrec *u1 = NULL;
  10. if (!par[0]) {
  11. dprintf(idx, "%s: fwd <handle> [user@bot]\n", NOTES_USAGE);
  12. return;
  13. }
  14. handle = newsplit(&par);
  15. u1 = get_user_by_handle(userlist, handle);
  16. if (!u1) {
  17. dprintf(idx, "%s\n", NOTES_NO_SUCH_USER);
  18. return;
  19. }
  20. if ((u1->flags & USER_OWNER) && egg_strcasecmp(handle, dcc[idx].nick)) {
  21. dprintf(idx, "%s\n", NOTES_FWD_OWNER);
  22. return;
  23. }
  24. if (!par[0]) {
  25. putlog(LOG_CMDS, "*", "#%s# fwd %s", dcc[idx].nick, handle);
  26. dprintf(idx, NOTES_FWD_FOR, handle);
  27. set_user(&USERENTRY_FWD, u1, NULL);
  28. return;
  29. }
  30. /* Thanks to vertex & dw */
  31. if (strchr(par, '@') == NULL) {
  32. dprintf(idx, "%s\n", NOTES_FWD_BOTNAME);
  33. return;
  34. }
  35. putlog(LOG_CMDS, "*", "#%s# fwd %s %s", dcc[idx].nick, handle, par);
  36. dprintf(idx, NOTES_FWD_CHANGED, handle, par);
  37. set_user(&USERENTRY_FWD, u1, par);
  38. }
  39. static void cmd_notes(struct userrec *u, int idx, char *par)
  40. {
  41. char *fcn = NULL;
  42. if (!par[0]) {
  43. dprintf(idx, "%s: notes index\n", NOTES_USAGE);
  44. dprintf(idx, " notes read <# or ALL>\n");
  45. dprintf(idx, " notes erase <# or ALL>\n");
  46. dprintf(idx, " %s\n", NOTES_MAYBE);
  47. dprintf(idx, " ex: notes erase 2-4;8;16-\n");
  48. return;
  49. }
  50. fcn = newsplit(&par);
  51. if (!egg_strcasecmp(fcn, "index"))
  52. notes_read(dcc[idx].nick, "", "+", idx);
  53. else if (!egg_strcasecmp(fcn, "read")) {
  54. if (!egg_strcasecmp(par, "all"))
  55. notes_read(dcc[idx].nick, "", "-", idx);
  56. else
  57. notes_read(dcc[idx].nick, "", par, idx);
  58. } else if (!egg_strcasecmp(fcn, "erase")) {
  59. if (!egg_strcasecmp(par, "all"))
  60. notes_del(dcc[idx].nick, "", "-", idx);
  61. else
  62. notes_del(dcc[idx].nick, "", par, idx);
  63. } else {
  64. dprintf(idx, "%s\n", NOTES_MUSTBE);
  65. return;
  66. }
  67. putlog(LOG_CMDS, "*", "#%s# notes %s %s", dcc[idx].nick, fcn, par);
  68. }
  69. static void cmd_note(struct userrec *u, int idx, char *par)
  70. {
  71. char handle[512] = "", *p = NULL;
  72. int echo;
  73. p = newsplit(&par);
  74. if (!par[0]) {
  75. dprintf(idx, "%s: note <to-whom> <message>\n", NOTES_USAGE);
  76. return;
  77. }
  78. while ((*par == ' ') || (*par == '<') || (*par == '>'))
  79. par++; /* These are now illegal *starting* notes
  80. * characters */
  81. echo = (dcc[idx].status & STAT_ECHO);
  82. splitc(handle, p, ',');
  83. while (handle[0]) {
  84. rmspace(handle);
  85. add_note(handle, dcc[idx].nick, par, idx, echo);
  86. splitc(handle, p, ',');
  87. }
  88. rmspace(p);
  89. add_note(p, dcc[idx].nick, par, idx, echo);
  90. }
  91. static cmd_t notes_cmds[] =
  92. {
  93. {"fwd", "m", (Function) cmd_fwd, NULL},
  94. {"notes", "", (Function) cmd_notes, NULL},
  95. {"note", "", (Function) cmd_note, NULL},
  96. {NULL, NULL, NULL, NULL}
  97. };