00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #define MODULE_NAME "console"
00027 #define MAKING_CONSOLE
00028
00029 #include "src/mod/module.h"
00030 #include <stdlib.h>
00031 #include "console.h"
00032
00033 static Function *global = NULL;
00034 static int console_autosave = 0;
00035 static int force_channel = 0;
00036 static int info_party = 0;
00037
00038 struct console_info {
00039 char *channel;
00040 int conflags;
00041 int stripflags;
00042 int echoflags;
00043 int page;
00044 int conchan;
00045 };
00046
00047 static struct user_entry_type USERENTRY_CONSOLE;
00048
00049
00050 static int console_unpack(struct userrec *u, struct user_entry *e)
00051 {
00052 struct console_info *ci = user_malloc(sizeof(struct console_info));
00053 char *par, *arg;
00054
00055 par = e->u.list->extra;
00056 arg = newsplit(&par);
00057 ci->channel = user_malloc(strlen(arg) + 1);
00058 strcpy(ci->channel, arg);
00059 arg = newsplit(&par);
00060 ci->conflags = logmodes(arg);
00061 arg = newsplit(&par);
00062 ci->stripflags = stripmodes(arg);
00063 arg = newsplit(&par);
00064 ci->echoflags = (arg[0] == '1') ? 1 : 0;
00065 arg = newsplit(&par);
00066 ci->page = atoi(arg);
00067 arg = newsplit(&par);
00068 ci->conchan = atoi(arg);
00069 list_type_kill(e->u.list);
00070 e->u.extra = ci;
00071 return 1;
00072 }
00073
00074 static int console_pack(struct userrec *u, struct user_entry *e)
00075 {
00076 char work[1024];
00077 struct console_info *ci;
00078 int l;
00079
00080 ci = (struct console_info *) e->u.extra;
00081
00082 l = simple_sprintf(work, "%s %s %s %d %d %d",
00083 ci->channel, masktype(ci->conflags),
00084 stripmasktype(ci->stripflags), ci->echoflags,
00085 ci->page, ci->conchan);
00086
00087 e->u.list = user_malloc(sizeof(struct list_type));
00088 e->u.list->next = NULL;
00089 e->u.list->extra = user_malloc(l + 1);
00090 strcpy(e->u.list->extra, work);
00091
00092 nfree(ci->channel);
00093 nfree(ci);
00094 return 1;
00095 }
00096
00097 static int console_kill(struct user_entry *e)
00098 {
00099 struct console_info *i = e->u.extra;
00100
00101 nfree(i->channel);
00102 nfree(i);
00103 nfree(e);
00104 return 1;
00105 }
00106
00107 static int console_write_userfile(FILE *f, struct userrec *u,
00108 struct user_entry *e)
00109 {
00110 struct console_info *i = e->u.extra;
00111
00112 if (fprintf(f, "--CONSOLE %s %s %s %d %d %d\n",
00113 i->channel, masktype(i->conflags),
00114 stripmasktype(i->stripflags), i->echoflags,
00115 i->page, i->conchan) == EOF)
00116 return 0;
00117 return 1;
00118 }
00119
00120 static int console_set(struct userrec *u, struct user_entry *e, void *buf)
00121 {
00122 struct console_info *ci = (struct console_info *) e->u.extra;
00123
00124 if (!ci && !buf)
00125 return 1;
00126
00127 if (ci != buf) {
00128 if (ci) {
00129 nfree(ci->channel);
00130 nfree(ci);
00131 }
00132 ci = e->u.extra = buf;
00133 }
00134
00135
00136 return 1;
00137 }
00138
00139 static int console_tcl_get(Tcl_Interp *irp, struct userrec *u,
00140 struct user_entry *e, int argc, char **argv)
00141 {
00142 char work[1024];
00143 struct console_info *i = e->u.extra;
00144
00145 simple_sprintf(work, "%s %s %s %d %d %d",
00146 i->channel, masktype(i->conflags),
00147 stripmasktype(i->stripflags), i->echoflags,
00148 i->page, i->conchan);
00149 Tcl_AppendResult(irp, work, NULL);
00150 return TCL_OK;
00151 }
00152
00153 static int console_tcl_set(Tcl_Interp *irp, struct userrec *u,
00154 struct user_entry *e, int argc, char **argv)
00155 {
00156 struct console_info *i = e->u.extra;
00157 int l;
00158
00159 BADARGS(4, 9, " handle CONSOLE channel flags strip echo page conchan");
00160
00161 if (!i) {
00162 i = user_malloc(sizeof(struct console_info));
00163 egg_bzero(i, sizeof(struct console_info));
00164 }
00165 if (i->channel)
00166 nfree(i->channel);
00167 l = strlen(argv[3]);
00168 if (l > 80)
00169 l = 80;
00170 i->channel = user_malloc(l + 1);
00171 strncpy(i->channel, argv[3], l);
00172 i->channel[l] = 0;
00173 if (argc > 4) {
00174 i->conflags = logmodes(argv[4]);
00175 if (argc > 5) {
00176 i->stripflags = stripmodes(argv[5]);
00177 if (argc > 6) {
00178 i->echoflags = (argv[6][0] == '1') ? 1 : 0;
00179 if (argc > 7) {
00180 i->page = atoi(argv[7]);
00181 if (argc > 8)
00182 i->conchan = atoi(argv[8]);
00183 }
00184 }
00185 }
00186 }
00187 set_user(&USERENTRY_CONSOLE, u, i);
00188 return TCL_OK;
00189 }
00190
00191 static int console_expmem(struct user_entry *e)
00192 {
00193 struct console_info *i = e->u.extra;
00194
00195 return sizeof(struct console_info) + strlen(i->channel) + 1;
00196 }
00197
00198 static void console_display(int idx, struct user_entry *e)
00199 {
00200 struct console_info *i = e->u.extra;
00201
00202 if (dcc[idx].user && (dcc[idx].user->flags & USER_MASTER)) {
00203 dprintf(idx, " %s\n", CONSOLE_SAVED_SETTINGS);
00204 dprintf(idx, " %s %s\n", CONSOLE_CHANNEL, i->channel);
00205 dprintf(idx, " %s %s, %s %s, %s %s\n", CONSOLE_FLAGS,
00206 masktype(i->conflags), CONSOLE_STRIPFLAGS,
00207 stripmasktype(i->stripflags), CONSOLE_ECHO,
00208 i->echoflags ? CONSOLE_YES : CONSOLE_NO);
00209 dprintf(idx, " %s %d, %s %s%d\n", CONSOLE_PAGE_SETTING, i->page,
00210 CONSOLE_CHANNEL2, (i->conchan < GLOBAL_CHANS) ? "" : "*",
00211 i->conchan % GLOBAL_CHANS);
00212 }
00213 }
00214
00215 static int console_dupuser(struct userrec *new, struct userrec *old,
00216 struct user_entry *e)
00217 {
00218 struct console_info *i = e->u.extra, *j;
00219
00220 j = user_malloc(sizeof(struct console_info));
00221 my_memcpy(j, i, sizeof(struct console_info));
00222
00223 j->channel = user_malloc(strlen(i->channel) + 1);
00224 strcpy(j->channel, i->channel);
00225 return set_user(e->type, new, j);
00226 }
00227
00228 static struct user_entry_type USERENTRY_CONSOLE = {
00229 NULL,
00230 NULL,
00231 console_dupuser,
00232 console_unpack,
00233 console_pack,
00234 console_write_userfile,
00235 console_kill,
00236 NULL,
00237 console_set,
00238 console_tcl_get,
00239 console_tcl_set,
00240 console_expmem,
00241 console_display,
00242 "CONSOLE"
00243 };
00244
00245 static int console_chon(char *handle, int idx)
00246 {
00247 struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
00248 struct console_info *i = get_user(&USERENTRY_CONSOLE, dcc[idx].user);
00249
00250 if (dcc[idx].type == &DCC_CHAT) {
00251 if (i) {
00252 if (i->channel && i->channel[0])
00253 strcpy(dcc[idx].u.chat->con_chan, i->channel);
00254 get_user_flagrec(dcc[idx].user, &fr, i->channel);
00255 dcc[idx].u.chat->con_flags = check_conflags(&fr, i->conflags);
00256 dcc[idx].u.chat->strip_flags = i->stripflags;
00257 if (i->echoflags)
00258 dcc[idx].status |= STAT_ECHO;
00259 else
00260 dcc[idx].status &= ~STAT_ECHO;
00261 if (i->page) {
00262 dcc[idx].status |= STAT_PAGE;
00263 dcc[idx].u.chat->max_line = i->page;
00264 if (!dcc[idx].u.chat->line_count)
00265 dcc[idx].u.chat->current_lines = 0;
00266 }
00267 dcc[idx].u.chat->channel = i->conchan;
00268 } else if (force_channel > -1)
00269 dcc[idx].u.chat->channel = force_channel;
00270 if ((dcc[idx].u.chat->channel >= 0) &&
00271 (dcc[idx].u.chat->channel < GLOBAL_CHANS)) {
00272 botnet_send_join_idx(idx, -1);
00273 check_tcl_chjn(botnetnick, dcc[idx].nick, dcc[idx].u.chat->channel,
00274 geticon(idx), dcc[idx].sock, dcc[idx].host);
00275 }
00276 if (info_party) {
00277 char *p = get_user(&USERENTRY_INFO, dcc[idx].user);
00278
00279 if (p) {
00280 if (dcc[idx].u.chat->channel >= 0) {
00281 char x[1024];
00282
00283 chanout_but(-1, dcc[idx].u.chat->channel,
00284 "*** [%s] %s\n", dcc[idx].nick, p);
00285 simple_sprintf(x, "[%s] %s", dcc[idx].nick, p);
00286 botnet_send_chan(-1, botnetnick, NULL, dcc[idx].u.chat->channel, x);
00287 }
00288 }
00289 }
00290 }
00291 return 0;
00292 }
00293
00294 static int console_store(struct userrec *u, int idx, char *par)
00295 {
00296 struct console_info *i = get_user(&USERENTRY_CONSOLE, u);
00297
00298 if (!i) {
00299 i = user_malloc(sizeof(struct console_info));
00300 egg_bzero(i, sizeof(struct console_info));
00301 }
00302 if (i->channel)
00303 nfree(i->channel);
00304 i->channel = user_malloc(strlen(dcc[idx].u.chat->con_chan) + 1);
00305 strcpy(i->channel, dcc[idx].u.chat->con_chan);
00306 i->conflags = dcc[idx].u.chat->con_flags;
00307 i->stripflags = dcc[idx].u.chat->strip_flags;
00308 i->echoflags = (dcc[idx].status & STAT_ECHO) ? 1 : 0;
00309 if (dcc[idx].status & STAT_PAGE)
00310 i->page = dcc[idx].u.chat->max_line;
00311 else
00312 i->page = 0;
00313 i->conchan = dcc[idx].u.chat->channel;
00314 if (par) {
00315 dprintf(idx, "%s\n", CONSOLE_SAVED_SETTINGS2);
00316 dprintf(idx, " %s %s\n", CONSOLE_CHANNEL, i->channel);
00317 dprintf(idx, " %s %s, %s %s, %s %s\n", CONSOLE_FLAGS,
00318 masktype(i->conflags), CONSOLE_STRIPFLAGS,
00319 stripmasktype(i->stripflags), CONSOLE_ECHO,
00320 i->echoflags ? CONSOLE_YES : CONSOLE_NO);
00321 dprintf(idx, " %s %d, %s %d\n", CONSOLE_PAGE_SETTING, i->page,
00322 CONSOLE_CHANNEL2, i->conchan);
00323 }
00324 set_user(&USERENTRY_CONSOLE, u, i);
00325 return 0;
00326 }
00327
00328
00329 static int console_dostore(int idx)
00330 {
00331 if (console_autosave)
00332 console_store(dcc[idx].user, idx, NULL);
00333 return 0;
00334 }
00335
00336 static tcl_ints myints[] = {
00337 {"console-autosave", &console_autosave, 0},
00338 {"force-channel", &force_channel, 0},
00339 {"info-party", &info_party, 0},
00340 {NULL, NULL, 0}
00341 };
00342
00343 static cmd_t mychon[] = {
00344 {"*", "", console_chon, "console:chon"},
00345 {NULL, NULL, NULL, NULL}
00346 };
00347
00348 static cmd_t mydcc[] = {
00349 {"store", "", console_store, NULL},
00350 {NULL, NULL, NULL, NULL}
00351 };
00352
00353 static char *console_close()
00354 {
00355 rem_builtins(H_chon, mychon);
00356 rem_builtins(H_dcc, mydcc);
00357 rem_tcl_ints(myints);
00358 rem_help_reference("console.help");
00359 del_entry_type(&USERENTRY_CONSOLE);
00360 del_lang_section("console");
00361 module_undepend(MODULE_NAME);
00362 return NULL;
00363 }
00364
00365 EXPORT_SCOPE char *console_start();
00366
00367 static Function console_table[] = {
00368 (Function) console_start,
00369 (Function) console_close,
00370 (Function) NULL,
00371 (Function) NULL,
00372 (Function) console_dostore,
00373 };
00374
00375 char *console_start(Function *global_funcs)
00376 {
00377 global = global_funcs;
00378
00379 module_register(MODULE_NAME, console_table, 1, 2);
00380 if (!module_depend(MODULE_NAME, "eggdrop", 106, 20)) {
00381 module_undepend(MODULE_NAME);
00382 return "This module requires Eggdrop 1.6.20 or later.";
00383 }
00384 add_builtins(H_chon, mychon);
00385 add_builtins(H_dcc, mydcc);
00386 add_tcl_ints(myints);
00387 add_help_reference("console.help");
00388 USERENTRY_CONSOLE.get = def_get;
00389 add_entry_type(&USERENTRY_CONSOLE);
00390 add_lang_section("console");
00391 return NULL;
00392 }