core_binds.c 5.9 KB

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