mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added /room command validation, reduced to one subcommand
This commit is contained in:
parent
eba3a7cb30
commit
1e26b7a4ff
@ -305,7 +305,7 @@ static struct cmd_t command_defs[] =
|
||||
NULL } } },
|
||||
|
||||
{ "/room",
|
||||
cmd_room, parse_args, 2, 2, NULL,
|
||||
cmd_room, parse_args, 1, 1, NULL,
|
||||
{ "/room config accept|destroy|edit|cancel", "Room configuration.",
|
||||
{ "/room config accept|destroy|edit|cancel",
|
||||
"---------------------------------------",
|
||||
@ -956,7 +956,6 @@ static Autocomplete alias_ac;
|
||||
static Autocomplete aliases_ac;
|
||||
static Autocomplete join_property_ac;
|
||||
static Autocomplete room_ac;
|
||||
static Autocomplete room_config_ac;
|
||||
|
||||
/*
|
||||
* Initialise command autocompleter and history
|
||||
@ -1209,13 +1208,11 @@ cmd_init(void)
|
||||
autocomplete_add(alias_ac, "list");
|
||||
|
||||
room_ac = autocomplete_new();
|
||||
autocomplete_add(room_ac, "accept");
|
||||
autocomplete_add(room_ac, "destroy");
|
||||
autocomplete_add(room_ac, "config");
|
||||
|
||||
room_config_ac = autocomplete_new();
|
||||
autocomplete_add(room_config_ac, "accept");
|
||||
autocomplete_add(room_config_ac, "destroy");
|
||||
autocomplete_add(room_config_ac, "edit");
|
||||
autocomplete_add(room_config_ac, "cancel");
|
||||
autocomplete_add(room_ac, "submit");
|
||||
autocomplete_add(room_ac, "cancel");
|
||||
|
||||
cmd_history_init();
|
||||
}
|
||||
@ -1261,7 +1258,6 @@ cmd_uninit(void)
|
||||
autocomplete_free(aliases_ac);
|
||||
autocomplete_free(join_property_ac);
|
||||
autocomplete_free(room_ac);
|
||||
autocomplete_free(room_config_ac);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -1386,7 +1382,6 @@ cmd_reset_autocomplete()
|
||||
autocomplete_reset(aliases_ac);
|
||||
autocomplete_reset(join_property_ac);
|
||||
autocomplete_reset(room_ac);
|
||||
autocomplete_reset(room_config_ac);
|
||||
bookmark_autocomplete_reset();
|
||||
}
|
||||
|
||||
@ -2080,11 +2075,6 @@ _room_autocomplete(char *input, int *size)
|
||||
{
|
||||
char *result = NULL;
|
||||
|
||||
result = autocomplete_param_with_ac(input, size, "/room config", room_config_ac, TRUE);
|
||||
if (result != NULL) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_ac(input, size, "/room", room_ac, TRUE);
|
||||
if (result != NULL) {
|
||||
return result;
|
||||
|
@ -1797,84 +1797,103 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// room command allowed in window
|
||||
win_type_t win_type = ui_current_win_type();
|
||||
if (win_type != WIN_MUC && win_type != WIN_MUC_CONFIG) {
|
||||
cons_show("Command /room only usable in chat rooms.");
|
||||
cons_show("Command '/room' does not apply to this window.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "config") != 0) {
|
||||
// validate subcommand
|
||||
if ((g_strcmp0(args[0], "accept") != 0) &&
|
||||
(g_strcmp0(args[0], "destroy") != 0) &&
|
||||
(g_strcmp0(args[0], "config") != 0) &&
|
||||
(g_strcmp0(args[0], "submit") != 0) &&
|
||||
(g_strcmp0(args[0], "cancel") != 0)) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ((g_strcmp0(args[1], "accept") != 0) &&
|
||||
(g_strcmp0(args[1], "cancel") != 0) &&
|
||||
(g_strcmp0(args[1], "destroy") != 0) &&
|
||||
(g_strcmp0(args[1], "submit") != 0) &&
|
||||
(g_strcmp0(args[1], "edit") != 0)) {
|
||||
cons_show("Usage: %s", help.usage);
|
||||
// validate subcommand for window type
|
||||
if (win_type == WIN_MUC &&
|
||||
((g_strcmp0(args[0], "submit") == 0) ||
|
||||
(g_strcmp0(args[0], "cancel") == 0))) {
|
||||
cons_show("Command '/room %s' only allowed in room configuration windows.", args[0]);
|
||||
return TRUE;
|
||||
}
|
||||
if (win_type == WIN_MUC_CONFIG &&
|
||||
((g_strcmp0(args[0], "accept") == 0) ||
|
||||
(g_strcmp0(args[0], "destroy") == 0) ||
|
||||
(g_strcmp0(args[0], "config") == 0))) {
|
||||
cons_show("Command '/room %s' only allowed in chat room windows.", args[0]);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char *room = ui_current_recipient();
|
||||
ProfWin *window = wins_get_by_recipient(room);
|
||||
int num = wins_get_num(window);
|
||||
int ui_index = num;
|
||||
if (ui_index == 10) {
|
||||
ui_index = 0;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[1], "accept") == 0) {
|
||||
gboolean requires_config = muc_requires_config(room);
|
||||
if (!requires_config) {
|
||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Current room does not require configuration.");
|
||||
// commands available in room
|
||||
if ((g_strcmp0(args[0], "accept") == 0) ||
|
||||
(g_strcmp0(args[0], "destroy") == 0) ||
|
||||
(g_strcmp0(args[0], "config") == 0)) {
|
||||
|
||||
ProfWin *window = wins_get_by_recipient(room);
|
||||
int num = wins_get_num(window);
|
||||
int ui_index = num;
|
||||
if (ui_index == 10) {
|
||||
ui_index = 0;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "accept") == 0) {
|
||||
gboolean requires_config = muc_requires_config(room);
|
||||
if (!requires_config) {
|
||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Current room does not require configuration.");
|
||||
return TRUE;
|
||||
} else {
|
||||
iq_confirm_instant_room(room);
|
||||
muc_set_requires_config(room, FALSE);
|
||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room unlocked.");
|
||||
cons_show("Room unlocked: %s (%d)", room, ui_index);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "destroy") == 0) {
|
||||
iq_destroy_instant_room(room);
|
||||
return TRUE;
|
||||
} else {
|
||||
iq_confirm_instant_room(room);
|
||||
muc_set_requires_config(room, FALSE);
|
||||
win_save_vprint(window, '!', NULL, 0, COLOUR_ROOMINFO, "", "Room unlocked.");
|
||||
cons_show("Room unlocked: %s (%d)", room, ui_index);
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "config") == 0) {
|
||||
GString *win_title = g_string_new(room);
|
||||
g_string_append(win_title, " config");
|
||||
ProfWin *window = wins_get_by_recipient(win_title->str);
|
||||
g_string_free(win_title, TRUE);
|
||||
if (window != NULL) {
|
||||
num = wins_get_num(window);
|
||||
ui_switch_win(num);
|
||||
} else {
|
||||
iq_request_room_config_form(room);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[1], "destroy") == 0) {
|
||||
iq_destroy_instant_room(room);
|
||||
return TRUE;
|
||||
}
|
||||
// commands allowed in room config
|
||||
if ((g_strcmp0(args[0], "submit") == 0) ||
|
||||
(g_strcmp0(args[0], "cancel") == 0)) {
|
||||
|
||||
if (g_strcmp0(args[1], "edit") == 0) {
|
||||
GString *win_title = g_string_new(room);
|
||||
g_string_append(win_title, " config");
|
||||
ProfWin *window = wins_get_by_recipient(win_title->str);
|
||||
g_string_free(win_title, TRUE);
|
||||
if (window != NULL) {
|
||||
int num = wins_get_num(window);
|
||||
ui_switch_win(num);
|
||||
} else {
|
||||
iq_request_room_config_form(room);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[1], "submit") == 0) {
|
||||
ProfWin *current = wins_get_current();
|
||||
if (current->type != WIN_MUC_CONFIG) {
|
||||
cons_show("Room configuration can only be submitted when in the room configuration window.");
|
||||
return TRUE;
|
||||
} else {
|
||||
if (g_strcmp0(args[0], "submit") == 0) {
|
||||
ProfWin *current = wins_get_current();
|
||||
gchar **split_recipient = g_strsplit(room, " ", 2);
|
||||
room = split_recipient[0];
|
||||
iq_submit_room_config(room, current->form);
|
||||
g_strfreev(split_recipient);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[1], "cancel") == 0) {
|
||||
iq_room_config_cancel(room);
|
||||
return TRUE;
|
||||
if (g_strcmp0(args[0], "cancel") == 0) {
|
||||
iq_room_config_cancel(room);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
Loading…
Reference in New Issue
Block a user