]> jfr.im git - solanum.git/blobdiff - modules/core/m_nick.c
make more snotes L_NETWIDE
[solanum.git] / modules / core / m_nick.c
index cd9dc9c0fc5c9bfb50da718047fb802958d30a92..a5b94d59161657c7e4f429c5b92d4a5f724ed160 100644 (file)
@@ -40,7 +40,6 @@
 #include "msg.h"
 #include "parse.h"
 #include "modules.h"
-#include "common.h"
 #include "packet.h"
 #include "scache.h"
 #include "s_newconf.h"
@@ -80,6 +79,9 @@ static void perform_nick_collides(struct Client *, struct Client *,
 static void perform_nickchange_collides(struct Client *, struct Client *,
                                        struct Client *, int, const char **, time_t, const char *);
 
+static int h_local_nick_change;
+static int h_remote_nick_change;
+
 struct Message nick_msgtab = {
        "NICK", 0, 0, 0, 0,
        {{mr_nick, 0}, {m_nick, 0}, {mc_nick, 3}, {ms_nick, 0}, mg_ignore, {m_nick, 0}}
@@ -100,10 +102,16 @@ struct Message save_msgtab = {
 mapi_clist_av1 nick_clist[] = { &nick_msgtab, &uid_msgtab, &euid_msgtab,
        &save_msgtab, NULL };
 
+mapi_hlist_av1 nick_hlist[] = {
+       { "local_nick_change", &h_local_nick_change },
+       { "remote_nick_change", &h_remote_nick_change },
+       { NULL, NULL }
+};
+
 static const char nick_desc[] =
        "Provides the NICK client and server commands as well as the UID, EUID, and SAVE TS6 server commands";
 
-DECLARE_MODULE_AV2(nick, NULL, NULL, nick_clist, NULL, NULL, NULL, NULL, nick_desc);
+DECLARE_MODULE_AV2(nick, NULL, NULL, nick_clist, nick_hlist, NULL, NULL, NULL, nick_desc);
 
 /* mr_nick()
  *       parv[1] = nickname
@@ -114,7 +122,7 @@ mr_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
        struct Client *target_p;
        char nick[NICKLEN];
 
-       if (strlen(client_p->id) == 3)
+       if (strlen(client_p->id) == 3 || (source_p->preClient && !EmptyString(source_p->preClient->id)))
        {
                exit_client(client_p, client_p, client_p, "Mixing client and server protocol");
                return;
@@ -156,7 +164,7 @@ mr_nick(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
        if((target_p = find_named_client(nick)) == NULL)
                set_initial_nick(client_p, source_p, nick);
        else if(source_p == target_p)
-               strcpy(source_p->name, nick);
+               rb_strlcpy(source_p->name, nick, sizeof(source_p->name));
        else
                sendto_one(source_p, form_str(ERR_NICKNAMEINUSE), me.name, "*", nick);
 }
@@ -317,7 +325,7 @@ ms_uid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
 
        if(parc != 10)
        {
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                     "Dropping server %s due to (invalid) command 'UID' "
                                     "with %d arguments (expecting 10)", client_p->name, parc);
                ilog(L_SERVER, "Excess parameters (%d) for command 'UID' from %s.",
@@ -348,7 +356,7 @@ ms_uid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
        if(!clean_username(parv[5]) || !clean_host(parv[6]))
        {
                ServerStats.is_kill++;
-               sendto_realops_snomask(SNO_DEBUG, L_ALL,
+               sendto_realops_snomask(SNO_DEBUG, L_NETWIDE,
                                     "Bad user@host: %s@%s From: %s(via %s)",
                                     parv[5], parv[6], source_p->name, client_p->name);
                sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name);
@@ -359,7 +367,7 @@ ms_uid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
        if(strlen(parv[9]) > REALLEN)
        {
                char *s = LOCAL_COPY(parv[9]);
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s",
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Long realname from server %s for %s",
                                     source_p->name, parv[1]);
                s[REALLEN] = '\0';
                parv[9] = s;
@@ -406,7 +414,7 @@ ms_euid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
 
        if(parc != 12)
        {
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                     "Dropping server %s due to (invalid) command 'EUID' "
                                     "with %d arguments (expecting 12)", client_p->name, parc);
                ilog(L_SERVER, "Excess parameters (%d) for command 'EUID' from %s.",
@@ -437,7 +445,7 @@ ms_euid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
        if(!clean_username(parv[5]) || !clean_host(parv[6]))
        {
                ServerStats.is_kill++;
-               sendto_realops_snomask(SNO_DEBUG, L_ALL,
+               sendto_realops_snomask(SNO_DEBUG, L_NETWIDE,
                                     "Bad user@host: %s@%s From: %s(via %s)",
                                     parv[5], parv[6], source_p->name, client_p->name);
                sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name);
@@ -447,7 +455,7 @@ ms_euid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
        if(strcmp(parv[9], "*") && !clean_host(parv[9]))
        {
                ServerStats.is_kill++;
-               sendto_realops_snomask(SNO_DEBUG, L_ALL,
+               sendto_realops_snomask(SNO_DEBUG, L_NETWIDE,
                                     "Bad realhost: %s From: %s(via %s)",
                                     parv[9], source_p->name, client_p->name);
                sendto_one(client_p, ":%s KILL %s :%s (Bad user@host)", me.id, parv[8], me.name);
@@ -458,7 +466,7 @@ ms_euid(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_
        if(strlen(parv[11]) > REALLEN)
        {
                char *s = LOCAL_COPY(parv[11]);
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "Long realname from server %s for %s",
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Long realname from server %s for %s",
                                     source_p->name, parv[1]);
                s[REALLEN] = '\0';
                parv[11] = s;
@@ -594,7 +602,7 @@ set_initial_nick(struct Client *client_p, struct Client *source_p, char *nick)
        if(source_p->name[0])
                del_from_client_hash(source_p->name, source_p);
 
-       strcpy(source_p->name, nick);
+       rb_strlcpy(source_p->name, nick, sizeof(source_p->name));
        add_to_client_hash(nick, source_p);
 
        snprintf(note, sizeof(note), "Nick: %s", nick);
@@ -616,6 +624,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
        struct Channel *chptr;
        char note[NICKLEN + 10];
        int samenick;
+       hook_cdata hook_info;
 
        if (dosend)
        {
@@ -633,7 +642,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
                source_p->localClient->last_nick_change = rb_current_time();
                source_p->localClient->number_of_nick_changes++;
 
-               if(ConfigFileEntry.anti_nick_flood && !IsOper(source_p) &&
+               if(ConfigFileEntry.anti_nick_flood && !IsOperGeneral(source_p) &&
                                source_p->localClient->number_of_nick_changes > ConfigFileEntry.max_nick_changes)
                {
                        sendto_one(source_p, form_str(ERR_NICKTOOFAST),
@@ -659,6 +668,11 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
                        invalidate_bancache_user(source_p);
        }
 
+       hook_info.client = source_p;
+       hook_info.arg1 = source_p->name;
+       hook_info.arg2 = nick;
+       call_hook(h_local_nick_change, &hook_info);
+
        sendto_realops_snomask(SNO_NCHANGE, L_ALL,
                             "Nick change: From %s to %s [%s@%s]",
                             source_p->name, nick, source_p->username, source_p->host);
@@ -681,7 +695,7 @@ change_local_nick(struct Client *client_p, struct Client *source_p,
 
        /* Finally, add to hash */
        del_from_client_hash(source_p->name, source_p);
-       strcpy(source_p->name, nick);
+       rb_strlcpy(source_p->name, nick, sizeof(source_p->name));
        add_to_client_hash(nick, source_p);
 
        if(!samenick)
@@ -717,6 +731,7 @@ change_remote_nick(struct Client *client_p, struct Client *source_p,
 {
        struct nd_entry *nd;
        int samenick = irccmp(source_p->name, nick) ? 0 : 1;
+       hook_cdata hook_info;
 
        /* client changing their nick - dont reset ts if its same */
        if(!samenick)
@@ -725,6 +740,11 @@ change_remote_nick(struct Client *client_p, struct Client *source_p,
                monitor_signoff(source_p);
        }
 
+       hook_info.client = source_p;
+       hook_info.arg1 = source_p->name;
+       hook_info.arg2 = nick;
+       call_hook(h_remote_nick_change, &hook_info);
+
        sendto_common_channels_local(source_p, NOCAPS, NOCAPS, ":%s!%s@%s NICK :%s",
                                     source_p->name, source_p->username, source_p->host, nick);
 
@@ -744,7 +764,7 @@ change_remote_nick(struct Client *client_p, struct Client *source_p,
        if((nd = rb_dictionary_retrieve(nd_dict, nick)))
                free_nd_entry(nd);
 
-       strcpy(source_p->name, nick);
+       rb_strlcpy(source_p->name, nick, sizeof(source_p->name));
        add_to_client_hash(nick, source_p);
 
        if(!samenick)
@@ -770,7 +790,7 @@ perform_nick_collides(struct Client *source_p, struct Client *client_p,
        /* if we dont have a ts, or their TS's are the same, kill both */
        if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo))
        {
-               sendto_realops_snomask(SNO_SKILL, L_ALL,
+               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                     "Nick collision on %s(%s <- %s)(both %s)",
                                     target_p->name, target_p->from->name, client_p->name, action);
 
@@ -833,12 +853,12 @@ perform_nick_collides(struct Client *source_p, struct Client *client_p,
                else
                {
                        if(sameuser)
-                               sendto_realops_snomask(SNO_SKILL, L_ALL,
+                               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                                     "Nick collision on %s(%s <- %s)(older %s)",
                                                     target_p->name, target_p->from->name,
                                                     client_p->name, action);
                        else
-                               sendto_realops_snomask(SNO_SKILL, L_ALL,
+                               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                                     "Nick collision on %s(%s <- %s)(newer %s)",
                                                     target_p->name, target_p->from->name,
                                                     client_p->name, action);
@@ -885,7 +905,7 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p,
        /* its a client changing nick and causing a collide */
        if(!newts || !target_p->tsinfo || (newts == target_p->tsinfo) || !source_p->user)
        {
-               sendto_realops_snomask(SNO_SKILL, L_ALL,
+               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                     "Nick change collision from %s to %s(%s <- %s)(both %s)",
                                     source_p->name, target_p->name, target_p->from->name,
                                     client_p->name, action);
@@ -928,12 +948,12 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p,
                   (!sameuser && newts > target_p->tsinfo))
                {
                        if(sameuser)
-                               sendto_realops_snomask(SNO_SKILL, L_ALL,
+                               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                                     "Nick change collision from %s to %s(%s <- %s)(older %s)",
                                                     source_p->name, target_p->name,
                                                     target_p->from->name, client_p->name, action);
                        else
-                               sendto_realops_snomask(SNO_SKILL, L_ALL,
+                               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                                     "Nick change collision from %s to %s(%s <- %s)(newer %s)",
                                                     source_p->name, target_p->name,
                                                     target_p->from->name, client_p->name, action);
@@ -973,12 +993,12 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p,
                else
                {
                        if(sameuser)
-                               sendto_realops_snomask(SNO_SKILL, L_ALL,
+                               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                                     "Nick collision on %s(%s <- %s)(older %s)",
                                                     target_p->name, target_p->from->name,
                                                     client_p->name, action);
                        else
-                               sendto_realops_snomask(SNO_SKILL, L_ALL,
+                               sendto_realops_snomask(SNO_SKILL, L_NETWIDE,
                                                     "Nick collision on %s(%s <- %s)(newer %s)",
                                                     target_p->name, target_p->from->name,
                                                     client_p->name, action);
@@ -1024,7 +1044,7 @@ register_client(struct Client *client_p, struct Client *server,
        source_p->hopcount = atoi(parv[2]);
        source_p->tsinfo = newts;
 
-       strcpy(source_p->name, nick);
+       rb_strlcpy(source_p->name, nick, sizeof(source_p->name));
        rb_strlcpy(source_p->username, parv[5], sizeof(source_p->username));
        rb_strlcpy(source_p->host, parv[6], sizeof(source_p->host));
        rb_strlcpy(source_p->orighost, source_p->host, sizeof(source_p->orighost));
@@ -1148,7 +1168,7 @@ save_user(struct Client *client_p, struct Client *source_p,
        {
                /* This shouldn't happen */
                /* Note we only need SAVE support in this direction */
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)",
                                target_p->name, target_p->username, target_p->host, source_p->name, target_p->from->name);
                kill_client_serv_butone(NULL, target_p, "%s (Nick collision (no SAVE support))", me.name);