From 50fde1c5c8d87c38a160f4cb42c730bf70f78eb7 Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Wed, 26 May 2010 09:38:14 +0200 Subject: [PATCH] Updated the broadcast command to not send the message back to the user that sent it, but instead summarize the number of users that received it. --- src/core/commands.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/commands.c b/src/core/commands.c index ecb21f7..19a556c 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -424,6 +424,8 @@ static int command_broadcast(struct hub_info* hub, struct hub_user* user, struct struct adc_message* command = 0; char pm_flag[7] = "PM"; char from_sid[5]; + char buffer[128]; + size_t recipients = 0; memcpy(from_sid, sid_to_string(user->id.sid), sizeof(from_sid)); memcpy(pm_flag + 2, from_sid, sizeof(from_sid)); @@ -431,17 +433,25 @@ static int command_broadcast(struct hub_info* hub, struct hub_user* user, struct struct hub_user* target = (struct hub_user*) list_get_first(hub->users->list); while (target) { - command = adc_msg_construct(ADC_CMD_DMSG, message_len + 23); - adc_msg_add_argument(command, from_sid); - adc_msg_add_argument(command, sid_to_string(target->id.sid)); - adc_msg_add_argument(command, (cmd->message + offset)); - adc_msg_add_argument(command, pm_flag); + if (target != user) + { + recipients++; + command = adc_msg_construct(ADC_CMD_DMSG, message_len + 23); + if (!command) + break; - route_to_user(hub, target, command); + adc_msg_add_argument(command, from_sid); + adc_msg_add_argument(command, sid_to_string(target->id.sid)); + adc_msg_add_argument(command, (cmd->message + offset)); + adc_msg_add_argument(command, pm_flag); + route_to_user(hub, target, command); + adc_msg_free(command); + } target = (struct hub_user*) list_get_next(hub->users->list); - adc_msg_free(command); } + + snprintf(buffer, sizeof(buffer), "*** %s: Delivered to " PRINTF_SIZE_T " user%s", cmd->prefix, recipients, (recipients != 1 ? "s" : "")); return 0; #endif }