Author: Perry Lorier <isomer@undernet.org>
[ircu2.10.12-pk.git] / ircd / s_user.c
index 8226a8e002b3e6be96f931a1501cd41454244d2f..a5a75a1817c2110926d47aa9ee3841f40fe64cc2 100644 (file)
@@ -118,6 +118,7 @@ void free_user(struct User* user)
     assert(0 == user->channel);
 
     MyFree(user);
+    assert(userCount>0);
     --userCount;
   }
 }
@@ -452,10 +453,12 @@ int register_user(struct Client *cptr, struct Client *sptr)
     SetUser(sptr);
   }
 
-  if (IsInvisible(sptr))
-    ++UserStats.inv_clients;
-  if (IsOper(sptr))
-    ++UserStats.opers;
+  /* If they get both +x and an account during registration, hide
+   * their hostmask here.  Calling hide_hostmask() from IAuth's
+   * account assignment causes a numeric reply during registration.
+   */
+  if (HasHiddenHost(sptr))
+    hide_hostmask(sptr, FLAG_HIDDENHOST);
 
   tmpstr = umode_str(sptr);
   /* Send full IP address to IPv6-grokking servers. */
@@ -599,7 +602,8 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
     }
     if (HasHiddenHost(new_client))
       ircd_snprintf(0, cli_user(new_client)->host, HOSTLEN, "%s.%s",
-        account, feature_str(FEAT_HIDDEN_HOST));
+                    cli_user(new_client)->account,
+                    feature_str(FEAT_HIDDEN_HOST));
 
     return register_user(cptr, new_client);
   }
@@ -977,13 +981,15 @@ hide_hostmask(struct Client *cptr, unsigned int flag)
  * @param[in] sptr Client who sent the mode change message.
  * @param[in] parc Number of parameters in \a parv.
  * @param[in] parv Parameters to MODE.
+ * @param[in] allow_modes ALLOWMODES_ANY for any mode, ALLOWMODES_DEFAULT for 
+ *                        only permitting legitimate default user modes.
  * @return Zero.
  */
-int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
+int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, 
+               char *parv[], int allow_modes)
 {
   char** p;
   char*  m;
-  struct Client *acptr;
   int what;
   int i;
   struct Flags setflags;
@@ -995,27 +1001,6 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv
 
   what = MODE_ADD;
 
-  if (parc < 2)
-    return need_more_params(sptr, "MODE");
-
-  if (!(acptr = FindUser(parv[1])))
-  {
-    if (MyConnect(sptr))
-      send_reply(sptr, ERR_NOSUCHCHANNEL, parv[1]);
-    return 0;
-  }
-
-  if (IsServer(sptr) || sptr != acptr)
-  {
-    if (IsServer(cptr))
-      sendwallto_group_butone(&me, WALL_WALLOPS, 0, 
-                           "MODE for User %s from %s!%s", parv[1],
-                            cli_name(cptr), cli_name(sptr));
-    else
-      send_reply(sptr, ERR_USERSDONTMATCH);
-    return 0;
-  }
-
   if (parc < 3)
   {
     m = buf;
@@ -1201,17 +1186,23 @@ int set_user_mode(struct Client *cptr, struct Client *sptr, int parc, char *parv
   if (FlagHas(&setflags, FLAG_OPER) && !IsOper(sptr))
   {
     /* user no longer oper */
+    assert(UserStats.opers > 0);
     --UserStats.opers;
     client_set_privs(sptr, NULL); /* will clear propagate privilege */
   }
-  if (FlagHas(&setflags, FLAG_INVISIBLE) && !IsInvisible(sptr))
+  if (FlagHas(&setflags, FLAG_INVISIBLE) && !IsInvisible(sptr)) {
+    assert(UserStats.inv_clients > 0);
     --UserStats.inv_clients;
+  }
   if (!FlagHas(&setflags, FLAG_INVISIBLE) && IsInvisible(sptr))
     ++UserStats.inv_clients;
-  if (!FlagHas(&setflags, FLAG_HIDDENHOST) && do_host_hiding)
+  if (!FlagHas(&setflags, FLAG_HIDDENHOST) && do_host_hiding && allow_modes != ALLOWMODES_DEFAULT)
     hide_hostmask(sptr, FLAG_HIDDENHOST);
-  send_umode_out(cptr, sptr, &setflags, prop);
+  if (IsRegistered(sptr))
+    send_umode_out(cptr, sptr, &setflags, prop);
 
+  assert(UserStats.opers <= UserStats.clients + UserStats.unknowns);
+  assert(UserStats.inv_clients <= UserStats.clients + UserStats.unknowns);
   return 0;
 }