src/mod/console.mod/console.c File Reference

#include "src/mod/module.h"
#include <stdlib.h>
#include "console.h"
Include dependency graph for console.c:

Go to the source code of this file.

Data Structures

struct  console_info

Defines

#define MODULE_NAME   "console"
#define MAKING_CONSOLE

Functions

static int console_unpack (struct userrec *u, struct user_entry *e)
static int console_pack (struct userrec *u, struct user_entry *e)
static int console_kill (struct user_entry *e)
static int console_write_userfile (FILE *f, struct userrec *u, struct user_entry *e)
static int console_set (struct userrec *u, struct user_entry *e, void *buf)
static int console_tcl_get (Tcl_Interp *irp, struct userrec *u, struct user_entry *e, int argc, char **argv)
static int console_tcl_set (Tcl_Interp *irp, struct userrec *u, struct user_entry *e, int argc, char **argv)
static int console_expmem (struct user_entry *e)
static void console_display (int idx, struct user_entry *e)
static int console_dupuser (struct userrec *new, struct userrec *old, struct user_entry *e)
static int console_chon (char *handle, int idx)
static int console_store (struct userrec *u, int idx, char *par)
static int console_dostore (int idx)
static char * console_close ()
EXPORT_SCOPE char * console_start ()
char * console_start (Function *global_funcs)

Variables

static Functionglobal = 0
static int console_autosave = 0
static int force_channel = 0
static int info_party = 0
static struct user_entry_type USERENTRY_CONSOLE
static tcl_ints myints []
static cmd_t mychon []
static cmd_t mydcc []
static Function console_table []

Define Documentation

#define MAKING_CONSOLE

Definition at line 27 of file console.c.

#define MODULE_NAME   "console"

Definition at line 26 of file console.c.


Function Documentation

static int console_chon ( char *  handle,
int  idx 
) [static]

Definition at line 245 of file console.c.

References botnet_send_chan, botnet_send_join_idx, botnetnick, console_info::channel, chanout_but, check_conflags, check_tcl_chjn, console_info::conchan, console_info::conflags, dcc, DCC_CHAT, console_info::echoflags, force_channel, FR_CHAN, FR_GLOBAL, get_user, get_user_flagrec, geticon, GLOBAL_CHANS, info_party, NULL, console_info::page, simple_sprintf, STAT_ECHO, STAT_PAGE, console_info::stripflags, user, and USERENTRY_INFO.

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 }

static char* console_close (  )  [static]

Definition at line 353 of file console.c.

References del_entry_type, del_lang_section, H_chon, H_dcc, MODULE_NAME, module_undepend, NULL, rem_builtins, rem_help_reference, and rem_tcl_ints.

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 }

static void console_display ( int  idx,
struct user_entry e 
) [static]
static int console_dostore ( int  idx  )  [static]

Definition at line 329 of file console.c.

References console_autosave, console_store(), dcc, NULL, and user.

00330 {
00331   if (console_autosave)
00332     console_store(dcc[idx].user, idx, NULL);
00333   return 0;
00334 }

Here is the call graph for this function:

static int console_dupuser ( struct userrec new,
struct userrec old,
struct user_entry e 
) [static]

Definition at line 215 of file console.c.

References console_info::channel, user_entry::extra, my_memcpy, set_user, user_entry::type, user_entry::u, and user_malloc.

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 }

static int console_expmem ( struct user_entry e  )  [static]

Definition at line 191 of file console.c.

References user_entry::extra, and user_entry::u.

00192 {
00193   struct console_info *i = e->u.extra;
00194 
00195   return sizeof(struct console_info) + strlen(i->channel) + 1;
00196 }

static int console_kill ( struct user_entry e  )  [static]

Definition at line 97 of file console.c.

References console_info::channel, user_entry::extra, nfree, and user_entry::u.

00098 {
00099   struct console_info *i = e->u.extra;
00100 
00101   nfree(i->channel);
00102   nfree(i);
00103   nfree(e);
00104   return 1;
00105 }

static int console_pack ( struct userrec u,
struct user_entry e 
) [static]

Definition at line 74 of file console.c.

References console_info::channel, console_info::conchan, console_info::conflags, console_info::echoflags, list_type::extra, user_entry::extra, user_entry::list, masktype, list_type::next, nfree, NULL, console_info::page, simple_sprintf, console_info::stripflags, stripmasktype, user_entry::u, and user_malloc.

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 }

static int console_set ( struct userrec u,
struct user_entry e,
void *  buf 
) [static]

Definition at line 120 of file console.c.

References console_info::channel, user_entry::extra, nfree, and user_entry::u.

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   /* Note: Do not share console info */
00136   return 1;
00137 }

char* console_start ( Function global_funcs  ) 

Definition at line 375 of file console.c.

References add_builtins, add_entry_type, add_help_reference, add_lang_section, add_tcl_ints, console_table, def_get, user_entry_type::get, global, H_chon, H_dcc, module_depend, MODULE_NAME, module_register, module_undepend, and NULL.

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 }

EXPORT_SCOPE char* console_start (  ) 
static int console_store ( struct userrec u,
int  idx,
char *  par 
) [static]

Definition at line 294 of file console.c.

References console_info::channel, console_info::conchan, console_info::conflags, CONSOLE_CHANNEL, CONSOLE_CHANNEL2, CONSOLE_ECHO, CONSOLE_FLAGS, CONSOLE_NO, CONSOLE_PAGE_SETTING, CONSOLE_SAVED_SETTINGS2, CONSOLE_STRIPFLAGS, CONSOLE_YES, dcc, dprintf, console_info::echoflags, egg_bzero, get_user, masktype, nfree, console_info::page, set_user, STAT_ECHO, STAT_PAGE, console_info::stripflags, stripmasktype, and user_malloc.

Referenced by console_dostore().

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 }

Here is the caller graph for this function:

static int console_tcl_get ( Tcl_Interp irp,
struct userrec u,
struct user_entry e,
int  argc,
char **  argv 
) [static]

Definition at line 139 of file console.c.

References console_info::channel, console_info::conchan, console_info::conflags, console_info::echoflags, user_entry::extra, masktype, NULL, console_info::page, simple_sprintf, console_info::stripflags, stripmasktype, and user_entry::u.

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 }

static int console_tcl_set ( Tcl_Interp irp,
struct userrec u,
struct user_entry e,
int  argc,
char **  argv 
) [static]

Definition at line 153 of file console.c.

References BADARGS, console_info::channel, console_info::conchan, console_info::conflags, console_info::echoflags, egg_bzero, user_entry::extra, logmodes, nfree, console_info::page, set_user, console_info::stripflags, stripmodes, user_entry::u, user_malloc, and USERENTRY_CONSOLE.

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 }

static int console_unpack ( struct userrec u,
struct user_entry e 
) [static]

Definition at line 50 of file console.c.

References console_info::channel, console_info::conchan, console_info::conflags, console_info::echoflags, user_entry::extra, list_type::extra, user_entry::list, list_type_kill, logmodes, newsplit, console_info::page, console_info::stripflags, stripmodes, user_entry::u, and user_malloc.

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 }

static int console_write_userfile ( FILE *  f,
struct userrec u,
struct user_entry e 
) [static]

Definition at line 107 of file console.c.

References console_info::channel, console_info::conchan, console_info::conflags, console_info::echoflags, user_entry::extra, masktype, console_info::page, console_info::stripflags, stripmasktype, and user_entry::u.

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 }


Variable Documentation

int console_autosave = 0 [static]

Definition at line 34 of file console.c.

Referenced by console_dostore().

Function console_table[] [static]
Initial value:

Definition at line 367 of file console.c.

Referenced by console_start().

int force_channel = 0 [static]

Definition at line 35 of file console.c.

Referenced by console_chon().

Function* global = 0 [static]

Definition at line 33 of file console.c.

int info_party = 0 [static]

Definition at line 36 of file console.c.

Referenced by console_chon().

cmd_t mychon[] [static]
Initial value:
 {
  {"*",  "",   console_chon, "console:chon"},
  { 0 ,  0 ,  0 ,                    0 }
}

Definition at line 343 of file console.c.

cmd_t mydcc[] [static]
Initial value:
 {
  {"store", "",   console_store,  0 },
  { 0 ,     0 ,  0 ,           0 }
}

Definition at line 348 of file console.c.

tcl_ints myints[] [static]
Initial value:
 {
  {"console-autosave", &console_autosave, 0},
  {"force-channel",    &force_channel,    0},
  {"info-party",       &info_party,       0},
  { 0 ,                0 ,              0}
}

Definition at line 336 of file console.c.

static struct user_entry_type USERENTRY_CONSOLE [static, read]

Generated on 7 Sep 2016 for Eggdrop by  doxygen 1.6.1