core_binds.c 4.0 KB

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