~ubuntu-branches/ubuntu/oneiric/eggdrop/oneiric

« back to all changes in this revision

Viewing changes to src/mod/assoc.mod/assoc.c

  • Committer: Bazaar Package Importer
  • Author(s): Guilherme de S. Pastore
  • Date: 2004-06-17 09:15:28 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040617091528-64rrw1sa33lkfhmh
Tags: 1.6.16-2
* Fixed typo on README.Debian
* Fixed hyphens in manual page
* Converted debian/rules to CDBS
* Set path to binary on example config file
* Changed LANGDIR on src/eggdrop.h (Closes: #254824)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * assoc.c -- part of assoc.mod
3
3
 *   the assoc code, moved here mainly from botnet.c for module work
4
4
 *
5
 
 * $Id: assoc.c,v 1.19 2002/01/02 08:06:14 tothwolf Exp $
 
5
 * $Id: assoc.c,v 1.28 2004/01/09 05:56:37 wcc Exp $
6
6
 */
7
7
/*
8
8
 * Copyright (C) 1997 Robey Pointer
9
 
 * Copyright (C) 1999, 2000, 2001, 2002 Eggheads Development Team
 
9
 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Eggheads Development Team
10
10
 *
11
11
 * This program is free software; you can redistribute it and/or
12
12
 * modify it under the terms of the GNU General Public License
43
43
/* Channel name-number associations */
44
44
static assoc_t *assoc;
45
45
 
46
 
static void botnet_send_assoc(int idx, int chan, char *nick,
47
 
                              char *buf)
 
46
static void botnet_send_assoc(int idx, int chan, char *nick, char *buf)
48
47
{
49
48
  char x[1024];
50
49
  int idx2;
52
51
  simple_sprintf(x, "assoc %D %s %s", chan, nick, buf);
53
52
  for (idx2 = 0; idx2 < dcc_total; idx2++)
54
53
    if ((dcc[idx2].type == &DCC_BOT) && (idx2 != idx) &&
55
 
        (b_numver(idx2) >= NEAT_BOTNET) &&
56
 
        !(bot_flags(dcc[idx2].user) & BOT_ISOLATE))
 
54
        (b_numver(idx2) >= NEAT_BOTNET) &&
 
55
        !(bot_flags(dcc[idx2].user) & BOT_ISOLATE))
57
56
      botnet_send_zapf(idx2, botnetnick, dcc[idx2].nick, x);
58
57
}
59
58
 
77
76
 
78
77
    if (!(bot_flags(dcc[idx].user) & BOT_ISOLATE)) {
79
78
      for (a = assoc; a && a->name[0]; a = a->next) {
80
 
          simple_sprintf(x, "assoc %D %s %s", (int) a->channel, botnetnick,
81
 
                        a->name);
82
 
          botnet_send_zapf(idx, botnetnick, dcc[idx].nick, x);
83
 
        }
 
79
        simple_sprintf(x, "assoc %D %s %s", (int) a->channel, botnetnick,
 
80
                       a->name);
 
81
        botnet_send_zapf(idx, botnetnick, dcc[idx].nick, x);
 
82
      }
84
83
    }
85
84
  }
86
85
}
92
91
  while (a) {
93
92
    if (a->channel == chan) {
94
93
      if (last != NULL)
95
 
        last->next = a->next;
 
94
        last->next = a->next;
96
95
      else
97
 
        assoc = a->next;
 
96
        assoc = a->next;
98
97
      nfree(a);
99
98
      a = NULL;
100
99
    } else {
138
137
      b->channel = chan;
139
138
      strncpyz(b->name, name, sizeof b->name);
140
139
      if (old == NULL)
141
 
        assoc = b;
 
140
        assoc = b;
142
141
      else
143
 
        old->next = b;
 
142
        old->next = b;
144
143
      return;
145
144
    }
146
145
  }
185
184
  }
186
185
  dprintf(idx, " %s  %s\n", ASSOC_CHAN, ASSOC_NAME);
187
186
  for (; a && a->name[0]; a = a->next)
188
 
      dprintf(idx, "%c%5d %s\n", (a->channel < 100000) ? ' ' : '*',
189
 
              a->channel % 100000, a->name);
 
187
    dprintf(idx, "%c%5d %s\n", (a->channel < GLOBAL_CHANS) ? ' ' : '*',
 
188
            a->channel % GLOBAL_CHANS, a->name);
190
189
  return;
191
190
}
192
191
 
198
197
  if (!par[0]) {
199
198
    putlog(LOG_CMDS, "*", "#%s# assoc", dcc[idx].nick);
200
199
    dump_assoc(idx);
201
 
  } else if (!u || !(u->flags & USER_BOTMAST)) {
202
 
    dprintf(idx, "%s", ASSOC_NOSUCHCMD);
203
 
  } else {
 
200
  } else if (!u || !(u->flags & USER_BOTMAST))
 
201
    dprintf(idx, "%s", MISC_NOSUCHCMD);
 
202
  else {
204
203
    num = newsplit(&par);
205
204
    if (num[0] == '*') {
206
 
      chan = 100000 + atoi(num + 1);
207
 
      if ((chan < 100000) || (chan > 199999)) {
208
 
           dprintf(idx, "%s\n", ASSOC_LCHAN_RANGE);
209
 
        return 0;
 
205
      chan = GLOBAL_CHANS + atoi(num + 1);
 
206
      if ((chan < GLOBAL_CHANS) || (chan > 199999)) {
 
207
        dprintf(idx, "%s\n", ASSOC_LCHAN_RANGE);
 
208
        return 0;
210
209
      }
211
210
    } else {
212
211
      chan = atoi(num);
213
212
      if (chan == 0) {
214
 
            dprintf(idx, "%s\n", ASSOC_PARTYLINE);
215
 
        return 0;
216
 
      } else if ((chan < 1) || (chan > 99999)) {
217
 
            dprintf(idx, "%s\n", ASSOC_CHAN_RANGE);
218
 
        return 0;
 
213
        dprintf(idx, "%s\n", ASSOC_PARTYLINE);
 
214
        return 0;
 
215
      } else if ((chan < 1) || (chan >= GLOBAL_CHANS)) {
 
216
        dprintf(idx, "%s\n", ASSOC_CHAN_RANGE);
 
217
        return 0;
219
218
      }
220
219
    }
221
220
    if (!par[0]) {
222
221
      /* Remove an association */
223
222
      if (get_assoc_name(chan) == NULL) {
224
 
            dprintf(idx, ASSOC_NONAME_CHAN, (chan < 100000) ? "" : "*",
225
 
                    chan % 100000);
226
 
        return 0;
 
223
        dprintf(idx, ASSOC_NONAME_CHAN, (chan < GLOBAL_CHANS) ? "" : "*",
 
224
                chan % GLOBAL_CHANS);
 
225
        return 0;
227
226
      }
228
227
      kill_assoc(chan);
229
228
      putlog(LOG_CMDS, "*", "#%s# assoc %d", dcc[idx].nick, chan);
230
 
      dprintf(idx, ASSOC_REMNAME_CHAN, (chan < 100000) ? "" : "*",
231
 
              chan % 100000);
 
229
      dprintf(idx, ASSOC_REMNAME_CHAN, (chan < GLOBAL_CHANS) ? "" : "*",
 
230
              chan % GLOBAL_CHANS);
232
231
      chanout_but(-1, chan, ASSOC_REMOUT_CHAN, dcc[idx].nick);
233
 
      if (chan < 100000)
234
 
        botnet_send_assoc(-1, chan, dcc[idx].nick, "0");
 
232
      if (chan < GLOBAL_CHANS)
 
233
        botnet_send_assoc(-1, chan, dcc[idx].nick, "0");
235
234
      return 0;
236
235
    }
237
236
    if (strlen(par) > 20) {
244
243
    }
245
244
    add_assoc(par, chan);
246
245
    putlog(LOG_CMDS, "*", "#%s# assoc %d %s", dcc[idx].nick, chan, par);
247
 
    dprintf(idx, ASSOC_NEWNAME_CHAN, (chan < 100000) ? "" : "*",
248
 
            chan % 100000, par);
249
 
    chanout_but(-1, chan, ASSOC_NEWOUT_CHAN, dcc[idx].nick,
250
 
                par);
251
 
    if (chan < 100000)
 
246
    dprintf(idx, ASSOC_NEWNAME_CHAN, (chan < GLOBAL_CHANS) ? "" : "*",
 
247
            chan % GLOBAL_CHANS, par);
 
248
    chanout_but(-1, chan, ASSOC_NEWOUT_CHAN, dcc[idx].nick, par);
 
249
    if (chan < GLOBAL_CHANS)
252
250
      botnet_send_assoc(-1, chan, dcc[idx].nick, par);
253
251
  }
254
252
  return 0;
255
253
}
256
254
 
257
 
static int tcl_killassoc STDVAR {
 
255
static int tcl_killassoc STDVAR
 
256
{
258
257
  int chan;
259
258
 
260
259
  BADARGS(2, 2, " chan");
 
260
  
261
261
  if (argv[1][0] == '&')
262
262
    kill_all_assoc();
263
263
  else {
267
267
      return TCL_ERROR;
268
268
    }
269
269
    kill_assoc(chan);
 
270
 
270
271
    botnet_send_assoc(-1, chan, "*script*", "0");
271
272
  }
272
273
  return TCL_OK;
273
274
}
274
275
 
275
 
static int tcl_assoc STDVAR {
 
276
static int tcl_assoc STDVAR
 
277
{
276
278
  int chan;
277
279
  char name[21], *p;
278
280
 
279
281
  BADARGS(2, 3, " chan ?name?");
 
282
  
280
283
  if ((argc == 2) && ((argv[1][0] < '0') || (argv[1][0] > '9'))) {
281
284
    chan = get_assoc(argv[1]);
282
285
    if (chan == -1)
322
325
      nick = newsplit(&par);
323
326
      s1 = get_assoc_name(chan);
324
327
      if (linking && ((s1 == NULL) || (s1[0] == 0) ||
325
 
                      (((int) get_user(find_entry_type("BOTFL"),
326
 
                                       dcc[idx].user) & BOT_HUB)))) {
327
 
        add_assoc(par, chan);
328
 
        botnet_send_assoc(idx, chan, nick, par);
329
 
        chanout_but(-1, chan, ASSOC_CHNAME_NAMED, nick, par);
 
328
          (((int) get_user(find_entry_type("BOTFL"),
 
329
          dcc[idx].user) & BOT_HUB)))) {
 
330
        add_assoc(par, chan);
 
331
        botnet_send_assoc(idx, chan, nick, par);
 
332
        chanout_but(-1, chan, ASSOC_CHNAME_NAMED, nick, par);
330
333
      } else if (par[0] == '0') {
331
 
        kill_assoc(chan);
332
 
        chanout_but(-1, chan, ASSOC_CHNAME_REM, botnick, nick);
 
334
        kill_assoc(chan);
 
335
        chanout_but(-1, chan, ASSOC_CHNAME_REM, botnick, nick);
333
336
      } else if (get_assoc(par) != chan) {
334
 
        /* New one i didn't know about -- pass it on */
335
 
        s1 = get_assoc_name(chan);
336
 
        add_assoc(par, chan);
337
 
        chanout_but(-1, chan, ASSOC_CHNAME_NAMED2, botnick, nick, par);
 
337
        /* New one i didn't know about -- pass it on */
 
338
        s1 = get_assoc_name(chan);
 
339
        add_assoc(par, chan);
 
340
        chanout_but(-1, chan, ASSOC_CHNAME_NAMED2, botnick, nick, par);
338
341
      }
339
342
    }
340
343
  }
341
344
}
342
345
 
343
 
/* A report on the module status.
344
 
 */
345
346
static void assoc_report(int idx, int details)
346
347
{
347
 
  assoc_t *a;
348
 
  int size = 0, count = 0;;
349
 
 
350
348
  if (details) {
 
349
    assoc_t *a;
 
350
    int size = 0, count = 0;
 
351
  
351
352
    for (a = assoc; a; a = a->next) {
352
353
      count++;
353
354
      size += sizeof(assoc_t);
354
355
    }
355
 
    dprintf(idx, "    %d assocs using %d bytes\n",
356
 
            count, size);
 
356
 
 
357
    dprintf(idx, "    %d current association%s\n", count,
 
358
            (count != 1) ? "s" : "");
 
359
    dprintf(idx, "    Using %d byte%s of memory\n", size,
 
360
            (size != 1) ? "s" : "");
357
361
  }
358
362
}
359
363
 
360
 
static cmd_t mydcc[] =
361
 
{
362
 
  {"assoc",     "",     cmd_assoc,              NULL},
363
 
  {NULL,        NULL,   NULL,                   NULL}
364
 
};
365
 
 
366
 
static cmd_t mybot[] =
367
 
{
368
 
  {"assoc",     "",     (Function) zapf_assoc,  NULL},
369
 
  {NULL,        NULL,   NULL,                   NULL}
370
 
};
371
 
 
372
 
static cmd_t mylink[] =
373
 
{
374
 
  {"*",         "",     (Function) link_assoc,  "assoc"},
375
 
  {NULL,        NULL,   NULL,                   NULL}
376
 
};
377
 
 
378
 
static tcl_cmds mytcl[] =
379
 
{
380
 
  {"assoc",             tcl_assoc},
381
 
  {"killassoc",         tcl_killassoc},
382
 
  {NULL,                NULL}
 
364
static cmd_t mydcc[] = {
 
365
  {"assoc", "",   cmd_assoc, NULL},
 
366
  {NULL,    NULL, NULL,      NULL}
 
367
};
 
368
 
 
369
static cmd_t mybot[] = {
 
370
  {"assoc", "",   (Function) zapf_assoc, NULL},
 
371
  {NULL,    NULL, NULL,                  NULL}
 
372
};
 
373
 
 
374
static cmd_t mylink[] = {
 
375
  {"*",  "",   (Function) link_assoc, "assoc"},
 
376
  {NULL, NULL, NULL,                     NULL}
 
377
};
 
378
 
 
379
static tcl_cmds mytcl[] = {
 
380
  {"assoc",         tcl_assoc},
 
381
  {"killassoc", tcl_killassoc},
 
382
  {NULL,                 NULL}
383
383
};
384
384
 
385
385
static char *assoc_close()
397
397
 
398
398
EXPORT_SCOPE char *assoc_start();
399
399
 
400
 
static Function assoc_table[] =
401
 
{
 
400
static Function assoc_table[] = {
402
401
  (Function) assoc_start,
403
402
  (Function) assoc_close,
404
403
  (Function) assoc_expmem,
405
404
  (Function) assoc_report,
406
405
};
407
406
 
408
 
char *assoc_start(Function * global_funcs)
 
407
char *assoc_start(Function *global_funcs)
409
408
{
410
409
  global = global_funcs;
411
410
 
412
411
  module_register(MODULE_NAME, assoc_table, 2, 0);
413
412
  if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
414
413
    module_undepend(MODULE_NAME);
415
 
    return "This module requires eggdrop1.6.0 or later";
 
414
    return "This module requires Eggdrop 1.6.0 or later.";
416
415
  }
417
416
  assoc = NULL;
418
417
  add_builtins(H_dcc, mydcc);