src/mod/assoc.mod/assoc.c File Reference

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

Go to the source code of this file.

Data Structures

struct  assoc_t_

Defines

#define MODULE_NAME   "assoc"
#define MAKING_ASSOC

Typedefs

typedef struct assoc_t_ assoc_t

Functions

static void botnet_send_assoc (int idx, int chan, char *nick, char *buf)
static int assoc_expmem ()
static void link_assoc (char *bot, char *via)
static void kill_assoc (int chan)
static void kill_all_assoc ()
static void add_assoc (char *name, int chan)
static int get_assoc (char *name)
static char * get_assoc_name (int chan)
static void dump_assoc (int idx)
static int cmd_assoc (struct userrec *u, int idx, char *par)
static char * assoc_close ()
EXPORT_SCOPE char * assoc_start ()
char * assoc_start (Function *global_funcs)

Variables

static Functionglobal = 0
static assoc_tassoc
static cmd_t mybot []
static cmd_t mylink []
static tcl_cmds mytcl []
static Function assoc_table []

Define Documentation

#define MAKING_ASSOC

Definition at line 27 of file assoc.c.

#define MODULE_NAME   "assoc"

Typedef Documentation

typedef struct assoc_t_ assoc_t

Function Documentation

static void add_assoc ( char *  name,
int  chan 
) [static]

Definition at line 118 of file assoc.c.

References assoc_t_::channel, egg_strcasecmp, kill_assoc(), assoc_t_::name, assoc_t_::next, nmalloc, NULL, and strncpyz.

Referenced by cmd_assoc().

00119 {
00120   assoc_t *a, *b, *old = NULL;
00121 
00122   for (a = assoc; a; a = a->next) {
00123     if (name[0] != 0 && !egg_strcasecmp(a->name, name)) {
00124       kill_assoc(a->channel);
00125       add_assoc(name, chan);
00126       return;
00127     }
00128     if (a->channel == chan) {
00129       strncpyz(a->name, name, sizeof a->name);
00130       return;
00131     }
00132   }
00133   /* Add in numerical order */
00134   for (a = assoc; a; old = a, a = a->next) {
00135     if (a->channel > chan) {
00136       b = nmalloc(sizeof *b);
00137       b->next = a;
00138       b->channel = chan;
00139       strncpyz(b->name, name, sizeof b->name);
00140       if (old == NULL)
00141         assoc = b;
00142       else
00143         old->next = b;
00144       return;
00145     }
00146   }
00147   /* Add at the end */
00148   b = nmalloc(sizeof *b);
00149   b->next = NULL;
00150   b->channel = chan;
00151   strncpyz(b->name, name, sizeof b->name);
00152   if (old == NULL)
00153     assoc = b;
00154   else
00155     old->next = b;
00156 }

Here is the call graph for this function:

Here is the caller graph for this function:

static char* assoc_close (  )  [static]

Definition at line 386 of file assoc.c.

References del_lang_section, H_bot, H_dcc, H_link, kill_all_assoc(), MODULE_NAME, module_undepend, NULL, rem_builtins, rem_help_reference, and rem_tcl_commands.

00387 {
00388   kill_all_assoc();
00389   rem_builtins(H_dcc, mydcc);
00390   rem_builtins(H_bot, mybot);
00391   rem_builtins(H_link, mylink);
00392   rem_tcl_commands(mytcl);
00393   rem_help_reference("assoc.help");
00394   del_lang_section("assoc");
00395   module_undepend(MODULE_NAME);
00396   return NULL;
00397 }

Here is the call graph for this function:

static int assoc_expmem (  )  [static]

Definition at line 60 of file assoc.c.

References assoc_t_::next.

00061 {
00062   assoc_t *a;
00063   int size = 0;
00064 
00065   for (a = assoc; a; a = a->next)
00066     size += sizeof(assoc_t);
00067   return size;
00068 }

char* assoc_start ( Function global_funcs  ) 

Definition at line 408 of file assoc.c.

References add_builtins, add_help_reference, add_lang_section, add_tcl_commands, global, H_bot, H_dcc, H_link, module_depend, MODULE_NAME, module_register, module_undepend, and NULL.

00409 {
00410   global = global_funcs;
00411 
00412   module_register(MODULE_NAME, assoc_table, 2, 0);
00413   if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
00414     module_undepend(MODULE_NAME);
00415     return "This module requires Eggdrop 1.6.0 or later.";
00416   }
00417   assoc = NULL;
00418   add_builtins(H_dcc, mydcc);
00419   add_builtins(H_bot, mybot);
00420   add_builtins(H_link, mylink);
00421   add_lang_section("assoc");
00422   add_tcl_commands(mytcl);
00423   add_help_reference("assoc.help");
00424   return NULL;
00425 }

EXPORT_SCOPE char* assoc_start (  ) 
static void botnet_send_assoc ( int  idx,
int  chan,
char *  nick,
char *  buf 
) [static]

Definition at line 47 of file assoc.c.

References b_numver, bot_flags, BOT_ISOLATE, botnet_send_zapf, botnetnick, dcc, DCC_BOT, dcc_total, NEAT_BOTNET, simple_sprintf, and user.

Referenced by cmd_assoc().

00048 {
00049   char x[1024];
00050   int idx2;
00051 
00052   simple_sprintf(x, "assoc %D %s %s", chan, nick, buf);
00053   for (idx2 = 0; idx2 < dcc_total; idx2++)
00054     if ((dcc[idx2].type == &DCC_BOT) && (idx2 != idx) &&
00055         (b_numver(idx2) >= NEAT_BOTNET) &&
00056         !(bot_flags(dcc[idx2].user) & BOT_ISOLATE))
00057       botnet_send_zapf(idx2, botnetnick, dcc[idx2].nick, x);
00058 }

Here is the caller graph for this function:

static int cmd_assoc ( struct userrec u,
int  idx,
char *  par 
) [static]

Definition at line 193 of file assoc.c.

References add_assoc(), ASSOC_CHAN_RANGE, ASSOC_CHNAME_FIRSTCHAR, ASSOC_CHNAME_TOOLONG, ASSOC_LCHAN_RANGE, ASSOC_NEWNAME_CHAN, ASSOC_NEWOUT_CHAN, ASSOC_NONAME_CHAN, ASSOC_PARTYLINE, ASSOC_REMNAME_CHAN, ASSOC_REMOUT_CHAN, botnet_send_assoc(), chanout_but, dcc, dprintf, dump_assoc(), userrec::flags, get_assoc_name(), GLOBAL_CHANS, kill_assoc(), LOG_CMDS, MISC_NOSUCHCMD, newsplit, NULL, putlog, and USER_BOTMAST.

00194 {
00195   char *num;
00196   int chan;
00197 
00198   if (!par[0]) {
00199     putlog(LOG_CMDS, "*", "#%s# assoc", dcc[idx].nick);
00200     dump_assoc(idx);
00201   } else if (!u || !(u->flags & USER_BOTMAST))
00202     dprintf(idx, "%s", MISC_NOSUCHCMD);
00203   else {
00204     num = newsplit(&par);
00205     if (num[0] == '*') {
00206       chan = GLOBAL_CHANS + atoi(num + 1);
00207       if ((chan < GLOBAL_CHANS) || (chan > 199999)) {
00208         dprintf(idx, "%s\n", ASSOC_LCHAN_RANGE);
00209         return 0;
00210       }
00211     } else {
00212       chan = atoi(num);
00213       if (chan == 0) {
00214         dprintf(idx, "%s\n", ASSOC_PARTYLINE);
00215         return 0;
00216       } else if ((chan < 1) || (chan >= GLOBAL_CHANS)) {
00217         dprintf(idx, "%s\n", ASSOC_CHAN_RANGE);
00218         return 0;
00219       }
00220     }
00221     if (!par[0]) {
00222       /* Remove an association */
00223       if (get_assoc_name(chan) == NULL) {
00224         dprintf(idx, ASSOC_NONAME_CHAN, (chan < GLOBAL_CHANS) ? "" : "*",
00225                 chan % GLOBAL_CHANS);
00226         return 0;
00227       }
00228       kill_assoc(chan);
00229       putlog(LOG_CMDS, "*", "#%s# assoc %d", dcc[idx].nick, chan);
00230       dprintf(idx, ASSOC_REMNAME_CHAN, (chan < GLOBAL_CHANS) ? "" : "*",
00231               chan % GLOBAL_CHANS);
00232       chanout_but(-1, chan, ASSOC_REMOUT_CHAN, dcc[idx].nick);
00233       if (chan < GLOBAL_CHANS)
00234         botnet_send_assoc(-1, chan, dcc[idx].nick, "0");
00235       return 0;
00236     }
00237     if (strlen(par) > 20) {
00238       dprintf(idx, "%s\n", ASSOC_CHNAME_TOOLONG);
00239       return 0;
00240     }
00241     if ((par[0] >= '0') && (par[0] <= '9')) {
00242       dprintf(idx, "%s\n", ASSOC_CHNAME_FIRSTCHAR);
00243       return 0;
00244     }
00245     add_assoc(par, chan);
00246     putlog(LOG_CMDS, "*", "#%s# assoc %d %s", dcc[idx].nick, chan, par);
00247     dprintf(idx, ASSOC_NEWNAME_CHAN, (chan < GLOBAL_CHANS) ? "" : "*",
00248             chan % GLOBAL_CHANS, par);
00249     chanout_but(-1, chan, ASSOC_NEWOUT_CHAN, dcc[idx].nick, par);
00250     if (chan < GLOBAL_CHANS)
00251       botnet_send_assoc(-1, chan, dcc[idx].nick, par);
00252   }
00253   return 0;
00254 }

Here is the call graph for this function:

static void dump_assoc ( int  idx  )  [static]

Definition at line 178 of file assoc.c.

References ASSOC_CHAN, ASSOC_NAME, ASSOC_NOCHNAMES, assoc_t_::channel, dprintf, GLOBAL_CHANS, assoc_t_::name, assoc_t_::next, and NULL.

Referenced by cmd_assoc().

00179 {
00180   assoc_t *a = assoc;
00181 
00182   if (a == NULL) {
00183     dprintf(idx, "%s\n", ASSOC_NOCHNAMES);
00184     return;
00185   }
00186   dprintf(idx, " %s  %s\n", ASSOC_CHAN, ASSOC_NAME);
00187   for (; a && a->name[0]; a = a->next)
00188     dprintf(idx, "%c%5d %s\n", (a->channel < GLOBAL_CHANS) ? ' ' : '*',
00189             a->channel % GLOBAL_CHANS, a->name);
00190   return;
00191 }

Here is the caller graph for this function:

static int get_assoc ( char *  name  )  [static]

Definition at line 158 of file assoc.c.

References assoc_t_::channel, egg_strcasecmp, assoc_t_::name, and assoc_t_::next.

00159 {
00160   assoc_t *a;
00161 
00162   for (a = assoc; a; a = a->next)
00163     if (!egg_strcasecmp(a->name, name))
00164       return a->channel;
00165   return -1;
00166 }

static char* get_assoc_name ( int  chan  )  [static]

Definition at line 168 of file assoc.c.

References assoc_t_::channel, assoc_t_::name, assoc_t_::next, and NULL.

Referenced by cmd_assoc().

00169 {
00170   assoc_t *a;
00171 
00172   for (a = assoc; a; a = a->next)
00173     if (a->channel == chan)
00174       return a->name;
00175   return NULL;
00176 }

Here is the caller graph for this function:

static void kill_all_assoc (  )  [static]

Definition at line 107 of file assoc.c.

References assoc_t_::next, nfree, and NULL.

Referenced by assoc_close().

00108 {
00109   assoc_t *a, *x;
00110 
00111   for (a = assoc; a; a = x) {
00112     x = a->next;
00113     nfree(a);
00114   }
00115   assoc = NULL;
00116 }

Here is the caller graph for this function:

static void kill_assoc ( int  chan  )  [static]

Definition at line 88 of file assoc.c.

References assoc_t_::channel, assoc_t_::next, nfree, and NULL.

Referenced by add_assoc(), and cmd_assoc().

00089 {
00090   assoc_t *a = assoc, *last = NULL;
00091 
00092   while (a) {
00093     if (a->channel == chan) {
00094       if (last != NULL)
00095         last->next = a->next;
00096       else
00097         assoc = a->next;
00098       nfree(a);
00099       a = NULL;
00100     } else {
00101       last = a;
00102       a = a->next;
00103     }
00104   }
00105 }

Here is the caller graph for this function:

static void link_assoc ( char *  bot,
char *  via 
) [static]

Definition at line 70 of file assoc.c.

References bot_flags, BOT_ISOLATE, botnet_send_zapf, botnetnick, assoc_t_::channel, dcc, egg_strcasecmp, assoc_t_::name, assoc_t_::next, nextbot, simple_sprintf, and user.

00071 {
00072   char x[1024];
00073 
00074   if (!egg_strcasecmp(via, botnetnick)) {
00075     int idx = nextbot(bot);
00076     assoc_t *a;
00077 
00078     if (!(bot_flags(dcc[idx].user) & BOT_ISOLATE)) {
00079       for (a = assoc; a && a->name[0]; a = a->next) {
00080         simple_sprintf(x, "assoc %D %s %s", (int) a->channel, botnetnick,
00081                        a->name);
00082         botnet_send_zapf(idx, botnetnick, dcc[idx].nick, x);
00083       }
00084     }
00085   }
00086 }


Variable Documentation

assoc_t* assoc [static]

Definition at line 45 of file assoc.c.

Function assoc_table[] [static]
Initial value:

Definition at line 401 of file assoc.c.

Function* global = 0 [static]
cmd_t mybot[] [static]
Initial value:
 {
  {"assoc", "",   (IntFunc) zapf_assoc,  0 },
  { 0 ,     0 ,  0 ,                   0 }
}

Definition at line 370 of file assoc.c.

cmd_t mylink[] [static]
Initial value:
 {
  {"*",  "",   (IntFunc) link_assoc, "assoc"},
  { 0 ,  0 ,  0 ,                      0 }
}

Definition at line 375 of file assoc.c.

tcl_cmds mytcl[] [static]
Initial value:
 {
  {"assoc",         tcl_assoc},
  {"killassoc", tcl_killassoc},
  { 0 ,                  0 }
}

Definition at line 380 of file assoc.c.


Generated on 7 Sep 2016 for Eggdrop by  doxygen 1.6.1