]> jfr.im git - solanum.git/blobdiff - extensions/hurt.c
m_stats: z: remove unnecessary casting and fix format strings
[solanum.git] / extensions / hurt.c
index d5e08fe3169cfc632421e52512c1fa1ae6ae1a1a..851665aa43b14c5b7b0f8db0d97af22df677a1fd 100644 (file)
@@ -1,10 +1,8 @@
 /*
- * charybdis: an advanced Internet Relay Chat Daemon(ircd).
+ * Solanum: a slightly advanced ircd
  *
  * Copyright (C) 2006 charybdis development team
  * All rights reserved
- *
- * $Id: hurt.c 3161 2007-01-25 07:23:01Z nenolod $
  */
 #include "stdinc.h"
 #include "modules.h"
@@ -49,17 +47,17 @@ typedef struct _hurt {
 /* }}} */
 
 /* {{{ Prototypes */
-static int mo_hurt(struct Client *, struct Client *, int, const char **);
-static int me_hurt(struct Client *, struct Client *, int, const char **);
-static int mo_heal(struct Client *, struct Client *, int, const char **);
-static int me_heal(struct Client *, struct Client *, int, const char **);
+static void mo_hurt(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
+static void me_hurt(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
+static void mo_heal(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
+static void me_heal(struct MsgBuf *msgbuf_p, struct Client *, struct Client *, int, const char **);
 
 static int modinit(void);
 static void modfini(void);
 
-static void client_exit_hook(hook_data_client_exit *);
-static void new_local_user_hook(struct Client *);
-static void doing_stats_hook(hook_data_int *hdata);
+static void client_exit_hook(void *);
+static void new_local_user_hook(void *);
+static void doing_stats_hook(void *);
 
 static void hurt_check_event(void *);
 static void hurt_expire_event(void *);
@@ -72,9 +70,8 @@ static hurt_t *hurt_find_exact(const char *ip);
 static void hurt_remove(const char *ip);
 static void hurt_destroy(void *hurt);
 
-static int heal_nick(struct Client *, struct Client *);
+static void heal_nick(struct Client *, struct Client *);
 
-static int nick_is_valid(const char *);
 /* }}} */
 
 /* {{{ State containers */
@@ -85,14 +82,14 @@ rb_dlink_list hurt_confs = { NULL, NULL, 0 };
 
 /* {{{ Messages */
 struct Message hurt_msgtab = {
-       "HURT", 0, 0, 0, MFLG_SLOW, {
+       "HURT", 0, 0, 0, 0, {
                mg_ignore, mg_ignore, mg_ignore,
                mg_ignore, {me_hurt, 0}, {mo_hurt, 3}
        }
 };
 
 struct Message heal_msgtab = {
-       "HEAL", 0, 0, 0, MFLG_SLOW, {
+       "HEAL", 0, 0, 0, 0, {
                mg_ignore, mg_ignore, mg_ignore,
                mg_ignore, {me_heal, 0}, {mo_heal, 2}
        }
@@ -101,22 +98,28 @@ struct Message heal_msgtab = {
 
 /* {{{ Misc module stuff */
 mapi_hfn_list_av1 hurt_hfnlist[] = {
-       {"client_exit",         (hookfn) client_exit_hook},
-       {"new_local_user",      (hookfn) new_local_user_hook},
-       {"doing_stats",         (hookfn) doing_stats_hook},
+       {"client_exit",         client_exit_hook},
+       {"new_local_user",      new_local_user_hook},
+       {"doing_stats",         doing_stats_hook},
        {NULL,                  NULL},
 };
 
 mapi_clist_av1 hurt_clist[] = { &hurt_msgtab, &heal_msgtab, NULL };
 
-DECLARE_MODULE_AV1(
+static const char hurt_desc[] =
+       "Prevents \"hurt\" users from messaging anyone but operators or "
+       "services until they identify or are \"healed\"";
+
+DECLARE_MODULE_AV2(
        hurt,
        modinit,
        modfini,
        hurt_clist,
        NULL,
        hurt_hfnlist,
-       "$Revision: 3161 $"
+       NULL,
+       NULL,
+       hurt_desc
 );
 /* }}} */
 
@@ -170,7 +173,7 @@ modfini(void)
  * Message handlers.
  */
 
-/* {{{ static int mo_hurt()
+/* {{{ static void mo_hurt()
  *
  * HURT [<expire>] <ip> <reason>
  *
@@ -178,8 +181,8 @@ modfini(void)
  * parv[2] - ip or reason
  * parv[3] - reason or NULL
  */
-static int
-mo_hurt(struct Client *client_p, struct Client *source_p,
+static void
+mo_hurt(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                int parc, const char **parv)
 {
        const char                      *ip, *expire, *reason;
@@ -190,7 +193,7 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
        if (!IsOperK(source_p)) {
                sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
                                source_p->name, "kline");
-               return 0;
+               return;
        }
 
        if (parc == 3)
@@ -202,11 +205,11 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
                expire_time = HURT_DEFAULT_EXPIRE;
        if (expire && (expire_time = valid_temp_time(expire)) < 1) {
                sendto_one_notice(source_p, ":Permanent HURTs are not supported");
-               return 0;
+               return;
        }
        if (EmptyString(reason)) {
                sendto_one_notice(source_p, ":Empty HURT reasons are bad for business");
-               return 0;
+               return;
        }
 
        /* Is this a client? */
@@ -217,7 +220,7 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
                {
                        sendto_one_numeric(source_p, ERR_NOSUCHNICK,
                                           form_str(ERR_NOSUCHNICK), ip);
-                       return 0;
+                       return;
                }
                ip = target_p->orighost;
        }
@@ -229,13 +232,13 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
                {
                        sendto_one_notice(source_p, ":Invalid HURT mask [%s]",
                                        ip);
-                       return 0;
+                       return;
                }
        }
 
        if (hurt_find(ip) != NULL) {
                sendto_one(source_p, ":[%s] already HURT", ip);
-               return 0;
+               return;
        }
 
        /*
@@ -249,12 +252,10 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
        hurt = hurt_new(expire_time, ip, reason);
        hurt_add(hurt);
        hurt_propagate(NULL, source_p, hurt);
-
-       return 0;
 }
 /* }}} */
 
-/* {{{ static int me_hurt()
+/* {{{ static void me_hurt()
  *
  * [ENCAP mask] HURT <target> <expire> <ip> <reason>
  *
@@ -262,8 +263,8 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
  * parv[2] - ip
  * parv[3] - reason
  */
-static int
-me_hurt(struct Client *client_p, struct Client *source_p,
+static void
+me_hurt(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                int parc, const char **parv)
 {
        time_t                          expire_time;
@@ -275,32 +276,30 @@ me_hurt(struct Client *client_p, struct Client *source_p,
         * dropping a server over.
         */
        if (parc < 4 || !IsPerson(source_p))
-               return 0;
+               return;
        if ((expire_time = atoi(parv[1])) < 1)
-               return 0;
+               return;
        if (hurt_find(parv[2]) != NULL)
-               return 0;
+               return;
        if (EmptyString(parv[3]))
-               return 0;
+               return;
 
        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                        "%s added HURT on [%s] for %ld minutes with reason [%s]",
                        get_oper_name(source_p), parv[2], (long) expire_time / 60, parv[3]);
        hurt = hurt_new(expire_time, parv[2], parv[3]);
        hurt_add(hurt);
-
-       return 0;
 }
 /* }}} */
 
-/* {{{ static int mo_heal()
+/* {{{ static void mo_heal()
  *
  * HURT <nick>|<ip>
  *
  * parv[1] - nick or ip
  */
-static int
-mo_heal(struct Client *client_p, struct Client *source_p,
+static void
+mo_heal(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                int parc, const char **parv)
 {
        struct Client *target_p;
@@ -309,17 +308,17 @@ mo_heal(struct Client *client_p, struct Client *source_p,
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
                                me.name, source_p->name, "unkline");
-               return 0;
+               return;
        }
 
-       if (nick_is_valid(parv[1]))
+       if (clean_nick(parv[1], 0))
        {
                target_p = find_named_person(parv[1]);
                if (target_p == NULL)
                {
                        sendto_one_numeric(source_p, ERR_NOSUCHNICK,
                                        form_str(ERR_NOSUCHNICK), parv[1]);
-                       return 0;
+                       return;
                }
                if (MyConnect(target_p))
                        heal_nick(source_p, target_p);
@@ -334,7 +333,7 @@ mo_heal(struct Client *client_p, struct Client *source_p,
                if (hurt_find_exact(parv[1]) == NULL)
                {
                        sendto_one_notice(source_p, ":Mask [%s] is not HURT", parv[1]);
-                       return 0;
+                       return;
                }
                hurt_remove(parv[1]);
                sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s",
@@ -345,15 +344,13 @@ mo_heal(struct Client *client_p, struct Client *source_p,
        else
        {
                sendto_one(source_p, ":[%s] is not a valid IP address/nick", parv[1]);
-               return 0;
+               return;
        }
-
-       return 0;
 }
 /* }}} */
 
-static int
-me_heal(struct Client *client_p, struct Client *source_p,
+static void
+me_heal(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                int parc, const char **parv)
 {
        struct Client *target_p;
@@ -362,9 +359,9 @@ me_heal(struct Client *client_p, struct Client *source_p,
         * *poof*, it's dropped...
         */
        if (parc < 2)
-               return 0;
+               return;
 
-       if (nick_is_valid(parv[1]))
+       if (clean_nick(parv[1], 0))
        {
                target_p = find_person(parv[1]);
                if (target_p != NULL && MyConnect(target_p))
@@ -373,16 +370,12 @@ me_heal(struct Client *client_p, struct Client *source_p,
        else if (strchr(parv[1], '.'))  /* host or mask to remove ban for */
        {
                if (hurt_find_exact(parv[1]) == NULL)
-                       return 0;
+                       return;
 
                hurt_remove(parv[1]);
                sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s",
                                get_oper_name(source_p), parv[1]);
        }
-       else
-               return 0;
-
-       return 0;
 }
 
 /*
@@ -436,8 +429,9 @@ hurt_expire_event(void *unused)
 
 /* {{{ static void client_exit_hook() */
 static void
-client_exit_hook(hook_data_client_exit *data)
+client_exit_hook(void *data_)
 {
+       hook_data_client_exit *data = data_;
        s_assert(data != NULL);
        s_assert(data->target != NULL);
 
@@ -447,8 +441,9 @@ client_exit_hook(hook_data_client_exit *data)
 
 /* {{{ static void new_local_user_hook() */
 static void
-new_local_user_hook(struct Client *source_p)
+new_local_user_hook(void *data)
 {
+       struct Client *source_p = data;
        if (IsAnyDead(source_p) || !EmptyString(source_p->user->suser) ||
                        IsExemptKline(source_p))
                return;
@@ -465,8 +460,9 @@ new_local_user_hook(struct Client *source_p)
 
 /* {{{ static void doing_stats_hook() */
 static void
-doing_stats_hook(hook_data_int *hdata)
+doing_stats_hook(void *data)
 {
+       hook_data_int *hdata = data;
        rb_dlink_node   *ptr;
        hurt_t          *hurt;
        struct Client   *source_p;
@@ -477,9 +473,9 @@ doing_stats_hook(hook_data_int *hdata)
        source_p = hdata->client;
        if(hdata->arg2 != (int) 's')
                return;
-       if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
+       if((ConfigFileEntry.stats_k_oper_only == 2) && !IsOperGeneral(source_p))
                return;
-       if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
+       if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOperGeneral(source_p))
        {
                hurt = hurt_find(source_p->sockhost);
                if (hurt != NULL)
@@ -496,7 +492,6 @@ doing_stats_hook(hook_data_int *hdata)
                        sendto_one_numeric(source_p, RPL_STATSKLINE,
                                        form_str(RPL_STATSKLINE), 's',
                                        "*", hurt->ip, hurt->reason, "", "");
-                       return;
                }
                return;
        }
@@ -584,7 +579,7 @@ hurt_find_exact(const char *ip)
        {
                hurt = (hurt_t *) ptr->data;
 
-               if (!strcasecmp(ip, hurt->ip))
+               if (!rb_strcasecmp(ip, hurt->ip))
                        return hurt;
        }
 
@@ -617,43 +612,22 @@ hurt_remove(const char *ip)
        hurt_destroy(hurt);
 }
 
-/* {{{ static int heal_nick() */
-static int
+/* {{{ static void heal_nick() */
+static void
 heal_nick(struct Client *source_p, struct Client *target_p)
 {
        if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients))
        {
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s used HEAL on %s",
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "%s used HEAL on %s",
                                get_oper_name(source_p), get_client_name(target_p, HIDE_IP));
                sendto_one_notice(target_p, ":HURT restriction temporarily removed by operator");
                sendto_one_notice(source_p, ":HURT restriction on %s temporarily removed", target_p->name);
                target_p->localClient->target_last = rb_current_time();         /* don't ask --nenolod */
-               return 1;
        }
        else
        {
                sendto_one_notice(source_p, ":%s was not hurt", target_p->name);
-               return 0;
-       }
-}
-/* }}} */
-
-/*
- * Anything else...
- */
-
-/* {{{ static int nick_is_valid() */
-static int
-nick_is_valid(const char *nick)
-{
-       const char *s = nick;
-
-       for (; *s != '\0'; s++) {
-               if (!IsNickChar(*s))
-                       return 0;
        }
-
-       return 1;
 }
 /* }}} */