core_binds.c 6.1 KB

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