From 80c6ad9d76890fb9e1413a878e71847f9eeae22c Mon Sep 17 00:00:00 2001 From: Jan Vidar Krey Date: Tue, 19 Jan 2010 22:58:03 +0100 Subject: [PATCH] Added mute/unmute functionality. --- src/core/commands.c | 26 +++++++++++++++++++++++++- src/core/commands.h | 2 +- src/core/hub.c | 2 +- src/core/user.c | 2 +- src/core/user.h | 3 ++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/core/commands.c b/src/core/commands.c index c4096b1..a1861c6 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -1,6 +1,6 @@ /* * uhub - A tiny ADC p2p connection hub - * Copyright (C) 2007-2009, Jan Vidar Krey + * Copyright (C) 2007-2010, Jan Vidar Krey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -276,6 +276,28 @@ static int command_unban(struct hub_info* hub, struct hub_user* user, struct hub return command_status(hub, user, cmd, "Not implemented"); } +static int command_mute(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd) +{ + char* nick = list_get_first(cmd->args); + if (!nick) + return -1; // FIXME: bad syntax. + + struct hub_user* target = uman_get_user_by_nick(hub, nick); + + if (!target) + return command_status_user_not_found(hub, user, cmd, nick); + + if (strlen(cmd->prefix) == 4) + { + user_flag_set(target, flag_muted); + } + else + { + user_flag_unset(target, flag_muted); + } + return command_status(hub, user, cmd, nick); +} + static int command_reload(struct hub_info* hub, struct hub_user* user, struct hub_command* cmd) { hub->status = hub_status_restart; @@ -565,6 +587,8 @@ static struct commands_handler command_handlers[] = { { "whoip", 5, "a", cred_operator, command_whoip, "Show users matching IP range" }, { "broadcast", 9, "m", cred_operator, command_broadcast,"Send a message to all users" }, { "log", 3, 0, cred_operator, command_log, "Display log" }, + { "mute", 4, "n", cred_operator, command_mute, "Mute user" }, + { "unmute", 6, "n", cred_operator, command_mute, "Unmute user" }, #ifdef CRASH_DEBUG { "crash", 5, 0, cred_admin, command_crash, "Crash the hub (DEBUG)." }, #endif diff --git a/src/core/commands.h b/src/core/commands.h index aa0809d..45f211e 100644 --- a/src/core/commands.h +++ b/src/core/commands.h @@ -1,6 +1,6 @@ /* * uhub - A tiny ADC p2p connection hub - * Copyright (C) 2007-2009, Jan Vidar Krey + * Copyright (C) 2007-2010, Jan Vidar Krey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/core/hub.c b/src/core/hub.c index 6b51e67..db69ab2 100644 --- a/src/core/hub.c +++ b/src/core/hub.c @@ -206,7 +206,7 @@ int hub_handle_chat_message(struct hub_info* hub, struct hub_user* u, struct adc } } - if (hub->config->chat_is_privileged && !user_is_protected(u) && (cmd->cache[0] == 'B' || cmd->cache[0] == 'F')) + if (((hub->config->chat_is_privileged && !user_is_protected(u)) || (user_flag_get(u, flag_muted))) && (cmd->cache[0] == 'B' || cmd->cache[0] == 'F')) { relay = 0; } diff --git a/src/core/user.c b/src/core/user.c index 577020a..7e0c000 100644 --- a/src/core/user.c +++ b/src/core/user.c @@ -1,6 +1,6 @@ /* * uhub - A tiny ADC p2p connection hub - * Copyright (C) 2007-2009, Jan Vidar Krey + * Copyright (C) 2007-2010, Jan Vidar Krey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/core/user.h b/src/core/user.h index 998fc98..b2f2f87 100644 --- a/src/core/user.h +++ b/src/core/user.h @@ -1,6 +1,6 @@ /* * uhub - A tiny ADC p2p connection hub - * Copyright (C) 2007-2009, Jan Vidar Krey + * Copyright (C) 2007-2010, Jan Vidar Krey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,6 +45,7 @@ enum user_flags feature_ping = 0x00000080, /** PING: Hub pinger information extension */ feature_link = 0x00000100, /** LINK: Hub link (not supported) */ feature_adcs = 0x00000200, /** ADCS: ADC over TLS/SSL */ + flag_muted = 0x00800000, /** User is muted (cannot chat) */ flag_ignore = 0x01000000, /** Ignore further reads */ flag_maxbuf = 0x02000000, /** Hit max buf read, ignore msg */ flag_choke = 0x04000000, /** Choked: Cannot send, waiting for write event */