console.c 11 KB

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