IRC_USERHOST(): Code cleanup & some documentation

This commit is contained in:
Alexander Barton 2010-08-17 23:55:40 +02:00
parent 0263fa4c66
commit a51670005f
1 changed files with 32 additions and 23 deletions

View File

@ -627,42 +627,51 @@ IRC_TIME( CLIENT *Client, REQUEST *Req )
} /* IRC_TIME */ } /* IRC_TIME */
/**
* Handler for the IRC command "USERHOST".
* See RFC 2812 section 4.8.
*/
GLOBAL bool GLOBAL bool
IRC_USERHOST( CLIENT *Client, REQUEST *Req ) IRC_USERHOST(CLIENT *Client, REQUEST *Req)
{ {
char rpl[COMMAND_LEN]; char rpl[COMMAND_LEN];
CLIENT *c; CLIENT *c;
int max, i; int max, i;
assert( Client != NULL ); assert(Client != NULL);
assert( Req != NULL ); assert(Req != NULL);
if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); if ((Req->argc < 1))
return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
Client_ID(Client), Req->command);
if( Req->argc > 5 ) max = 5; if (Req->argc > 5)
else max = Req->argc; max = 5;
else
max = Req->argc;
strlcpy( rpl, RPL_USERHOST_MSG, sizeof rpl ); strlcpy(rpl, RPL_USERHOST_MSG, sizeof rpl);
for( i = 0; i < max; i++ ) for (i = 0; i < max; i++) {
{ c = Client_Search(Req->argv[i]);
c = Client_Search( Req->argv[i] ); if (c && (Client_Type(c) == CLIENT_USER)) {
if( c && ( Client_Type( c ) == CLIENT_USER ))
{
/* This Nick is "online" */ /* This Nick is "online" */
strlcat( rpl, Client_ID( c ), sizeof( rpl )); strlcat(rpl, Client_ID(c), sizeof(rpl));
if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl )); if (Client_HasMode(c, 'o'))
strlcat( rpl, "=", sizeof( rpl )); strlcat(rpl, "*", sizeof(rpl));
if( Client_HasMode( c, 'a' )) strlcat( rpl, "-", sizeof( rpl )); strlcat(rpl, "=", sizeof(rpl));
else strlcat( rpl, "+", sizeof( rpl )); if (Client_HasMode(c, 'a'))
strlcat( rpl, Client_User( c ), sizeof( rpl )); strlcat(rpl, "-", sizeof(rpl));
strlcat( rpl, "@", sizeof( rpl )); else
strlcat( rpl, Client_Hostname( c ), sizeof( rpl )); strlcat(rpl, "+", sizeof(rpl));
strlcat( rpl, " ", sizeof( rpl )); strlcat(rpl, Client_User(c), sizeof(rpl));
strlcat(rpl, "@", sizeof(rpl));
strlcat(rpl, Client_Hostname(c), sizeof(rpl));
strlcat(rpl, " ", sizeof(rpl));
} }
} }
ngt_TrimLastChr( rpl, ' '); ngt_TrimLastChr(rpl, ' ');
return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) ); return IRC_WriteStrClient(Client, rpl, Client_ID(Client));
} /* IRC_USERHOST */ } /* IRC_USERHOST */