[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FNC patch



Hi,

the following is a patch which activates a 'forced nick change' (FNC) on  
nick collisions, which means that the colliders get automatically a new  
nick (if possible). The patch does not (yet) disable nick delay (ND).

If you want to test it, please don't test it in a larger network [and make  
sure that always both involved servers run it]. And if you find a bug or  
something, let me know.

Bye, Kasi

--- cut here ---
*** s_user.c    Mon Mar 31 17:41:15 1997
--- old/s_user.c        Fri Mar 28 09:22:17 1997
***************
*** 614,624 ****
  {
	aClient *acptr;
	int     delayed = 0;
!       int     i;
!       char    nick[NICKLEN+2], nick2[NICKLEN+2], *s, *user, *host;
!       char    *rnd_ch = "v[a_u0tb-n1s]cg2hm3ox4}de5ylp6f{k7q\\w8ir9z^j";
!                         /* '\\' (escape sequence) becomes '\' */
!
	if (IsService(sptr))
	    {
		sendto_one(sptr, err_str(ERR_ALREADYREGISTRED, parv[0]));
--- 614,621 ----
  {
	aClient *acptr;
	int     delayed = 0;
!       char    nick[NICKLEN+2], *s, *user, *host;
!
	if (IsService(sptr))
	    {
		sendto_one(sptr, err_str(ERR_ALREADYREGISTRED, parv[0]));
***************
*** 759,770 ****
			** version would treat it as nick collision.
			*/
			return 2; /* NICK Message ignored */
-
	/*
	** Note: From this point forward it can be assumed that
	** acptr != sptr (point to different client structures).
	*/
-
	/*
	** If the older one is "non-person", the new entry is just
	** allowed to overwrite it. Just silently drop non-person,
--- 756,765 ----
***************
*** 776,782 ****
		(void) exit_client(acptr, acptr, &me, "Overridden");
		goto nickkilldone;
	    }
-
	/*
	** Decide, we really have a nick collision and deal with it
	*/
--- 771,776 ----
***************
*** 787,861 ****
		** send error reply and ignore the command.
		*/
		sendto_one(sptr, err_str((delayed) ? ERR_UNAVAILRESOURCE
!                                                  : ERR_NICKNAMEINUSE,
					 parv[0]), nick);
		return 2; /* NICK message ignored */
	    }
-
-       /*
-       ** We have two users with the same nick on two different servers.
-       ** So we do (basically) the following:
-       **   1) change the nick of the local 'collider'
-       **   2) register the remote user
-       ** It seems to work... somehow.
-       **                                               -Kasi 03/29/1997
-       */
-       if (acptr && IsServer(cptr) && (sptr == cptr))
-         {
-           srand(me.since); /* initialize seed for new random numbers */
-           /*
-           ** Replace the last two characters of the nickname by 2
-           ** of the 43 (44 - 1) characters (of rnd_ch).
-           ** [We change _two_ characters because it reduces the
-           ** possibility that both servers choose the same new nick.]
-           **
-           ** When we have the new formed nick, we check 1. whether it is
-           ** already in use and 2. whether it equals to the old nick.
-           ** And if we really can't find something acceptable, we KILL
-           ** both colliders (which should only happen very rarely!).
-           **
-           ** We use 'acptr->name' instead of 'nick' since there can be
-           ** differences (lowercase <-> uppercase) between the two nicks.
-           ** e.g.: 'Kasi' and 'kAsi'
-           */
-           for (i = 0; i < 4; i++)
-             {
-               strncpyzt(nick2, acptr->name, NICKLEN+1);
-               /* special treatment for nicks with only one character */
-               if (strlen(nick2) == 1)
-                 {
-                   nick2[strlen(nick2)-1] = rnd_ch[rand() / (RAND_MAX / 44)];
-                   nick2[strlen(nick2)]   = rnd_ch[rand() / (RAND_MAX / 44)];
-                   nick2[strlen(nick2)+1] = '\0'; /* end of nickname */
-                 }
-               else
-                 {
-                   nick2[strlen(nick2)-2] = rnd_ch[rand() / (RAND_MAX / 44)];
-                   nick2[strlen(nick2)-1] = rnd_ch[rand() / (RAND_MAX / 44)];
-                 }
-               if ((strcasecmp(nick, nick2) == 0) || find_client(nick2, NULL))
-                 continue;
-               else
-                 break;
-             }
-           if (i < 4)
-             {
-               sendto_one(acptr,
-                    ":%s NOTICE %s :*** Forced nick change (nick collision)",
-                          ME, acptr->name);
-               sendto_common_channels(acptr, ":%s NICK :%s",
-                                      acptr->name, nick2);
-               if (acptr->user)
-                 add_history(acptr, acptr);
-               sendto_serv_butone(acptr, ":%s NICK :%s", acptr->name, nick2);
-               if (acptr->name[0])
-                 (void)del_from_client_hash_table(acptr->name, acptr);
-               (void)strcpy(acptr->name, nick2);
-               (void)add_to_client_hash_table(nick2, acptr);
-               goto nickkilldone;
-             }
-         }
-
	/*
	** NICK was coming from a server connection. Means that the same
	** nick is registered for different users by different server.
--- 781,790 ----
		** send error reply and ignore the command.
		*/
		sendto_one(sptr, err_str((delayed) ? ERR_UNAVAILRESOURCE
!                                                  : ERR_NICKNAMEINUSE,
					 parv[0]), nick);
		return 2; /* NICK message ignored */
	    }
	/*
	** NICK was coming from a server connection. Means that the same
	** nick is registered for different users by different server.
--- cut here ---

-- 
Kaspar Landsberg, <kl@xxxxxxxxxxx>