Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / gline.c
index 21e3a48d75e2359db69389e02ba1c70f5d73f168..50c8773b6453bdd792f5d98943980910d34faa7c 100644 (file)
@@ -152,12 +152,12 @@ do_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline)
          (!acptr->user->username ||
           match(gline->gl_user, acptr->user->username) == 0)) {
        /* ok, here's one that got G-lined */
-       sendto_one(acptr, ":%s %d %s :*** %s.", me.name, ERR_YOUREBANNEDCREEP,
-                  acptr->name, gline->gl_reason);
+       send_reply(acptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s",
+                  gline->gl_reason);
 
        /* let the ops know about it */
-       sendto_op_mask(SNO_GLINE, "G-line active for %s",
-                      get_client_name(acptr, FALSE));
+       sendto_opmask_butone(0, SNO_GLINE, "G-line active for %s",
+                            get_client_name(acptr, FALSE));
 
        /* and get rid of him */
        if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)",
@@ -206,14 +206,13 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
    */
   if (!(flags & GLINE_FORCE) && (expire <= 0 || expire > GLINE_MAX_EXPIRE)) {
     if (!IsServer(sptr) && MyConnect(sptr))
-      send_error_to_client(sptr, ERR_BADEXPIRE, expire);
+      send_reply(sptr, ERR_BADEXPIRE, expire);
     return 0;
   }
 
   expire += CurrentTime; /* convert from lifetime to timestamp */
 
   /* NO_OLD_GLINE allows *@#channel to work correctly */
-#ifdef BADCHAN
   if (*userhost == '#' || *userhost == '&' || *userhost == '+'
 # ifndef NO_OLD_GLINE
       || userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+'
@@ -225,31 +224,21 @@ gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
 # endif
     flags |= GLINE_BADCHAN;
   }
-#endif /* BADCHAN */
 
   /* Inform ops... */
-  sendto_op_mask(SNO_GLINE, "%s adding %s %s for %s, expiring at "
-                TIME_T_FMT ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                flags & GLINE_LOCAL ? "local" : "global",
-                flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
-                expire + TSoffset, reason);
+  sendto_opmask_butone(0, SNO_GLINE, "%s adding %s %s for %s, expiring at "
+                      "%Tu: %s",
+                      IsServer(sptr) ? sptr->name : sptr->user->server->name,
+                      flags & GLINE_LOCAL ? "local" : "global",
+                      flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
+                      expire + TSoffset, reason);
 
 #ifdef GPATH
   /* and log it */
-  if (IsServer(sptr))
-    write_log(GPATH, "# " TIME_T_FMT " %s adding %s %s for %s, expiring at "
-             TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             flags & GLINE_LOCAL ? "local" : "global",
-             flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
-             expire + TSoffset, reason);
-  else
-    write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s adding %s %s for %s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host,
-             flags & GLINE_LOCAL ? "local" : "global",
-             flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
-             expire + TSoffset, reason);
+  write_log(GPATH, "# %Tu %C adding %s %s for %s, expiring at %Tu: %s\n",
+           TStime(), sptr, flags & GLINE_LOCAL ? "local" : "global",
+           flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
+           expire + TSoffset, reason);
 #endif /* GPATH */
 
   /* make the gline */
@@ -298,33 +287,25 @@ gline_activate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
     return 0; /* was active to begin with */
 
   /* Inform ops and log it */
-  sendto_op_mask(SNO_GLINE, "%s activating global %s for %s%s%s, expiring at "
-                TIME_T_FMT ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-                gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-                GlineIsBadChan(gline) ? "" : gline->gl_host,
-                gline->gl_expire + TSoffset, gline->gl_reason);
+  sendto_opmask_butone(0, SNO_GLINE, "%s activating global %s for %s%s%s, "
+                      "expiring at %Tu: %s",
+                      IsServer(sptr) ? sptr->name : sptr->user->server->name,
+                      GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+                      gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+                      GlineIsBadChan(gline) ? "" : gline->gl_host,
+                      gline->gl_expire + TSoffset, gline->gl_reason);
 
 #ifdef GPATH
-  if (IsServer(sptr))
-    write_log(GPATH, "# " TIME_T_FMT " %s activating global %s for %s%s%s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
-  else
-    write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s activating %s for "
-             "%s%s%s, expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host,
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
+  write_log(GPATH, "# %Tu %C activating global %s for %s%s%s, expiring at "
+           "%Tu: %s\n", TStime(), sptr,
+           GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+           gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+           GlineIsBadChan(gline) ? "" : gline->gl_host,
+           gline->gl_expire + TSoffset, gline->gl_reason);
 #endif /* GPATH */
 
-  propagate_gline(cptr, sptr, gline);
+  if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
+    propagate_gline(cptr, sptr, gline);
 
   return GlineIsBadChan(gline) ? 0 : do_gline(cptr, sptr, gline);
 }
@@ -334,12 +315,19 @@ gline_deactivate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
                 time_t lastmod, unsigned int flags)
 {
   unsigned int saveflags = 0;
+  char *msg;
 
   assert(0 != gline);
 
   saveflags = gline->gl_flags;
 
-  if (!GlineIsLocal(gline)) {
+  if (GlineIsLocal(gline))
+    msg = "removing local";
+  else if (!gline->gl_lastmod && !(flags & GLINE_LOCAL))
+    msg = "removing global";
+  else {
+    msg = "deactivating global";
+
     if (flags & GLINE_LOCAL)
       gline->gl_flags |= GLINE_LDEACT;
     else {
@@ -356,39 +344,25 @@ gline_deactivate(struct Client *cptr, struct Client *sptr, struct Gline *gline,
   }
 
   /* Inform ops and log it */
-  sendto_op_mask(SNO_GLINE, "%s %s %s for %s%s%s, expiring at "
-                TIME_T_FMT ": %s",
-                IsServer(sptr) ? sptr->name : sptr->user->server->name,
-                GlineIsLocal(gline) ? "removing local" :
-                "deactivating global",
-                GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-                gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-                GlineIsBadChan(gline) ? "" : gline->gl_host,
-                gline->gl_expire + TSoffset, gline->gl_reason);
+  sendto_opmask_butone(0, SNO_GLINE, "%s %s %s for %s%s%s, expiring at %Tu: "
+                      "%s",
+                      IsServer(sptr) ? sptr->name : sptr->user->server->name,
+                      msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+                      gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+                      GlineIsBadChan(gline) ? "" : gline->gl_host,
+                      gline->gl_expire + TSoffset, gline->gl_reason);
 
 #ifdef GPATH
-  if (IsServer(sptr))
-    write_log(GPATH, "# " TIME_T_FMT " %s %s %s for %s%s%s, "
-             "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             GlineIsLocal(gline) ? "removing local" : "deactivating global",
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
-  else
-    write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s %s %s for "
-             "%s%s%s, expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
-             sptr->user->username, sptr->user->host,
-             GlineIsLocal(gline) ? "removing local" : "deactivating global",
-             GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
-             gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
-             GlineIsBadChan(gline) ? "" : gline->gl_host,
-             gline->gl_expire + TSoffset, gline->gl_reason);
+  write_log(GPATH, "# %Tu %C %s %s for %s%s%s, expiring at %Tu: %s\n",
+           TStime(), sptr, msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+           gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+           GlineIsBadChan(gline) ? "" : gline->gl_host,
+           gline->gl_expire + TSoffset, gline->gl_reason);
 #endif /* GPATH */
 
-  if (GlineIsLocal(gline))
+  if (GlineIsLocal(gline) || (!gline->gl_lastmod && !(flags & GLINE_LOCAL)))
     gline_free(gline);
-  else
+  else if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
     propagate_gline(cptr, sptr, gline);
 
   return 0;
@@ -539,7 +513,7 @@ gline_list(struct Client *sptr, char *userhost)
 
   if (userhost) {
     if (!(gline = gline_find(userhost, GLINE_ANY))) /* no such gline */
-      return send_error_to_client(sptr, ERR_NOSUCHGLINE, userhost);
+      return send_reply(sptr, ERR_NOSUCHGLINE, userhost);
 
     /* send gline information along */
     send_reply(sptr, RPL_GLIST, gline->gl_user,