about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c10
-rw-r--r--src/command/commands.c42
-rw-r--r--src/command/commands.h1
3 files changed, 53 insertions, 0 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 9abc4cf3..e382c03c 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -274,6 +274,16 @@ static struct cmd_t command_defs[] =
           "Example : /status jon",
           NULL } } },
 
+    { "/resource",
+        cmd_resource, parse_args, 1, 2, NULL,
+        { "/resource set|off [resource]", "Set the contact's resource.",
+        { "/resource set|off [resource]",
+          "----------------------------",
+          "Set the resource to use when chatting to a contact.",
+          "set resource - Set the resource.",
+          "off          - Let the server choose which resource to route messages to.",
+          NULL } } },
+
     { "/join",
         cmd_join, parse_args, 1, 5, NULL,
         { "/join room[@server] [nick value] [password value]", "Join a chat room.",
diff --git a/src/command/commands.c b/src/command/commands.c
index 4a69a05b..62a5a6dd 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1528,6 +1528,48 @@ cmd_roster(gchar **args, struct cmd_help_t help)
 }
 
 gboolean
+cmd_resource(gchar **args, struct cmd_help_t help)
+{
+    ProfWin *current = wins_get_current();
+    if (current->type != WIN_CHAT) {
+        cons_show("The /resource command is only valid in chat windows.");
+        return TRUE;
+    }
+
+    char *cmd = args[0];
+
+    if (g_strcmp0(cmd, "set") == 0) {
+        char *resource = args[1];
+        if (!resource) {
+            cons_show("Usage: %s", help.usage);
+            return TRUE;
+        }
+
+        char *recipent = ui_current_recipient();
+        PContact contact = roster_get_contact(recipent);
+        if (!contact) {
+            cons_show("Cannot choose resource for contact not in roster.");
+            return TRUE;
+        }
+
+        if (!p_contact_get_resource(contact, resource)) {
+            cons_show("No such resource %s.", resource);
+            return TRUE;
+        }
+
+        current->chat_resource = strdup(resource);
+        return TRUE;
+
+    } else if (g_strcmp0(cmd, "off") == 0) {
+        FREE_SET_NULL(current->chat_resource);
+        return TRUE;
+    } else {
+        cons_show("Usage: %s", help.usage);
+        return TRUE;
+    }
+}
+
+gboolean
 cmd_status(gchar **args, struct cmd_help_t help)
 {
     char *usr = args[0];
diff --git a/src/command/commands.h b/src/command/commands.h
index b5646caf..5245b2c7 100644
--- a/src/command/commands.h
+++ b/src/command/commands.h
@@ -135,6 +135,7 @@ gboolean cmd_privileges(gchar **args, struct cmd_help_t help);
 gboolean cmd_presence(gchar **args, struct cmd_help_t help);
 gboolean cmd_wrap(gchar **args, struct cmd_help_t help);
 gboolean cmd_time(gchar **args, struct cmd_help_t help);
+gboolean cmd_resource(gchar **args, struct cmd_help_t help);
 
 gboolean cmd_form_field(char *tag, gchar **args);