[eggheads-patches] PATCH1.4: udef_chanflags2.patch

Florian Sander gquann at gmx.de
Wed Oct 13 12:03:58 CST 1999


Hi :)

next attempt ^_^

I rewrote the complete patch. And now it's no longer limited to 4
settings. The maximum number of settings is now #defined in channels.c
and can be easily changed. (default is 10)

This is how to "activate" a setting:
.tcl setudef flag 3 test
.chanset +test
=>
[17:01] <Lamestbot>      -protectfriends           -revengebot
[17:01] <Lamestbot> User defined channel flags:
[17:01] <Lamestbot>  +test
[17:01] <Lamestbot> flood settings: chan ctcp join kick deop

.tcl setudef setting 7 blub
.chanset blub 4
=>
[16:59] <Lamestbot>      -protectfriends           -revengebot
[16:59] <Lamestbot> User defined channel flags:
[16:59] <Lamestbot>  +test
[16:59] <Lamestbot> User defined channel settings:
[16:59] <Lamestbot> blub: 4 
[16:59] <Lamestbot> flood settings: chan ctcp join kick deop

I hope you're satisfied. :)

  cu

-- 
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 13 17:50:51 1999
@@ -14,6 +14,8 @@
 #define MAKING_CHANNELS
 #include "../module.h"
 #include <sys/stat.h>
+#define MAX_UDEFS 10
+#define MAX_UDEF_LENGTH 20
 
 static int setstatic = 0;
 static int use_info = 1;
@@ -37,6 +39,22 @@
 /* default chanmode (drummer,990731) */
 static char glob_chanmode[64] = "nt";
 
+/* user defines chanmodes/settings */
+struct udef_set_str {
+  int defined;
+  char name[MAX_UDEF_LENGTH];
+  int status;
+};
+
+struct udef_set_int {
+  int defined;
+  char name[MAX_UDEF_LENGTH];
+  int value;
+};
+
+static struct udef_set_str udef_chanflags[MAX_UDEFS];
+static struct udef_set_int udef_chansets[MAX_UDEFS];
+
 /* global flood settings */
 static int gfld_chan_thr;
 static int gfld_chan_time;
@@ -287,7 +305,7 @@
 {
   FILE *f;
   char s[121], w[1024], name[163];
-  int i, j;
+  int i, j, nr;
   struct chanset_t *chan;
 
   context;
@@ -325,6 +343,11 @@
       fprintf(f, "idle-kick %d ", chan->idle_kick);
     else
       fprintf(f, "dont-idle-kick ");
+    for (nr=0;nr<MAX_UDEFS;nr++) {
+      if (udef_chansets[nr].defined) {
+        fprintf(f, "udef-setting-%d %d ", nr, udef_chansets[nr].value);
+      }
+    }
     if (chan->need_op[0])
       fprintf(f, "need-op {%s} ", chan->need_op);
     if (chan->need_invite[0])
@@ -396,7 +419,11 @@
  	    channel_dynamicinvites(chan) ? '+' : '-');
     fprintf(f, "%cuserinvites ", 
             channel_nouserinvites(chan) ? '-' : '+');
-
+    for (nr=0;nr<MAX_UDEFS;nr++) {
+      if (udef_chanflags[nr].defined) {
+        fprintf(f, "%cudef-flag-%d ", udef_chanflags[nr].status ? '+' : '-', nr);
+      }
+    }
     fprintf(f, "%c\n", channel_static(chan) ? ' ' : '}');
     if (fflush(f)) {
       putlog(LOG_MISC, "*", "ERROR writing channel file.");
@@ -818,6 +845,8 @@
 
 char *channels_start(Function * global_funcs)
 {
+  int i;
+  
   global = global_funcs;
 
   gfld_chan_thr = 10;
@@ -854,5 +883,13 @@
   add_tcl_coups(mychan_tcl_coups);
   read_channels(0);
   setstatic = 1;
+  for (i=0;i<MAX_UDEFS;i++) {
+    udef_chanflags[i].defined = 0;
+    udef_chanflags[i].name[0] = '\0';
+    udef_chanflags[i].status = 0;
+    udef_chansets[i].defined = 0;
+    udef_chansets[i].name[0] = '0';
+    udef_chansets[i].value = 0;
+  }
   return NULL;
 }
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 13 17:50:52 1999
@@ -1168,6 +1168,7 @@
 {
   char *chname, work[512];
   struct chanset_t *chan;
+  int i,ii, tmp;
 
   if (!par[0]) {
     chname = dcc[idx].u.chat->con_chan;
@@ -1241,6 +1242,48 @@
     dprintf(idx, "     %cprotectfriends           %crevengebot\n",
             (chan->status & CHAN_PROTECTFRIENDS) ? '+' : '-',
 	    (chan->status & CHAN_REVENGEBOT) ? '+' : '-');
+    simple_sprintf(work, "    ");
+    ii = 1;
+    tmp = 0;
+    for (i=0;i<MAX_UDEFS;i++) {
+      if (udef_chanflags[i].defined) {
+        if (!tmp) {
+          dprintf(idx, "User defined channel flags:\n");
+          tmp = 1;
+        }
+        simple_sprintf(work, "%s %c%s", work, udef_chanflags[i].status ? '+' : '-', udef_chanflags[i].name);
+        ii++;
+        if (ii>4) {
+          dprintf(idx, "%s\n", work);
+          simple_sprintf(work, "    ");
+          ii = 1;
+        }
+      }
+    }
+    if (ii > 1) {
+      dprintf(idx, "%s\n", work);
+    }
+    simple_sprintf(work, "");
+    ii = 1;
+    tmp = 0;
+    for (i=0;i<MAX_UDEFS;i++) {
+      if (udef_chansets[i].defined) {
+        if (!tmp) {
+          dprintf(idx, "User defined channel settings:\n");
+          tmp = 1;
+        }
+        simple_sprintf(work, "%s%s: %d   ", work, udef_chansets[i].name, udef_chansets[i].value);
+        ii++;
+        if (ii>4) {
+          dprintf(idx, "%s\n", work);
+          simple_sprintf(work, "");
+          ii = 1;
+        }
+      }
+    }
+    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 13 17:50:52 1999
@@ -700,6 +700,7 @@
 static int tcl_channel_info(Tcl_Interp * irp, struct chanset_t *chan)
 {
   char s[121];
+  int i;
 
   get_mode_protect(chan, s);
   Tcl_AppendElement(irp, s);
@@ -820,6 +821,18 @@
     Tcl_AppendElement(irp, "-userinvites");
   else
     Tcl_AppendElement(irp, "+userinvites");
+  for (i=0;i<MAX_UDEFS;i++) {
+    if (udef_chanflags[i].defined) {
+      simple_sprintf(s,"%c%s", udef_chanflags[i].status ? '+' : '-', udef_chanflags[i].name);
+      Tcl_AppendElement(irp, s);
+    }
+  }
+  for (i=0;i<MAX_UDEFS;i++) {
+    if (udef_chansets[i].defined) {
+      simple_sprintf(s,"%s %d", udef_chansets[i].name, udef_chansets[i].value);
+      Tcl_AppendElement(irp, s);
+    }
+  }
   return TCL_OK;
 }
 
@@ -885,6 +898,7 @@
   int oldstatus;
   int x=0;
   module_entry *me;
+  int nr, found;
 
   oldstatus = chan->status;
   for (i = 0; i < items; i++) {
@@ -951,6 +965,17 @@
 	return TCL_ERROR;
       }
       chan->idle_kick = atoi(item[i]);
+    } else if (!strncmp(item[i], "udef-setting-", 13)) {
+      nr = atoi(item[i] + 13);
+      if (nr >= 0 && nr < MAX_UDEFS) {
+        i++;
+        if (i >= items) {
+          if (irp)
+            Tcl_AppendResult(irp, "channel udef-setting-x needs argument", NULL);
+          return TCL_ERROR;
+        }
+        udef_chansets[nr].value = atoi(item[i]);
+      }
     } else if (!strcmp(item[i], "dont-idle-kick"))
       chan->idle_kick = 0;
     else if (!strcmp(item[i], "+clearbans"))
@@ -1094,9 +1119,50 @@
 	*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)) {
+        nr = atoi(item[i] + 11);
+        if (nr >= 0 && nr < MAX_UDEFS) {
+          found = 1;
+          if (item[i][0] == '+')
+            udef_chanflags[nr].status = 1;
+          else
+            udef_chanflags[nr].status = 0;
+        }
+      } else {
+        for (nr=0;nr < MAX_UDEFS;nr++) {
+          if (udef_chanflags[nr].defined) {
+            if (!strcmp(item[i] + 1, udef_chanflags[nr].name)) {
+              found = 1;
+              if (item[i][0] == '+')
+                udef_chanflags[nr].status = 1;
+              else
+                udef_chanflags[nr].status = 0;
+            }
+          }
+        }
+      }
+      if (!found) {
+        for (nr=0;nr < MAX_UDEFS;nr++) {
+          if (udef_chansets[nr].defined) {
+            if (!strcmp(item[i], udef_chansets[nr].name)) {
+              found = 1;
+              i++;
+              if (i >= items) {
+                if (irp)
+                  Tcl_AppendResult(irp, "channel udef-setting-x needs argument", NULL);
+                return TCL_ERROR;
+              }
+              udef_chansets[nr].value = 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 +1558,49 @@
   return ret; 
 }
 
+static int tcl_setudef STDVAR
+{
+  int i;
+  
+  context;
+  BADARGS(3, 4, " type nr ?name?");
+  if (strcasecmp(argv[1], "flag") && strcasecmp(argv[1], "setting")) {
+    Tcl_AppendResult(irp, "invalid type. Must be one of: flag, setting", NULL);
+    return TCL_ERROR;
+  }
+  i = atoi(argv[2]);
+  if (i < 0 || i >= MAX_UDEFS) {
+    Tcl_AppendResult(irp, "invalid nr. (0 <= nr < MAX_UDEFS)", NULL);
+    return TCL_ERROR;
+  }
+  if (!strcasecmp(argv[1], "flag")) {
+    if (argc < 4) {
+      udef_chansets[i].defined = 0;
+      return TCL_OK;
+    }
+    if (strlen(argv[3]) < 1) {
+      udef_chansets[i].defined = 0;
+      return TCL_OK;
+    }
+    udef_chanflags[i].defined = 1;
+    strncpy(udef_chanflags[i].name, argv[3], MAX_UDEF_LENGTH - 1);
+    return TCL_OK;
+  } else if (!strcasecmp(argv[1], "setting")) {
+    if (argc < 4) {
+      udef_chansets[i].defined = 0;
+      return TCL_OK;
+    }
+    if (strlen(argv[3]) < 1) {
+      udef_chansets[i].defined = 0;
+      return TCL_OK;
+    }
+    udef_chansets[i].defined = 1;
+    strncpy(udef_chansets[i].name, argv[3], MAX_UDEF_LENGTH - 1);
+    return TCL_OK;
+  }
+  return TCL_ERROR;
+}
+
 static tcl_cmds channels_cmds[] =
 {
   {"killban", tcl_killban},
@@ -1534,5 +1643,6 @@
   {"delchanrec", tcl_delchanrec},
   {"stick", tcl_stick},
   {"unstick", tcl_unstick},
+  {"setudef", tcl_setudef},
   {0, 0}
 };


More information about the Patches mailing list