Added support for removing client from invite list when kicked.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 25 Nov 2002 22:09:31 +0000 (22:09 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 25 Nov 2002 22:09:31 +0000 (22:09 +0000)
CHANGES
TODO
apps/silcd/command.c
apps/silcd/packet_receive.c

diff --git a/CHANGES b/CHANGES
index ebdab9faea9a2fa0c33e66693b03c6858ba4bdb1..ae92f9e706c6fbcb7e568292f19cf28c6eb3cc1c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,10 @@ Mon Nov 25 18:21:43 EET 2002  Pekka Riikonen <priikone@silcnet.org>
        * Added support to client sending new BAN command.  Affected
          file is lib/silcclient/command.c.
 
+       * Added support for removing client from invite list when kicked
+         from channel, as SILC 1.2 dictates.  Affected files are
+         silcd/packet_receive.c and silcd/command.c.
+
 Sun Nov 24 18:26:42 EET 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * If iv argument to silc_cipher_[encrypt/decrypt] is NULL, use
diff --git a/TODO b/TODO
index e597065a0c864ce460d4f0cd8221dd4addf81bf9..58ba631d06109eb4751f8578af6863374bed6e2b 100644 (file)
--- a/TODO
+++ b/TODO
@@ -18,7 +18,7 @@ TODO for Irssi SILC Client 1.0
 TODO for SILC Server 1.0
 ========================
 
- o Remove client from invite lists in KICKED and KILLED.
+ o Remove client from invite lists KILLED.
 
  o 1.2 backup router support
 
index 10c546573d8cd19e03e08425f6b60d1f4416a498..c053236d89e04fc73886ac5d8f8d727ce92a4305 100644 (file)
@@ -1212,7 +1212,7 @@ SILC_SERVER_CMD_FUNC(invite)
 
   /* Encode invite list */
   list = NULL;
-  if (channel->invite_list) {
+  if (channel->invite_list && silc_hash_table_count(channel->invite_list)) {
     list = silc_buffer_alloc_size(2);
     silc_buffer_format(list,
                       SILC_STR_UI_SHORT(silc_hash_table_count(
@@ -1899,6 +1899,7 @@ static void silc_server_command_join_channel(SilcServer server,
     /* Check invite list if channel is invite-only channel */
     if (channel->mode & SILC_CHANNEL_MODE_INVITE) {
       if (!channel->invite_list ||
+         !silc_hash_table_count(channel->invite_list) ||
          (!silc_server_inviteban_match(server, channel->invite_list,
                                        3, client->id) &&
           !silc_server_inviteban_match(server, channel->invite_list,
@@ -1916,14 +1917,14 @@ static void silc_server_command_join_channel(SilcServer server,
     /* Check ban list if it exists. If the client's nickname, server,
        username and/or hostname is in the ban list the access to the
        channel is denied. */
-    if (channel->ban_list) {
-      if (silc_server_inviteban_match(server, channel->invite_list,
+    if (channel->ban_list && silc_hash_table_count(channel->ban_list)) {
+      if (silc_server_inviteban_match(server, channel->ban_list,
                                      3, client->id) ||
-         silc_server_inviteban_match(server, channel->invite_list,
+         silc_server_inviteban_match(server, channel->ban_list,
                                      2, client->data.public_key) ||
-         !silc_server_inviteban_match(server, channel->invite_list,
+         !silc_server_inviteban_match(server, channel->ban_list,
                                       1, check) ||
-         !silc_server_inviteban_match(server, channel->invite_list,
+         !silc_server_inviteban_match(server, channel->ban_list,
                                       1, check2)) {
        silc_server_command_send_status_reply(
                                      cmd, SILC_COMMAND_JOIN,
@@ -2024,7 +2025,7 @@ static void silc_server_command_join_channel(SilcServer server,
 
   /* Encode invite list */
   invite_list = NULL;
-  if (channel->invite_list) {
+  if (channel->invite_list && silc_hash_table_count(channel->invite_list)) {
     SilcHashTableList htl;
 
     invite_list = silc_buffer_alloc_size(2);
@@ -2050,7 +2051,7 @@ static void silc_server_command_join_channel(SilcServer server,
 
   /* Encode ban list */
   ban_list = NULL;
-  if (channel->ban_list) {
+  if (channel->ban_list && silc_hash_table_count(channel->ban_list)) {
     SilcHashTableList htl;
 
     ban_list = silc_buffer_alloc_size(2);
@@ -3543,6 +3544,17 @@ SILC_SERVER_CMD_FUNC(kick)
                                 SILC_BROADCAST(server), channel,
                                 target_client->id, client->id, comment);
 
+  /* Remove the client from channel's invite list */
+  if (channel->invite_list && silc_hash_table_count(channel->invite_list)) {
+    SilcBuffer ab =
+      silc_argument_payload_encode_one(NULL, target_idp, target_idp_len, 3);
+    SilcArgumentPayload args =
+      silc_argument_payload_parse(ab->data, ab->len, 1);
+    silc_server_inviteban_process(server, channel->invite_list, 1, args);
+    silc_buffer_free(ab);
+    silc_argument_payload_free(args);
+  }
+
   /* Remove the client from the channel. If the channel does not exist
      after removing the client then the client kicked itself off the channel
      and we don't have to send anything after that. */
@@ -4148,7 +4160,7 @@ SILC_SERVER_CMD_FUNC(ban)
     }
 
     /* Get the type of action */
-    tmp = silc_argument_get_arg_type(cmd->args, 3, &len);
+    tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
     if (tmp && len == 1) {
       if (tmp[0] == 0x00) {
        /* Allocate hash table for ban list if it doesn't exist yet */
@@ -4175,7 +4187,7 @@ SILC_SERVER_CMD_FUNC(ban)
 
   /* Encode ban list */
   list = NULL;
-  if (channel->ban_list) {
+  if (channel->ban_list && silc_hash_table_count(channel->ban_list)) {
     list = silc_buffer_alloc_size(2);
     silc_buffer_format(list,
                       SILC_STR_UI_SHORT(silc_hash_table_count(
index fbb5a9d0badb8c9c2740340781030b1223050572..7f3a8ba92f9be64938ef46235d01edbbdd4e4fb0 100644 (file)
@@ -1383,41 +1383,53 @@ void silc_server_notify(SilcServer server,
     if (chl->mode & SILC_CHANNEL_UMODE_CHANFO)
       goto out;
     
-    /* From protocol version 1.1 we get the kicker's ID as well. */
+    /* Get the kicker's Client ID */
     tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
-    if (tmp) {
-      client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
-      if (!client_id)
-       goto out;
+    if (!tmp)
+      goto out;
+    client_id = silc_id_payload_parse_id(tmp, tmp_len, NULL);
+    if (!client_id)
+      goto out;
 
-      /* If the the client is not in local list we check global list */
-      client2 = silc_idlist_find_client_by_id(server->global_list, 
+    /* If the the client is not in local list we check global list */
+    client2 = silc_idlist_find_client_by_id(server->global_list, 
+                                           client_id, TRUE, NULL);
+    if (!client2) {
+      client2 = silc_idlist_find_client_by_id(server->local_list, 
                                              client_id, TRUE, NULL);
       if (!client2) {
-       client2 = silc_idlist_find_client_by_id(server->local_list, 
-                                               client_id, TRUE, NULL);
-       if (!client2) {
-         silc_free(client_id);
-         goto out;
-       }
-      }
-      silc_free(client_id);
-
-      /* Kicker must be operator on channel */
-      if (!silc_server_client_on_channel(client2, channel, &chl))
-       goto out;
-      if (!(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
-         !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
-       SILC_LOG_DEBUG(("Kicking is not allowed"));
+       silc_free(client_id);
        goto out;
       }
     }
+    silc_free(client_id);
+
+    /* Kicker must be operator on channel */
+    if (!silc_server_client_on_channel(client2, channel, &chl))
+      goto out;
+    if (!(chl->mode & SILC_CHANNEL_UMODE_CHANOP) &&
+       !(chl->mode & SILC_CHANNEL_UMODE_CHANFO)) {
+      SILC_LOG_DEBUG(("Kicking is not allowed"));
+      goto out;
+    }
 
     /* Send to channel */
     silc_server_packet_send_to_channel(server, sock, channel, packet->type, 
                                       FALSE, packet->buffer->data, 
                                       packet->buffer->len, FALSE);
 
+    /* Remove the client from channel's invite list */
+    if (channel->invite_list && silc_hash_table_count(channel->invite_list)) {
+      SilcBuffer ab;
+      SilcArgumentPayload iargs;
+      tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
+      ab = silc_argument_payload_encode_one(NULL, tmp, tmp_len, 3);
+      iargs = silc_argument_payload_parse(ab->data, ab->len, 1);
+      silc_server_inviteban_process(server, channel->invite_list, 1, iargs);
+      silc_buffer_free(ab);
+      silc_argument_payload_free(iargs);
+    }
+
     /* Remove the client from channel */
     silc_server_remove_from_one_channel(server, sock, channel, client, FALSE);
 
@@ -1468,34 +1480,34 @@ void silc_server_notify(SilcServer server,
       if (comment_len > 128)
        comment_len = 127;
 
-      /* From protocol version 1.1 we get the killer's ID as well. */
+      /* Get the killer's Client ID */
       tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
-      if (tmp) {
-       client_id = silc_id_payload_parse_id(tmp, tmp_len, &id_type);
-       if (!client_id)
-         goto out;
+      if (!tmp)
+       goto out;
+      client_id = silc_id_payload_parse_id(tmp, tmp_len, &id_type);
+      if (!client_id)
+       goto out;
 
-       if (id_type == SILC_ID_CLIENT) {
-         /* If the the client is not in local list we check global list */
-         client2 = silc_idlist_find_client_by_id(server->global_list, 
+      if (id_type == SILC_ID_CLIENT) {
+       /* If the the client is not in local list we check global list */
+       client2 = silc_idlist_find_client_by_id(server->global_list, 
+                                               client_id, TRUE, NULL);
+       if (!client2) {
+         client2 = silc_idlist_find_client_by_id(server->local_list, 
                                                  client_id, TRUE, NULL);
          if (!client2) {
-           client2 = silc_idlist_find_client_by_id(server->local_list, 
-                                                   client_id, TRUE, NULL);
-           if (!client2) {
-             silc_free(client_id);
-             goto out;
-           }
-         }
-         silc_free(client_id);
-
-         /* Killer must be router operator */
-         if (server->server_type != SILC_SERVER &&
-             !(client2->mode & SILC_UMODE_ROUTER_OPERATOR)) {
-           SILC_LOG_DEBUG(("Killing is not allowed"));
+           silc_free(client_id);
            goto out;
          }
        }
+       silc_free(client_id);
+
+       /* Killer must be router operator */
+       if (server->server_type != SILC_SERVER &&
+           !(client2->mode & SILC_UMODE_ROUTER_OPERATOR)) {
+         SILC_LOG_DEBUG(("Killing is not allowed"));
+         goto out;
+       }
       }
 
       /* Send the notify to local clients on the channels except to the