Преглед изворни кода

* Port [3332] to 1.2.14
* Added cmd_clearhosts



svn: 3333

Bryan Drewery пре 19 година
родитељ
комит
0d9c42157c
3 измењених фајлова са 89 додато и 4 уклоњено
  1. 1 0
      doc/UPDATES
  2. 13 4
      misc/help.txt
  3. 75 0
      src/cmds.c

+ 1 - 0
doc/UPDATES

@@ -30,6 +30,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * cmd_adduser sends a PRIVMSG now instead of a NOTICE
 * Rewrote op-cookies to be fix a security hole. (They also react to '.set hijack' now)
 * Fixed +voice flaw where users in channels that were +voice AND +private would only be voiced with |v.
+* Added cmd_clearhosts
 
 1.2.13 - http://wraith.shatow.net/milestone/1.2.13
 * Fix cmd_chanset accepting invalid flags

+ 13 - 4
misc/help.txt

@@ -33,7 +33,7 @@ See also: exempts, -exempt, stick, unstick
    handle on IRC. If a handle is not specified, the hostmask will be added to
    YOUR user record. List as many hosts as wanted.
  
-See also: -host
+See also: -host, clearhosts
 ::+ignore
 ###  $b+ignore$b <hostmask> [%%<XdXhXm>] [comment]
    Adds an ignore to the list of ignores stored on the bot, with optional
@@ -55,7 +55,7 @@ See also: invites, -invite, stick, unstick
    have no flags, an optional hostmask, and a random pass/secpass.
    List as many hosts as needed.
  
-See also: -user, +host, -host%{+ni}, newleaf%{-}
+See also: -user, +host, -host, cleearhosts%{+ni}, newleaf%{-}
 ::-ban
 ###  $b-ban$b <banmask or number> [channel]
    Removes the specified ban from the list of bans stored on the bot. You may
@@ -103,7 +103,7 @@ See also: exempts, +exempt, stick, unstick
    Removes a hostmask from a user's user record.
 %{-}
  
-See also: +host
+See also: +host, clearhosts
 ::-ignore
 ###  $b-ignore$b <hostmask/number>
    Removes the specified ignore from the list of ignores stored on the bot. You
@@ -161,7 +161,7 @@ See also: whois
  
    The user being added is sent a NOTICE with their initial password.
  
-See also: +host, -host%{+m}, +user, -user%{-}
+See also: +host, -host, clearhosts%{+m}, +user, -user%{-}
 :leaf:authed:
 ###  $bauthed$b
    Displays users who are authed on the bot for chan/msg cmds.
@@ -632,6 +632,15 @@ See also: chhandle%{+n}, chsecpass%{-}
    will be used.
  
 See also: chhandle, chpass
+::clearhosts
+###  $bclearhosts$b
+   Removes all hosts from your handle.
+%{+m|m}
+###  $bclearhosts$b <handle>
+   Removes all hosts from a user's user record.
+%{-}
+ 
+See also: +host, -host
 :leaf:clearqueue
 ###  $bclearqueue$b <queue>
    removes all msgs from the specified queue (mode/server/help/all)

+ 75 - 0
src/cmds.c

@@ -3607,6 +3607,80 @@ static void cmd_mns_host(int idx, char *par)
     dprintf(idx, "Failed.\n");
 }
 
+static void cmd_clearhosts(int idx, char *par)
+{
+  putlog(LOG_CMDS, "*", "#%s# clearhosts %s", dcc[idx].nick, par);
+
+  char *handle = NULL;
+  struct userrec *u2 = NULL;
+
+  if (par[0]) {
+    handle = newsplit(&par);
+    u2 = get_user_by_handle(userlist, handle);
+  } else {
+    handle = dcc[idx].nick;
+    u2 = dcc[idx].user;
+  }
+
+  if (!u2 || !dcc[idx].user) {
+    dprintf(idx, "No such user.\n");
+    return;
+  }
+
+  struct flag_record fr2 = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 },
+                     fr  = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
+
+  get_user_flagrec(dcc[idx].user, &fr, NULL);
+  get_user_flagrec(u2, &fr2, NULL);
+
+  /* check to see if user is +d or +k and don't let them remove hosts from THEMSELVES*/
+  if (dcc[idx].user == u2 && (glob_deop(fr) || glob_kick(fr) || (!glob_master(fr) && (chan_deop(fr) || chan_kick (fr))))) {
+    dprintf(idx, "You can't remove hostmasks from yourself while having the +d or +k flag.\n");
+      return;
+    }
+
+  if (egg_strcasecmp(handle, dcc[idx].nick)) {
+    if (!glob_master(fr) && !glob_bot(fr2) && !chan_master(fr)) {
+      dprintf(idx, "You can't remove hostmasks from non-bots.\n");
+      return;
+    }
+    if (glob_bot(fr2) && !glob_owner(fr)) {
+      dprintf(idx, "You can't remove hostmasks from bots.\n");
+      return;
+    }
+    if (glob_admin(fr2) && !isowner(dcc[idx].nick)) {
+      dprintf(idx, "You can't remove hostmasks from an admin.\n");
+      return;
+    }
+    if ((glob_owner(fr2) || glob_master(fr2)) && !glob_owner(fr)) {
+      dprintf(idx, "You can't remove hostmasks from a bot owner/master.\n");
+      return;
+    }
+    if ((chan_owner(fr2) || chan_master(fr2)) && !glob_master(fr) &&
+        !glob_owner(fr) && !chan_owner(fr)) {
+      dprintf(idx, "You can't remove hostmasks from a channel owner/master.\n");
+      return;
+    }
+    if (!glob_master(fr) && !chan_master(fr)) {
+      dprintf(idx, "Permission denied.\n");
+      return;
+    }
+  }
+
+  if (get_user(&USERENTRY_HOSTS, u2)) {
+    while (struct list_type *q = (struct list_type *) get_user(&USERENTRY_HOSTS, u2)) {
+      char *host = strdup(q->extra);
+      delhost_by_handle(handle, host);
+      check_this_user(handle, 1, host);
+      free(host);
+    }
+    dprintf(idx, "Cleared hosts for %s.\n", handle);
+  } else
+    dprintf(idx, "%s had no hosts set.\n", handle);
+  if (conf.bot->hub)
+    write_userfile(idx);
+}
+
 /* netserver */
 static void cmd_netserver(int idx, char * par) {
   putlog(LOG_CMDS, "*", "#%s# netserver", dcc[idx].nick);
@@ -4368,6 +4442,7 @@ cmd_t C_dcc[] =
 /*  {"chnick",		"m",	(Function) cmd_chhandle,	NULL, HUB}, */
   {"chpass",		"m",	(Function) cmd_chpass,		NULL, HUB},
   {"chsecpass",		"n",	(Function) cmd_chsecpass,	NULL, HUB},
+  {"clearhosts",	"",	(Function) cmd_clearhosts,	NULL, 0},
   {"cmdpass",           "a",    (Function) cmd_cmdpass,         NULL, HUB},
   {"color",		"",     (Function) cmd_color,           NULL, 0},
   {"comment",		"m|m",	(Function) cmd_comment,		NULL, 0},