added possibility to recover connections using Login on Connect
[ircu2.10.12-pk.git] / ircd / s_user.c
index 2c9a9bce35be8aeaa46866eab9ef0925ba10f38e..96d88a15e3db5ab173052a8a5c78159063c90e8f 100644 (file)
@@ -728,7 +728,23 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
   }
   else {
     /* Local client setting NICK the first time */
-    strcpy(cli_name(sptr), nick);
+    if(!force)
+      strcpy(cli_name(sptr), nick);
+    else {
+      /* use a "temponary" nick here (we'll switch later) */
+      char tmpnick[NICKLEN + 2];
+      int tmpnickend; 
+      strcpy(tmpnick, nick);
+      /* we need at least 10 characters */
+      if (strlen(tmpnick) > IRCD_MIN(NICKLEN, feature_int(FEAT_NICKLEN)) - 10)
+        tmpnick[IRCD_MIN(NICKLEN, feature_int(FEAT_NICKLEN))-10] = '\0';
+      tmpnickend = strlen(tmpnick);
+      
+      do { /* get a non-used nick... */
+        sprintf(tmpnick + tmpnickend, "[rz%d]", ircrandom() % 10000);
+      } while(FindClient(tmpnick));
+      strcpy(cli_name(sptr), tmpnick);
+    }
     hAddClient(sptr);
     return auth_set_nick(cli_auth(sptr), nick);
   }