1
0

core_binds.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * core_binds.c -- handles:
  3. *
  4. * binds for the CORE
  5. *
  6. */
  7. #include "common.h"
  8. #include "dccutil.h"
  9. #include "userrec.h"
  10. #include "main.h"
  11. #include "settings.h"
  12. #include "users.h"
  13. #include "misc.h"
  14. #include "tclhash.h"
  15. #include "cfg.h"
  16. extern cmd_t C_dcc[];
  17. static bind_table_t *BT_away = NULL, *BT_dcc = NULL;
  18. static bind_table_t *BT_note = NULL;
  19. static bind_table_t *BT_bot = NULL, *BT_nkch = NULL, *BT_chon = NULL;
  20. static bind_table_t *BT_time = NULL;
  21. void core_binds_init()
  22. {
  23. BT_away = bind_table_add("away", 3, "sis", MATCH_MASK, BIND_STACKABLE);
  24. BT_bot = bind_table_add("bot", 3, "sss", MATCH_EXACT, 0);
  25. BT_chon = bind_table_add("chon", 2, "si", MATCH_MASK | MATCH_FLAGS, BIND_STACKABLE);
  26. BT_dcc = bind_table_add("dcc", 3, "Uis", MATCH_PARTIAL | MATCH_FLAGS, 0);
  27. add_builtins("dcc", C_dcc);
  28. BT_nkch = bind_table_add("nkch", 2, "ss", MATCH_MASK, BIND_STACKABLE);
  29. BT_note = bind_table_add("note", 3 , "sss", MATCH_EXACT, 0);
  30. BT_time = bind_table_add("time", 5, "iiiii", MATCH_MASK, BIND_STACKABLE);
  31. }
  32. void check_bind_dcc(const char *cmd, int idx, const char *text)
  33. {
  34. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  35. int x, hits, found = 0;
  36. bind_entry_t *entry = NULL;
  37. bind_table_t *table = NULL;
  38. char *args = strdup(text);
  39. get_user_flagrec(dcc[idx].user, &fr, dcc[idx].u.chat->con_chan);
  40. table = bind_table_lookup("dcc");
  41. for (entry = table->entries; entry && entry->next; entry = entry->next) {
  42. if (!egg_strcasecmp(cmd, entry->mask)) {
  43. found = 1;
  44. break;
  45. }
  46. }
  47. if (found) {
  48. if (has_cmd_pass(cmd)) {
  49. char *p = NULL, work[1024] = "", pass[128] = "";
  50. p = strchr(args, ' ');
  51. if (p)
  52. *p = 0;
  53. strncpyz(pass, args, sizeof(pass));
  54. if (check_cmd_pass(cmd, pass)) {
  55. if (p)
  56. *p = ' ';
  57. strncpyz(work, args, sizeof(work));
  58. p = work;
  59. newsplit(&p);
  60. strcpy(args, p);
  61. } else {
  62. dprintf(idx, "Invalid command password. Use %scommand password arguments\n", settings.dcc_prefix);
  63. putlog(LOG_MISC, "*", "%s attempted %s%s with missing or incorrect command password", dcc[idx].nick, settings.dcc_prefix, cmd);
  64. free(args);
  65. return;
  66. }
  67. }
  68. }
  69. x = check_bind_hits(BT_dcc, cmd, &fr, &hits, dcc[idx].user, idx, args);
  70. if (hits != 1)
  71. putlog(LOG_CMDS, "*", "! #%s# %s %s", dcc[idx].nick, cmd, args);
  72. if (hits == 0)
  73. dprintf(idx, "What? You need '%shelp'\n", settings.dcc_prefix);
  74. else if (hits > 1)
  75. dprintf(idx, "Ambiguous command.\n");
  76. free(args);
  77. }
  78. void check_bind_bot(const char *nick, const char *code, const char *param)
  79. {
  80. char *mynick = NULL, *myparam = NULL, *p1 = NULL, *p2 = NULL;
  81. mynick = p1 = strdup(nick);
  82. myparam = p2 = strdup(param);
  83. check_bind(BT_bot, code, NULL, mynick, code, myparam);
  84. free(p1);
  85. free(p2);
  86. }
  87. void check_bind_chon(char *hand, int idx)
  88. {
  89. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
  90. struct userrec *u = NULL;
  91. u = get_user_by_handle(userlist, hand);
  92. touch_laston(u, "partyline", now);
  93. get_user_flagrec(u, &fr, NULL);
  94. check_bind(BT_chon, hand, &fr, hand, idx);
  95. }
  96. void check_bind_chof(char *hand, int idx)
  97. {
  98. struct userrec *u = NULL;
  99. u = get_user_by_handle(userlist, hand);
  100. touch_laston(u, "partyline", now);
  101. }
  102. void check_bind_nkch(const char *ohand, const char *nhand)
  103. {
  104. check_bind(BT_nkch, ohand, NULL, ohand, nhand);
  105. }
  106. int check_bind_note(const char *from, const char *to, const char *text)
  107. {
  108. return check_bind(BT_note, to, NULL, from, to, text);
  109. }
  110. void check_bind_away(const char *bot, int idx, const char *msg)
  111. {
  112. check_bind(BT_away, bot, NULL, bot, idx, msg);
  113. }
  114. void check_bind_time(struct tm *tm)
  115. {
  116. char full[32] = "";
  117. egg_snprintf(full, sizeof(full), "%02d %02d %02d %02d %04d", tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
  118. check_bind(BT_time, full, NULL, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
  119. }