console.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /*
  2. * console.c -- part of console.mod
  3. * saved console settings based on console.tcl
  4. * by cmwagner/billyjoe/D. Senso
  5. *
  6. */
  7. #include "console.h"
  8. #include "src/common.h"
  9. #include "src/mod/share.mod/share.h"
  10. #include "src/tclhash.h"
  11. #include "src/tandem.h"
  12. #include "src/cmds.h"
  13. #include "src/users.h"
  14. #include "src/userent.h"
  15. #include "src/botmsg.h"
  16. #include "src/userrec.h"
  17. #include "src/users.h"
  18. #include "src/misc.h"
  19. #include "src/core_binds.h"
  20. static int console_autosave = 1;
  21. static int info_party = 1;
  22. struct console_info {
  23. char *channel;
  24. int conflags;
  25. int stripflags;
  26. int echoflags;
  27. int page;
  28. int conchan;
  29. int color;
  30. int banner;
  31. int channels;
  32. int bots;
  33. int whom;
  34. };
  35. static bool
  36. console_unpack(struct userrec *u, struct user_entry *e)
  37. {
  38. struct console_info *ci = (struct console_info *) my_calloc(1, sizeof(struct console_info));
  39. char *par = e->u.list->extra, *arg = NULL;
  40. arg = newsplit(&par);
  41. ci->channel = strdup(arg);
  42. arg = newsplit(&par);
  43. ci->conflags = logmodes(arg);
  44. arg = newsplit(&par);
  45. ci->stripflags = stripmodes(arg);
  46. arg = newsplit(&par);
  47. ci->echoflags = (arg[0] == '1') ? 1 : 0;
  48. arg = newsplit(&par);
  49. ci->page = atoi(arg);
  50. arg = newsplit(&par);
  51. ci->conchan = atoi(arg);
  52. arg = newsplit(&par);
  53. ci->color = atoi(arg);
  54. arg = newsplit(&par);
  55. ci->banner = atoi(arg);
  56. arg = newsplit(&par);
  57. ci->channels = atoi(arg);
  58. arg = newsplit(&par);
  59. ci->bots = atoi(arg);
  60. arg = newsplit(&par);
  61. ci->whom = atoi(arg);
  62. list_type_kill(e->u.list);
  63. e->u.extra = ci;
  64. return 1;
  65. }
  66. static bool
  67. console_kill(struct user_entry *e)
  68. {
  69. struct console_info *i = (struct console_info *) e->u.extra;
  70. free(i->channel);
  71. free(i);
  72. free(e);
  73. return 1;
  74. }
  75. static bool
  76. console_write_userfile(FILE * f, struct userrec *u, struct user_entry *e)
  77. {
  78. if (u->bot)
  79. return 1;
  80. struct console_info *i = (struct console_info *) e->u.extra;
  81. if (lfprintf(f, "--CONSOLE %s %s %s %d %d %d %d %d %d %d %d\n",
  82. i->channel, masktype(i->conflags),
  83. stripmasktype(i->stripflags), i->echoflags,
  84. i->page, i->conchan, i->color, i->banner, i->channels, i->bots, i->whom) == EOF)
  85. return 0;
  86. return 1;
  87. }
  88. static bool
  89. console_set(struct userrec *u, struct user_entry *e, void *buf)
  90. {
  91. struct console_info *ci = (struct console_info *) e->u.extra;
  92. if (!ci && !buf)
  93. return 1;
  94. if (ci != buf) {
  95. if (ci) {
  96. free(ci->channel);
  97. free(ci);
  98. }
  99. ci = (struct console_info *) buf;
  100. e->u.extra = (struct console_info *) buf;
  101. }
  102. if (!noshare && !u->bot) {
  103. char string[501] = "";
  104. egg_snprintf(string, sizeof string, "%s %s %s %d %d %d %d %d %d %d %d", ci->channel,
  105. masktype(ci->conflags), stripmasktype(ci->stripflags), ci->echoflags, ci->page, ci->conchan,
  106. ci->color, ci->banner, ci->channels, ci->bots, ci->whom);
  107. /* shareout("c %s %s %s\n", e->type->name, u->handle, string); */
  108. shareout("c CONSOLE %s %s\n", u->handle, string);
  109. }
  110. return 1;
  111. }
  112. static bool
  113. console_gotshare(struct userrec *u, struct user_entry *e, char *par, int idx)
  114. {
  115. struct console_info *ci = (struct console_info *) e->u.extra;
  116. char *arg = NULL;
  117. arg = newsplit(&par);
  118. if (ci) {
  119. free(ci->channel);
  120. free(ci);
  121. }
  122. ci = (struct console_info *) my_calloc(1, sizeof(struct console_info));
  123. ci->channel = strdup(arg);
  124. arg = newsplit(&par);
  125. ci->conflags = logmodes(arg);
  126. arg = newsplit(&par);
  127. ci->stripflags = stripmodes(arg);
  128. arg = newsplit(&par);
  129. ci->echoflags = (arg[0] == '1') ? 1 : 0;
  130. arg = newsplit(&par);
  131. ci->page = atoi(arg);
  132. arg = newsplit(&par);
  133. ci->conchan = atoi(arg);
  134. arg = newsplit(&par);
  135. ci->color = atoi(arg);
  136. arg = newsplit(&par);
  137. ci->banner = atoi(arg);
  138. arg = newsplit(&par);
  139. ci->channels = atoi(arg);
  140. arg = newsplit(&par);
  141. ci->bots = atoi(arg);
  142. arg = newsplit(&par);
  143. ci->whom = atoi(arg);
  144. e->u.extra = ci;
  145. /* now let's propogate to the dcc list */
  146. for (int i = 0; i < dcc_total; i++) {
  147. if (dcc[i].type && (dcc[i].type == &DCC_CHAT) && !strcmp(dcc[i].user->handle, u->handle)) {
  148. if (ci->channel && ci->channel[0])
  149. strcpy(dcc[i].u.chat->con_chan, ci->channel);
  150. dcc[i].u.chat->con_flags = ci->conflags;
  151. dcc[i].u.chat->strip_flags = ci->stripflags;
  152. if (ci->echoflags)
  153. dcc[i].status |= STAT_ECHO;
  154. else
  155. dcc[i].status &= ~STAT_ECHO;
  156. if (ci->page) {
  157. dcc[i].status |= STAT_PAGE;
  158. dcc[i].u.chat->max_line = ci->page;
  159. if (!dcc[i].u.chat->line_count)
  160. dcc[i].u.chat->current_lines = 0;
  161. }
  162. if (ci->color)
  163. dcc[i].status |= STAT_COLOR;
  164. else
  165. dcc[i].status &= ~STAT_COLOR;
  166. if (ci->banner)
  167. dcc[i].status |= STAT_BANNER;
  168. else
  169. dcc[i].status &= ~STAT_BANNER;
  170. if (ci->channels)
  171. dcc[i].status |= STAT_CHANNELS;
  172. else
  173. dcc[i].status &= ~STAT_CHANNELS;
  174. if (ci->bots)
  175. dcc[i].status |= STAT_BOTS;
  176. else
  177. dcc[i].status &= ~STAT_BOTS;
  178. if (ci->whom)
  179. dcc[i].status |= STAT_WHOM;
  180. else
  181. dcc[i].status &= ~STAT_WHOM;
  182. }
  183. }
  184. return 1;
  185. }
  186. static void
  187. console_display(int idx, struct user_entry *e, struct userrec *u)
  188. {
  189. struct console_info *i = (struct console_info *) e->u.extra;
  190. if (dcc[idx].user && (dcc[idx].user->flags & USER_MASTER)) {
  191. dprintf(idx, " %s\n", CONSOLE_SAVED_SETTINGS);
  192. dprintf(idx, " %s %s\n", CONSOLE_CHANNEL, i->channel);
  193. dprintf(idx, " %s %s, %s %s, %s %s\n", CONSOLE_FLAGS,
  194. masktype(i->conflags), CONSOLE_STRIPFLAGS,
  195. stripmasktype(i->stripflags), CONSOLE_ECHO, i->echoflags ? CONSOLE_YES : CONSOLE_NO);
  196. dprintf(idx, " %s %d, %s %s%d\n", CONSOLE_PAGE_SETTING, i->page,
  197. CONSOLE_CHANNEL2, (i->conchan < GLOBAL_CHANS) ? "" : "*", i->conchan % GLOBAL_CHANS);
  198. dprintf(idx, " Color: $b%s$b\n", i->color ? "on" : "off");
  199. dprintf(idx, " Login settings:\n");
  200. dprintf(idx, " Banner: $b%-3s$b Bots: $b%-3s$b\n", i->banner ? "on" : "off", i->bots ? "on" : "off");
  201. dprintf(idx, " Channels: $b%-3s$b Whom: $b%-3s$b\n", i->channels ? "on" : "off", i->whom ? "on" : "off");
  202. }
  203. }
  204. static struct user_entry_type USERENTRY_CONSOLE = {
  205. 0, /* always 0 ;) */
  206. console_gotshare,
  207. console_unpack,
  208. console_write_userfile,
  209. console_kill,
  210. def_get,
  211. console_set,
  212. console_display,
  213. "CONSOLE"
  214. };
  215. static int
  216. console_chon(char *handle, int idx)
  217. {
  218. if (dcc[idx].type == &DCC_CHAT) {
  219. struct console_info *i = (struct console_info *) get_user(&USERENTRY_CONSOLE, dcc[idx].user);
  220. if (i) {
  221. if (i->channel && i->channel[0])
  222. strcpy(dcc[idx].u.chat->con_chan, i->channel);
  223. dcc[idx].u.chat->con_flags = i->conflags;
  224. dcc[idx].u.chat->strip_flags = i->stripflags;
  225. if (i->echoflags)
  226. dcc[idx].status |= STAT_ECHO;
  227. else
  228. dcc[idx].status &= ~STAT_ECHO;
  229. if (i->page) {
  230. dcc[idx].status |= STAT_PAGE;
  231. dcc[idx].u.chat->max_line = i->page;
  232. if (!dcc[idx].u.chat->line_count)
  233. dcc[idx].u.chat->current_lines = 0;
  234. }
  235. if (i->color)
  236. dcc[idx].status |= STAT_COLOR;
  237. else
  238. dcc[idx].status &= ~STAT_COLOR;
  239. if (i->banner)
  240. dcc[idx].status |= STAT_BANNER;
  241. else
  242. dcc[idx].status &= ~STAT_BANNER;
  243. if (i->channels)
  244. dcc[idx].status |= STAT_CHANNELS;
  245. else
  246. dcc[idx].status &= ~STAT_CHANNELS;
  247. if (i->bots)
  248. dcc[idx].status |= STAT_BOTS;
  249. else
  250. dcc[idx].status &= ~STAT_BOTS;
  251. if (i->whom)
  252. dcc[idx].status |= STAT_WHOM;
  253. else
  254. dcc[idx].status &= ~STAT_WHOM;
  255. }
  256. if ((dcc[idx].u.chat->channel >= 0) && (dcc[idx].u.chat->channel < GLOBAL_CHANS)) {
  257. botnet_send_join_idx(idx);
  258. }
  259. if (info_party) {
  260. char *p = (char *) get_user(&USERENTRY_INFO, dcc[idx].user);
  261. if (p) {
  262. if (dcc[idx].u.chat->channel >= 0) {
  263. char x[1024] = "";
  264. chanout_but(-1, dcc[idx].u.chat->channel, "*** [%s] %s\n", dcc[idx].nick, p);
  265. simple_sprintf(x, "[%s] %s", dcc[idx].nick, p);
  266. botnet_send_chan(-1, conf.bot->nick, NULL, dcc[idx].u.chat->channel, x);
  267. }
  268. }
  269. }
  270. }
  271. return 0;
  272. }
  273. static int
  274. console_store(int idx, char *par)
  275. {
  276. struct console_info *i = (struct console_info *) get_user(&USERENTRY_CONSOLE, dcc[idx].user);
  277. if (!i)
  278. i = (struct console_info *) my_calloc(1, sizeof(struct console_info));
  279. if (i->channel)
  280. free(i->channel);
  281. i->channel = strdup(dcc[idx].u.chat->con_chan);
  282. i->conflags = dcc[idx].u.chat->con_flags;
  283. i->stripflags = dcc[idx].u.chat->strip_flags;
  284. i->echoflags = (dcc[idx].status & STAT_ECHO) ? 1 : 0;
  285. if (dcc[idx].status & STAT_PAGE)
  286. i->page = dcc[idx].u.chat->max_line;
  287. else
  288. i->page = 0;
  289. if (dcc[idx].status & STAT_COLOR)
  290. i->color = 1;
  291. else
  292. i->color = 0;
  293. if (dcc[idx].status & STAT_BANNER)
  294. i->banner = 1;
  295. else
  296. i->banner = 0;
  297. if (dcc[idx].status & STAT_CHANNELS)
  298. i->channels = 1;
  299. else
  300. i->channels = 0;
  301. if (dcc[idx].status & STAT_BOTS)
  302. i->bots = 1;
  303. else
  304. i->bots = 0;
  305. if (dcc[idx].status & STAT_WHOM)
  306. i->whom = 1;
  307. else
  308. i->whom = 0;
  309. i->conchan = dcc[idx].u.chat->channel;
  310. if (par) {
  311. dprintf(idx, "%s\n", CONSOLE_SAVED_SETTINGS2);
  312. dprintf(idx, " %s %s\n", CONSOLE_CHANNEL, i->channel);
  313. dprintf(idx, " %s %s, %s %s, %s %s\n", CONSOLE_FLAGS,
  314. masktype(i->conflags), CONSOLE_STRIPFLAGS,
  315. stripmasktype(i->stripflags), CONSOLE_ECHO, i->echoflags ? CONSOLE_YES : CONSOLE_NO);
  316. dprintf(idx, " %s %d, %s %d\n", CONSOLE_PAGE_SETTING, i->page, CONSOLE_CHANNEL2, i->conchan);
  317. dprintf(idx, " Color: $b%s$b\n", i->color ? "on" : "off");
  318. dprintf(idx, " Login settings:\n");
  319. dprintf(idx, " Login settings:\n");
  320. dprintf(idx, " Banner: $b%-3s$b Bots: $b%-3s$b\n", i->banner ? "on" : "off", i->bots ? "on" : "off");
  321. dprintf(idx, " Channels: $b%-3s$b Whom: $b%-3s$b\n", i->channels ? "on" : "off", i->whom ? "on" : "off");
  322. }
  323. set_user(&USERENTRY_CONSOLE, dcc[idx].user, i);
  324. dprintf(idx, "Console setting stored.\n");
  325. if (conf.bot->hub)
  326. write_userfile(idx);
  327. return 0;
  328. }
  329. /* cmds.c:cmd_console calls this, better than chof bind - drummer,07/25/1999 */
  330. void
  331. console_dostore(int idx)
  332. {
  333. if (console_autosave)
  334. console_store(idx, NULL);
  335. return;
  336. }
  337. static cmd_t mychon[] = {
  338. {"*", "", (Function) console_chon, "console:chon", 0},
  339. {NULL, NULL, NULL, NULL, 0}
  340. };
  341. static cmd_t mydcc[] = {
  342. {"store", "", (Function) console_store, NULL, 0},
  343. {NULL, NULL, NULL, NULL, 0}
  344. };
  345. void
  346. console_init()
  347. {
  348. add_builtins("dcc", mydcc);
  349. add_builtins("chon", mychon);
  350. add_entry_type(&USERENTRY_CONSOLE);
  351. }