updates.
[silc.git] / apps / silcd / packet_send.c
index 9e1582b9ca067052480d91c80859885a3ae5afab..814758b82a4806190b4805b4d2bcf4f8c8657f98 100644 (file)
@@ -591,6 +591,7 @@ void silc_server_packet_relay_to_channel(SilcServer server,
                                         SilcChannelEntry channel,
                                         void *sender, 
                                         SilcIdType sender_type,
+                                        void *sender_entry,
                                         unsigned char *data,
                                         uint32 data_len,
                                         int force_send)
@@ -660,7 +661,8 @@ void silc_server_packet_relay_to_channel(SilcServer server,
     if (client) {
 
       /* If sender is one on the channel do not send it the packet. */
-      if (!found && !SILC_ID_CLIENT_COMPARE(client->id, sender)) {
+      if (!found && sender_type == SILC_ID_CLIENT &&
+         !SILC_ID_CLIENT_COMPARE(client->id, sender)) {
        found = TRUE;
        continue;
       }
@@ -688,6 +690,13 @@ void silc_server_packet_relay_to_channel(SilcServer server,
        sock = (SilcSocketConnection)client->router->connection;
        idata = (SilcIDListData)client->router;
 
+       /* Do not send to the sender. Check first whether the true
+          sender's router is same as this client's router. Also check
+          if the sender socket is the same as this client's router
+          socket. */
+       if (sender_entry && 
+           ((SilcClientEntry)sender_entry)->router == client->router)
+         continue;
        if (sender_sock && sock == sender_sock)
          continue;
 
@@ -716,6 +725,9 @@ void silc_server_packet_relay_to_channel(SilcServer server,
            memcpy(tmp, data, data_len);
 
            /* Decrypt the channel message (we don't check the MAC) */
+           /* XXX this could be optimized and removed all together by
+              taking a copy of the original data before encrypting it
+              and thus would not required decrypting. */
            if (channel->channel_key &&
                !silc_channel_message_payload_decrypt(tmp, data_len, 
                                                      channel->channel_key,
@@ -1065,15 +1077,15 @@ void silc_server_send_notify_cumode(SilcServer server,
                                    int broadcast,
                                    SilcChannelEntry channel,
                                    uint32 mode_mask,
-                                   SilcClientID *client_id,
-                                   uint32 client_id_len,
+                                   void *id, SilcIdType id_type,
+                                   uint32 id_len,
                                    SilcClientID *target,
                                    uint32 target_len)
 {
   SilcBuffer idp1, idp2;
   unsigned char mode[4];
 
-  idp1 = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
+  idp1 = silc_id_payload_encode((void *)id, id_type);
   idp2 = silc_id_payload_encode((void *)target, SILC_ID_CLIENT);
   SILC_PUT32_MSB(mode_mask, mode);