summaryrefslogtreecommitdiff
path: root/src/fe-common
diff options
context:
space:
mode:
Diffstat (limited to 'src/fe-common')
-rw-r--r--src/fe-common/core/fe-settings.c8
-rw-r--r--src/fe-common/core/keyboard.c7
-rw-r--r--src/fe-common/core/keyboard.h6
-rw-r--r--src/fe-common/irc/fe-irc-commands.c47
4 files changed, 64 insertions, 4 deletions
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c
index a4abc7b8..b2ffbd5a 100644
--- a/src/fe-common/core/fe-settings.c
+++ b/src/fe-common/core/fe-settings.c
@@ -29,6 +29,7 @@
#include "levels.h"
#include "printtext.h"
+#include "keyboard.h"
static void set_print(SETTINGS_REC *rec)
{
@@ -274,10 +275,9 @@ static void cmd_save(const char *data)
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
IRCTXT_CONFIG_MODIFIED, data);
- signal_emit("gui entry redirect", 4,
- settings_save_confirm,
- _("Overwrite config (y/N)?"),
- GINT_TO_POINTER(FALSE), g_strdup(data));
+ keyboard_entry_redirect((SIGNAL_FUNC) settings_save_confirm,
+ _("Overwrite config (y/N)?"),
+ 0, g_strdup(data));
}
void fe_settings_init(void)
diff --git a/src/fe-common/core/keyboard.c b/src/fe-common/core/keyboard.c
index 5c47edb9..4952a2cc 100644
--- a/src/fe-common/core/keyboard.c
+++ b/src/fe-common/core/keyboard.c
@@ -234,6 +234,13 @@ int key_pressed(const char *key, void *data)
return ret;
}
+void keyboard_entry_redirect(SIGNAL_FUNC func, const char *entry,
+ int flags, void *data)
+{
+ signal_emit("gui entry redirect", 4, func, entry,
+ GINT_TO_POINTER(flags), data);
+}
+
static void sig_command(const char *data)
{
const char *cmdchars;
diff --git a/src/fe-common/core/keyboard.h b/src/fe-common/core/keyboard.h
index 6c41fbfd..f3cc4d1a 100644
--- a/src/fe-common/core/keyboard.h
+++ b/src/fe-common/core/keyboard.h
@@ -29,6 +29,12 @@ void key_configure_remove(const char *key);
KEYINFO_REC *key_info_find(const char *id);
int key_pressed(const char *key, void *data);
+#define ENTRY_REDIRECT_FLAG_HOTKEY 0x01
+#define ENTRY_REDIRECT_FLAG_HIDDEN 0x02
+
+void keyboard_entry_redirect(SIGNAL_FUNC func, const char *entry,
+ int flags, void *data);
+
void keyboard_init(void);
void keyboard_deinit(void);
diff --git a/src/fe-common/irc/fe-irc-commands.c b/src/fe-common/irc/fe-irc-commands.c
index 252b568d..71f2a3d8 100644
--- a/src/fe-common/irc/fe-irc-commands.c
+++ b/src/fe-common/irc/fe-irc-commands.c
@@ -37,6 +37,7 @@
#include "fe-windows.h"
#include "window-items.h"
#include "printtext.h"
+#include "keyboard.h"
/* SYNTAX: ME <message> */
static void cmd_me(gchar *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
@@ -371,6 +372,50 @@ static void cmd_ts(const char *data)
}
}
+typedef struct {
+ IRC_SERVER_REC *server;
+ char *nick;
+} OPER_PASS_REC;
+
+static void cmd_oper_got_pass(const char *password, OPER_PASS_REC *rec)
+{
+ if (*password != '\0')
+ irc_send_cmdv(rec->server, "OPER %s %s", rec->nick, password);
+ g_free(rec->nick);
+ g_free(rec);
+}
+
+/* SYNTAX: OPER [<nick> [<password>]] */
+static void cmd_oper(const char *data, IRC_SERVER_REC *server)
+{
+ char *nick, *password;
+ void *free_arg;
+
+ g_return_if_fail(data != NULL);
+ if (!IS_IRC_SERVER(server) || !server->connected)
+ cmd_return_error(CMDERR_NOT_CONNECTED);
+
+ if (!cmd_get_params(data, &free_arg, 2, &nick, &password))
+ return;
+ if (*password == '\0') {
+ /* password not given, ask it.
+ irc/core handles the /OPER when password is given */
+ OPER_PASS_REC *rec;
+
+ rec = g_new(OPER_PASS_REC, 1);
+ rec->server = server;
+ rec->nick = g_strdup(*nick != '\0' ? nick : server->nick);
+
+ keyboard_entry_redirect((SIGNAL_FUNC) cmd_oper_got_pass,
+ _("Operator password:"),
+ ENTRY_REDIRECT_FLAG_HIDDEN, rec);
+
+ signal_stop();
+ }
+
+ cmd_params_free(free_arg);
+}
+
void fe_irc_commands_init(void)
{
command_bind_last("me", NULL, (SIGNAL_FUNC) cmd_me);
@@ -386,6 +431,7 @@ void fe_irc_commands_init(void)
command_bind("ver", NULL, (SIGNAL_FUNC) cmd_ver);
command_bind("topic", NULL, (SIGNAL_FUNC) cmd_topic);
command_bind("ts", NULL, (SIGNAL_FUNC) cmd_ts);
+ command_bind("oper", NULL, (SIGNAL_FUNC) cmd_oper);
}
void fe_irc_commands_deinit(void)
@@ -403,4 +449,5 @@ void fe_irc_commands_deinit(void)
command_unbind("ver", (SIGNAL_FUNC) cmd_ver);
command_unbind("topic", (SIGNAL_FUNC) cmd_topic);
command_unbind("ts", (SIGNAL_FUNC) cmd_ts);
+ command_unbind("oper", (SIGNAL_FUNC) cmd_oper);
}