- if( target != Client_ThisServer( ))
- {
- /* Ok, anderer Server ist das Ziel: forwarden */
- return IRC_WriteStrClientPrefix( target, from, "LIST %s :%s", from, Req->argv[1] );
+/**
+ * Handler for the IRC "LIST" command.
+ *
+ * See RFC 2812, 3.2.6 "List message".
+ *
+ * This implementation handles the local case as well as the forwarding of the
+ * LIST command to other servers in the IRC network.
+ *
+ * @param Client The client from which this command has been received.
+ * @param Req Request structure with prefix and all parameters.
+ * @return CONNECTED or DISCONNECTED.
+ */
+GLOBAL bool
+IRC_LIST( CLIENT *Client, REQUEST *Req )
+{
+ char *pattern;
+ CHANNEL *chan;
+ CLIENT *from, *target;
+ int count = 0;
+
+ assert(Client != NULL);
+ assert(Req != NULL);
+
+ /* Bad number of prameters? */
+ if (Req->argc > 2)
+ return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
+ Client_ID(Client), Req->command);
+
+ if (Req->argc > 0)
+ pattern = strtok(Req->argv[0], ",");
+ else
+ pattern = "*";
+
+ /* Get sender from prefix, if any */
+ if (Client_Type(Client) == CLIENT_SERVER)
+ from = Client_Search(Req->prefix);
+ else
+ from = Client;
+
+ if (!from)
+ return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
+ Client_ID(Client), Req->prefix);
+
+ if (Req->argc == 2) {
+ /* Forward to other server? */
+ target = Client_Search(Req->argv[1]);
+ if (! target || Client_Type(target) != CLIENT_SERVER)
+ return IRC_WriteStrClient(from, ERR_NOSUCHSERVER_MSG,
+ Client_ID(Client),
+ Req->argv[1]);
+
+ if (target != Client_ThisServer()) {
+ /* Target is indeed an other server, forward it! */
+ return IRC_WriteStrClientPrefix(target, from,
+ "LIST %s :%s",
+ Req->argv[0],
+ Req->argv[1]);