cqd.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* vcc/plugins/cqd/cqd.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <vcc/vcc.h>
  21. #include <vcc/pretty.h>
  22. #include <vcc/plugin.h>
  23. #include <vcc/version.h>
  24. #include <vcc/interfaces.h>
  25. int do_cmd_cqd(int argc, char **argv);
  26. int cqd_init(void);
  27. struct cmdtable cqd_cmdtab[] = {
  28. { "-cqd", do_cmd_cqd, "Raise CQD. " },
  29. { NULL, NULL, NULL }
  30. };
  31. struct plugin plg_cqd = {
  32. .state = 0,
  33. .name = "cqd",
  34. .descr = "Raise CQD. ",
  35. .init = cqd_init,
  36. .cmdtab = cqd_cmdtab
  37. };
  38. #define this_plg (&plg_cqd)
  39. int do_cmd_cqd(int argc, char **argv) {
  40. char buf[MSG_SIZE];
  41. char *p;
  42. (void) argv;
  43. plg_check_enabled();
  44. switch (argc) {
  45. case 1:
  46. p = "CQD\n";
  47. break;
  48. case 2:
  49. p = argv[1];
  50. break;
  51. default:
  52. fprintf(stderr, _("usage: -cqd\n"));
  53. return 1;
  54. }
  55. sprintf(buf, "-cqd#%s\n", p);
  56. send_msg(buf, usrname);
  57. return 0;
  58. }
  59. char *cqd_hook(struct hook_info *hi) {
  60. if (strncmp(hi->msg, "-cqd#", 5))
  61. return HOOK_IGNORE;
  62. pretty_cqd(hi->usr, hi->msg + 5);
  63. return HOOK_HANDLED;
  64. }
  65. int cqd_init(void) {
  66. register_hook(HOOK_RECV, cqd_hook);
  67. return 0;
  68. }