From f50b40fb924d111e61e8e375815515b9a45e248f Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Tue, 6 Oct 2009 18:02:37 +0200 Subject: [PATCH] Fix bug #85 - Do not broadcast unknown commands, but allow for commands to be broadcasted if they are double escaped with ++ or !!. --- src/core/commands.c | 4 ++-- src/core/hub.c | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/commands.c b/src/core/commands.c index 59fde80..f328fb6 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -490,7 +490,7 @@ int command_dipatcher(struct hub_info* hub, struct hub_user* user, const char* m /* Parse and validate the command */ struct hub_command* cmd = command_create(message); - if (!cmd) return 1; + if (!cmd) return 0; for (n = 0; command_handlers[n].prefix; n++) { @@ -524,7 +524,7 @@ int command_dipatcher(struct hub_info* hub, struct hub_user* user, const char* m command_not_found(hub, user, cmd); command_destroy(cmd); - return 1; + return 0; } static struct commands_handler command_handlers[] = { diff --git a/src/core/hub.c b/src/core/hub.c index 2e253fb..0bb528e 100644 --- a/src/core/hub.c +++ b/src/core/hub.c @@ -183,9 +183,23 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc int ret = 0; int relay = 1; - if (message[0] == '!' || message[0] == '+') + if ((cmd->cache[0] == 'B') && (message[0] == '!' || message[0] == '+')) { - relay = command_dipatcher(hub, u, message); + /* + * A message such as "++message" is handled as "+message", by removing the first character. + * The first character is removed by memmoving the string one byte to the left. + */ + if (message[1] == message[0]) + { + relay = 1; + int offset = adc_msg_get_arg_offset(cmd); + memmove(cmd->cache+offset+1, cmd->cache+offset+2, cmd->length - offset); + cmd->length--; + } + else + { + relay = command_dipatcher(hub, u, message); + } } if (hub->config->chat_is_privileged && !user_is_protected(u) && (cmd->cache[0] == 'B' || cmd->cache[0] == 'F'))