From 309044fc31a2f198f57256fd37bb36d9305691cf Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 3 Jul 2000 05:49:48 +0000 Subject: [PATCH] Implemented LEAVE command. Minor bug fixes. --- apps/silc/client.c | 9 +++- apps/silc/client.h | 1 + apps/silc/command.c | 97 +++++++++++++++++++++++++++++++++------ apps/silc/command_reply.c | 20 +++++--- apps/silc/idlist.h | 1 + apps/silc/testi.conf | 2 +- 6 files changed, 106 insertions(+), 24 deletions(-) diff --git a/apps/silc/client.c b/apps/silc/client.c index 80e2784d..91a26845 100644 --- a/apps/silc/client.c +++ b/apps/silc/client.c @@ -20,8 +20,11 @@ /* * $Id$ * $Log$ - * Revision 1.1 2000/06/27 11:36:56 priikone - * Initial revision + * Revision 1.2 2000/07/03 05:49:48 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. * * */ @@ -2200,6 +2203,7 @@ void silc_client_receive_new_id(SilcClient client, void silc_client_new_channel_id(SilcClient client, SilcSocketConnection sock, char *channel_name, + unsigned int mode, unsigned char *id_string) { SilcClientWindow win = (SilcClientWindow)sock->user_data; @@ -2215,6 +2219,7 @@ void silc_client_new_channel_id(SilcClient client, channel = silc_calloc(1, sizeof(*channel)); channel->channel_name = channel_name; channel->id = id; + channel->mode = mode; win->current_channel = channel; /* Put it to the ID cache */ diff --git a/apps/silc/client.h b/apps/silc/client.h index 661bd83a..0089dcd0 100644 --- a/apps/silc/client.h +++ b/apps/silc/client.h @@ -239,6 +239,7 @@ void silc_client_receive_new_id(SilcClient client, void silc_client_new_channel_id(SilcClient client, SilcSocketConnection sock, char *channel_name, + unsigned int mode, unsigned char *id_string); void silc_client_receive_channel_key(SilcClient client, SilcSocketConnection sock, diff --git a/apps/silc/command.c b/apps/silc/command.c index 67307f22..4d91bd9b 100644 --- a/apps/silc/command.c +++ b/apps/silc/command.c @@ -20,6 +20,9 @@ /* * $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. * @@ -80,6 +83,9 @@ SilcClientCommand silc_command_list[] = { 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; @@ -169,8 +175,7 @@ SILC_CLIENT_CMD_FUNC(whois) } 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; } @@ -207,8 +212,7 @@ SILC_CLIENT_CMD_FUNC(identify) } 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; } @@ -237,8 +241,7 @@ SILC_CLIENT_CMD_FUNC(nick) 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; } @@ -301,7 +304,6 @@ SILC_CLIENT_CMD_FUNC(server) port = atoi(cmd->argv[1] + 1 + len); } else { hostname = cmd->argv[1]; - /* XXX */ port = 334; } @@ -332,8 +334,7 @@ SILC_CLIENT_CMD_FUNC(quit) 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; } @@ -401,8 +402,7 @@ SILC_CLIENT_CMD_FUNC(join) /* 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; } @@ -411,8 +411,7 @@ SILC_CLIENT_CMD_FUNC(join) } 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; } @@ -480,8 +479,76 @@ SILC_CLIENT_CMD_FUNC(silcoper) { } +/* 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 "); + 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) @@ -535,8 +602,7 @@ SILC_CLIENT_CMD_FUNC(msg) } 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; } @@ -578,6 +644,7 @@ SILC_CLIENT_CMD_FUNC(msg) 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 diff --git a/apps/silc/command_reply.c b/apps/silc/command_reply.c index 3b54072a..d1a34d2f 100644 --- a/apps/silc/command_reply.c +++ b/apps/silc/command_reply.c @@ -24,8 +24,11 @@ /* * $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. * * */ @@ -414,7 +417,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) 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; @@ -437,14 +440,19 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) 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; diff --git a/apps/silc/idlist.h b/apps/silc/idlist.h index 9c769e98..b9e6f756 100644 --- a/apps/silc/idlist.h +++ b/apps/silc/idlist.h @@ -44,6 +44,7 @@ typedef SilcClientEntryObject *SilcClientEntry; typedef struct SilcChannelEntryStruct { char *channel_name; SilcChannelID *id; + unsigned int mode; int on_channel; /* Channel keys */ diff --git a/apps/silc/testi.conf b/apps/silc/testi.conf index 72dbaed5..a8a8768f 100644 --- a/apps/silc/testi.conf +++ b/apps/silc/testi.conf @@ -16,6 +16,6 @@ sha1::64:20 #lassi.kuo.fi.ssh.com:passwd::1333 [commands] -#/server lassi.kuo.fi.ssh.com:1333 +#/server lassi.kuo.fi.ssh.com #/server lassi:1334 #/server leevi:1333 -- 2.43.0