int adc_msg_is_empty(struct adc_message* msg) { int offset = adc_msg_get_arg_offset(msg); if (offset == -1) return -1; if ((msg->length - 1) == (size_t) offset) return 1; return 0; }
int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc_message* cmd) { char* message = adc_msg_get_argument(cmd, 0); char* message_decoded = NULL; int ret = 0; int relay = 1; int broadcast; int private_msg; int command; int offset; if (!message) return 0; message_decoded = adc_msg_unescape(message); if (!message_decoded) { hub_free(message); return 0; } if (!user_is_logged_in(u)) { hub_free(message); return 0; } broadcast = (cmd->cache[0] == 'B'); private_msg = (cmd->cache[0] == 'D' || cmd->cache[0] == 'E'); command = (message[0] == '!' || message[0] == '+'); if (broadcast && command) { /* * 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; offset = adc_msg_get_arg_offset(cmd); memmove(cmd->cache+offset+1, cmd->cache+offset+2, cmd->length - offset); cmd->length--; } else { relay = command_invoke(hub->commands, u, message_decoded); } } /* FIXME: Plugin should do this! */ if (relay && (((hub->config->chat_is_privileged && !user_is_protected(u)) || (user_flag_get(u, flag_muted))) && broadcast)) { relay = 0; } if (relay) { plugin_st status = st_default; if (broadcast) { status = plugin_handle_chat_message(hub, u, message_decoded, 0); } else if (private_msg) { struct hub_user* target = uman_get_user_by_sid(hub->users, cmd->target); if (target) status = plugin_handle_private_message(hub, u, target, message_decoded, 0); else relay = 0; } if (status == st_deny) relay = 0; } if (relay) { /* adc_msg_remove_named_argument(cmd, "PM"); */ if (broadcast) { plugin_log_chat_message(hub, u, message_decoded, 0); } ret = route_message(hub, u, cmd); } hub_free(message); hub_free(message_decoded); return ret; }