unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

userhost.c (3137B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/userhost.c
      3  *   (C) 2004 The UnrealIRCd Team
      4  *
      5  *   See file AUTHORS in IRC package for additional names of
      6  *   the programmers.
      7  *
      8  *   This program is free software; you can redistribute it and/or modify
      9  *   it under the terms of the GNU General Public License as published by
     10  *   the Free Software Foundation; either version 1, or (at your option)
     11  *   any later version.
     12  *
     13  *   This program is distributed in the hope that it will be useful,
     14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  *   GNU General Public License for more details.
     17  *
     18  *   You should have received a copy of the GNU General Public License
     19  *   along with this program; if not, write to the Free Software
     20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     21  */
     22 
     23 #include "unrealircd.h"
     24 
     25 CMD_FUNC(cmd_userhost);
     26 
     27 #define MSG_USERHOST 	"USERHOST"	
     28 
     29 ModuleHeader MOD_HEADER
     30   = {
     31 	"userhost",
     32 	"5.0",
     33 	"command /userhost", 
     34 	"UnrealIRCd Team",
     35 	"unrealircd-6",
     36     };
     37 
     38 MOD_INIT()
     39 {
     40 	CommandAdd(modinfo->handle, MSG_USERHOST, cmd_userhost, 1, CMD_USER);
     41 	MARK_AS_OFFICIAL_MODULE(modinfo);
     42 	return MOD_SUCCESS;
     43 }
     44 
     45 MOD_LOAD()
     46 {
     47 	return MOD_SUCCESS;
     48 }
     49 
     50 MOD_UNLOAD()
     51 {
     52 	return MOD_SUCCESS;
     53 }
     54 
     55 /*
     56  * cmd_userhost added by Darren Reed 13/8/91 to aid clients and reduce
     57  * the need for complicated requests like WHOIS. It returns user/host
     58  * information only (no spurious AWAY labels or channels).
     59  * Re-written by Dianora 1999
     60  */
     61 /* Keep this at 5!!!! */
     62 #define MAXUSERHOSTREPLIES 5
     63 CMD_FUNC(cmd_userhost)
     64 {
     65 	char *p;		/* scratch end pointer */
     66 	char *cn;		/* current name */
     67 	Client *acptr;
     68 	char request[BUFSIZE];
     69 	char response[MAXUSERHOSTREPLIES][NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30];
     70 	int i;			/* loop counter */
     71 	int w;
     72 
     73 	if (parc < 2)
     74 	{
     75 		sendnumeric(client, ERR_NEEDMOREPARAMS, "USERHOST");
     76 		return;
     77 	}
     78 
     79 	/* The idea is to build up the response string out of pieces
     80 	 * none of this strlen() nonsense.
     81 	 * MAXUSERHOSTREPLIES * (NICKLEN*2+CHANNELLEN+USERLEN+HOSTLEN+30) is still << sizeof(buf)
     82 	 * and our ircsnprintf() truncates it to fit anyway. There is
     83 	 * no danger of an overflow here. -Dianora
     84 	 */
     85 	response[0][0] = response[1][0] = response[2][0] = response[3][0] = response[4][0] = '\0';
     86 
     87 	strlcpy(request, parv[1], sizeof(request));
     88 	cn = request;
     89 
     90 	for (w = 0, i = 0; (i < MAXUSERHOSTREPLIES) && cn; i++)
     91 	{
     92 		if ((p = strchr(cn, ' ')))
     93 			*p = '\0';
     94 
     95 		if ((acptr = find_user(cn, NULL)))
     96 		{
     97 			ircsnprintf(response[w], NICKLEN * 2 + CHANNELLEN + USERLEN + HOSTLEN + 30,
     98                             "%s%s=%c%s@%s",
     99 			    acptr->name,
    100 			    (IsOper(acptr) && (!IsHideOper(acptr) || client == acptr || IsOper(client)))
    101 				? "*" : "",
    102 			    (acptr->user->away) ? '-' : '+',
    103 			    acptr->user->username,
    104 			    ((acptr != client) && !IsOper(client)
    105 			    && IsHidden(acptr) ? acptr->user->virthost :
    106 			    acptr->user->realhost));
    107 			w++;
    108 		}
    109 		if (p)
    110 			p++;
    111 		cn = p;
    112 	}
    113 
    114 	sendnumeric(client, RPL_USERHOST, response[0], response[1], response[2], response[3], response[4]);
    115 }