[eggheads-patches] PATCH1.4: udef_chanstuff3

Florian Sander gquann at gmx.de
Thu Oct 21 14:28:27 CST 1999


Hi :)

This patch is the successor of udef_chanflags2. It now uses linked
lists, so the number of user defined flags isn't limited anymore.

See DESCription on eggdev@ for more details. :)

  bye

-- 
G`Quann at IRCNet
http://www.visions-of-fantasy.de
-------------- next part --------------
diff -urN eggdrop1.4/src/mod/channels.mod/channels.c patched1.4/src/mod/channels.mod/channels.c
--- eggdrop1.4/src/mod/channels.mod/channels.c	Mon Oct 11 09:59:57 1999
+++ patched1.4/src/mod/channels.mod/channels.c	Wed Oct 20 17:55:40 1999
@@ -37,6 +37,34 @@
 /* default chanmode (drummer,990731) */
 static char glob_chanmode[64] = "nt";
 
+/* user defines chanmodes/settings */
+#define UDEF_FLAG 1
+#define UDEF_INT 2
+
+struct udef_chans {
+  struct udef_chans *next;
+  char *chan;
+  int value;
+};
+
+struct udef_struct {
+  struct udef_struct *next;
+  char *name;
+  int defined;
+  int type;
+  struct udef_chans *values;
+};
+
+static int expmem_udef(struct udef_struct *);
+static int expmem_udef_chans (struct udef_chans *);
+static void free_udef(struct udef_struct *);
+static void free_udef_chans(struct udef_chans *);
+static int getudef(struct udef_chans *, char *);
+static void initudef(int type, char *, int);
+static void setudef(struct udef_struct *, struct udef_chans *, char *, int);
+
+static struct udef_struct *udef = NULL;
+
 /* global flood settings */
 static int gfld_chan_thr;
 static int gfld_chan_time;
@@ -67,6 +95,145 @@
   return p;
 }
 
+/* user defined channel flags/settings */
+
+static int expmem_udef (struct udef_struct *ul)
+{
+  int i = 0;
+
+  while (ul) {
+    i += sizeof(struct udef_struct);
+    i += strlen(ul->name);
+    i += expmem_udef_chans(ul->values);
+    ul = ul->next;
+  }
+  return i;
+}
+
+static int expmem_udef_chans (struct udef_chans *ul)
+{
+  int i = 0;
+  
+  while (ul) {
+    i += sizeof(struct udef_chans);
+    i += strlen(ul->chan);
+    ul = ul->next;
+  }
+  return i;
+}
+
+static int getudef(struct udef_chans *ul, char *name)
+{
+  int val = 0;
+
+  context;
+  while (ul) {
+    if (!strcasecmp(ul->chan, name)) {
+      val = ul->value;
+      break;
+    }
+    ul = ul->next;
+  }
+  return val;
+}
+
+static void setudef(struct udef_struct *us, struct udef_chans *ul, char *name, int value)
+{
+  struct udef_chans *ull;
+
+  context;
+  ull = ul;
+  while (ul) {
+    if (!strcasecmp(ul->chan, name)) {
+      ul->value = value;
+      return;
+    }
+    ul = ul->next;
+  }
+  ul = ull;
+  while (ul && ul->next)
+    ul = ul->next;
+  ull = nmalloc(sizeof(struct udef_chans));
+  ull->chan = nmalloc(strlen(name));
+  strcpy(ull->chan, name);
+  ull->value = value;
+  ull->next = NULL;
+  if (ul)
+    ul->next = ull;
+  else
+    us->values = ull;
+  return;
+}
+  
+static void initudef (int type, char *name, int defined)
+{
+  struct udef_struct *ul = udef;
+  struct udef_struct *ull = NULL;
+  int found = 0;
+
+  context;
+  if (strlen(name) < 1)
+    return;
+  while (ul) {
+    if (ul->name && !strcasecmp(ul->name, name)) {
+      if (defined) {
+        debug1("UDEF: %s defined", ul->name);
+        ul->defined = 1;
+      }
+      found = 1;
+    }
+    ul = ul->next;
+  }
+  if (!found) {
+    debug2("Creating %s (type %d)", name, type);
+    ull = udef;
+    while (ull && ull->next)
+      ull = ull->next;
+    ul = nmalloc(sizeof(struct udef_struct));
+    ul->name = nmalloc(strlen(name));
+    strcpy(ul->name, name);
+    if (defined)
+      ul->defined = 1;
+    else
+      ul->defined = 0;
+    ul->type = type;
+    ul->values = NULL;
+    ul->next = NULL;
+    if (ull)
+      ull->next = ul;
+    else
+      udef = ul;
+  }
+  return;
+}
+
+static void free_udef(struct udef_struct *ul)
+{
+  struct udef_struct *ull;
+
+  while (ul) {
+    ull = ul->next;
+    free_udef_chans(ul->values);
+    nfree(ul->name);
+    nfree(ul);
+    ul = ull;
+  }
+  return;
+}
+
+static void free_udef_chans(struct udef_chans *ul)
+{
+  struct udef_chans *ull;
+  
+  while (ul) {
+    ull = ul->next;
+    nfree(ul->chan);
+    nfree(ul);
+    ul = ull;
+  }
+  return;
+}
+
 static void set_mode_protect(struct chanset_t *chan, char *set)
 {
   int i, pos = 1;
@@ -289,6 +456,7 @@
   char s[121], w[1024], name[163];
   int i, j;
   struct chanset_t *chan;
+  struct udef_struct *ul;
 
   context;
   if (!chanfile[0])
@@ -396,7 +564,16 @@
  	    channel_dynamicinvites(chan) ? '+' : '-');
     fprintf(f, "%cuserinvites ", 
             channel_nouserinvites(chan) ? '-' : '+');
-
+    for (ul = udef; ul; ul = ul->next) {
+      if (ul->defined && ul->name) {
+        if (ul->type == UDEF_FLAG)
+          fprintf(f,"%c%s%s ", getudef(ul->values, chan->name) ? '+' : '-', "udef-flag-", ul->name);
+        else if (ul->type == UDEF_INT)
+          fprintf(f,"%s%s %d ", "udef-int-", ul->name, getudef(ul->values, chan->name));
+        else
+          debug1("UDEF-ERROR: unknown type %d", ul->type);
+      }
+    }
     fprintf(f, "%c\n", channel_static(chan) ? ' ' : '}');
     if (fflush(f)) {
       putlog(LOG_MISC, "*", "ERROR writing channel file.");
@@ -653,6 +830,7 @@
 
     chan = chan->next;
   }
+  tot += expmem_udef(udef);
   return tot;
 }
 
@@ -730,6 +908,7 @@
 {
   context;
   write_channels();
+  free_udef(udef);
   rem_builtins(H_chon, my_chon);
   rem_builtins(H_dcc, C_dcc_irc);
   rem_tcl_commands(channels_cmds);
diff -urN eggdrop1.4/src/mod/channels.mod/cmdschan.c patched1.4/src/mod/channels.mod/cmdschan.c
--- eggdrop1.4/src/mod/channels.mod/cmdschan.c	Mon Oct 11 09:59:57 1999
+++ patched1.4/src/mod/channels.mod/cmdschan.c	Wed Oct 20 17:55:41 1999
@@ -1168,6 +1168,8 @@
 {
   char *chname, work[512];
   struct chanset_t *chan;
+  int ii, tmp;
+  struct udef_struct *ul = udef;
 
   if (!par[0]) {
     chname = dcc[idx].u.chat->con_chan;
@@ -1241,6 +1243,49 @@
     dprintf(idx, "     %cprotectfriends           %crevengebot\n",
             (chan->status & CHAN_PROTECTFRIENDS) ? '+' : '-',
 	    (chan->status & CHAN_REVENGEBOT) ? '+' : '-');
+    simple_sprintf(work, "    ");
+    ii = 1;
+    tmp = 0;
+    while (ul) {
+      if (ul->defined && (ul->type == UDEF_FLAG)) {
+        if (!tmp) {
+          dprintf(idx, "User defined channel flags:\n");
+          tmp = 1;
+        }
+        simple_sprintf(work, "%s %c%s", work, getudef(ul->values, chan->name) ? '+' : '-', ul->name);
+        ii++;
+        if (ii > 4) {
+          dprintf(idx, "%s\n", work);
+          simple_sprintf(work, "    ");
+          ii = 1;
+        }
+      }
+      ul = ul->next;
+    }
+    if (ii > 1)
+      dprintf(idx, "%s\n", work);
+    simple_sprintf(work, "");
+    ii = 1;
+    tmp = 0;
+    ul = udef;
+    while (ul) {
+      if (ul->defined && (ul->type == UDEF_INT)) {
+        if (!tmp) {
+          dprintf(idx, "User defined channel settings:\n");
+          tmp = 1;
+        }
+        simple_sprintf(work, "%s%s: %d   ", work, ul->name, getudef(ul->values, chan->name));
+        ii++;
+        if (ii > 4) {
+          dprintf(idx, "%s\n", work);
+          simple_sprintf(work, "");
+          ii = 1;
+        }
+      }
+      ul = ul->next;
+    }
+    if (ii > 1)
+      dprintf(idx, "%s\n", work);
     dprintf(idx, "flood settings: chan ctcp join kick deop\n");
     dprintf(idx, "number:          %3d  %3d  %3d  %3d  %3d\n",
 	    chan->flood_pub_thr, chan->flood_ctcp_thr,
diff -urN eggdrop1.4/src/mod/channels.mod/tclchan.c patched1.4/src/mod/channels.mod/tclchan.c
--- eggdrop1.4/src/mod/channels.mod/tclchan.c	Sat Oct  9 17:46:36 1999
+++ patched1.4/src/mod/channels.mod/tclchan.c	Wed Oct 20 17:55:42 1999
@@ -700,6 +700,7 @@
 static int tcl_channel_info(Tcl_Interp * irp, struct chanset_t *chan)
 {
   char s[121];
+  struct udef_struct *ul = udef;
 
   get_mode_protect(chan, s);
   Tcl_AppendElement(irp, s);
@@ -820,6 +821,19 @@
     Tcl_AppendElement(irp, "-userinvites");
   else
     Tcl_AppendElement(irp, "+userinvites");
+  while (ul) {
+    if (ul->defined && ul->name) {
+      if (ul->type == UDEF_FLAG) {
+        simple_sprintf(s,"%c%s", getudef(ul->values, chan->name) ? '+' : '-', ul->name);
+        Tcl_AppendElement(irp, s);
+      } else if (ul->type == UDEF_INT) {
+        simple_sprintf(s,"%s %d", ul->name, getudef(ul->values, chan->name));
+        Tcl_AppendElement(irp, s);
+      } else
+        debug1("UDEF-ERROR: unknown type %d", ul->type);
+    }
+    ul = ul->next;
+  }
   return TCL_OK;
 }
 
@@ -885,6 +899,8 @@
   int oldstatus;
   int x=0;
   module_entry *me;
+  int found;
+  struct udef_struct *ul = udef;
 
   oldstatus = chan->status;
   for (i = 0; i < items; i++) {
@@ -1094,9 +1110,36 @@
 	*ptime = 1;
       }
     } else {
-      if (irp && item[i][0]) /* ignore "" */
-	Tcl_AppendResult(irp, "illegal channel option: ", item[i], NULL);
-	x++;
+      found = 0;
+      if (!strncmp(item[i] + 1, "udef-flag-", 10))
+        initudef(UDEF_FLAG, item[i] + 11, 0);
+      else if (!strncmp(item[i], "udef-int-", 9))
+        initudef(UDEF_INT, item[i] + 9, 0);
+      for (ul = udef; ul; ul = ul->next) {
+        if ((!strcasecmp(item[i] + 1, ul->name) || (!strncmp(item[i] + 1, "udef-flag-", 10) && !strcasecmp(item[i] + 11, ul->name)))
+            && (ul->type == UDEF_FLAG)) {
+          found = 1;
+          if (item[i][0] == '+')
+            setudef(ul, ul->values, chan->name, 1);
+          else
+            setudef(ul, ul->values, chan->name, 0);
+        } else if ((!strcasecmp(item[i], ul->name) || (!strncmp(item[i], "udef-int-", 9) && !strcasecmp(item[i] + 9, ul->name))) 
+            && (ul->type == UDEF_INT)) {
+          found = 1;
+          i++;
+          if (i >= items) {
+            if (irp)
+              Tcl_AppendResult(irp, "this setting needs an argument", NULL);
+            return TCL_ERROR;
+          }
+          setudef(ul, ul->values, chan->name, atoi(item[i]));
+        }
+      }
+      if (!found) {
+        if (irp && item[i][0]) /* ignore "" */
+      	  Tcl_AppendResult(irp, "illegal channel option: ", item[i], NULL);
+      	x++;
+      }
     }
   }
   if (((oldstatus ^ chan->status) & CHAN_INACTIVE) && module_find("irc", 0, 0)) {
@@ -1492,6 +1535,101 @@
   return ret; 
 }
 
+static int tcl_setudef STDVAR
+{
+  int type;
+  
+  context;
+  BADARGS(3, 3, " type name");
+  if (!strcasecmp(argv[1], "flag"))
+    type = UDEF_FLAG;
+  else if (!strcasecmp(argv[1], "int"))
+    type = UDEF_INT;
+  else {
+    Tcl_AppendResult(irp, "invalid type. Must be one of: flag, int", NULL);
+    return TCL_ERROR;
+  }
+  initudef(type, argv[2], 1);
+  return TCL_OK;
+}
+
+static int tcl_renudef STDVAR
+{
+  struct udef_struct *ul;
+  int type, found = 0;
+  
+  context;
+  BADARGS(4, 4, " type oldname newname");
+  if (!strcasecmp(argv[1], "flag"))
+    type = UDEF_FLAG;
+  else if (!strcasecmp(argv[1], "int"))
+    type = UDEF_INT;
+  else {
+    Tcl_AppendResult(irp, "invalid type. Must be one of: flag, int", NULL);
+    return TCL_ERROR;
+  }
+  for (ul = udef; ul; ul = ul->next) {
+    if (ul->type == type && !strcasecmp(ul->name, argv[2])) {
+      nfree(ul->name);
+      ul->name = nmalloc(strlen(argv[3]));
+      strcpy(ul->name,argv[3]);
+      found = 1;
+    }
+  }
+  if (!found) {
+    Tcl_AppendResult(irp, "not found", NULL);
+    return TCL_ERROR;
+  } else
+    return TCL_OK;
+}
+
+static int tcl_deludef STDVAR
+{
+  struct udef_struct *ul, *ull;
+  int type, found = 0;
+  
+  context;
+  BADARGS(3, 3, " type name");
+  if (!strcasecmp(argv[1], "flag"))
+    type = UDEF_FLAG;
+  else if (!strcasecmp(argv[1], "int"))
+    type = UDEF_INT;
+  else {
+    Tcl_AppendResult(irp, "invalid type. Must be one of: flag, int", NULL);
+    return TCL_ERROR;
+  }
+  ul = udef;
+  while (ul) {
+    ull = ul->next;
+    if (!ull)
+      break;
+    if (ull->type == type && !strcasecmp(ull->name, argv[2])) {
+      ul->next = ull->next;
+      nfree(ull->name);
+      free_udef_chans(ull->values);
+      nfree(ull);
+      found = 1;
+    }
+    ul = ul->next;
+  }
+  if (udef) {
+    if (udef->type == type && !strcasecmp(udef->name, argv[2])) {
+      ul = udef->next;
+      nfree(udef->name);
+      free_udef_chans(udef->values);
+      nfree(udef);
+      udef = ul;
+      found = 1;
+    }
+  }
+  context;
+  if (!found) {
+    Tcl_AppendResult(irp, "not found", NULL);
+    return TCL_ERROR;
+  } else
+    return TCL_OK;
+}
+
 static tcl_cmds channels_cmds[] =
 {
   {"killban", tcl_killban},
@@ -1534,5 +1672,8 @@
   {"delchanrec", tcl_delchanrec},
   {"stick", tcl_stick},
   {"unstick", tcl_unstick},
+  {"setudef", tcl_setudef},
+  {"renudef", tcl_renudef},
+  {"deludef", tcl_deludef},
   {0, 0}
 };


More information about the Patches mailing list