]> jfr.im git - solanum.git/blobdiff - modules/m_services.c
m_info: Correct description of general::client_exit like in example confs.
[solanum.git] / modules / m_services.c
index 1bbc4db692bb762f6549b5cacc54e803a0b6e557..dd99fbec8aa61a80a5c9d3b1f04b4cd0405b5b81 100644 (file)
 #include "whowas.h"
 #include "monitor.h"
 
+static int _modinit(void);
+static void _moddeinit(void);
+
+static void mark_services(void);
+static void unmark_services(void);
+
 static int me_su(struct Client *, struct Client *, int, const char **);
 static int me_login(struct Client *, struct Client *, int, const char **);
 static int me_rsfnc(struct Client *, struct Client *, int, const char **);
@@ -56,6 +62,8 @@ static int me_nickdelay(struct Client *, struct Client *, int, const char **);
 static void h_svc_server_introduced(hook_data_client *);
 static void h_svc_whois(hook_data_client *);
 static void h_svc_stats(hook_data_int *);
+static void h_svc_conf_read_start(void *);
+static void h_svc_conf_read_end(void *);
 
 struct Message su_msgtab = {
        "SU", 0, 0, 0, MFLG_SLOW,
@@ -82,10 +90,24 @@ mapi_hfn_list_av1 services_hfnlist[] = {
        { "doing_whois",        (hookfn) h_svc_whois },
        { "doing_whois_global", (hookfn) h_svc_whois },
        { "server_introduced",  (hookfn) h_svc_server_introduced },
+       { "conf_read_start", (hookfn) h_svc_conf_read_start },
+       { "conf_read_end", (hookfn) h_svc_conf_read_end },
        { NULL, NULL }
 };
 
-DECLARE_MODULE_AV1(services, NULL, NULL, services_clist, NULL, services_hfnlist, "$Revision: 1907 $");
+DECLARE_MODULE_AV1(services, _modinit, _moddeinit, services_clist, NULL, services_hfnlist, "$Revision: 1907 $");
+
+static int
+_modinit(void)
+{
+       mark_services();
+}
+
+static void
+_moddeinit(void)
+{
+       unmark_services();
+}
 
 static int
 me_su(struct Client *client_p, struct Client *source_p,
@@ -94,7 +116,11 @@ me_su(struct Client *client_p, struct Client *source_p,
        struct Client *target_p;
 
        if(!(source_p->flags & FLAGS_SERVICE))
+       {
+               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       "Non-service server %s attempting to execute services-only command SU", source_p->name);
                return 0;
+       }
 
        if((target_p = find_client(parv[1])) == NULL)
                return 0;
@@ -158,7 +184,11 @@ me_rsfnc(struct Client *client_p, struct Client *source_p,
        char note[NICKLEN + 10];
 
        if(!(source_p->flags & FLAGS_SERVICE))
+       {
+               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       "Non-service server %s attempting to execute services-only command RSFNC", source_p->name);
                return 0;
+       }
 
        if((target_p = find_person(parv[1])) == NULL)
                return 0;
@@ -236,7 +266,7 @@ doit:
                        use_id(target_p), parv[2], (long) target_p->tsinfo);
 
        del_from_client_hash(target_p->name, target_p);
-       strcpy(target_p->name, parv[2]);
+       rb_strlcpy(target_p->name, parv[2], NICKLEN);
        add_to_client_hash(target_p->name, target_p);
 
        monitor_signon(target_p);
@@ -260,7 +290,11 @@ me_nickdelay(struct Client *client_p, struct Client *source_p, int parc, const c
        struct nd_entry *nd;
 
        if(!(source_p->flags & FLAGS_SERVICE))
+       {
+               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                       "Non-service server %s attempting to execute services-only command NICKDELAY", source_p->name);
                return 0;
+       }
 
        duration = atoi(parv[1]);
        if (duration <= 0)
@@ -330,7 +364,48 @@ h_svc_stats(hook_data_int *data)
                {
                        sendto_one_numeric(data->client, RPL_STATSULINE,
                                                form_str(RPL_STATSULINE),
-                                               ptr->data, "*", "*", "s");
+                                               (const char *)ptr->data, "*", "*", "s");
                }
        }
 }
+
+static void
+h_svc_conf_read_start(void *dummy)
+{
+       unmark_services();
+}
+
+static void
+unmark_services(void)
+{
+       struct Client *target_p;
+       rb_dlink_node *ptr;
+
+       RB_DLINK_FOREACH(ptr, global_serv_list.head)
+       {
+               target_p = ptr->data;
+
+               target_p->flags &= ~FLAGS_SERVICE;
+       }
+}
+
+static void
+h_svc_conf_read_end(void *dummy)
+{
+       mark_services();
+}
+
+static void
+mark_services(void)
+{
+       struct Client *target_p;
+       rb_dlink_node *ptr;
+
+       RB_DLINK_FOREACH(ptr, service_list.head)
+       {
+               target_p = find_server(NULL, (const char *)ptr->data);
+
+               if (target_p)
+                       target_p->flags |= FLAGS_SERVICE;
+       }
+}