]> jfr.im git - solanum.git/blobdiff - modules/m_services.c
clean up some code duplication when checking nicks for validity
[solanum.git] / modules / m_services.c
index 1105a8b08bdc180ec27b797c7a14d100407b92f8..a1c93be6cd39fbb5ebfcb183a6666b327883c202 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,
@@ -74,7 +82,7 @@ struct Message nickdelay_msgtab = {
        {mg_unreg, mg_ignore, mg_ignore, mg_ignore, {me_nickdelay, 3}, mg_ignore}
 };
 
-mapi_clist_av1 services_clist[] = { 
+mapi_clist_av1 services_clist[] = {
        &su_msgtab, &login_msgtab, &rsfnc_msgtab, &nickdelay_msgtab, NULL
 };
 mapi_hfn_list_av1 services_hfnlist[] = {
@@ -82,10 +90,25 @@ 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();
+       return 0;
+}
+
+static void
+_moddeinit(void)
+{
+       unmark_services();
+}
 
 static int
 me_su(struct Client *client_p, struct Client *source_p,
@@ -111,7 +134,7 @@ me_su(struct Client *client_p, struct Client *source_p,
        else
                rb_strlcpy(target_p->user->suser, parv[2], sizeof(target_p->user->suser));
 
-       sendto_common_channels_local_butone(target_p, CLICAP_ACCOUNT_NOTIFY, ":%s!%s@%s ACCOUNT %s",
+       sendto_common_channels_local_butone(target_p, CLICAP_ACCOUNT_NOTIFY, NOCAPS, ":%s!%s@%s ACCOUNT %s",
                                            target_p->name, target_p->username, target_p->host,
                                            EmptyString(target_p->user->suser) ? "*" : target_p->user->suser);
 
@@ -131,27 +154,6 @@ me_login(struct Client *client_p, struct Client *source_p,
        return 0;
 }
 
-static int
-clean_nick(const char *nick)
-{
-       int len = 0;
-
-       if(EmptyString(nick) || *nick == '-' || IsDigit(*nick))
-               return 0;
-
-       for(; *nick; nick++)
-       {
-               len++;
-               if(!IsNickChar(*nick))
-                       return 0;
-       }
-
-       if(len >= NICKLEN)
-               return 0;
-
-       return 1;
-}
-
 static int
 me_rsfnc(struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
@@ -174,7 +176,7 @@ me_rsfnc(struct Client *client_p, struct Client *source_p,
        if(!MyClient(target_p))
                return 0;
 
-       if(!clean_nick(parv[2]))
+       if(!is_valid_nick(parv[2]))
                return 0;
 
        curts = atol(parv[4]);
@@ -191,7 +193,7 @@ me_rsfnc(struct Client *client_p, struct Client *source_p,
                char buf[BUFSIZE];
 
                /* this would be one hell of a race condition to trigger
-                * this one given the tsinfo check above, but its here for 
+                * this one given the tsinfo check above, but its here for
                 * safety --anfl
                 */
                if(target_p == exist_p)
@@ -235,7 +237,7 @@ doit:
                        target_p->name, parv[2], target_p->username,
                        target_p->host);
 
-       sendto_common_channels_local(target_p, NOCAPS, ":%s!%s@%s NICK :%s",
+       sendto_common_channels_local(target_p, NOCAPS, NOCAPS, ":%s!%s@%s NICK :%s",
                                target_p->name, target_p->username,
                                target_p->host, parv[2]);
 
@@ -346,3 +348,44 @@ h_svc_stats(hook_data_int *data)
                }
        }
 }
+
+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;
+       }
+}