fixed propagation of user mode changes (user should ALWAYS be notified)
[ircu2.10.12-pk.git] / ircd / s_user.c
index 9f45018041e994d00f334dcf0687ff8283baa4d5..e5d17b975d1d594ae7a0a066a319702bb7c0aaf8 100644 (file)
@@ -589,7 +589,9 @@ static const struct UserMode {
   { FLAG_WEBIRC,      'W' },
   { FLAG_SEE_IDLETIME,'t' },
   { FLAG_SECURITY_SERV,'D' },
-  { FLAG_HIDDENHOST,  'x' }
+  { FLAG_KEEPCONN_ENABLED, 'K' },
+  { FLAG_HIDDENHOST,  'x' },
+  { FLAG_NOTCONN,     'Z' }
 };
 
 /** Length of #userModeList. */
@@ -727,7 +729,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);
   }
@@ -930,6 +948,8 @@ void send_umode_out(struct Client *cptr, struct Client *sptr,
   }
   if (cptr && MyUser(cptr))
     send_umode(cptr, sptr, old, ALL_UMODES, 0);
+  if (sptr && sptr != cptr && MyUser(sptr))
+    send_umode(sptr, sptr, old, ALL_UMODES, 0);
 }
 
 
@@ -1118,7 +1138,7 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc,
   char buf[BUFSIZE];
   int prop = 0;
   int do_host_hiding = 0;
-  char* account = NULL, *fakehost = NULL;
+  char* account = NULL, *fakehost = NULL, *keepconn = NULL;
   struct Membership *chan;
 
   what = MODE_ADD;
@@ -1290,6 +1310,16 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc,
         else
           ClearWebIRC(sptr);
         break;
+      case 'K':
+        if (what == MODE_ADD) {
+          if(*(p + 1) == 0)
+            break;
+          keepconn = *(++p);
+          SetKeepConnEnabled(sptr);
+        } else {
+          ClearKeepConnEnabled(sptr);
+        }
+        break;
       case 'r':
         if (*(p + 1) && (what == MODE_ADD)) {
           account = *(++p);
@@ -1318,6 +1348,12 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc,
       case 'z': /* Formerly SSL mode; we ignore it. */
         break;
 #endif
+      case 'Z':
+        if (what == MODE_ADD)
+          SetNotConn(sptr);
+        else
+          ClearNotConn(sptr);
+        break;
       default:
         send_reply(sptr, ERR_UMODEUNKNOWNFLAG, *m);
         break;
@@ -1340,6 +1376,8 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc,
       ClrFlag(sptr, FLAG_FAKEHOST);
     if (!FlagHas(&setflags, FLAG_SEE_IDLETIME) && IsSeeIdletime(sptr))
       ClrFlag(sptr, FLAG_SEE_IDLETIME);
+    if (!FlagHas(&setflags, FLAG_NOTCONN) && IsNotConn(sptr))
+      ClrFlag(sptr, FLAG_NOTCONN);
     /*
      * new umode; servers and privileged opers can set it, local users cannot;
      * prevents users from /kick'ing or /mode -o'ing
@@ -1358,6 +1396,10 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc,
       ClearHiddenOper(sptr);
     if (!FlagHas(&setflags, FLAG_OVERRIDECC) && IsOverrideCC(sptr) && !HasPriv(sptr, PRIV_UMODE_OVERRIDECC))
       ClearOverrideCC(sptr);
+    if (!FlagHas(&setflags, FLAG_KEEPCONN_ENABLED) && IsKeepConnEnabled(sptr) && !HasPriv(sptr, PRIV_SET_KEEPCONN))
+      ClearKeepConnEnabled(sptr);
+    if(keepconn && !HasPriv(sptr, PRIV_SET_KEEPCONN))
+      keepconn = NULL;
     /* Opers are able to fake the webirc usermode only if FEAT_FAKE_WEBIRC is true. */
     if (!FlagHas(&setflags, FLAG_WEBIRC) && IsWebIRC(sptr) && !(feature_bool(FEAT_FAKE_WEBIRC) && IsOper(sptr)))
       ClearWebIRC(sptr);
@@ -1418,6 +1460,12 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc,
   if (!FlagHas(&setflags, FLAG_FAKEHOST) && IsFakeHost(sptr)) {
     ircd_strncpy(cli_user(sptr)->fakehost, fakehost, HOSTLEN);
   }
+  if (!FlagHas(&setflags, FLAG_KEEPCONN_ENABLED) && IsKeepConnEnabled(sptr)) {
+    sptr->keepconn = atoi(keepconn);
+  } else if(keepconn && sptr->keepconn != atoi(keepconn)) {
+    FlagClr(&setflags, FLAG_KEEPCONN_ENABLED);
+    sptr->keepconn = atoi(keepconn);
+  }
 
   if (IsRegistered(sptr)) {
     if(do_host_hiding)
@@ -1545,7 +1593,7 @@ int send_umode(struct Client *cptr, struct Client *sptr, struct Flags *old,
   int flag;
   char *m;
   int what = MODE_NULL;
-  int add_fakehost = 0, add_account = 0;
+  int add_fakehost = 0, add_account = 0, add_keepconn = 0;
 
   /*
    * Build a string in umodeBuf to represent the change in the user's
@@ -1572,6 +1620,10 @@ int send_umode(struct Client *cptr, struct Client *sptr, struct Flags *old,
       if(!serv_modes || FlagHas(old, flag)) continue;
       add_fakehost = 1;
     }
+    
+    if(flag == FLAG_KEEPCONN_ENABLED) {
+      add_keepconn = 1;
+    }
 
     switch (sendset)
     {
@@ -1637,6 +1689,11 @@ int send_umode(struct Client *cptr, struct Client *sptr, struct Flags *old,
     while((*m++ = *t++)) ; /* Empty loop */
     --m; /* back up over previous nul-termination */
   }
+  
+  if(add_keepconn) {
+    *m++ = ' ';
+    m += sprintf(m, "%u", sptr->keepconn);
+  }
 
   *m = '\0';
   if (*umodeBuf && cptr)