core_binds.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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_link = NULL, *BT_disc = NULL, *BT_away = NULL, *BT_dcc = NULL;
  20. static bind_table_t *BT_chat = NULL, *BT_act = NULL, *BT_bcst = NULL, *BT_note = NULL;
  21. static bind_table_t *BT_bot = NULL, *BT_nkch = NULL, *BT_chon = NULL, *BT_chof = NULL;
  22. static bind_table_t *BT_chpt = NULL, *BT_chjn = NULL, *BT_time = NULL, *BT_event = NULL;
  23. void core_binds_init()
  24. {
  25. BT_act = bind_table_add("act", 3, "sis", MATCH_MASK, BIND_STACKABLE);
  26. BT_away = bind_table_add("away", 3, "sis", MATCH_MASK, BIND_STACKABLE);
  27. BT_bcst = bind_table_add("bcst", 3, "sis", MATCH_MASK, BIND_STACKABLE);
  28. BT_bot = bind_table_add("bot", 3, "sss", MATCH_EXACT, 0);
  29. BT_chat = bind_table_add("chat", 3, "sis", MATCH_MASK, BIND_STACKABLE | BIND_BREAKABLE);
  30. BT_chjn = bind_table_add("chjn", 6, "ssisis", MATCH_MASK, BIND_STACKABLE);
  31. BT_chon = bind_table_add("chon", 2, "si", MATCH_MASK, BIND_USE_ATTR | BIND_STACKABLE);
  32. BT_chof = bind_table_add("chof", 2, "si", MATCH_MASK, BIND_USE_ATTR | BIND_STACKABLE);
  33. BT_chpt = bind_table_add("chpt", 4, "ssii", MATCH_MASK, BIND_STACKABLE);
  34. BT_dcc = bind_table_add("dcc", 3, "Uis", MATCH_PARTIAL, BIND_USE_ATTR);
  35. add_builtins("dcc", C_dcc);
  36. BT_disc = bind_table_add("disc", 1, "s", MATCH_MASK, BIND_STACKABLE);
  37. BT_event = bind_table_add("event", 1, "s", MATCH_MASK, BIND_STACKABLE);
  38. BT_link = bind_table_add("link", 2, "ss", MATCH_MASK, BIND_STACKABLE);
  39. BT_nkch = bind_table_add("nkch", 2, "ss", MATCH_MASK, BIND_STACKABLE);
  40. BT_note = bind_table_add("note", 3 , "sss", MATCH_EXACT, 0);
  41. BT_time = bind_table_add("time", 5, "iiiii", MATCH_MASK, BIND_STACKABLE);
  42. }
  43. void check_bind_dcc(const char *cmd, int idx, const char *text)
  44. {
  45. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  46. int x;
  47. #ifdef S_DCCPASS
  48. bind_entry_t *entry = NULL;
  49. bind_table_t *table = NULL;
  50. int found = 0;
  51. char *args = strdup(text);
  52. #endif
  53. get_user_flagrec(dcc[idx].user, &fr, dcc[idx].u.chat->con_chan);
  54. #ifdef S_DCCPASS
  55. table = bind_table_lookup("dcc");
  56. for (entry = table->entries; entry && entry->next; entry = entry->next) {
  57. if (!egg_strcasecmp(cmd, entry->mask)) {
  58. found = 1;
  59. break;
  60. }
  61. }
  62. if (found) {
  63. if (has_cmd_pass(cmd)) {
  64. char *p = NULL, work[1024] = "", pass[128] = "";
  65. p = strchr(args, ' ');
  66. if (p)
  67. *p = 0;
  68. strncpyz(pass, args, sizeof(pass));
  69. if (check_cmd_pass(cmd, pass)) {
  70. if (p)
  71. *p = ' ';
  72. strncpyz(work, args, sizeof(work));
  73. p = work;
  74. newsplit(&p);
  75. strcpy(args, p);
  76. } else {
  77. dprintf(idx, "Invalid command password. Use %scommand password arguments\n", dcc_prefix);
  78. putlog(LOG_MISC, "*", "%s attempted %s%s with missing or incorrect command password", dcc[idx].nick, dcc_prefix, cmd);
  79. free(args);
  80. return;
  81. }
  82. }
  83. }
  84. #endif /* S_DCCPASS */
  85. x = check_bind(BT_dcc, cmd, &fr, dcc[idx].user, idx, args);
  86. putlog(LOG_DEBUG, "*", "%s RETURNED: %d", cmd, x);
  87. if (x == -1)
  88. dprintf(idx, "What? You need '%shelp'\n", dcc_prefix);
  89. free(args);
  90. }
  91. void check_bind_bot(const char *nick, const char *code, const char *param)
  92. {
  93. char *mynick = NULL, *myparam = NULL, *p1 = NULL, *p2 = NULL;
  94. mynick = p1 = strdup(nick);
  95. myparam = p2 = strdup(param);
  96. check_bind(BT_bot, code, NULL, mynick, code, myparam);
  97. free(p1);
  98. free(p2);
  99. }
  100. void check_bind_chon(char *hand, int idx)
  101. {
  102. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  103. struct userrec *u = NULL;
  104. u = get_user_by_handle(userlist, hand);
  105. touch_laston(u, "partyline", now);
  106. get_user_flagrec(u, &fr, NULL);
  107. check_bind(BT_chon, hand, &fr, hand, idx);
  108. }
  109. void check_bind_chof(char *hand, int idx)
  110. {
  111. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  112. struct userrec *u = NULL;
  113. u = get_user_by_handle(userlist, hand);
  114. touch_laston(u, "partyline", now);
  115. get_user_flagrec(u, &fr, NULL);
  116. check_bind(BT_chof, hand, &fr, hand, idx);
  117. }
  118. int check_bind_chat(char *handle, int chan, const char *text)
  119. {
  120. return check_bind(BT_chat, text, NULL, handle, chan, text);
  121. }
  122. void check_bind_act(const char *from, int chan, const char *text)
  123. {
  124. check_bind(BT_act, text, NULL, from, chan, text);
  125. }
  126. void check_bind_bcst(const char *from, int chan, const char *text)
  127. {
  128. check_bind(BT_bcst, text, NULL, from, chan, text);
  129. }
  130. void check_bind_nkch(const char *ohand, const char *nhand)
  131. {
  132. check_bind(BT_nkch, ohand, NULL, ohand, nhand);
  133. }
  134. void check_bind_link(const char *bot, const char *via)
  135. {
  136. check_bind(BT_link, bot, NULL, bot, via);
  137. }
  138. void check_bind_disc(const char *bot)
  139. {
  140. check_bind(BT_disc, bot, NULL, bot);
  141. }
  142. int check_bind_note(const char *from, const char *to, const char *text)
  143. {
  144. return check_bind(BT_note, to, NULL, from, to, text);
  145. }
  146. void check_bind_chjn(const char *bot, const char *nick, int chan,
  147. const char type, int sock, const char *host)
  148. {
  149. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  150. char s[11] = "", t[2] = "";
  151. t[0] = type;
  152. t[1] = 0;
  153. switch (type) {
  154. case '^':
  155. fr.global = USER_ADMIN;
  156. break;
  157. case '*':
  158. fr.global = USER_OWNER;
  159. break;
  160. case '+':
  161. fr.global = USER_MASTER;
  162. break;
  163. case '@':
  164. fr.global = USER_OP;
  165. break;
  166. }
  167. egg_snprintf(s, sizeof s, "%d", chan);
  168. check_bind(BT_chjn, s, &fr, bot, nick, chan, t, sock, host);
  169. }
  170. void check_bind_chpt(const char *bot, const char *hand, int sock, int chan)
  171. {
  172. char v[11] = "";
  173. egg_snprintf(v, sizeof v, "%d", chan);
  174. check_bind(BT_chpt, v, NULL, bot, hand, sock, chan);
  175. }
  176. void check_bind_away(const char *bot, int idx, const char *msg)
  177. {
  178. check_bind(BT_away, bot, NULL, bot, idx, msg);
  179. }
  180. void check_bind_time(struct tm *tm)
  181. {
  182. char full[32] = "";
  183. 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);
  184. check_bind(BT_time, full, NULL, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
  185. }
  186. void check_bind_event(char *event)
  187. {
  188. check_bind(BT_event, event, NULL, event);
  189. }