Add /getbool command

This commit is contained in:
TingPing
2013-12-31 17:06:58 -05:00
parent 3a7fb4d8e1
commit 10d3c15143
4 changed files with 87 additions and 0 deletions

View File

@@ -122,6 +122,7 @@ void fe_set_lag (server *serv, long lag);
void fe_set_throttle (server *serv);
void fe_set_away (server *serv);
void fe_serverlist_open (session *sess);
void fe_get_bool (char *title, char *prompt, void *callback, void *userdata);
void fe_get_str (char *prompt, char *def, void *callback, void *ud);
void fe_get_int (char *prompt, int def, void *callback, void *ud);
#define FRF_WRITE 1 /* save file */

View File

@@ -1940,6 +1940,36 @@ typedef struct
session *sess;
} getvalinfo;
static void
get_bool_cb (int val, getvalinfo *info)
{
char buf[512];
snprintf (buf, sizeof (buf), "%s %d", info->cmd, val);
if (is_session (info->sess))
handle_command (info->sess, buf, FALSE);
free (info->cmd);
free (info);
}
static int
cmd_getbool (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{
getvalinfo *info;
if (!word[4][0])
return FALSE;
info = malloc (sizeof (*info));
info->cmd = strdup (word[2]);
info->sess = sess;
fe_get_bool (word[3], word_eol[4], get_bool_cb, info);
return TRUE;
}
static void
get_int_cb (int cancel, int val, getvalinfo *info)
{
@@ -3934,6 +3964,7 @@ const struct commands xc_cmds[] = {
N_("FLUSHQ, flushes the current server's send queue")},
{"GATE", cmd_gate, 0, 0, 1,
N_("GATE <host> [<port>], proxies through a host, port defaults to 23")},
{"GETBOOL", cmd_getbool, 0, 0, 1, "GETBOOL <command> <title> <text>"},
{"GETFILE", cmd_getfile, 0, 0, 1, "GETFILE [-folder] [-multi] [-save] <command> <title> [<initial>]"},
{"GETINT", cmd_getint, 0, 0, 1, "GETINT <default> <command> <prompt>"},
{"GETSTR", cmd_getstr, 0, 0, 1, "GETSTR <default> <command> <prompt>"},