mirror of
https://github.com/osmarks/ngircd.git
synced 2025-11-15 13:07:12 +00:00
IRC_LIST(): Code cleanup
This commit is contained in:
@@ -592,9 +592,9 @@ IRC_TOPIC( CLIENT *Client, REQUEST *Req )
|
|||||||
* This implementation handles the local case as well as the forwarding of the
|
* This implementation handles the local case as well as the forwarding of the
|
||||||
* LIST command to other servers in the IRC network.
|
* LIST command to other servers in the IRC network.
|
||||||
*
|
*
|
||||||
* @param Client The client from which this command has been received
|
* @param Client The client from which this command has been received.
|
||||||
* @param Req Request structure with prefix and all parameters
|
* @param Req Request structure with prefix and all parameters.
|
||||||
* @returns CONNECTED or DISCONNECTED
|
* @return CONNECTED or DISCONNECTED.
|
||||||
*/
|
*/
|
||||||
GLOBAL bool
|
GLOBAL bool
|
||||||
IRC_LIST( CLIENT *Client, REQUEST *Req )
|
IRC_LIST( CLIENT *Client, REQUEST *Req )
|
||||||
@@ -603,78 +603,74 @@ IRC_LIST( CLIENT *Client, REQUEST *Req )
|
|||||||
CHANNEL *chan;
|
CHANNEL *chan;
|
||||||
CLIENT *from, *target;
|
CLIENT *from, *target;
|
||||||
|
|
||||||
assert( Client != NULL );
|
assert(Client != NULL);
|
||||||
assert( Req != NULL );
|
assert(Req != NULL);
|
||||||
|
|
||||||
/* Bad number of prameters? */
|
/* Bad number of prameters? */
|
||||||
if( Req->argc > 2 )
|
if (Req->argc > 2)
|
||||||
return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG,
|
return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
|
||||||
Client_ID( Client ), Req->command );
|
Client_ID(Client), Req->command);
|
||||||
|
|
||||||
if( Req->argc > 0 )
|
if (Req->argc > 0)
|
||||||
pattern = strtok( Req->argv[0], "," );
|
pattern = strtok(Req->argv[0], ",");
|
||||||
else
|
else
|
||||||
pattern = "*";
|
pattern = "*";
|
||||||
|
|
||||||
/* Get sender from prefix, if any */
|
/* Get sender from prefix, if any */
|
||||||
if( Client_Type( Client ) == CLIENT_SERVER )
|
if (Client_Type(Client) == CLIENT_SERVER)
|
||||||
from = Client_Search( Req->prefix );
|
from = Client_Search(Req->prefix);
|
||||||
else
|
else
|
||||||
from = Client;
|
from = Client;
|
||||||
|
|
||||||
if( ! from )
|
if (!from)
|
||||||
return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG,
|
return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
|
||||||
Client_ID( Client ), Req->prefix );
|
Client_ID(Client), Req->prefix);
|
||||||
|
|
||||||
if( Req->argc == 2 )
|
if (Req->argc == 2) {
|
||||||
{
|
|
||||||
/* Forward to other server? */
|
/* Forward to other server? */
|
||||||
target = Client_Search( Req->argv[1] );
|
target = Client_Search(Req->argv[1]);
|
||||||
if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER ))
|
if (! target || Client_Type(target) != CLIENT_SERVER)
|
||||||
return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG,
|
return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
|
||||||
Client_ID( Client ), Req->argv[1] );
|
Client_ID(Client),
|
||||||
|
Req->argv[1]);
|
||||||
|
|
||||||
if( target != Client_ThisServer( ))
|
if (target != Client_ThisServer()) {
|
||||||
{
|
|
||||||
/* Target is indeed an other server, forward it! */
|
/* Target is indeed an other server, forward it! */
|
||||||
return IRC_WriteStrClientPrefix( target, from,
|
return IRC_WriteStrClientPrefix(target, from,
|
||||||
"LIST %s :%s", Client_ID( from ),
|
"LIST %s :%s",
|
||||||
Req->argv[1] );
|
Client_ID(from),
|
||||||
|
Req->argv[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while( pattern )
|
while (pattern) {
|
||||||
{
|
|
||||||
/* Loop through all the channels */
|
/* Loop through all the channels */
|
||||||
chan = Channel_First( );
|
chan = Channel_First();
|
||||||
while( chan )
|
while (chan) {
|
||||||
{
|
|
||||||
/* Check search pattern */
|
/* Check search pattern */
|
||||||
if( Match( pattern, Channel_Name( chan )))
|
if (Match(pattern, Channel_Name(chan))) {
|
||||||
{
|
|
||||||
/* Gotcha! */
|
/* Gotcha! */
|
||||||
if( ! strchr( Channel_Modes( chan ), 's' ) ||
|
if (!strchr(Channel_Modes(chan), 's')
|
||||||
Channel_IsMemberOf( chan, from ))
|
|| Channel_IsMemberOf(chan, from)) {
|
||||||
{
|
if (!IRC_WriteStrClient(from,
|
||||||
if( ! IRC_WriteStrClient( from,
|
RPL_LIST_MSG, Client_ID(from),
|
||||||
RPL_LIST_MSG, Client_ID( from ),
|
Channel_Name(chan),
|
||||||
Channel_Name( chan ),
|
Channel_MemberCount(chan),
|
||||||
Channel_MemberCount( chan ),
|
|
||||||
Channel_Topic( chan )))
|
Channel_Topic( chan )))
|
||||||
return DISCONNECTED;
|
return DISCONNECTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chan = Channel_Next( chan );
|
chan = Channel_Next(chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get next name ... */
|
/* Get next name ... */
|
||||||
if( Req->argc > 0 )
|
if(Req->argc > 0)
|
||||||
pattern = strtok( NULL, "," );
|
pattern = strtok(NULL, ",");
|
||||||
else
|
else
|
||||||
pattern = NULL;
|
pattern = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IRC_WriteStrClient( from, RPL_LISTEND_MSG, Client_ID( from ));
|
return IRC_WriteStrClient(from, RPL_LISTEND_MSG, Client_ID(from));
|
||||||
} /* IRC_LIST */
|
} /* IRC_LIST */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user