reimplemented fakeident support
[ircu2.10.12-pk.git] / ircd / s_user.c
index d2342620e8f812fedd5b96dfbd12ef9d929e85de..53cebf2602df7e646dd136b4238b39635972a014 100644 (file)
@@ -485,7 +485,7 @@ int register_user(struct Client *cptr, struct Client *sptr)
    * account assignment causes a numeric reply during registration.
    */
   if (HasHiddenHost(sptr))
-    hide_hostmask(sptr, FLAG_HIDDENHOST);
+    hide_hostmask(sptr, HIDE_HOSTMASK_FLAG_HIDDENHOST);
   if (IsInvisible(sptr))
     ++UserStats.inv_clients;
   if (IsOper(sptr))
@@ -667,7 +667,7 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
     if (MyUser(sptr)) {
       const char* channel_name;
       struct Membership *member;
-      if (!force && !IsXtraOp(sptr) && (channel_name = find_no_nickchange_channel(sptr))) {
+      if (!force && !IsXtraOp(sptr) && (channel_name = find_no_nickchange_channel(sptr, nick))) {
         return send_reply(cptr, ERR_BANNICKCHANGE, channel_name);
       }
       /*
@@ -734,24 +734,6 @@ int set_nick_name(struct Client* cptr, struct Client* sptr,
   return 0;
 }
 
-/* Refreshs the users host to the current fakehost. If no fakehost
- * is set, the account-host is created. If no Account is set,
- * nothing is done.
- * Returns 1 if the host changed and 0 if not.
- */
-int apply_fakehost(struct Client *cptr) {
-    char buf[HOSTLEN];
-    if(IsFakeHost(cptr)) {
-        ircd_strncpy(buf, cli_user(cptr)->fakehost, HOSTLEN);
-    }
-    else if (IsAccount(cptr)) {
-        ircd_snprintf(0, buf, HOSTLEN, "%s.%s", cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
-    }
-    if(strncmp(buf, cli_user(cptr)->host, HOSTLEN) == 0) return 0;
-    ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN);
-    return 1;
-}
-
 /** Calculate the hash value for a target.
  * @param[in] target Pointer to target, cast to unsigned int.
  * @return Hash value constructed from the pointer.
@@ -990,40 +972,54 @@ void send_user_info(struct Client* sptr, char* names, int rpl, InfoFormatter fmt
  * @param[in] flag Some flag that affects host-hiding (FLAG_HIDDENHOST, FLAG_ACCOUNT, FLAG_FAKEHOST).
  * @return Zero.
  */
 int
 hide_hostmask(struct Client *cptr, unsigned int flag)
 {
   struct Membership *chan;
   char buf[HOSTLEN];
 
-  switch (flag) {
-  case FLAG_HIDDENHOST:
+  if (flag & HIDE_HOSTMASK_FLAG_HIDDENHOST) {
     /* Local users cannot set +x unless FEAT_HOST_HIDING is true. */
     if (MyConnect(cptr) && !feature_bool(FEAT_HOST_HIDING))
       return 0;
-    break;
-  case FLAG_ACCOUNT:
-  case FLAG_FAKEHOST:
+  }
+  if (flag & (HIDE_HOSTMASK_FLAG_ACCOUNT | HIDE_HOSTMASK_FLAG_FAKEHOST | HIDE_HOSTMASK_FLAG_FAKEIDENT)) {
     /* Invalidate all bans against the user so we check them again */
     for (chan = (cli_user(cptr))->channel; chan;
          chan = chan->next_channel)
       ClearBanValid(chan);
-    break;
-  default:
-    /* default: no special handling */
-    break;
   }
 
   /* Set flags and stop if no fakehost has to be applied. */
-  SetFlag(cptr, flag);
+  if(flag & HIDE_HOSTMASK_FLAG_HIDDENHOST)
+    SetFlag(cptr, FLAG_HIDDENHOST);
+  if(flag & HIDE_HOSTMASK_FLAG_ACCOUNT)
+    SetFlag(cptr, FLAG_ACCOUNT);
+  if(flag & HIDE_HOSTMASK_FLAG_FAKEHOST)
+    SetFlag(cptr, FLAG_FAKEHOST);
+  if(flag & HIDE_HOSTMASK_FLAG_FAKEIDENT)
+    SetFlag(cptr, FLAG_FAKEIDENT);
+  
   if(!HasHiddenHost(cptr))
     return 0;
 
   /* Generate new fakehost. */
-  if(IsFakeHost(cptr)) ircd_strncpy(buf, cli_user(cptr)->fakehost, HOSTLEN);
-  else if (IsAccount(cptr)) ircd_snprintf(0, buf, HOSTLEN, "%s.%s", cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
-  else return 0;
-  if(strncmp(buf, cli_user(cptr)->host, HOSTLEN) == 0) return 0;
+  unsigned int reregister = 0;
+  if(IsFakeHost(cptr) || IsAccount(cptr)) {
+    if(IsFakeHost(cptr))
+      ircd_strncpy(buf, cli_user(cptr)->fakehost, HOSTLEN);
+    else
+      ircd_snprintf(0, buf, HOSTLEN, "%s.%s", cli_user(cptr)->account, feature_str(FEAT_HIDDEN_HOST));
+    if(strncmp(buf, cli_user(cptr)->host, HOSTLEN))
+      reregister |= HIDE_HOSTMASK_FLAG_FAKEHOST;
+  }
+  if(IsFakeIdent(cptr)) {
+    if(strncmp(cli_user(cptr)->fakeuser, cli_user(cptr)->username, USERLEN))
+      reregister |= HIDE_HOSTMASK_FLAG_FAKEIDENT;
+  }
+  
+  if (!reregister) return 0;
 
   /* Remove all "valid" marks on the bans. This forces them to be
    * rechecked if the ban is accessed again.
@@ -1034,11 +1030,19 @@ hide_hostmask(struct Client *cptr, unsigned int flag)
 
   /* Quit user and set the previously generated fakehost. */
   sendcmdto_common_channels_butone(cptr, CMD_QUIT, cptr, ":Registered");
-  ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN);
+  if(reregister & HIDE_HOSTMASK_FLAG_FAKEHOST)
+    ircd_strncpy(cli_user(cptr)->host, buf, HOSTLEN);
+  if(reregister & HIDE_HOSTMASK_FLAG_FAKEIDENT)
+    ircd_strncpy(cli_user(cptr)->username, cli_user(cptr)->fakeuser, USERLEN);
+  
 
   /* ok, the client is now fully hidden, so let them know -- hikari */
-  if (MyConnect(cptr))
-   send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host);
+  if(MyConnect(cptr)) {
+    if (IsFakeIdent(cptr))
+      send_reply(cptr, RPL_HOSTUSERHIDDEN, cli_user(cptr)->username, cli_user(cptr)->host);
+    else
+      send_reply(cptr, RPL_HOSTHIDDEN, cli_user(cptr)->host);
+  }
 
   /*
    * Go through all channels the client was on, rejoin him