Improved UTF-8 encoding and decoding, improved toolkit doc,
[silc.git] / apps / irssi / src / silc / core / silc-channels.c
index 9a11cb66095caed04fcb540325d899461378e5f5..afff90e60b28a94dbbe4f66297d476385b42e5cb 100644 (file)
@@ -66,6 +66,8 @@ static void sig_channel_destroyed(SILC_CHANNEL_REC *channel)
 {
   if (!IS_SILC_CHANNEL(channel))
     return;
+  if (channel->server && channel->server->disconnected)
+    return;
 
   if (channel->server != NULL && !channel->left && !channel->kicked) {
     /* destroying channel record without actually
@@ -156,6 +158,7 @@ static void command_part(const char *data, SILC_SERVER_REC *server,
   signal_emit("message part", 5, server, chanrec->name,
              server->nick, userhost, "");
   
+  chanrec->left = TRUE;
   silc_command_exec(server, "LEAVE", chanrec->name);
   signal_stop();
   
@@ -170,6 +173,7 @@ static void command_me(const char *data, SILC_SERVER_REC *server,
   SILC_CHANNEL_REC *chanrec;
   char *tmpcmd = "ME", *tmp;
   SilcUInt32 argc = 0;
+  unsigned char *message = NULL;
   unsigned char **argv;
   SilcUInt32 *argv_lens, *argv_types;
   int i;
@@ -195,11 +199,23 @@ static void command_me(const char *data, SILC_SERVER_REC *server,
   if (chanrec == NULL) 
     cmd_return_error(CMDERR_CHAN_NOT_FOUND);
 
+  if (!silc_term_utf8()) {
+    int len = silc_utf8_encoded_len(argv[1], argv_lens[1],
+                                   SILC_STRING_LANGUAGE);
+    message = silc_calloc(len + 1, sizeof(*message));
+    g_return_if_fail(message != NULL);
+    silc_utf8_encode(argv[1], argv_lens[1], SILC_STRING_LANGUAGE,
+                    message, len);
+  }
+
   /* Send the action message */
   silc_client_send_channel_message(silc_client, server->conn, 
                                   chanrec->entry, NULL,
-                                  SILC_MESSAGE_FLAG_ACTION, 
-                                  argv[1], argv_lens[1], TRUE);
+                                  SILC_MESSAGE_FLAG_ACTION |
+                                  SILC_MESSAGE_FLAG_UTF8,
+                                  message ? message : argv[1],
+                                  message ? strlen(message) : argv_lens[1],
+                                  TRUE);
 
   printformat_module("fe-common/silc", server, chanrec->entry->channel_name,
                     MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, 
@@ -209,6 +225,7 @@ static void command_me(const char *data, SILC_SERVER_REC *server,
     silc_free(argv[i]);
   silc_free(argv_lens);
   silc_free(argv_types);
+  silc_free(message);
 }
 
 /* ACTION local command. Same as ME but takes the channel as mandatory
@@ -220,6 +237,7 @@ static void command_action(const char *data, SILC_SERVER_REC *server,
   SILC_CHANNEL_REC *chanrec;
   char *tmpcmd = "ME", *tmp;
   SilcUInt32 argc = 0;
+  unsigned char *message = NULL;
   unsigned char **argv;
   SilcUInt32 *argv_lens, *argv_types;
   int i;
@@ -244,11 +262,23 @@ static void command_action(const char *data, SILC_SERVER_REC *server,
   if (chanrec == NULL) 
     cmd_return_error(CMDERR_CHAN_NOT_FOUND);
 
+  if (!silc_term_utf8()) {
+    int len = silc_utf8_encoded_len(argv[2], argv_lens[2],
+                                   SILC_STRING_LANGUAGE);
+    message = silc_calloc(len + 1, sizeof(*message));
+    g_return_if_fail(message != NULL);
+    silc_utf8_encode(argv[2], argv_lens[2], SILC_STRING_LANGUAGE,
+                    message, len);
+  }
+
   /* Send the action message */
   silc_client_send_channel_message(silc_client, server->conn, 
                                   chanrec->entry, NULL,
-                                  SILC_MESSAGE_FLAG_ACTION, 
-                                  argv[2], argv_lens[2], TRUE);
+                                  SILC_MESSAGE_FLAG_ACTION |
+                                  SILC_MESSAGE_FLAG_UTF8,
+                                  message ? message : argv[2],
+                                  message ? strlen(message) : argv_lens[2],
+                                  TRUE);
 
   printformat_module("fe-common/silc", server, chanrec->entry->channel_name,
                     MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, 
@@ -258,6 +288,7 @@ static void command_action(const char *data, SILC_SERVER_REC *server,
     silc_free(argv[i]);
   silc_free(argv_lens);
   silc_free(argv_types);
+  silc_free(message);
 }
 
 /* NOTICE local command. */
@@ -268,6 +299,7 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
   SILC_CHANNEL_REC *chanrec;
   char *tmpcmd = "ME", *tmp;
   SilcUInt32 argc = 0;
+  unsigned char *message = NULL;
   unsigned char **argv;
   SilcUInt32 *argv_lens, *argv_types;
   int i;
@@ -292,11 +324,23 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
   if (chanrec == NULL) 
     cmd_return_error(CMDERR_CHAN_NOT_FOUND);
 
+  if (!silc_term_utf8()) {
+    int len = silc_utf8_encoded_len(argv[1], argv_lens[1],
+                                   SILC_STRING_LANGUAGE);
+    message = silc_calloc(len + 1, sizeof(*message));
+    g_return_if_fail(message != NULL);
+    silc_utf8_encode(argv[1], argv_lens[1], SILC_STRING_LANGUAGE,
+                    message, len);
+  }
+
   /* Send the action message */
   silc_client_send_channel_message(silc_client, server->conn, 
                                   chanrec->entry, NULL,
-                                  SILC_MESSAGE_FLAG_NOTICE, 
-                                  argv[1], argv_lens[1], TRUE);
+                                  SILC_MESSAGE_FLAG_NOTICE |
+                                  SILC_MESSAGE_FLAG_UTF8,
+                                  message ? message : argv[1],
+                                  message ? strlen(message) : argv_lens[1],
+                                  TRUE);
 
   printformat_module("fe-common/silc", server, chanrec->entry->channel_name,
                     MSGLEVEL_NOTICES, SILCTXT_CHANNEL_OWNNOTICE, 
@@ -306,6 +350,7 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
     silc_free(argv[i]);
   silc_free(argv_lens);
   silc_free(argv_types);
+  silc_free(message);
 }
 
 /* AWAY local command.  Sends UMODE command that sets the SILC_UMODE_GONE
@@ -337,6 +382,9 @@ static void command_away(const char *data, SILC_SERVER_REC *server,
                       SILCTXT_SET_AWAY, data);
   }
 
+  server->usermode_away = set;
+  if (set)
+    server->away_reason = g_strdup((char *)data);
   signal_emit("away mode changed", 1, server);
 
   silc_command_exec(server, "UMODE", set ? "+g" : "-g");
@@ -402,6 +450,17 @@ static void keyagr_completion(SilcClient client,
     printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_CRAP,
                       SILCTXT_KEY_AGREEMENT_ABORTED, client_entry->nickname);
     break;
+
+  case SILC_KEY_AGREEMENT_ALREADY_STARTED:
+    printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_CRAP,
+                      SILCTXT_KEY_AGREEMENT_ALREADY_STARTED,
+                      client_entry->nickname);
+    break;
+    
+  case SILC_KEY_AGREEMENT_SELF_DENIED:
+    printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_CRAP,
+                      SILCTXT_KEY_AGREEMENT_SELF_DENIED);
+    break;
     
   default:
     break;