updates.
[runtime.git] / apps / irssi / src / silc / core / silc-channels.c
index 57678937fe86bfbe5a4289b624fd0c9f36039476..f6dc52f89351cf4795110edcd92473357ebbce11 100644 (file)
@@ -85,6 +85,7 @@ static void silc_channels_join(SILC_SERVER_REC *server,
     silc_command_exec(server, "JOIN", channel);
     g_free(channel);
   }
+
   g_strfreev(list);
 }
 
@@ -99,7 +100,7 @@ static void sig_connected(SILC_SERVER_REC *server)
 
 static void sig_server_quit(SILC_SERVER_REC *server, const char *msg)
 {
-  if (IS_SILC_SERVER(server))
+  if (IS_SILC_SERVER(server) && server->conn && server->conn->sock)
     silc_command_exec(server, "QUIT", msg);
 }
 
@@ -289,7 +290,9 @@ static void event_cmode(SILC_SERVER_REC *server, va_list va)
   (void)va_arg(va, char *);
   channel = va_arg(va, SilcChannelEntry);
 
-  mode = silc_client_chmode(modei, channel);
+  mode = silc_client_chmode(modei, 
+                           channel->channel_key->cipher->name,
+                           channel->hmac->hmac->name);
   
   chanrec = silc_channel_find_entry(server, channel);
   if (chanrec != NULL) {
@@ -479,7 +482,56 @@ static void command_me(const char *data, SILC_SERVER_REC *server,
                                   argv[1], argv_lens[1], TRUE);
 
   printformat_module("fe-common/silc", server, chanrec->entry->channel_name,
-                    MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, argv[1]);
+                    MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, 
+                     server->conn->local_entry->nickname, argv[1]);
+
+  for (i = 0; i < argc; i++)
+    silc_free(argv[i]);
+  silc_free(argv_lens);
+  silc_free(argv_types);
+}
+
+/* ACTION local command. Same as ME but takes the channel as mandatory
+   argument. */
+
+static void command_action(const char *data, SILC_SERVER_REC *server,
+                          WI_ITEM_REC *item)
+{
+  SILC_CHANNEL_REC *chanrec;
+  char *tmpcmd = "ME", *tmp;
+  uint32 argc = 0;
+  unsigned char **argv;
+  uint32 *argv_lens, *argv_types;
+  int i;
+  if (!IS_SILC_SERVER(server) || !server->connected)
+    cmd_return_error(CMDERR_NOT_CONNECTED);
+
+  if (!IS_SILC_CHANNEL(item))
+    cmd_return_error(CMDERR_NOT_JOINED);
+
+  /* Now parse all arguments */
+  tmp = g_strconcat(tmpcmd, " ", data, NULL);
+  silc_parse_command_line(tmp, &argv, &argv_lens,
+                         &argv_types, &argc, 3);
+  g_free(tmp);
+
+  if (argc < 3)
+    cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
+
+  chanrec = silc_channel_find(server, argv[1]);
+  if (chanrec == NULL) 
+    cmd_return_error(CMDERR_CHAN_NOT_FOUND);
+
+  /* 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);
+
+  printformat_module("fe-common/silc", server, chanrec->entry->channel_name,
+                    MSGLEVEL_ACTIONS, SILCTXT_CHANNEL_OWNACTION, 
+                     server->conn->local_entry->nickname, argv[2]);
 
   for (i = 0; i < argc; i++)
     silc_free(argv[i]);
@@ -525,7 +577,8 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
                                   argv[1], argv_lens[1], TRUE);
 
   printformat_module("fe-common/silc", server, chanrec->entry->channel_name,
-                    MSGLEVEL_NOTICES, SILCTXT_CHANNEL_OWNNOTICE, argv[1]);
+                    MSGLEVEL_NOTICES, SILCTXT_CHANNEL_OWNNOTICE, 
+                     server->conn->local_entry->nickname, argv[1]);
 
   for (i = 0; i < argc; i++)
     silc_free(argv[i]);
@@ -539,10 +592,30 @@ static void command_notice(const char *data, SILC_SERVER_REC *server,
 static void command_away(const char *data, SILC_SERVER_REC *server,
                         WI_ITEM_REC *item)
 {
+  bool set;
+
   if (!IS_SILC_SERVER(server) || !server->connected)
     cmd_return_error(CMDERR_NOT_CONNECTED);
 
-  /* XXX TODO */
+  if (*data == '\0') {
+    /* Remove any possible away message */
+    silc_client_set_away_message(silc_client, server->conn, NULL);
+    set = FALSE;
+
+    printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, 
+                      SILCTXT_UNSET_AWAY);
+  } else {
+    /* Set the away message */
+    silc_client_set_away_message(silc_client, server->conn, (char *)data);
+    set = TRUE;
+
+    printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP, 
+                      SILCTXT_SET_AWAY, data);
+  }
+
+  signal_emit("away mode changed", 1, server);
+
+  silc_command_exec(server, "UMODE", set ? "+g" : "-g");
 }
 
 typedef struct {
@@ -550,8 +623,6 @@ typedef struct {
   SILC_SERVER_REC *server;
 } *KeyInternal;
 
-static SilcSKEKeyMaterial *curr_key = NULL;
-
 /* Key agreement callback that is called after the key agreement protocol
    has been performed. This is called also if error occured during the
    key agreement protocol. The `key' is the allocated key material and
@@ -569,8 +640,6 @@ static void keyagr_completion(SilcClient client,
 {
   KeyInternal i = (KeyInternal)context;
 
-  curr_key = NULL;
-
   switch(status) {
   case SILC_KEY_AGREEMENT_OK:
     printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES,
@@ -685,7 +754,8 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
     } else {
       /* Parse the typed nickname. */
       if (!silc_parse_nickname(argv[2], &nickname, &serv, &num)) {
-       silc_say(silc_client, conn, "Bad nickname");
+       printformat_module("fe-common/silc", server, NULL,
+                          MSGLEVEL_CRAP, SILCTXT_BAD_NICK, argv[2]);
        return;
       }
       
@@ -740,15 +810,6 @@ static void command_key(const char *data, SILC_SERVER_REC *server,
   if (!strcasecmp(argv[3], "set")) {
     command = 1;
 
-    if (argc == 4) {
-      if (curr_key && type == 1 && client_entry) {
-       silc_client_del_private_message_key(silc_client, conn, client_entry);
-       silc_client_add_private_message_key_ske(silc_client, conn, 
-                                               client_entry, NULL, curr_key);
-       goto out;
-      }
-    }
-
     if (argc >= 5) {
       if (type == 1 && client_entry) {
        /* Set private message key */
@@ -1050,6 +1111,7 @@ void silc_channels_init(void)
   
   command_bind("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
   command_bind("me", MODULE_NAME, (SIGNAL_FUNC) command_me);
+  command_bind("action", MODULE_NAME, (SIGNAL_FUNC) command_action);
   command_bind("notice", MODULE_NAME, (SIGNAL_FUNC) command_notice);
   command_bind("away", MODULE_NAME, (SIGNAL_FUNC) command_away);
   command_bind("key", MODULE_NAME, (SIGNAL_FUNC) command_key);
@@ -1082,6 +1144,7 @@ void silc_channels_deinit(void)
   
   command_unbind("part", (SIGNAL_FUNC) command_part);
   command_unbind("me", (SIGNAL_FUNC) command_me);
+  command_unbind("action", (SIGNAL_FUNC) command_action);
   command_unbind("notice", (SIGNAL_FUNC) command_notice);
   command_unbind("away", (SIGNAL_FUNC) command_away);
   command_unbind("key", (SIGNAL_FUNC) command_key);