Eggheads: requesting functions to be exported and other things

Pan panter at gmx.de
Thu Oct 28 05:25:15 CST 2004


The set_key function is available.

I did write them down but they should not be defined in my modules.
The flags are settings the user can change thats why they are not an
integer.

static int handlematchattr(char *handle, char *flags, char *chan) {
  struct userrec *u;
  struct flag_record plus, minus, user;
  int ok = 0, f;

  			
  if ((u = get_user_by_handle(userlist, handle)) && findchan_by_dname(chan))
{
    			
    user.match = FR_GLOBAL | FR_CHAN | FR_BOT;
    get_user_flagrec(u, &user, chan);
    plus.match = user.match;
    break_down_flags(flags, &plus, &minus);
    f = (minus.global || minus.udef_global || minus.chan ||
	 minus.udef_chan || minus.bot);
    if (flagrec_eq(&plus, &user)) {
      			
      if (!f)
	ok = 1;
      else {
	minus.match = plus.match ^ (FR_AND | FR_OR);
	if (!flagrec_eq(&minus, &user))
	  ok = 1;
      }
    }
  }
  return ok;
}

static int usermatchattr(struct userrec *u, char *flags, char *chan) {
  struct flag_record plus, minus, user;
  int ok = 0, f;

  			
  if ((u)) {
    			
    user.match = FR_GLOBAL | FR_CHAN | FR_BOT;
    get_user_flagrec(u, &user, chan);
    plus.match = user.match;
    break_down_flags(flags, &plus, &minus);
    f = (minus.global || minus.udef_global || minus.chan ||
	 minus.udef_chan || minus.bot);
    if (flagrec_eq(&plus, &user)) {
      			
      if (!f)
	ok = 1;
      else {
	minus.match = plus.match ^ (FR_AND | FR_OR);
	if (!flagrec_eq(&minus, &user))
	  ok = 1;
      }
    }
  }
  return ok;
}

int getudefstr (char *setting, int *value, int len, struct chanset_t *chan)
{
  char s[121], *str = NULL;
  struct udef_struct *ul;

  /* Hopefully it's a user-defined flag. */
  for (ul = udef; ul && ul->name; ul = ul->next) {
    if (!strcmp(setting, ul->name))
      break;
  }
  if (!ul || !ul->name) {
    /* Error if it wasn't found. */
    return 0;
  }

  if (ul->type == UDEF_STR) {
    str = (char *) getudef(ul->values, chan->dname);
    if (!str)
      str = "{}";
  }

  return 0;
}
int getudefint (char *setting, int *value, struct chanset_t *chan) {
  struct udef_struct *ul;

  /* Hopefully it's a user-defined flag. */
  for (ul = udef; ul && ul->name; ul = ul->next) {
    if (!strcmp(setting, ul->name))
      break;
  }
  if (!ul || !ul->name) {
    /* Error if it wasn't found. */
    return 0;
  }

  if (ul->type == UDEF_STR) {
    return 0;
  }

  value = getudef(ul->values, chan->dname);
  return 1;
}

int setudefint (char *setting, int value, struct chanset_t *chan) {
  struct udef_struct *ul;
  for (ul = udef; ul; ul = ul->next) {
    if (ul->type == UDEF_INT && (!egg_strcasecmp(setting, ul->name)
      setudef(ul, chan->dname, value);
      return 1;
  }
  return 0;
}

int setudefstr (char *setting, char *value, struct chanset_t *chan) {
  struct udef_struct *ul;
  for (ul = udef; ul; ul = ul->next) {

    if (ul->type == UDEF_STR && (!egg_strcasecmp(setting, ul->name) {
      char *val;

      val = (char *) getudef(ul->values, chan->dname);
      if (val)
        nfree(val);

      /* Get extra room for new braces, etc */
      val = nmalloc(3 * strlen(value) + 10);
      convert_element(value, val);
      val = nrealloc(val, strlen(val) + 1);
      setudef(ul, chan->dname, (int) val);
      return 1;
    }
  }
  return 0;
}


> None of these functions are available in eggdrop1.6, they have to exist
> before they can be exported. however if you need these functions, write
> them. and a hint on the flags, if the humans never see them just use
> there integer values, &, |, and ^ do wonders with ints. check out
> src/flags.h
> 
> 
> you can use the memberlist pointers, but don't store them anyplace for
> any time, if the person parts the memory will be free()ed and your still
> have that pointer to that memory laying around
> 
> 
> 
> On Wed, 2004-10-27 at 04:37, panter at gmx.de wrote:
> > Hello,
> > i want some functions to be exported to be visible in modules.
> > For my botnetop like module i need:
> > 
> >  void set_key(struct chanset_t *chan, char *k);
> > 
> > A get_key function would be nice too (i know chan->channel.key).
> > 
> >  int handlematchattr(char *handle, char *flags, char *chan);
> >  int usermatchattr(struct userrec *u, char *flags, char *chan):
> > 
> > functions to get or set an udef(channel setting).
> > 
> >  int getudefstr (char *setting, int *value, int len, struct chanset_t
> > *chan);
> >  int getudefint (char *setting, int *value, struct chanset_t *chan);
> >  int setudefint (char *setting, int value, struct chanset_t *chan);
> >  int setudefstr (char *setting, char *value, struct chanset_t *chan);
> > 
> > could write these functions by myself but udef isnt known in modules.
> > 
> > A bind that tells if a user gets added to thet bot.
> > 
> > I have an extra questions. i made a noclones module that kickbans clones
> on
> > join. it is using pointers to the nick and hostname of the memberlist
> entry.
> > is that okay?
> > 
> > --
> > Pan
> 
> -- 
> winkey <rush at winkey.oompah.org>
> 

-- 
NEU +++ DSL Komplett von GMX +++ http://www.gmx.net/de/go/dsl
GMX DSL-Netzanschluss + Tarif zum supergünstigen Komplett-Preis!




More information about the Eggheads mailing list