]> jfr.im git - solanum.git/blobdiff - modules/m_resv.c
client: refactor del_all_accepts to allow skipping own accept list
[solanum.git] / modules / m_resv.c
index a94689b556af0b5d2dfbc12f754ed0c5b76a609e..4160326cd53695bec887c9db17d625996b6d5951 100644 (file)
@@ -19,8 +19,6 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
- *
- *  $Id$
  */
 
 #include "stdinc.h"
 #include "bandbi.h"
 #include "operhash.h"
 
-static int mo_resv(struct Client *, struct Client *, int, const char **);
-static int ms_resv(struct Client *, struct Client *, int, const char **);
-static int me_resv(struct Client *, struct Client *, int, const char **);
-static int mo_unresv(struct Client *, struct Client *, int, const char **);
-static int ms_unresv(struct Client *, struct Client *, int, const char **);
-static int me_unresv(struct Client *, struct Client *, int, const char **);
+static const char resv_desc[] =
+       "Provides management of reserved nicknames and channels using (UN)RESV";
+
+static void mo_resv(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_resv(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_resv(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void mo_unresv(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void ms_unresv(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_unresv(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 struct Message resv_msgtab = {
-       "RESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
+       "RESV", 0, 0, 0, 0,
        {mg_ignore, mg_not_oper, {ms_resv, 4}, {ms_resv, 4}, {me_resv, 5}, {mo_resv, 3}}
 };
 
 struct Message unresv_msgtab = {
-       "UNRESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
+       "UNRESV", 0, 0, 0, 0,
        {mg_ignore, mg_not_oper, {ms_unresv, 3}, {ms_unresv, 3}, {me_unresv, 2}, {mo_unresv, 2}}
 };
 
 mapi_clist_av1 resv_clist[] = { &resv_msgtab, &unresv_msgtab, NULL };
 
-DECLARE_MODULE_AV1(resv, NULL, NULL, resv_clist, NULL, NULL, "$Revision$");
+DECLARE_MODULE_AV2(resv, NULL, NULL, resv_clist, NULL, NULL, NULL, NULL, resv_desc);
 
 static void parse_resv(struct Client *source_p, const char *name,
                       const char *reason, int temp_time, int propagated);
@@ -68,17 +69,15 @@ static void propagate_resv(struct Client *source_p, const char *target,
 static void cluster_resv(struct Client *source_p, int temp_time,
                         const char *name, const char *reason);
 
-static void handle_remote_unresv(struct Client *source_p, const char *name);
 static void remove_resv(struct Client *source_p, const char *name, int propagated);
 
 /*
  * mo_resv()
- *      parv[0] = sender prefix
  *      parv[1] = channel/nick to forbid
  *      parv[2] = reason
  */
-static int
-mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+mo_resv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        const char *name;
        const char *reason;
@@ -90,7 +89,7 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
        if(!IsOperResv(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv");
-               return 0;
+               return;
        }
 
        /* RESV [time] <name> [ON <server>] :<reason> */
@@ -110,7 +109,7 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
                {
                        sendto_one(source_p, form_str(ERR_NOPRIVS),
                                   me.name, source_p->name, "remoteban");
-                       return 0;
+                       return;
                }
 
                target_server = parv[loc + 1];
@@ -123,7 +122,7 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
        if(parc <= loc || EmptyString(parv[loc]))
        {
                sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "RESV");
-               return 0;
+               return;
        }
 
        reason = parv[loc];
@@ -131,10 +130,17 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
        /* remote resv.. */
        if(target_server)
        {
+               if (temp_time)
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is adding a %d min. RESV for [%s] on %s [%s]",
+                                       get_oper_name(source_p), temp_time / 60, name, target_server, reason);
+               else
+                       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s is adding a permanent RESV for [%s] on %s [%s]",
+                                       get_oper_name(source_p), name, target_server, reason);
+
                propagate_resv(source_p, target_server, temp_time, name, reason);
 
                if(match(target_server, me.name) == 0)
-                       return 0;
+                       return;
        }
        else if(!propagated && rb_dlink_list_length(&cluster_conf_list) > 0)
                cluster_resv(source_p, temp_time, name, reason);
@@ -142,22 +148,19 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
        if(propagated && temp_time == 0)
        {
                sendto_one_notice(source_p, ":Cannot set a permanent global ban");
-               return 0;
+               return;
        }
 
        parse_resv(source_p, name, reason, temp_time, propagated);
-
-       return 0;
 }
 
 /* ms_resv()
- *     parv[0] = sender prefix
  *     parv[1] = target server
  *     parv[2] = channel/nick to forbid
  *     parv[3] = reason
  */
-static int
-ms_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+ms_resv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* parv[0]  parv[1]        parv[2]  parv[3]
         * oper     target server  resv     reason
@@ -165,24 +168,22 @@ ms_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
        propagate_resv(source_p, parv[1], 0, parv[2], parv[3]);
 
        if(!match(parv[1], me.name))
-               return 0;
+               return;
 
        if(!IsPerson(source_p))
-               return 0;
+               return;
 
        parse_resv(source_p, parv[2], parv[3], 0, 0);
-       return 0;
 }
 
-static int
-me_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+me_resv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* time name 0 :reason */
        if(!IsPerson(source_p))
-               return 0;
+               return;
 
        parse_resv(source_p, parv[2], parv[4], atoi(parv[1]), 0);
-       return 0;
 }
 
 /* parse_resv()
@@ -198,12 +199,6 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
 {
        struct ConfItem *aconf;
 
-       if(!MyClient(source_p) &&
-          !find_shared_conf(source_p->username, source_p->host,
-                            source_p->servptr->name,
-                            (temp_time > 0) ? SHARED_TRESV : SHARED_PRESV))
-               return;
-
        if(IsChannelName(name))
        {
                if(hash_find_resv(name))
@@ -219,12 +214,6 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
                        return;
                }
 
-               if(strchr(reason, '"'))
-               {
-                       sendto_one_notice(source_p, ":Invalid character '\"' in comment");
-                       return;
-               }
-
                aconf = make_conf();
                aconf->status = CONF_RESV_CHANNEL;
                aconf->port = 0;
@@ -239,7 +228,7 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
                        aconf->hold = rb_current_time() + temp_time;
                        aconf->lifetime = aconf->hold;
                        replace_old_ban(aconf);
-                       rb_dlinkAddAlloc(aconf, &prop_bans);
+                       add_prop_ban(aconf);
 
                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                               "%s added global %d min. RESV for [%s] [%s]",
@@ -293,12 +282,6 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
                        return;
                }
 
-               if(strchr(reason, '"'))
-               {
-                       sendto_one_notice(source_p, ":Invalid character '\"' in comment");
-                       return;
-               }
-
                if(!valid_wild_card_simple(name))
                {
                        sendto_one_notice(source_p,
@@ -329,7 +312,7 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
                        aconf->hold = rb_current_time() + temp_time;
                        aconf->lifetime = aconf->hold;
                        replace_old_ban(aconf);
-                       rb_dlinkAddAlloc(aconf, &prop_bans);
+                       add_prop_ban(aconf);
 
                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                               "%s added global %d min. RESV for [%s] [%s]",
@@ -373,6 +356,7 @@ parse_resv(struct Client *source_p, const char *name, const char *reason, int te
                }
 
                rb_dlinkAddAlloc(aconf, &resv_conf_list);
+               resv_nick_fnc(aconf->host, aconf->passwd, temp_time);
        }
        else
                sendto_one_notice(source_p, ":You have specified an invalid resv: [%s]", name);
@@ -433,18 +417,17 @@ cluster_resv(struct Client *source_p, int temp_time, const char *name, const cha
 
 /*
  * mo_unresv()
- *     parv[0] = sender prefix
  *     parv[1] = channel/nick to unforbid
  */
-static int
-mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+mo_unresv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        int propagated = 1;
 
        if(!IsOperResv(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv");
-               return 0;
+               return;
        }
 
        if((parc == 4) && (irccmp(parv[2], "ON") == 0))
@@ -453,13 +436,13 @@ mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char
                {
                        sendto_one(source_p, form_str(ERR_NOPRIVS),
                                   me.name, source_p->name, "remoteban");
-                       return 0;
+                       return;
                }
 
                propagate_generic(source_p, "UNRESV", parv[3], CAP_CLUSTER, "%s", parv[1]);
 
                if(match(parv[3], me.name) == 0)
-                       return 0;
+                       return;
 
                propagated = 0;
        }
@@ -470,16 +453,14 @@ mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char
        /* cluster{} moved to remove_resv */
 
        remove_resv(source_p, parv[1], propagated);
-       return 0;
 }
 
 /* ms_unresv()
- *     parv[0] = sender prefix
  *     parv[1] = target server
  *     parv[2] = resv to remove
  */
-static int
-ms_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+ms_unresv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* parv[0]  parv[1]        parv[2]
         * oper     target server  resv to remove
@@ -487,36 +468,22 @@ ms_unresv(struct Client *client_p, struct Client *source_p, int parc, const char
        propagate_generic(source_p, "UNRESV", parv[1], CAP_CLUSTER, "%s", parv[2]);
 
        if(!match(parv[1], me.name))
-               return 0;
+               return;
 
        if(!IsPerson(source_p))
-               return 0;
+               return;
 
-       handle_remote_unresv(source_p, parv[2]);
-       return 0;
+       remove_resv(source_p, parv[2], 0);
 }
 
-static int
-me_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
+static void
+me_unresv(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        /* name */
        if(!IsPerson(source_p))
-               return 0;
-
-       handle_remote_unresv(source_p, parv[1]);
-       return 0;
-}
-
-static void
-handle_remote_unresv(struct Client *source_p, const char *name)
-{
-       if(!find_shared_conf(source_p->username, source_p->host,
-                            source_p->servptr->name, SHARED_UNRESV))
                return;
 
-       remove_resv(source_p, name, 0);
-
-       return;
+       remove_resv(source_p, parv[1], 0);
 }
 
 static void
@@ -524,6 +491,7 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
 {
        struct ConfItem *aconf = NULL;
        rb_dlink_node *ptr;
+       time_t now;
 
        if(IsChannelName(name))
        {
@@ -543,16 +511,16 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
                                sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name);
                                return;
                        }
-                       ptr = rb_dlinkFind(aconf, &prop_bans);
-                       if(ptr == NULL)
+                       if (!lookup_prop_ban(aconf))
                                return;
                        sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                               "%s has removed the global RESV for: [%s]",
                                               get_oper_name(source_p), name);
                        ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
-                       if(aconf->created < rb_current_time())
-                               aconf->created = rb_current_time();
+                       now = rb_current_time();
+                       if(aconf->created < now)
+                               aconf->created = now;
                        else
                                aconf->created++;
                        aconf->hold = aconf->created;
@@ -565,7 +533,7 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
                                        (unsigned long)aconf->created,
                                        0,
                                        (int)(aconf->lifetime - aconf->created));
-                       deactivate_conf(aconf, ptr);
+                       deactivate_conf(aconf, now);
                        return;
                }
                else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0)
@@ -616,16 +584,16 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
                                sendto_one_notice(source_p, ":Cannot remove global RESV %s on specific servers", name);
                                return;
                        }
-                       ptr = rb_dlinkFind(aconf, &prop_bans);
-                       if(ptr == NULL)
+                       if (!lookup_prop_ban(aconf))
                                return;
                        sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                               "%s has removed the global RESV for: [%s]",
                                               get_oper_name(source_p), name);
                        ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
-                       if(aconf->created < rb_current_time())
-                               aconf->created = rb_current_time();
+                       now = rb_current_time();
+                       if(aconf->created < now)
+                               aconf->created = now;
                        else
                                aconf->created++;
                        aconf->hold = aconf->created;
@@ -638,7 +606,7 @@ remove_resv(struct Client *source_p, const char *name, int propagated)
                                        (unsigned long)aconf->created,
                                        0,
                                        (int)(aconf->lifetime - aconf->created));
-                       deactivate_conf(aconf, ptr);
+                       deactivate_conf(aconf, now);
                        return;
                }
                else if(propagated && rb_dlink_list_length(&cluster_conf_list) > 0)