updates.
[silc.git] / apps / silc / local_command.c
index 1938e9f9d2832cc74453736b3e320f07441bcfc1..79aa0f04ed64dbfa2fa942cd9ad76753ce42c121 100644 (file)
@@ -32,6 +32,8 @@ SilcClientCommand silc_local_command_list[] =
   SILC_CLIENT_LCMD(msg, MSG, "MSG", 0, 3),
   SILC_CLIENT_LCMD(away, AWAY, "AWAY", 0, 2),
   SILC_CLIENT_LCMD(key, KEY, "KEY", 0, 7),
+  SILC_CLIENT_LCMD(me, ME, "ME", 0, 3),
+  SILC_CLIENT_LCMD(notice, NOTICE, "NOTICE", 0, 3),
 
   { NULL, 0, NULL, 0, 0 },
 };
@@ -131,7 +133,7 @@ SILC_CLIENT_LCMD_FUNC(msg)
   silc_print(client, "-> *%s* %s", cmd->argv[1], cmd->argv[2]);
 
   /* Send the private message */
-  silc_client_send_private_message(client, conn, client_entry,
+  silc_client_send_private_message(client, conn, client_entry, 0,
                                   cmd->argv[2], cmd->argv_lens[2],
                                   TRUE);
 
@@ -216,6 +218,8 @@ SILC_CLIENT_LCMD_FUNC(away)
   SilcClientConnection conn = cmd->conn;
   SilcClient client = cmd->client;
   SilcClientInternal app = (SilcClientInternal)client->application;
+  unsigned char modebuf[4];
+  SilcBuffer idp, buffer;
 
   if (!cmd->conn) {
     silc_say(client, conn,
@@ -224,6 +228,8 @@ SILC_CLIENT_LCMD_FUNC(away)
   }
 
   if (cmd->argc == 1) {
+    conn->local_entry->mode &= ~SILC_UMODE_GONE;
+
     if (conn->away) {
       silc_free(conn->away->away);
       silc_free(conn->away);
@@ -234,7 +240,8 @@ SILC_CLIENT_LCMD_FUNC(away)
       silc_screen_print_bottom_line(app->screen, 0);
     }
   } else {
-
+    conn->local_entry->mode |= SILC_UMODE_GONE;
+  
     if (conn->away)
       silc_free(conn->away->away);
     else
@@ -247,6 +254,19 @@ SILC_CLIENT_LCMD_FUNC(away)
     silc_screen_print_bottom_line(app->screen, 0);
   }
 
+  /* Send the UMODE command to se myself as gone */
+  idp = silc_id_payload_encode(conn->local_id, SILC_ID_CLIENT);
+  SILC_PUT32_MSB(conn->local_entry->mode, modebuf);
+  buffer = silc_command_payload_encode_va(SILC_COMMAND_UMODE, 
+                                         ++conn->cmd_ident, 2, 
+                                         1, idp->data, idp->len, 
+                                         2, modebuf, sizeof(modebuf));
+  silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, 
+                         NULL, 0, NULL, NULL, buffer->data, 
+                         buffer->len, TRUE);
+  silc_buffer_free(buffer);
+  silc_buffer_free(idp);
+
  out:
   silc_client_command_free(cmd);
 }
@@ -417,7 +437,7 @@ SILC_CLIENT_LCMD_FUNC(key)
   if (!strcasecmp(cmd->argv[3], "set")) {
     command = 1;
 
-    if (cmd->argc == 3) {
+    if (cmd->argc == 4) {
       if (curr_key && type == 1 && client_entry) {
        silc_client_del_private_message_key(client, conn, client_entry);
        silc_client_add_private_message_key_ske(client, conn, client_entry,
@@ -426,13 +446,13 @@ SILC_CLIENT_LCMD_FUNC(key)
       }
     }
 
-    if (cmd->argc >= 4) {
+    if (cmd->argc >= 5) {
       if (type == 1 && client_entry) {
        /* Set private message key */
        
        silc_client_del_private_message_key(client, conn, client_entry);
 
-       if (cmd->argc >= 5)
+       if (cmd->argc >= 6)
          silc_client_add_private_message_key(client, conn, client_entry,
                                              cmd->argv[5], cmd->argv[4],
                                              cmd->argv_lens[4],
@@ -458,9 +478,9 @@ SILC_CLIENT_LCMD_FUNC(key)
          goto out;
        }
 
-       if (cmd->argc >= 5)
-         cipher = cmd->argv[5];
        if (cmd->argc >= 6)
+         cipher = cmd->argv[5];
+       if (cmd->argc >= 7)
          hmac = cmd->argv[6];
 
        if (!silc_client_add_channel_private_key(client, conn, channel_entry,
@@ -489,10 +509,10 @@ SILC_CLIENT_LCMD_FUNC(key)
       unsigned int keys_count;
       int number;
 
-      if (cmd->argc == 3)
+      if (cmd->argc == 4)
        silc_client_del_channel_private_keys(client, conn, channel_entry);
 
-      if (cmd->argc > 3) {
+      if (cmd->argc > 4) {
        number = atoi(cmd->argv[4]);
        keys = silc_client_list_channel_private_keys(client, conn, 
                                                     channel_entry,
@@ -533,7 +553,7 @@ SILC_CLIENT_LCMD_FUNC(key)
       if (nickname[0] == '*') {
        silc_say(client, conn, "Private message keys");
        silc_say(client, conn, 
-                "  Client                        Cipher        Key");
+                "  Client                         Cipher         Key");
        for (k = 0; k < keys_count; k++) {
          memset(buf, 0, sizeof(buf));
          strncat(buf, "  ", 2);
@@ -562,7 +582,7 @@ SILC_CLIENT_LCMD_FUNC(key)
        silc_say(client, conn, "Private message key", 
                 client_entry->nickname);
        silc_say(client, conn, 
-                "  Client                        Cipher        Key");
+                "  Client                         Cipher         Key");
        for (k = 0; k < keys_count; k++) {
          if (keys[k].client_entry != client_entry)
            continue;
@@ -607,7 +627,7 @@ SILC_CLIENT_LCMD_FUNC(key)
       silc_say(client, conn, "Channel %s private keys", 
               channel_entry->channel_name);
       silc_say(client, conn, 
-              "  Cipher          Hmac            Key");
+              "  Cipher           Hmac             Key");
       for (k = 0; k < keys_count; k++) {
        memset(buf, 0, sizeof(buf));
        strncat(buf, "  ", 2);
@@ -691,3 +711,100 @@ SILC_CLIENT_LCMD_FUNC(key)
     silc_free(server);
   silc_client_command_free(cmd);
 }
+
+/* Sends an action to the channel.  Equals CTCP's ACTION (IRC's /ME) 
+   command. */
+
+SILC_CLIENT_LCMD_FUNC(me)
+{
+  SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+  SilcClientConnection conn = cmd->conn;
+  SilcClient client = cmd->client;
+  SilcChannelEntry channel_entry;
+  char *name;
+
+  if (!cmd->conn) {
+    silc_say(client, conn,
+            "You are not connected to a server, use /SERVER to connect");
+    goto out;
+  }
+
+  if (cmd->argc < 3) {
+    silc_say(client, conn, "Usage: /ME <channel> <action message>");
+    goto out;
+  }
+
+  if (cmd->argv[1][0] == '*') {
+    if (!conn->current_channel) {
+      cmd->client->ops->say(cmd->client, conn, "You are not on any channel");
+      goto out;
+    }
+    name = conn->current_channel->channel_name;
+  } else {
+    name = cmd->argv[1];
+  }
+
+  channel_entry = silc_client_get_channel(client, conn, name);
+  if (!channel_entry) {
+    silc_say(client, conn, "You are not on that channel");
+    goto out;
+  }
+
+  /* Send the action message */
+  silc_client_send_channel_message(client, conn, channel_entry, NULL,
+                                  SILC_MESSAGE_FLAG_ACTION, 
+                                  cmd->argv[2], cmd->argv_lens[2], TRUE);
+
+  silc_print(client, "* %s %s", conn->nickname, cmd->argv[2]);
+
+ out:
+  silc_client_command_free(cmd);
+}
+
+/* Sends an notice to the channel.  */
+
+SILC_CLIENT_LCMD_FUNC(notice)
+{
+  SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+  SilcClientConnection conn = cmd->conn;
+  SilcClient client = cmd->client;
+  SilcChannelEntry channel_entry;
+  char *name;
+
+  if (!cmd->conn) {
+    silc_say(client, conn,
+            "You are not connected to a server, use /SERVER to connect");
+    goto out;
+  }
+
+  if (cmd->argc < 3) {
+    silc_say(client, conn, "Usage: /NOTICE <channel> <message>");
+    goto out;
+  }
+
+  if (cmd->argv[1][0] == '*') {
+    if (!conn->current_channel) {
+      cmd->client->ops->say(cmd->client, conn, "You are not on any channel");
+      goto out;
+    }
+    name = conn->current_channel->channel_name;
+  } else {
+    name = cmd->argv[1];
+  }
+
+  channel_entry = silc_client_get_channel(client, conn, name);
+  if (!channel_entry) {
+    silc_say(client, conn, "You are not on that channel");
+    goto out;
+  }
+
+  /* Send the action message */
+  silc_client_send_channel_message(client, conn, channel_entry, NULL,
+                                  SILC_MESSAGE_FLAG_NOTICE, 
+                                  cmd->argv[2], cmd->argv_lens[2], TRUE);
+
+  silc_print(client, "- %s %s", conn->nickname, cmd->argv[2]);
+
+ out:
+  silc_client_command_free(cmd);
+}