/*
* $Id$
* $Log$
+ * Revision 1.3 2000/07/03 05:49:49 priikone
+ * Implemented LEAVE command. Minor bug fixes.
+ *
* Revision 1.2 2000/06/27 19:38:40 priikone
* Added missing goto flag.
*
{ NULL, 0, NULL, 0},
};
+#define SILC_NOT_CONNECTED(x) \
+ silc_say((x), "You are not connected to a server, use /SERVER to connect");
+
/* List of pending commands. */
SilcClientCommandPending *silc_command_pending = NULL;
}
if (!cmd->client->current_win->sock) {
- silc_say(cmd->client,
- "You are not connected to a server, use /SERVER to connect");
+ SILC_NOT_CONNECTED(cmd->client);
goto out;
}
}
if (!cmd->client->current_win->sock) {
- silc_say(cmd->client,
- "You are not connected to a server, use /SERVER to connect");
+ SILC_NOT_CONNECTED(cmd->client);
goto out;
}
SilcBuffer buffer;
if (!cmd->sock) {
- silc_say(cmd->client,
- "You are not connected to a server, use /SERVER to connect");
+ SILC_NOT_CONNECTED(cmd->client);
goto out;
}
port = atoi(cmd->argv[1] + 1 + len);
} else {
hostname = cmd->argv[1];
- /* XXX */
port = 334;
}
SilcBuffer buffer;
if (!cmd->client->current_win->sock) {
- silc_say(cmd->client,
- "You are not connected to a server, use /SERVER to connect");
+ SILC_NOT_CONNECTED(cmd->client);
goto out;
}
/* Show channels currently joined to */
if (!cmd->client->current_win->sock) {
silc_say(cmd->client, "No current channel for this window");
- silc_say(cmd->client,
- "You are not connected to a server, use /SERVER to connect");
+ SILC_NOT_CONNECTED(cmd->client);
goto out;
}
}
if (!cmd->client->current_win->sock) {
- silc_say(cmd->client,
- "You are not connected to a server, use /SERVER to connect");
+ SILC_NOT_CONNECTED(cmd->client);
goto out;
}
{
}
+/* LEAVE command. Leaves a channel. Client removes itself from a channel. */
+
SILC_CLIENT_CMD_FUNC(leave)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientWindow win = NULL;
+ SilcIDCache *id_cache = NULL;
+ SilcBuffer buffer;
+ unsigned char *id_string;
+ char *name;
+
+#define CIDC(x) win->channel_id_cache[(x) - 32]
+#define CIDCC(x) win->channel_id_cache_count[(x) - 32]
+
+ if (cmd->argc != 2) {
+ silc_say(cmd->client, "Usage: /LEAVE <channel>");
+ goto out;
+ }
+
+ if (!cmd->client->current_win->sock) {
+ SILC_NOT_CONNECTED(cmd->client);
+ goto out;
+ }
+
+ win = (SilcClientWindow)cmd->sock->user_data;
+
+ if (!win->current_channel) {
+ silc_say(cmd->client, "You are not on that channel", name);
+ goto out;
+ }
+
+ if (cmd->argv[1][0] == '*')
+ name = win->current_channel->channel_name;
+ else
+ name = cmd->argv[1];
+
+ /* Get the Channel ID of the channel */
+ silc_idcache_find_by_data(CIDC(name[0]), CIDCC(name[0]), name, &id_cache);
+ if (!id_cache) {
+ silc_say(cmd->client, "You are not on that channel", name);
+ goto out;
+ }
+
+ /* Send LEAVE command to the server */
+ id_string = silc_id_id2str(id_cache->id, SILC_ID_CHANNEL);
+ buffer = silc_command_encode_payload_va(SILC_COMMAND_LEAVE, 1,
+ id_string, SILC_ID_CHANNEL_LEN);
+ silc_client_packet_send(cmd->client, cmd->client->current_win->sock,
+ SILC_PACKET_COMMAND, NULL, 0, NULL, NULL,
+ buffer->data, buffer->len, TRUE);
+ silc_buffer_free(buffer);
+
+ /* We won't talk anymore on this channel */
+ silc_say(cmd->client, "You have left channel %s", name);
+ cmd->client->screen->bottom_line->channel = NULL;
+ silc_screen_print_bottom_line(cmd->client->screen, 0);
+
+ silc_idcache_del_by_id(CIDC(name[0]), CIDCC(name[0]),
+ SILC_ID_CHANNEL, win->current_channel->id);
+ silc_free(win->current_channel->channel_name);
+ silc_free(win->current_channel->id);
+ silc_free(win->current_channel->key);
+ silc_cipher_free(win->current_channel->channel_key);
+ silc_free(win->current_channel);
+ win->current_channel = NULL;
+
+ out:
+ silc_client_command_free(cmd);
+#undef CIDC
+#undef CIDCC
}
SILC_CLIENT_CMD_FUNC(names)
}
if (!cmd->client->current_win->sock) {
- silc_say(cmd->client,
- "You are not connected to a server, use /SERVER to connect");
+ SILC_NOT_CONNECTED(cmd->client);
goto out;
}
silc_client_packet_send_private_message(client, cmd->sock, id_cache->context,
cmd->argv[2], cmd->argv_lens[2],
TRUE);
+
out:
silc_client_command_free(cmd);
#undef CIDC
/*
* $Id$
* $Log$
- * Revision 1.1 2000/06/27 11:36:56 priikone
- * Initial revision
+ * Revision 1.2 2000/07/03 05:49:49 priikone
+ * Implemented LEAVE command. Minor bug fixes.
+ *
+ * Revision 1.1.1.1 2000/06/27 11:36:56 priikone
+ * Importet from internal CVS/Added Log headers.
*
*
*/
SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
SilcClient client = cmd->client;
SilcCommandStatus status;
- unsigned int argc;
+ unsigned int argc, mode;
unsigned char *id_string;
char *topic, *tmp, *channel_name;
tmp = silc_command_get_arg_type(cmd->payload, 2, NULL);
channel_name = strdup(tmp);
- /* Get channel ID */
+ /* Get Channel ID */
id_string = silc_command_get_arg_type(cmd->payload, 3, NULL);
+ /* Get channel mode */
+ tmp = silc_command_get_arg_type(cmd->payload, 4, NULL);
+ SILC_GET32_MSB(mode, tmp);
+
/* Get topic */
- topic = silc_command_get_arg_type(cmd->payload, 4, NULL);
+ topic = silc_command_get_arg_type(cmd->payload, 5, NULL);
/* Save received Channel ID */
- silc_client_new_channel_id(cmd->client, cmd->sock, channel_name, id_string);
+ silc_client_new_channel_id(cmd->client, cmd->sock, channel_name,
+ mode, id_string);
/* Print channel name on screen */
client->screen->bottom_line->channel = channel_name;