diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-03-18 18:20:05 +0100 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-03-18 18:20:05 +0100 |
commit | 3c56b289ed04f8525affd532d0192d653e1dcd95 (patch) | |
tree | afb0b55eea620a1d8f4968a67756f88a00c3b25d /src | |
parent | ed97e3730a846dd17d6350cbe6cce25e419f83e4 (diff) | |
download | profani-tty-3c56b289ed04f8525affd532d0192d653e1dcd95.tar.gz |
Add slashguard feature
New command `/slashguard` tries to protect against typing ` /quit` by not allowing a slash in the first 4 characters.
Diffstat (limited to 'src')
-rw-r--r-- | src/command/cmd_ac.c | 2 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 17 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 12 | ||||
-rw-r--r-- | src/command/cmd_funcs.h | 1 | ||||
-rw-r--r-- | src/config/preferences.c | 3 | ||||
-rw-r--r-- | src/config/preferences.h | 1 | ||||
-rw-r--r-- | src/ui/console.c | 10 | ||||
-rw-r--r-- | src/ui/inputwin.c | 7 | ||||
-rw-r--r-- | src/ui/ui.h | 1 |
9 files changed, 53 insertions, 1 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 12331bfb..0266d8f5 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1567,7 +1567,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", - "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/os"}; + "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/os", "/slashguard"}; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous, NULL); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 8b45f646..3845b901 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2418,6 +2418,23 @@ static struct cmd_t command_defs[] = { "message", "The corrected message."}) CMD_NOEXAMPLES }, + + { "/slashguard", + parse_args, 1, 1, &cons_slashguard_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_slashguard) + CMD_TAGS( + CMD_TAG_UI, + CMD_TAG_CHAT) + CMD_SYN( + "/slashguard on|off") + CMD_DESC( + "Slashguard won't accept a slash in the first 4 characters of your input field. " + "It tries to protect you from typing ' /quit' and similar things in chats.") + CMD_ARGS( + { "on|off", "Enable or disable slashguard." }) + CMD_NOEXAMPLES + }, }; static GHashTable *search_index; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 1776c72e..cee58c7a 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8836,3 +8836,15 @@ cmd_correct(ProfWin *window, const char *const command, gchar **args) win_println(window, THEME_DEFAULT, "!", "Command /correct only valid in regular chat windows."); return TRUE; } + +gboolean +cmd_slashguard(ProfWin *window, const char *const command, gchar **args) +{ + if (args[0] == NULL) { + return FALSE; + } + + _cmd_set_boolean_preference(args[0], command, "Slashguard", PREF_SLASH_GUARD); + + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 58d99635..bcb633d2 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -231,4 +231,5 @@ gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args); gboolean cmd_os(ProfWin *window, const char *const command, gchar **args); gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args); gboolean cmd_correct(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_slashguard(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/config/preferences.c b/src/config/preferences.c index a4e5700b..fe9c185b 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1744,6 +1744,7 @@ _get_group(preference_t pref) case PREF_STATUSBAR_ROOM: case PREF_TITLEBAR_MUC_TITLE: case PREF_HISTORY_COLOR_MUC: + case PREF_SLASH_GUARD: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -2051,6 +2052,8 @@ _get_key(preference_t pref) return "history.muc.color"; case PREF_AVATAR_CMD: return "avatar.cmd"; + case PREF_SLASH_GUARD: + return "slashguard"; default: return NULL; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 37040214..8703043c 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -167,6 +167,7 @@ typedef enum { PREF_CORRECTION_ALLOW, PREF_HISTORY_COLOR_MUC, PREF_AVATAR_CMD, + PREF_SLASH_GUARD, } preference_t; typedef struct prof_alias_t { diff --git a/src/ui/console.c b/src/ui/console.c index 2b9b8aad..8d2fb26d 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2050,6 +2050,16 @@ cons_avatar_setting(void) } void +cons_slashguard_setting(void) +{ + if (prefs_get_boolean(PREF_SLASH_GUARD)) { + cons_show("Slashguard (/slashguard) : ON"); + } else { + cons_show("Slashguard (/slashguard) : OFF"); + } +} + +void cons_show_connection_prefs(void) { cons_show("Connection preferences:"); diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index ca3b688c..40875935 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -196,6 +196,13 @@ inp_readline(void) } if (inp_line) { + if (!get_password && prefs_get_boolean(PREF_SLASH_GUARD)) { + char *res = (char*) memchr (inp_line+1, '/', 3); + if (res) { + cons_show("Your text contains a slash in the first 4 characters"); + return NULL; + } + } return strdup(inp_line); } else { return NULL; diff --git a/src/ui/ui.h b/src/ui/ui.h index b3e512aa..a4878106 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -320,6 +320,7 @@ void cons_color_setting(void); void cons_os_setting(void); void cons_correction_setting(void); void cons_avatar_setting(void); +void cons_slashguard_setting(void); void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); void cons_show_contact_offline(PContact contact, char *resource, char *status); void cons_theme_properties(void); |