]> jfr.im git - solanum.git/blobdiff - extensions/hurt.c
Message handlers should return void.
[solanum.git] / extensions / hurt.c
index 0708fab03196547213a58a919fc1b285e00197ed..086557219af55789cb6fc307b7c470b5336f6d71 100644 (file)
@@ -3,8 +3,6 @@
  *
  * Copyright (C) 2006 charybdis development team
  * All rights reserved
- *
- * $Id: hurt.c 1905 2006-08-29 14:51:31Z jilles $
  */
 #include "stdinc.h"
 #include "modules.h"
 #include "send.h"
 #include "numeric.h"
 #include "hostmask.h"
-#include "event.h"
 #include "s_conf.h"
 #include "s_newconf.h"
 #include "hash.h"
+#include "messages.h"
+#include "s_assert.h"
 
 /* {{{ Structures */
 #define HURT_CUTOFF             (10)            /* protocol messages. */
@@ -32,26 +31,26 @@ enum {
 typedef struct _hurt_state {
         time_t start_time;
         uint32_t n_hurts;
-        dlink_list hurt_clients;
+        rb_dlink_list hurt_clients;
         uint16_t cutoff;
         time_t default_expire;
         const char *exit_reason;
 } hurt_state_t;
 
 typedef struct _hurt {
-        const char *ip;
+        char *ip;
         struct sockaddr *saddr;
         int saddr_bits;
-        const char *reason;
+        char *reason;
         time_t expire;
 } hurt_t;
 /* }}} */
 
 /* {{{ 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);
@@ -71,27 +70,26 @@ 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 */
 
-dlink_list hurt_confs = { NULL, NULL, 0 };
+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}
        }
@@ -108,14 +106,20 @@ mapi_hfn_list_av1 hurt_hfnlist[] = {
 
 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: 1905 $"
+       NULL,
+       NULL,
+       hurt_desc
 );
 /* }}} */
 
@@ -130,15 +134,19 @@ hurt_state_t hurt_state = {
  */
 
 /* {{{ static int modinit() */
+
+struct ev_entry *hurt_expire_ev = NULL;
+struct ev_entry *hurt_check_ev = NULL;
+
 static int
 modinit(void)
 {
        /* set-up hurt_state. */
-       hurt_state.start_time = CurrentTime;
+       hurt_state.start_time = rb_current_time();
 
        /* add our event handlers. */
-       eventAdd("hurt_expire", hurt_expire_event, NULL, 60);
-       eventAdd("hurt_check", hurt_check_event, NULL, 5);
+       hurt_expire_ev = rb_event_add("hurt_expire", hurt_expire_event, NULL, 60);
+       hurt_check_ev = rb_event_add("hurt_check", hurt_check_event, NULL, 5);
 
        return 0;
 }
@@ -148,15 +156,15 @@ modinit(void)
 static void
 modfini(void)
 {
-       dlink_node      *ptr, *next_ptr;
+       rb_dlink_node   *ptr, *next_ptr;
 
        /* and delete our events. */
-       eventDelete(hurt_expire_event, NULL);
-       eventDelete(hurt_check_event, NULL);
+       rb_event_delete(hurt_expire_ev);
+       rb_event_delete(hurt_check_ev);
 
-       DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head)
+       RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head)
        {
-               dlinkDestroy(ptr, &hurt_state.hurt_clients);
+               rb_dlinkDestroy(ptr, &hurt_state.hurt_clients);
        }
 }
 /* }}} */
@@ -165,16 +173,16 @@ modfini(void)
  * Message handlers.
  */
 
-/* {{{ static int mo_hurt()
+/* {{{ static void mo_hurt()
  *
  * HURT [<expire>] <ip> <reason>
- * 
+ *
  * parv[1] - expire or ip
  * 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;
@@ -185,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)
@@ -196,16 +204,12 @@ mo_hurt(struct Client *client_p, struct Client *source_p,
        if (!expire)
                expire_time = HURT_DEFAULT_EXPIRE;
        if (expire && (expire_time = valid_temp_time(expire)) < 1) {
-               sendto_one(source_p,
-                               ":%s NOTICE %s :Permanent HURTs are not supported",
-                               me.name, source_p->name);
-               return 0;
+               sendto_one_notice(source_p, ":Permanent HURTs are not supported");
+               return;
        }
        if (EmptyString(reason)) {
-               sendto_one(source_p,
-                               ":%s NOTICE %s :Empty HURT reasons are bad for business",
-                               me.name, source_p->name);
-               return 0;
+               sendto_one_notice(source_p, ":Empty HURT reasons are bad for business");
+               return;
        }
 
        /* Is this a client? */
@@ -216,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;
        }
@@ -228,15 +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 NOTICE %s :[%s] already HURT",
-                               me.name, source_p->name, ip);
-               return 0;
+               sendto_one(source_p, ":[%s] already HURT", ip);
+               return;
        }
 
        /*
@@ -250,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>
  *
@@ -263,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;
@@ -276,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;
@@ -310,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,9 +332,8 @@ mo_heal(struct Client *client_p, struct Client *source_p,
        {
                if (hurt_find_exact(parv[1]) == NULL)
                {
-                       sendto_one(source_p, ":%s NOTICE %s :Mask [%s] is not HURT",
-                                       me.name, source_p->name, parv[1]);
-                       return 0;
+                       sendto_one_notice(source_p, ":Mask [%s] is not HURT", parv[1]);
+                       return;
                }
                hurt_remove(parv[1]);
                sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s removed HURT on %s",
@@ -346,18 +343,14 @@ mo_heal(struct Client *client_p, struct Client *source_p,
        }
        else
        {
-               sendto_one(source_p,
-                               ":%s NOTICE %s :[%s] is not a valid IP address/nick",
-                               me.name, source_p->name, parv[1]);
-               return 0;
+               sendto_one(source_p, ":[%s] is not a valid IP address/nick", parv[1]);
+               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;
@@ -366,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))
@@ -377,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;
 }
 
 /*
@@ -397,17 +386,16 @@ me_heal(struct Client *client_p, struct Client *source_p,
 static void
 hurt_check_event(void *arg)
 {
-       dlink_node      *ptr, *next_ptr;
+       rb_dlink_node   *ptr, *next_ptr;
        struct Client   *client_p;
 
-       DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) {
+       RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) {
                client_p = ptr->data;
                if (!EmptyString(client_p->user->suser))
                {
-                       dlinkDestroy(ptr, &hurt_state.hurt_clients);
+                       rb_dlinkDestroy(ptr, &hurt_state.hurt_clients);
                        sendto_one_notice(client_p, ":HURT restriction removed for this session");
-                       USED_TARGETS(client_p) = 0;
-                       client_p->localClient->target_last = CurrentTime;               /* don't ask --nenolod */
+                       client_p->localClient->target_last = rb_current_time();         /* don't ask --nenolod */
                }
                else if (client_p->localClient->receiveM > hurt_state.cutoff)
                        exit_client(NULL, client_p, &me, hurt_state.exit_reason);
@@ -419,16 +407,16 @@ hurt_check_event(void *arg)
 static void
 hurt_expire_event(void *unused)
 {
-       dlink_node      *ptr, *next_ptr;
+       rb_dlink_node   *ptr, *next_ptr;
        hurt_t          *hurt;
 
-       DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head)
+       RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head)
        {
                hurt = (hurt_t *) ptr->data;
 
-               if (hurt->expire <= CurrentTime)
+               if (hurt->expire <= rb_current_time())
                {
-                       dlinkFindDestroy(hurt, &hurt_confs);
+                       rb_dlinkFindDestroy(hurt, &hurt_confs);
                        hurt_destroy(hurt);
                }
        }
@@ -446,7 +434,7 @@ client_exit_hook(hook_data_client_exit *data)
        s_assert(data != NULL);
        s_assert(data->target != NULL);
 
-       dlinkFindDestroy(data->target, &hurt_state.hurt_clients);
+       rb_dlinkFindDestroy(data->target, &hurt_state.hurt_clients);
 }
 /* }}} */
 
@@ -460,12 +448,11 @@ new_local_user_hook(struct Client *source_p)
 
        if (hurt_find(source_p->sockhost) || hurt_find(source_p->orighost))
        {
-               USED_TARGETS(source_p) = 10;
-               source_p->localClient->target_last = CurrentTime + 600;         /* don't ask --nenolod */
+               source_p->localClient->target_last = rb_current_time() + 600;           /* don't ask --nenolod */
                SetTGChange(source_p);
-               dlinkAddAlloc(source_p, &hurt_state.hurt_clients);
+               rb_dlinkAddAlloc(source_p, &hurt_state.hurt_clients);
                sendto_one_notice(source_p, ":You are hurt. Please identify to services immediately, or use /stats p for assistance.");
-       }       
+       }
 }
 /* }}} */
 
@@ -473,7 +460,7 @@ new_local_user_hook(struct Client *source_p)
 static void
 doing_stats_hook(hook_data_int *hdata)
 {
-       dlink_node      *ptr;
+       rb_dlink_node   *ptr;
        hurt_t          *hurt;
        struct Client   *source_p;
 
@@ -502,12 +489,11 @@ 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;
        }
 
-       DLINK_FOREACH(ptr, hurt_confs.head)
+       RB_DLINK_FOREACH(ptr, hurt_confs.head)
        {
                hurt = (hurt_t *) ptr->data;
                sendto_one_numeric(source_p, RPL_STATSKLINE,
@@ -531,13 +517,13 @@ hurt_propagate(struct Client *client_p, struct Client *source_p, hurt_t *hurt)
                sendto_one(client_p,
                                ":%s ENCAP %s HURT %ld %s :%s",
                                source_p->name, client_p->name,
-                               (long)(hurt->expire - CurrentTime),
+                               (long)(hurt->expire - rb_current_time()),
                                hurt->ip, hurt->reason);
        else
                sendto_server(&me, NULL, NOCAPS, NOCAPS,
                                ":%s ENCAP * HURT %ld %s :%s",
                                source_p->name,
-                               (long)(hurt->expire - CurrentTime),
+                               (long)(hurt->expire - rb_current_time()),
                                hurt->ip, hurt->reason);
 }
 /* }}} */
@@ -548,11 +534,11 @@ hurt_new(time_t expire, const char *ip, const char *reason)
 {
        hurt_t *hurt;
 
-       hurt = MyMalloc(sizeof(hurt_t));
+       hurt = rb_malloc(sizeof(hurt_t));
 
-       DupString(hurt->ip, ip);
-       DupString(hurt->reason, reason);
-       hurt->expire = CurrentTime + expire;
+       hurt->ip = rb_strdup(ip);
+       hurt->reason = rb_strdup(reason);
+       hurt->expire = rb_current_time() + expire;
 
        return hurt;
 }
@@ -568,25 +554,25 @@ hurt_destroy(void *hurt)
                return;
 
        h = (hurt_t *) hurt;
-       MyFree((char *) h->ip);
-       MyFree((char *) h->reason);
-       MyFree(h);
+       rb_free(h->ip);
+       rb_free(h->reason);
+       rb_free(h);
 }
 /* }}} */
 
 static void
 hurt_add(hurt_t *hurt)
 {
-       dlinkAddAlloc(hurt, &hurt_confs);
+       rb_dlinkAddAlloc(hurt, &hurt_confs);
 }
 
 static hurt_t *
 hurt_find_exact(const char *ip)
 {
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        hurt_t *hurt;
 
-       DLINK_FOREACH(ptr, hurt_confs.head)
+       RB_DLINK_FOREACH(ptr, hurt_confs.head)
        {
                hurt = (hurt_t *) ptr->data;
 
@@ -600,10 +586,10 @@ hurt_find_exact(const char *ip)
 static hurt_t *
 hurt_find(const char *ip)
 {
-       dlink_node *ptr;
+       rb_dlink_node *ptr;
        hurt_t *hurt;
 
-       DLINK_FOREACH(ptr, hurt_confs.head)
+       RB_DLINK_FOREACH(ptr, hurt_confs.head)
        {
                hurt = (hurt_t *) ptr->data;
 
@@ -619,51 +605,29 @@ hurt_remove(const char *ip)
 {
        hurt_t *hurt = hurt_find_exact(ip);
 
-       dlinkFindDestroy(hurt, &hurt_confs);
+       rb_dlinkFindDestroy(hurt, &hurt_confs);
        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 (dlinkFindDestroy(target_p, &hurt_state.hurt_clients))
+       if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients))
        {
                sendto_realops_snomask(SNO_GENERAL, L_ALL, "%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);
-               USED_TARGETS(target_p) = 0;
-               target_p->localClient->target_last = CurrentTime;               /* don't ask --nenolod */
-               return 1;
+               target_p->localClient->target_last = rb_current_time();         /* don't ask --nenolod */
        }
        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;
-}
-/* }}} */
-
 /*
  * vim: ts=8 sw=8 noet fdm=marker tw=80
  */