- if (!conn->current_channel) {
- cmd->client->ops->say(cmd->client, conn, "You are not on that channel");
- COMMAND_ERROR;
- goto out;
- }
-
- /* Get the Channel ID of the channel */
- if (!silc_idcache_find_by_data_one(conn->channel_cache, name, &id_cache)) {
- /* XXX should resolve the channel ID; LIST command */
- cmd->client->ops->say(cmd->client, conn,
- "You are not on that channel", name);
- COMMAND_ERROR;
- goto out;
- }
-
- channel = (SilcChannelEntry)id_cache->context;
-
- if (!cmd->pending) {
- /* Send USERS command to the server */
- idp = silc_id_payload_encode(id_cache->id, SILC_ID_CHANNEL);
- buffer = silc_command_payload_encode_va(SILC_COMMAND_USERS,
- ++conn->cmd_ident, 1,
- 1, idp->data, idp->len);
- silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND,
- NULL, 0, NULL, NULL, buffer->data,
- buffer->len, TRUE);
- silc_buffer_free(buffer);
- silc_buffer_free(idp);
-
- /* Register pending callback which will recall this command callback with
- same context and reprocesses the command. When reprocessing we actually
- display the information on the screen. */
- silc_client_command_pending(conn, SILC_COMMAND_USERS, conn->cmd_ident,
- silc_client_command_destructor,
- silc_client_command_users,
- silc_client_command_dup(cmd));
- cmd->pending = TRUE;
- return;
- }
-
- if (cmd->pending) {
- /* Pending command. Now we've resolved the information from server and
- we are ready to display the information on screen. */
- int i;
- SilcChannelUser chu;
-
- cmd->client->ops->say(cmd->client, conn, "Users on %s",
- channel->channel_name);
-
- line = silc_calloc(4096, sizeof(*line));
- line_len = 4096;
- silc_list_start(channel->clients);
- while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) {
- SilcClientEntry e = chu->client;
- char *m, tmp[80], len1;
-
- memset(line, 0, sizeof(line_len));
-
- if (strlen(e->nickname) + strlen(e->server) + 100 > line_len) {
- silc_free(line);
- line_len += strlen(e->nickname) + strlen(e->server) + 100;
- line = silc_calloc(line_len, sizeof(*line));
- }
-
- memset(tmp, 0, sizeof(tmp));
- m = silc_client_chumode_char(chu->mode);
-
- strncat(line, " ", 1);
- strncat(line, e->nickname, strlen(e->nickname));
- strncat(line, e->server ? "@" : "", 1);
-
- len1 = 0;
- if (e->server)
- len1 = strlen(e->server);
- strncat(line, e->server ? e->server : "", len1 > 30 ? 30 : len1);
-
- len1 = strlen(line);
- if (len1 >= 30) {
- memset(&line[29], 0, len1 - 29);
- } else {
- for (i = 0; i < 30 - len1 - 1; i++)
- strcat(line, " ");
- }
-
- strncat(line, " H", 3);
- strcat(tmp, m ? m : "");
- strncat(line, tmp, strlen(tmp));
-
- if (strlen(tmp) < 5)
- for (i = 0; i < 5 - strlen(tmp); i++)
- strcat(line, " ");
-
- strcat(line, e->username ? e->username : "");
-
- cmd->client->ops->say(cmd->client, conn, "%s", line);
-
- if (m)
- silc_free(m);
- }
- }
-
- if (line)
- silc_free(line);