]> jfr.im git - irc/quakenet/newserv.git/commitdiff
Added reason support for ns-gline.c and ns-kill.c
authorIan Barker <redacted>
Thu, 7 Jun 2007 10:47:49 +0000 (11:47 +0100)
committerIan Barker <redacted>
Thu, 7 Jun 2007 10:47:49 +0000 (11:47 +0100)
newsearch/newsearch.h
newsearch/ns-gline.c
newsearch/ns-kill.c

index 28714aa52424f1ad68259691320c0eba54828fd3..bd94144dc28017825b2c6e0339d2a044fa71f72e 100644 (file)
@@ -17,6 +17,8 @@
 /* gline duration, in seconds */
 #define    NSGLINE_DURATION       3600
 
+#define    NSMAX_REASON_LEN       120
+
 
 #define    RETURNTYPE_BOOL        0x01
 #define    RETURNTYPE_INT         0x02
index 7f6a27d4e456dc2d0a07998bcf8da4e03d6296df..270f64c2bda34a0b2bb573283a39b83a8a227ad5 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "../control/control.h" /* controlreply() */
 #include "../irc/irc.h" /* irc_send() */
@@ -23,11 +24,13 @@ struct gline_localdata {
   unsigned int duration;
   int count;
   int type;
+  char reason[NSMAX_REASON_LEN];
 };
 
 struct searchNode *gline_parse(int type, int argc, char **argv) {
   struct gline_localdata *localdata;
   struct searchNode *thenode;
+  int len;
 
   if (!(localdata = (struct gline_localdata *) malloc(sizeof(struct gline_localdata)))) {
     parseError = "malloc: could not allocate memory for this search.";
@@ -40,14 +43,44 @@ struct searchNode *gline_parse(int type, int argc, char **argv) {
   else
     localdata->marker = nextnickmarker();
 
-  /* gline durations */
-  if (argc<1)
+  switch (argc) {
+  case 0:
     localdata->duration = NSGLINE_DURATION;
-  else {
+    snprintf(localdata->reason, NSMAX_REASON_LEN, ".");
+    break;
+
+  case 1:
+    if (strchr(argv[0], ' ') == NULL) { /* duration specified */
+      localdata->duration = durationtolong(argv[0]);
+      /* error checking on gline duration */
+      if (localdata->duration == 0)
+        localdata->duration = NSGLINE_DURATION;
+      snprintf(localdata->reason, NSMAX_REASON_LEN, ".");
+    }
+    else { /* reason specified */
+      localdata->duration = NSGLINE_DURATION;
+      len = snprintf(localdata->reason, NSMAX_REASON_LEN, ":%s", argv[0]);
+      /* strip leading and trailing '"'s */
+      localdata->reason[1] = ' ';
+      localdata->reason[len-1] = '\0';
+    }
+    break;
+
+  case 2:
     localdata->duration = durationtolong(argv[0]);
     /* error checking on gline duration */
     if (localdata->duration == 0)
       localdata->duration = NSGLINE_DURATION;
+    len = snprintf(localdata->reason, NSMAX_REASON_LEN, ":%s", argv[1]);
+    /* strip leading and trailing '"'s */
+    localdata->reason[1] = ' ';
+    localdata->reason[len-1] = '\0';
+    break;
+
+  default:
+    free(localdata);
+    parseError = "gline: invalid number of arguments";
+    return NULL;
   }
 
   if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
@@ -114,11 +147,11 @@ void gline_free(struct searchNode *thenode) {
             if ((np=getnickbynumeric(cip->channel->users->content[j]))) {
               if (!IsOper(np) && !IsService(np) && !IsXOper(np)) {
                 if (np->host->clonecount <= NSMAX_GLINE_CLONES)
-                  irc_send("%s GL * +*@%s %u :You (%s!%s@%s) have been glined for violating our terms of service.", 
-                    mynumeric->content, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr));
+                  irc_send("%s GL * +*@%s %u :You (%s!%s@%s) have been glined for violating our terms of service%s", 
+                    mynumeric->content, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr), localdata->reason);
                 else
-                  irc_send("%s GL * +%s@%s %u :You (%s!%s@%s) have been glined for violating our terms of service.", 
-                    mynumeric->content, np->ident, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr));
+                  irc_send("%s GL * +%s@%s %u :You (%s!%s@%s) have been glined for violating our terms of service%s", 
+                    mynumeric->content, np->ident, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr), localdata->reason);
                 }
                 else
                   safe++;
@@ -135,11 +168,11 @@ void gline_free(struct searchNode *thenode) {
         if (np->marker == localdata->marker) {
           if (!IsOper(np) && !IsService(np) && !IsXOper(np)) {
             if (np->host->clonecount <= NSMAX_GLINE_CLONES)
-              irc_send("%s GL * +*@%s %u :You (%s!%s@%s) have been glined for violating our terms of service.", 
-                mynumeric->content, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr));
+              irc_send("%s GL * +*@%s %u :You (%s!%s@%s) have been glined for violating our terms of service%s", 
+                mynumeric->content, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr), localdata->reason);
             else
-              irc_send("%s GL * +%s@%s %u :You (%s!%s@%s) have been glined for violating our terms of service.", 
-                mynumeric->content, np->ident, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr));
+              irc_send("%s GL * +%s@%s %u :You (%s!%s@%s) have been glined for violating our terms of service%s", 
+                mynumeric->content, np->ident, IPtostr(np->p_ipaddr), localdata->duration, np->nick, np->ident, IPtostr(np->p_ipaddr), localdata->reason);
           }
           else
               safe++;
index a1b7e7ec0978cc9027596c325817cf834a4adcab..4929bb1c71cbfd36b7f4df90f3012d3adf727c00 100644 (file)
@@ -22,11 +22,13 @@ struct kill_localdata {
   unsigned int marker;
   int count;
   int type;
+  char reason[NSMAX_REASON_LEN];
 };
 
 struct searchNode *kill_parse(int type, int argc, char **argv) {
   struct kill_localdata *localdata;
   struct searchNode *thenode;
+  int len;
 
   if (!(localdata = (struct kill_localdata *) malloc(sizeof(struct kill_localdata)))) {
     parseError = "malloc: could not allocate memory for this search.";
@@ -39,6 +41,15 @@ struct searchNode *kill_parse(int type, int argc, char **argv) {
   else
     localdata->marker = nextnickmarker();
 
+  if (argc==1) {
+    len = snprintf(localdata->reason, NSMAX_REASON_LEN, ":%s", argv[0]);
+    /* strip leading and trailing '"'s */
+    localdata->reason[1] = ' ';
+    localdata->reason[len-1] = '\0';
+  }
+  else
+    snprintf(localdata->reason, NSMAX_REASON_LEN, ".");
+
   if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
     /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
     parseError = "malloc: could not allocate memory for this search.";
@@ -102,8 +113,8 @@ void kill_free(struct searchNode *thenode) {
     
             if ((np=getnickbynumeric(cip->channel->users->content[j]))) {
               if (!IsOper(np) && !IsService(np) && !IsXOper(np)) {
-                killuser(NULL, np, "You (%s!%s@%s) have been disconnected for violating our terms of service.", np->nick,
-                  np->ident, IPtostr(np->p_ipaddr));
+                killuser(NULL, np, "You (%s!%s@%s) have been disconnected for violating our terms of service%s", np->nick,
+                  np->ident, IPtostr(np->p_ipaddr), localdata->reason);
               }
               else
                 safe++;
@@ -119,8 +130,8 @@ void kill_free(struct searchNode *thenode) {
         nnp = np->next;
         if (np->marker == localdata->marker) {
           if (!IsOper(np) && !IsService(np) && !IsXOper(np)) {
-            killuser(NULL, np, "You (%s!%s@%s) have been disconnected for violating our terms of service.", np->nick,
-              np->ident, IPtostr(np->p_ipaddr));
+            killuser(NULL, np, "You (%s!%s@%s) have been disconnected for violating our terms of service%s", np->nick,
+              np->ident, IPtostr(np->p_ipaddr), localdata->reason);
           }
           else
               safe++;