- char Return[MAXBUF],junk[MAXBUF];
- snprintf(Return,MAXBUF,"340 %s :",user->nick);
- for (int i = 0; i < pcnt; i++)
- {
- userrec *u = Find(parameters[i]);
- if (u)
- {
- snprintf(junk,MAXBUF,"%s%s=+%s@%s ",u->nick,strchr(u->modes,'o') ? "*" : "",u->ident,u->ip);
- strlcat(Return,junk,MAXBUF);
- }
- }
- WriteServ(user->fd,Return);
+ std::string retbuf = "340 " + user->nick + " :";
+ int nicks = 0;
+ bool checked_privs = false;
+ bool has_privs = false;
+
+ for (int i = 0; i < (int)parameters.size(); i++)
+ {
+ User *u = ServerInstance->FindNickOnly(parameters[i]);
+ if ((u) && (u->registered == REG_ALL))
+ {
+ // Anyone may query their own IP
+ if (u != user)
+ {
+ if (!checked_privs)
+ {
+ // Do not trigger the insufficient priviliges message more than once
+ checked_privs = true;
+ has_privs = user->HasPrivPermission("users/auspex");
+ if (!has_privs)
+ user->WriteNumeric(ERR_NOPRIVILEGES, ":Permission Denied - You do not have the required operator privileges");
+ }
+
+ if (!has_privs)
+ continue;
+ }
+
+ retbuf = retbuf + u->nick + (u->IsOper() ? "*" : "") + "=";
+ if (u->IsAway())
+ retbuf += "-";
+ else
+ retbuf += "+";
+ retbuf += u->ident + "@" + u->GetIPString() + " ";
+ nicks++;
+ }
+ }
+
+ if (nicks != 0)
+ user->WriteServ(retbuf);
+
+ return CMD_SUCCESS;