core_binds.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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, *BT_disc, *BT_away, *BT_dcc;
  19. static bind_table_t *BT_chat, *BT_act, *BT_bcst, *BT_note;
  20. static bind_table_t *BT_bot, *BT_nkch, *BT_chon, *BT_chof;
  21. static bind_table_t *BT_chpt, *BT_chjn, *BT_time, *BT_event;
  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,
  60. work[1024],
  61. pass[128];
  62. p = strchr(args, ' ');
  63. if (p)
  64. *p = 0;
  65. strncpyz(pass, args, sizeof(pass));
  66. if (check_cmd_pass(cmd, pass)) {
  67. if (p)
  68. *p = ' ';
  69. strncpyz(work, args, sizeof(work));
  70. p = work;
  71. newsplit(&p);
  72. strcpy(args, p);
  73. } else {
  74. dprintf(idx, "Invalid command password. Use %scommand password arguments\n", dcc_prefix);
  75. putlog(LOG_MISC, "*", "%s attempted %s%s with missing or incorrect command password", dcc[idx].nick, dcc_prefix, cmd);
  76. return 0;
  77. }
  78. }
  79. }
  80. #endif /* S_DCCPASS */
  81. x = check_bind(BT_dcc, cmd, &fr, dcc[idx].user, idx, text);
  82. putlog(LOG_DEBUG, "*", "%s RETURNED: %d", cmd, x);
  83. if (x == -1)
  84. dprintf(idx, "What? You need '%shelp'\n", dcc_prefix);
  85. else if (x & BIND_RET_LOG) {
  86. putlog(LOG_CMDS, "*", "#%s# %s %s", dcc[idx].nick, cmd, text);
  87. }
  88. }
  89. void check_bind_bot(const char *nick, const char *code, const char *param)
  90. {
  91. check_bind(BT_bot, code, NULL, nick, code, param);
  92. }
  93. void check_bind_chon(char *hand, int idx)
  94. {
  95. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  96. struct userrec *u;
  97. u = get_user_by_handle(userlist, hand);
  98. touch_laston(u, "partyline", now);
  99. get_user_flagrec(u, &fr, NULL);
  100. check_bind(BT_chon, hand, &fr, hand, idx);
  101. }
  102. void check_bind_chof(char *hand, int idx)
  103. {
  104. struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
  105. struct userrec *u;
  106. u = get_user_by_handle(userlist, hand);
  107. touch_laston(u, "partyline", now);
  108. get_user_flagrec(u, &fr, NULL);
  109. check_bind(BT_chof, hand, &fr, hand, idx);
  110. }
  111. int check_bind_chat(char *handle, int chan, const char *text)
  112. {
  113. return check_bind(BT_chat, text, NULL, handle, chan, text);
  114. }
  115. void check_bind_act(const char *from, int chan, const char *text)
  116. {
  117. check_bind(BT_act, text, NULL, from, chan, text);
  118. }
  119. void check_bind_bcst(const char *from, int chan, const char *text)
  120. {
  121. check_bind(BT_bcst, text, NULL, from, chan, text);
  122. }
  123. void check_bind_nkch(const char *ohand, const char *nhand)
  124. {
  125. check_bind(BT_nkch, ohand, NULL, ohand, nhand);
  126. }
  127. void check_bind_link(const char *bot, const char *via)
  128. {
  129. check_bind(BT_link, bot, NULL, bot, via);
  130. }
  131. void check_bind_disc(const char *bot)
  132. {
  133. check_bind(BT_disc, bot, NULL, bot);
  134. }
  135. int check_bind_note(const char *from, const char *to, const char *text)
  136. {
  137. return check_bind(BT_note, to, NULL, from, to, text);
  138. }
  139. void check_bind_chjn(const char *bot, const char *nick, int chan,
  140. const char type, int sock, const char *host)
  141. {
  142. struct flag_record fr = {FR_GLOBAL, 0, 0, 0, 0, 0};
  143. char s[11], t[2];
  144. t[0] = type;
  145. t[1] = 0;
  146. switch (type) {
  147. case '^':
  148. fr.global = USER_ADMIN;
  149. break;
  150. case '*':
  151. fr.global = USER_OWNER;
  152. break;
  153. case '+':
  154. fr.global = USER_MASTER;
  155. break;
  156. case '@':
  157. fr.global = USER_OP;
  158. break;
  159. }
  160. egg_snprintf(s, sizeof s, "%d", chan);
  161. check_bind(BT_chjn, s, &fr, bot, nick, chan, t, sock, host);
  162. }
  163. void check_bind_chpt(const char *bot, const char *hand, int sock, int chan)
  164. {
  165. char v[11];
  166. egg_snprintf(v, sizeof v, "%d", chan);
  167. check_bind(BT_chpt, v, NULL, bot, hand, sock, chan);
  168. }
  169. void check_bind_away(const char *bot, int idx, const char *msg)
  170. {
  171. check_bind(BT_away, bot, NULL, bot, idx, msg);
  172. }
  173. void check_bind_time(struct tm *tm)
  174. {
  175. char full[32];
  176. 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);
  177. check_bind(BT_time, full, NULL, tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
  178. }
  179. void check_bind_event(char *event)
  180. {
  181. check_bind(BT_event, event, NULL, event);
  182. }