From 6745dd6159afc6ff220d09d7adc1923218fa756b Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 18 Mar 2016 20:18:58 +0100 Subject: [PATCH] Throw an error when a chatnet has no available url If you type /connect and the chatnet has no url available let's just throw an error instead of trying to process as a url. --- src/core/chat-commands.c | 7 +++++++ src/core/commands.h | 3 ++- src/core/servers-setup.c | 2 ++ src/fe-common/core/fe-core-commands.c | 3 ++- src/fe-common/core/module-formats.c | 1 + src/fe-common/core/module-formats.h | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/chat-commands.c b/src/core/chat-commands.c index 7f000cf5..a9404fa3 100644 --- a/src/core/chat-commands.c +++ b/src/core/chat-commands.c @@ -73,6 +73,13 @@ static SERVER_CONNECT_REC *get_server_connect(const char *data, int *plus_addr, conn = server_create_conn(proto != NULL ? proto->id : -1, addr, atoi(portstr), chatnet, password, nick); + if (conn == NULL) { + signal_emit("error command", 1, + GINT_TO_POINTER(CMDERR_NO_SERVER_DEFINED)); + cmd_params_free(free_arg); + return NULL; + } + if (proto == NULL) proto = chat_protocol_find_id(conn->chat_type); diff --git a/src/core/commands.h b/src/core/commands.h index 72105ad3..93d6276b 100644 --- a/src/core/commands.h +++ b/src/core/commands.h @@ -41,7 +41,8 @@ enum { CMDERR_INVALID_TIME, /* invalid time specification */ CMDERR_INVALID_CHARSET, /* invalid charset specification */ CMDERR_EVAL_MAX_RECURSE, /* eval hit recursion limit */ - CMDERR_PROGRAM_NOT_FOUND /* program not found */ + CMDERR_PROGRAM_NOT_FOUND, /* program not found */ + CMDERR_NO_SERVER_DEFINED, /* no server has been defined for a given chatnet */ }; /* Return the full command for `alias' */ diff --git a/src/core/servers-setup.c b/src/core/servers-setup.c index 4a048282..990d2d4b 100644 --- a/src/core/servers-setup.c +++ b/src/core/servers-setup.c @@ -323,6 +323,8 @@ server_create_conn(int chat_type, const char *dest, int port, rec = create_chatnet_conn(chatrec->name, port, password, nick); if (rec != NULL) return rec; + /* The chatnet has no url to connect to */ + return NULL; } chatrec = chatnet == NULL ? NULL : chatnet_find(chatnet); diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 7b1d7b94..97a246ec 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -51,7 +51,8 @@ static int ret_texts[] = { TXT_INVALID_TIME, TXT_INVALID_CHARSET, TXT_EVAL_MAX_RECURSE, - TXT_PROGRAM_NOT_FOUND + TXT_PROGRAM_NOT_FOUND, + TXT_NO_SERVER_DEFINED, }; int command_hide_output; diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index e6d32b6d..b897b0c6 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -223,6 +223,7 @@ FORMAT_REC fecommon_core_formats[] = { { "invalid_charset", "Invalid charset: $0", 1, { 0 } }, { "eval_max_recurse", "/eval hit maximum recursion limit", 0 }, { "program_not_found", "Could not find file or file is not executable", 0 }, + { "no_server_defined", "No servers defined for this network, see /help server for how to add one", 0 }, /* ---- */ { NULL, "Themes", 0 }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 3f06bb97..de1e13f2 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -192,6 +192,7 @@ enum { TXT_INVALID_CHARSET, TXT_EVAL_MAX_RECURSE, TXT_PROGRAM_NOT_FOUND, + TXT_NO_SERVER_DEFINED, TXT_FILL_11,